• Resolved Jay

    (@phyrax)


    I’ve been working on some hacks for a theme I downloaded, and more appropriately I have been adding options to it. A day or so ago the options were saving perfectly and everything went as planned… but now the options aren’t saving at all, in fact, if I manually add a value to the options table under the option name via phpmyadmin, the options are getting pulled properly but when I save even by changing it a little, the options aren’t saved at all… Here’s a link to the pastebin file, could someone please have a look at the functions.php file and tell me why teh options aren’t saving but they’re clearing?

    https://pastebin.com/wAg2HdAd

    Moderator note:
    Don’t bump posts within the first 24 hours please.

Viewing 7 replies - 1 through 7 (of 7 total)
  • I don’t think there’s a problem with the code you posted, what’s inside this file though?

    include("options/regOptions.php");

    Thread Starter Jay

    (@phyrax)

    In regOptions.php I just used an array to register the options.

    <?php
            $options = array( "column_1_title", "column_1_text", "column_1_l_text", "column_1_p_page", "column_2_title","column_2_text","column_2_l_text","column_2_p_page", "column_3_title", "column_3_text", "column_3_l_text","column_3_p_page", "contact_email","contact_phone","contact_address","logo_image", "logo_image_enabled", "logo_text", "google_analytics");
            foreach($options as $option){
                    register_setting(THEME_PREFIX, THEME_PREFIX."_".$option);
            }
    ?>

    Here is an example of the google analytics options page also.

    <div class="postbox">
        <h3>Google Analytics</h3>
    
        <p>Paste your Google Analytics code in the box below.</p>
    
        <div class="postbox-content">
    
                    <div class="option-row">
                    <div class="option-name">
                            <label>Analytics Code</label>
                    </div><!--end option-name-->
                    <div class="option-value">
                    <textarea class="background_pattern_input" id="google_analytics" name="google_analytics"  cols="40" rows="5"><?php
                                    echo get_option(THEME_PREFIX.'_google_analytics')
                    ?></textarea>
                    </div><!--end option-value-->
            </div><!--end option-row-->
    
                    <input type="submit" class="button" value="Save Changes" />
    
        </div><!--end postbox-content-->
    
    </div><!--end postbox-->

    Thread Starter Jay

    (@phyrax)

    Okay I still cannot seem to get this working. So I have resorted to turning on debug mode. Upon submitting the form I get the following message:

    Warning: Cannot modify header information – headers already sent by (output started at /home/jjswebs1/public_html/wp-includes/functions.php:3387) in /home/jjswebs1/public_html/wp-includes/pluggable.php on line 897

    I have not changed the wp-includes/functions.php, nor have I changed wp-includes/pluggable.php…

    The following is an excerpt from pluggable.php:

    883 function wp_redirect($location, $status = 302) {
     884         global $is_IIS;
     885
     886         $location = apply_filters('wp_redirect', $location, $status);
     887         $status = apply_filters('wp_redirect_status', $status, $location);
     888
     889         if ( !$location ) // allows the wp_redirect filter to cancel a redirect
     890                 return false;
     891
     892         $location = wp_sanitize_redirect($location);
     893
     894         if ( !$is_IIS && php_sapi_name() != 'cgi-fcgi' )
     895                 status_header($status); // This causes problems on IIS and some FastCGI setups
     896
     897         header("Location: $location", true, $status);
     898 }

    If someone can help me that’d be awesome, I can’t seem to find any solution to this issue.

    It’s not a problem with WP files, it’s with code that’s using or dependant on something in those core files, ie. plugin or theme code.

    Are you sure the settings are not being saved, or are you assuming so because no “Settings Updated” message is shown..

    if ( $_GET['updated'] ) echo '<div id="message" class="updated fade"><p>Jenzoo Options Saved.</p></div>';

    The query var used for updating settings recently changed, so that message may never appear, it should be updated to read.

    if ( $_GET['settings-updated'] ) echo '<div id="message" class="updated fade"><p>Jenzoo Options Saved.</p></div>';

    Thread Starter Jay

    (@phyrax)

    I too noticed that the URL variable was no longer ‘updated’ yet it was changed to ‘settings-updated’. Therefore for sanity’s sake, I just commented out the line. Settings were still not saved.

    To verify that settings could be pulled from the database using the get_option, I manually added values to the custom fields in the wp-options table in my SQL database. The options were pulling properly if manually entered.

    Therefore I figured I would just try to overwrite the settings I manually entered via the actual wp-admin options page for the theme. However, when I tried to change the settings in the theme options page itself, it seemed as if the page was just refreshing upon submission, rather than saving.

    I’ve even went as far as to overwriting the wp-includes folder with the same one I downloaded within the one’s from the latest.zip file… still nothing.

    Additionally I also get the following message directly above my “theme options” link in the admin menu, above the WP-Header, and above my previously stated error message upon submitting the form.

    has_cap was called with an argument that is deprecated since version 2.0! Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead. in /home/jjswebs1/public_html/wp-includes/functions.php on line 3387

    Thread Starter Jay

    (@phyrax)

    I actually went ahead and edited the add_theme_page function and it has since removed the warning messages:

    add_theme_page( "Jenzoo Theme Options", "Theme Options", 'manage_options', 'jenzoo_options', 'theme_options_admin');

    I added the ‘manage_options’ rather than assuming the user is level 8.

    Thread Starter Jay

    (@phyrax)

    Situation resolved,

    After further testing to figure out my issue, it was of course one of the simple things in life that have eluded me.

    FYI

    If you set a form field option with defined variables like so:
    <input class="checkbox" id="logo_image_enabled" type="checkbox" name="logo_image_enabled" value="true" <?php checked(TRUE, (bool) get_option(THEME_PREFIX.'_logo_image_enabled')); ?> />

    You must include the defined variable within the ID and Name attribute of the HTML DOM element also, like so:
    <input class="checkbox" id="<?php echo THEME_PREFIX ?>_logo_image_enabled" type="checkbox" name="<?php echo THEME_PREFIX ?>_logo_image_enabled" value="true" <?php checked(TRUE, (bool) get_option(THEME_PREFIX.'_logo_image_enabled')); ?> />

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Options not saving, but clearing fields???’ is closed to new replies.