• I recently upgraded to 6.0.3. I held out for more than a year because I knew it would break my custom theme that I started coding in 2010. I’ve gone through the due diligence of updating everything in my theme to ensure that it would work but I am stuck on one element related to the theme options page. I’m hoping someone can point me in the right direction.

    The options page includes a wp_editor form element, which worked perfectly. With the WP upgrade the options page now displays a broken Tiny MCE editor above the options page. Where the wp_editor is supposed to be displayed it is still displayed but it is broken, it doesn’t display anything in the editor.

    I’ve spent many hours googling and reading through articles (most are out of date) to no avail. I’m hoping someone can point me in the right direction for resolving this coding issue.

    I have the following code in my functions.php

    function x_theme_admin_styles() {
        wp_editor( "" , "main_text", array());
        wp_enqueue_script('word-count');
        wp_enqueue_script('post');
        wp_enqueue_script('editor');
        wp_enqueue_script('media-upload');
        wp_enqueue_script('jquery');
        wp_enqueue_script('thickbox');
        wp_enqueue_style('thickbox');
        }

    And this is how I am calling the wp_editor on the options page form:

    wp_editor($x_maincont_opt['x_main_text'], "main_text", array());

Viewing 7 replies - 16 through 22 (of 22 total)
  • There was an incorrect function used in my code snippet.

    Please use this instead:

    
    if( is_array( $_POST[ $optkey ] ) ) {
    	$x_maincont_details[ $key ] = $_POST[ $optkey ];
    } else {
    	$x_maincont_details[ $key ] = stripcslashes( $_POST[ $optkey ] );	
    }
    

    and let us know if it works.

    If you have a database backup, please revert it to make the previous content available.

    • This reply was modified 2 years, 5 months ago by aatanasov.

    After further debugging, something else prevents the data from being saved correctly (not the code snippet). However, please apply the latest snippet to fix the first error (Uncaught TypeError: stripcslashes).

    After that, we’ll need to investigate further what happens with the data on the options page.

    Please add this code: print_r( $x_maincont_details );
    before: update_option('x_main_content',$x_maincont_details);

    Also, please add: print_r( $x_maincont_opt );
    after: $x_maincont_opt = get_option('x_main_content');

    This will tell us how the data looks before the option is updated in the database and how the data looks after retrieving the option from the database.

    Please send the printed output and the form code from your previous message using https://pastebin.com/ or a similar tool because the code is too long.

    Thread Starter wlpdrpat

    (@wlpdrpat)

    @aatanasov After updating your code snippet the only error that shows on saving the options page is as follows:

    [02-Oct-2022 17:04:08 UTC] PHP Warning: Undefined array key “invite_display” in /var/web/site/public_html/wp-content/themes/x/maincontent.php on line 69

    In looking at lines 69-75 it looks like there is a duplicate. Are any of these lines of code redundant??

    update_option('x_invite_display',stripcslashes($_POST['invite_display']));
    update_option('x_invite',stripcslashes($_POST['invite']));
      
    $invite_display = (isset($_POST['invite_display'])) ? stripcslashes($_POST['invite_display']) : '';
    $invite = (isset($_POST['invite'])) ? stripcslashes($_POST['invite']) : '';
    update_option('x_invite_display',$invite_display);
    update_option('x_invite',$invite);

    All options saved and all form fields appear to be working.

    I will add the additional print_r codes now but I think we are very close.

    • This reply was modified 2 years, 5 months ago by wlpdrpat.

    Great, we’re very close indeed. No printed code is necessary for the time being.

    It looks like there is duplicated code.

    Please remove these code lines:

    
    update_option('x_invite_display',stripcslashes($_POST['invite_display']));
    update_option('x_invite',stripcslashes($_POST['invite']));
    

    The other code has the necessary validation before updating the 2 options.

    After that, these options must be tested on the back-end and the front-end.

    Thread Starter wlpdrpat

    (@wlpdrpat)

    @aatanasov Here at the 2 array prints (they look good)

    https://pastebin.com/LcnRC6g2

    The only error that is showing is PHP Warning: Undefined array key “invite_display” in /var/web/site/public_html/wp-content/themes/x/maincontent.php on line 69

    Here is the abbreviated array setup code I posted yesterday:

    https://pastebin.com/zuN4ppEQ

    This is the example markup of the form fields:

    https://pastebin.com/mt9Diupq

    Thread Starter wlpdrpat

    (@wlpdrpat)

    @aatanasov Awesome sauce!! I removed the redundant lines of code and now no errors and I have tested both frontend and backend. Looks like a winner, winner, chicken dinner!! Very much appreciated.

    Great, I’ve reviewed the printed code, and it looks good.

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Theme Options Page Form Field Question’ is closed to new replies.