Notice: Undefined index: parent
Support › MB Settings Page › Notice: Undefined index: parentResolved
- This topic has 4 replies, 3 voices, and was last updated 2 years, 10 months ago by
Long Nguyen.
-
AuthorPosts
-
June 16, 2022 at 5:40 PM #36531
Julien
ParticipantHello,
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.
June 16, 2022 at 5:52 PM #36532Julien
ParticipantI 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; }
June 16, 2022 at 6:15 PM #36533René
ParticipantHi 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; }
June 16, 2022 at 7:23 PM #36534Julien
ParticipantYep 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.
June 18, 2022 at 6:12 PM #36564Long Nguyen
ModeratorHi,
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.
-
AuthorPosts
- You must be logged in to reply to this topic.