• WordPress: Getting Error in Function PHP After Debut set true

    LillyIsaacson Member

    I’m getting error in my theme after set debug true can any body help me to resolve them

    Notice: Undefined index: in C:\xampp\htdocs\wp\wp-content\themes\mytheme\functions.php on line 396
    
    Notice: Undefined index: id in C:\xampp\htdocs\wp\wp-content\themes\mytheme\functions.php on line 399
    
    Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\wp\wp-content\themes\mytheme\functions.php:396) in C:\xampp\htdocs\wp\wp-content\themes\mytheme\functions.php on line 401
    

    Here is my function.php from line 386 to 419

    function mytheme_add_admin() {
    
    global $themename, $shortname, $options;
    
    if ( isset($_GET['page']) && $_GET['page'] == basename(__FILE__) ) {
    
      if ( 'save' == ( isset($_REQUEST['action'] ) && $_REQUEST['action'] ) ) {
    
          foreach ($options as $value) {
          update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    
    foreach ($options as $value) {
       if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    
       header("Location: admin.php?page=functions.php&saved=true");
    header("Location: themes.php?page=functions.php&saved=true");
    die;
    
    } else if ( 'reset' == ( isset($_REQUEST['action'] ) && $_REQUEST['action'] ) ) {
    
       foreach ($options as $value) {
          delete_option( $value['id'] ); }
    
       header("Location: admin.php?page=functions.php&reset=true");
          header("Location: themes.php?page=functions.php&reset=true");
    
    die;
    
    }
    }
    
    add_theme_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');
    
  • ShikhaTan Member

    You should try to buffer output first. as being a wp theme, headers are already sent, more exactly when u use update_option function.

    try:

    ob_start("ob_gzhandler");
    
      header("Location: admin.php?page=functions.php&saved=true");
    header("Location: themes.php?page=functions.php&saved=true");
    
    exit;
    
    ob_flush();
    

    still, I didn’t understood what you want to achieve with this function. GL.

  • Abhey Member

    well, this is quite simple to explain :

    in this section :

    function mytheme_add_admin() {
    
    global $themename, $shortname, $options;
    
    if ( isset($_GET['page']) && $_GET['page'] == basename(__FILE__) ) {
    
      if ( 'save' == ( isset($_REQUEST['action'] ) && $_REQUEST['action'] ) ) {
    
          foreach ($options as $value) {
          update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    
    foreach ($options as $value) {
       if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    
       header("Location: admin.php?page=functions.php&saved=true");
    header("Location: themes.php?page=functions.php&saved=true");
    die;
    
    } else if ( 'reset' == ( isset($_REQUEST['action'] ) && $_REQUEST['action'] ) ) {
    
       foreach ($options as $value) {
          delete_option( $value['id'] ); }
    
       header("Location: admin.php?page=functions.php&reset=true");
          header("Location: themes.php?page=functions.php&reset=true");
    
    die;
    
    }
    }
    
    add_theme_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');
    }
    

    you have a header() function , which is being called at some point in the script , the problem here is :

    a header has already been sent, hence the warning …

    If you want to clear the errors, either suppress them , or move the code to the top of the php file BEFORE any output is generated

  • SapnaVishwas Member

    Script and html not allow in admin panel that because of sanitization
    here is script to work

    /*
     * This is an example of how to override a default filter
     * for 'textarea' sanitization and $allowedposttags + embed and script.
     */
    add_action('admin_init','optionscheck_change_santiziation', 100);
    function optionscheck_change_santiziation() {
        remove_filter( 'of_sanitize_textarea', 'of_sanitize_textarea' );
        add_filter( 'of_sanitize_textarea', 'custom_sanitize_textarea' );
    }
    function custom_sanitize_textarea($input) {
        global $allowedposttags;
          $custom_allowedtags["script"] = array( "src" => array() );
          $custom_allowedtags = array_merge($custom_allowedtags, $allowedposttags);
          $output = wp_kses( $input, $custom_allowedtags);
        return $output;
    }
    
Viewing 3 reply threads
  • You must be logged in to reply to this topic.
en_USEnglish