0

Does anyone know how to create multiple admin widget pages with calling specific sidebars?

In Detail,

I have a custom post type called Groups and I am creating new admin pages in the back end.

I added a submenu to Groups called Widgets. I created a sidebar for Groups and I want to add this sidebar to the Groups widget page.

So, it is just like usual admin widget page but with only one sidebar.

So far,

$post_type = $_REQUEST['post_type'];
$retrieved_widgets = retrieve_widgets();
foreach ($retrieved_widgets as $key => $value) {
   if ( $key !== "groups-sidebar" ) {
    unset($retrieved_widgets[$key]);
    }
}

$wp_registered_sidebars = $retrieved_widgets;
//print_r($wp_registered_sidebars);
require_once(ABSPATH . 'wp-admin/widgets.php');

This code adds only the groups sidebar to the Groups Widget page. But I have some errors such as

Notice: Undefined index: class in D:\wp-admin\widgets.php on line 369 

So I am guessing something is missing or not configured properly.

1 Answer 1

0

Your code deletes keys from widgets. One of those keys is named 'class'. When WordPress looks for the 'class' key it is missing and PHP reports that.

I think you want this:

$groups_sidebars = array();

foreach ( retrieve_widgets() as $widget ) {
    if ( array_key_exists( 'groups-sidebar', $widget ) )
        $groups_sidebars[] = $widget;
}

$wp_registered_sidebars = $groups_sidebars;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.