Jump to content

Recommended Posts

I am writing the code for my options page in my wordpress theme. It was working for awhile and the next time i checked, it couldnt save. When i hit save, it redirects to options.php. When i remove the code for the social options it still doesnt work and yet it was working before i included that code. What could be the problem
here is the code
 

<?php

/**

 * This function introduces a single theme menu option into the WordPress 'Appearance'

 * menu.

 */

 



 

 

function blueray_theme_menu() {

 

    add_theme_page(

        'Blue Ray Theme',            // The title to be displayed in the browser window for this page.

        'Blue Ray Theme',            // The text to be displayed for this menu item

        'administrator',            // Which type of users can see this menu item

        'blueray_theme_menu',    // The unique ID - that is, the slug - for this menu item

        'blueray_theme_renderpage'     // The name of the function to call when rendering the page for this menu

    );

 

} // end blueray_theme_menu

add_action('admin_menu', 'blueray_theme_menu');

 

/**

 * Renders a simple page to display for the theme menu defined above.

 */

function blueray_theme_renderpage() {

 

    ?>

    <!-- Create a header in the default WordPress 'wrap' container -->

    <div class="wrap">

 

        <!-- Add the icon to the page -->

        <div id="icon-themes" class="icon32"></div>

        <h2>Blue Ray Theme Options</h2>

 

        <!-- Make a call to the WordPress function for rendering errors when settings are saved. -->

        <?php settings_errors(); ?>

        

<?php $active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'display_options';?>

 

<h2 class="nav-tab-wrapper">

    <a href="" class="nav-tab <?php echo $active_tab == 'display_options' ? 'nav-tab-active' : ''; ?>">Display Options</a>

    <a href="" class="nav-tab <?php echo $active_tab == 'social_options' ? 'nav-tab-active' : ''; ?>">Social Options</a>

</h2>





        <!-- Create the form that will be used to render our options -->

       <form method="post" action="options.php">

    <?php

         

        if( $active_tab == 'display_options' ) {

            settings_fields( 'blueray_theme_display_options_page' );

            do_settings_sections( 'blueray_theme_display_options_page' );

        } else {

            settings_fields( 'blueray_theme_social_options_page' );

            do_settings_sections( 'blueray_theme_social_options_page' );

        } // end if/else

         

        submit_button();

         

    ?>

</form>

 

    </div><!-- /.wrap -->

    <?php

     

} // end blueray_theme_renderpage







function blueray_initialize_theme_options() {

    

    if( false == get_option( 'blueray_theme_display_options' ) ) {

    add_option( 'blueray_theme_display_options' );

} // end if

 

    // First, we register a section. This is necessary since all future options must belong to a

  add_settings_section(

    'general_settings_section',         // ID used to identify this section and with which to register options

    'Display Options',                  // Title to be displayed on the administration page

    'blueray_general_options_callback', // Callback used to render the description of the section

    'blueray_theme_display_options_page'     // Page on which to add this section of options

);

     

    // Next, we'll introduce the fields for toggling the visibility of content elements.

   add_settings_field(

    'firstareatitle',                      // ID used to identify the field throughout the theme

    'First Area Title',                           // The label to the left of the option interface element

    'blueray_firstareatitle_callback',   // The name of the function responsible for rendering the option interface

    'blueray_theme_display_options_page',    // The page on which this option will be displayed

    'general_settings_section',         // The name of the section to which this field belongs

    array(                              // The array of arguments to pass to the callback. In this case, just a description.

        'First Area Title:'

    )

);

 

add_settings_field(

    'firstareatext',                    

    'First Area Text',             

    'blueray_firstareatext_callback',

    'blueray_theme_display_options_page',                   

    'general_settings_section',        

    array(                             

        'First Area Text:'

    )

);

 

add_settings_field(

    'firstarealink',                    

    'First Area Link',             

    'blueray_firstarealink_callback',

    'blueray_theme_display_options_page',                   

    'general_settings_section',        

    array(                             

        'First Area Link:'

    )

);

     

    // Finally, we register the fields with WordPress

     

   register_setting(

    'blueray_theme_display_options_page',

    'blueray_theme_display_options_page'

);

     

} // end blueray_initialize_theme_options

add_action('admin_init', 'blueray_initialize_theme_options');

 

/* ------------------------------------------------------------------------ *

 * Section Callbacks

 * ------------------------------------------------------------------------ */

 

function blueray_general_options_callback() {

    echo '<p>Set up the front page options</p>';

} // end sandbox_general_options_callback

 

/* ------------------------------------------------------------------------ *

 * Field Callbacks

 * ------------------------------------------------------------------------ */

 

function blueray_firstareatitle_callback($args) {

     

   // First, we read the options collection

    $options = get_option('blueray_theme_display_options_page');

     

    // Next, we update the name attribute to access this element's ID in the context of the display options array

    // We also access the show_header element of the options collection in the call to the checked() helper function

    $html = '<input type="checkbox" id="firstareatitle" name="blueray_theme_display_options_page[firstareatitle]" value="1" ' . checked(1, $options['firstareatitle'], false) . '/>';

     

    // Here, we'll take the first argument of the array and add it to a label next to the checkbox

    $html .= '<label for="firstareatitle"> '  . $args[0] . '</label>';

     

    echo $html;

     

} // end blueray_toggle_header_callback

 

function blueray_firstareatext_callback($args) {

 

   $options = get_option('blueray_theme_display_options_page');

     

    // Next, we update the name attribute to access this element's ID in the context of the display options array

    // We also access the show_header element of the options collection in the call to the checked() helper function

    $html = '<input type="checkbox" id="firstareatext" name="blueray_theme_display_options_page[firstareatext]" value="1" ' . checked(1, $options['firstareatext'], false) . '/>';

     

    // Here, we'll take the first argument of the array and add it to a label next to the checkbox

    $html .= '<label for="firstareatext"> '  . $args[0] . '</label>';

     

    echo $html;

     

} // end blueray_toggle_content_callback

 

function blueray_firstarealink_callback($args) {

     

     $options = get_option('blueray_theme_display_options_page');

     

    // Next, we update the name attribute to access this element's ID in the context of the display options array

    // We also access the show_header element of the options collection in the call to the checked() helper function

    $html = '<input type="checkbox" id="firstarealink" name="blueray_theme_display_options_page[firstarealink]" value="1" ' . checked(1, $options['firstarealink'], false) . '/>';

     

    // Here, we'll take the first argument of the array and add it to a label next to the checkbox

    $html .= '<label for="firstarealink"> '  . $args[0] . '</label>';

     

    echo $html;

     

} // end blueray_toggle_footer_callback





/**

 * Initializes the theme's social options by registering the Sections,

 * Fields, and Settings.

 *

 * This function is registered with the 'admin_init' hook.

 */

function blueray_theme_intialize_social_options() {

 

    // If the social options don't exist, create them.

    if( false == get_option( 'blueray_theme_social_options' ) ) {  

        add_option( 'blueray_theme_social_options' );

    } // end if

    

    

add_settings_section(

    'social_settings_section',          // ID used to identify this section and with which to register options

    'Social Options',                   // Title to be displayed on the administration page

    'blueray_social_options_callback',  // Callback used to render the description of the section

    'blueray_theme_social_options_page'      // Page on which to add this section of options

);    

    

add_settings_field(

    'twitter',                     

    'Twitter',                         

    'blueray_twitter_callback',

    'blueray_theme_social_options_page',

    'social_settings_section'

);

 

 add_settings_field(

    'facebook',                    

    'Facebook',                        

    'blueray_facebook_callback',   

    'blueray_theme_social_options_page',

    'social_settings_section'          

);

 

add_settings_field(

    'googleplus',                      

    'Google+',                         

    'blueray_googleplus_callback',

    'blueray_theme_social_options_page',

    'social_settings_section'          

);

 

 register_setting(

    'blueray_theme_social_options_page',

    'blueray_theme_social_options_page',

    'blueray_theme_sanitize_social_options_page'

);

} // end sandbox_theme_intialize_social_options

add_action( 'admin_init', 'blueray_theme_intialize_social_options' );



function blueray_social_options_callback() {

    echo '<p>Provide the URL to the social networks you\'d like to display.</p>';

} // end blueray_social_options_callback



function blueray_twitter_callback() {

     

    // First, we read the social options collection

    $options = get_option( 'blueray_theme_social_options_page' );

     

    // Next, we need to make sure the element is defined in the options. If not, we'll set an empty string.

    $url = '';

    if( isset( $options['twitter'] ) ) {

        $url = $options['twitter'];

    } // end if

     

    // Render the output

    echo '<input type="text" id="twitter" name="blueray_theme_social_options_page[twitter]" value="' . $options['twitter'] . '" />';

     

} // end blueray_twitter_callback



function blueray_facebook_callback() {

     

    $options = get_option( 'blueray_theme_social_options_page' );

     

    $url = '';

    if( isset( $options['facebook'] ) ) {

        $url = $options['facebook'];

    } // end if

     

    // Render the output

    echo '<input type="text" id="facebook" name="blueray_theme_social_options_page[facebook]" value="' . $options['facebook'] . '" />';

     

} // end blueray_facebook_callback

 

function blueray_googleplus_callback() {

     

    $options = get_option( 'blueray_theme_social_options_page' );

     

    $url = '';

    if( isset( $options['googleplus'] ) ) {

        $url = $options['googleplus'];

    } // end if

     

    // Render the output

    echo '<input type="text" id="googleplus" name="blueray_theme_social_options_page[googleplus]" value="' . $options['googleplus'] . '" />';

     

} // end sandbox_googleplus_callback







function blueray_theme_sanitize_social_options_page( $input ) {

     

    // Define the array for the updated options

    $output = array();

 

    // Loop through each of the options sanitizing the data

    foreach( $input as $key => $val ) {

     

        if( isset ( $input[$key] ) ) {

            $output[$key] = esc_url_raw( strip_tags( stripslashes( $input[$key] ) ) );

        } // end if

     

    } // end foreach

     

    // Return the new collection

    return apply_filters( 'blueray_theme_sanitize_social_options_page', $output, $input );

 

} // end blueray_theme_sanitize_social_options_page
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.