1

I want make a widget show on my wordpress dashboard and show for other users .

and I want make it always show (can't hiddden by other use ,only can by code).

Is here any one can help me ?

THIS IS MY CODE

function example_add_dashboard_widgets() {
    wp_add_dashboard_widget(
        'example_dashboard_widget', // Widget slug.
        'Example Dashboard Widget', // Title.
        'example_dashboard_widget_function' // Display function.
    );
}
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets');

function example_dashboard_widget_function() {
    echo "Hello World, I'm a great Dashboard Widget";
}
2
  • you mean that the users souldn't unselect this widget in the screen options of the dashboard ?
    – mmm
    Apr 29 '18 at 7:22
  • @mmm yes, i think you are right. do you make it success? Apr 29 '18 at 8:43
0

to block the ablility to hide it, you can use that :

const WIDGET_TO_SHOW = "example_dashboard_widget";


add_filter("get_user_option_metaboxhidden_dashboard", function ($result, $option, $user) {

    $result = array_diff($result, [WIDGET_TO_SHOW]);

    return $result;

}, 10, 3);

this is just server side. to be more clear for the user, you can use JavaScript to hide the checkbox in "screen options".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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