Notice: Undefined index: parent

Support MB Settings Page Notice: Undefined index: parentResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #36531
    JulienJulien
    Participant

    Hello,

    I since last update I have a notice on my development websites

    Notice: Undefined index: parent in /var/www/html/web/app/plugins/meta-box-aio/vendor/meta-box/mb-settings-page/src/Loader.php on line 22

    Code location at this line

    // Sort setting page array by "parent".
        usort( $settings_pages, function ( $a, $b ) {
        return strlen( $a['parent'] ) - strlen( $b['parent'] );
    } );

    I checked on old websites without last update, this code doesn't exist.

    Fix idea is to check 'parent' flag exist or not.

    On the documentation, this parameter is optional.

    Maybe this fix could be ok.

    // Sort setting page array by "parent".
         usort( $settings_pages, function ( $a, $b ) {
    	return (isset($a['parent']) ? strlen( $a['parent'] ) : 0) - (isset($b['parent']) ? strlen( $b['parent'] ) : 0);
    } );

    I apply temporary this fix on my side.

    #36532
    JulienJulien
    Participant

    I forgot my code for testing

    public function my_settings( $settings_pages ) {
    
          // Top level
          $settings_pages[] = array(
              'id'              => 'my-settings-id',
              'option_name'     => 'My Settings',
              'menu_title'      => 'Settings',
              'icon_url'        => 'dashicons-admin-settings',
              'submenu_title'   => 'Général',
              'style'           => 'no-boxes',
              'columns'         => 1,
              'position'        => 80,
          );
    
          return $settings_pages;
    
        }
    #36533
    RenéRené
    Participant

    Hi Julien, I have the same issue, the solution I found is put this in top level pages.

    'parent' => 0

    Using your example code:

    public function my_settings( $settings_pages ) {
    
          // Top level
          $settings_pages[] = array(
              'id'              => 'my-settings-id',
              'option_name'     => 'My Settings',
              'menu_title'      => 'Settings',
              'icon_url'        => 'dashicons-admin-settings',
              'submenu_title'   => 'Général',
              'parent'          => 0,
              'style'           => 'no-boxes',
              'columns'         => 1,
              'position'        => 80,
          );
    
          return $settings_pages;
    
        }
    #36534
    JulienJulien
    Participant

    Yep it could work too but it's not really ok with documentation provided by metabox.io

    I have more than 50 websites in production with metabox.io (without errors displayed), if documentation change, I will make adaptations.

    #36564
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for your feedback and solution.

    This issue has been fixed in a new commit, it will be included in the next update of this plugin.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.