1

I'm customizing the WP-admin and want to add a toggle button to switch between the customized admin and the default admin. I'd like to place that button in the Screen Options drop down tab.

Is there any way to extend this area?

In wp-admin/includes/screen.php I found

public function render_screen_meta() {

and attempted to copy the function into my dashboard.php file which contains all of my dashboard customization as

function render_screen_meta() {

and appending my changes to the default function, but it work. It didn't cause an error, but it was unsuccessful in altering the function. I tried creating it as a public function in my dashboard.php file but PHPStorm kept giving me an error saying "expecting statement". I'm not really familiar with the use of public.


What I'm attempting to do is create the button as illustrated in the screenshot below: enter image description here

  • Do you want the switch to appear in an existing or in a new tab in the Screen Options? – engelen Jun 9 '14 at 6:50
  • Screen options only exists as one tab with a series of radio buttons as far as I'm aware. The radio buttons represent the existing dashboard widgets and control whether or not they are displayed. I want to add a custom button to that same area to toggle whether or not the custom dashboard or default dashboard is used. I'll add a screenshot to my question. – davidcondrey Jun 9 '14 at 7:28
  • My bad, I was (wrongly) thinking about the "Help" dropdown. Let me provide you with a proper answer! It will be cooked and ready within 5 minutes :-). – engelen Jun 9 '14 at 7:44
  • I'll check it out tomorrow. Calling it a night right now. Thanks for your assistance. – davidcondrey Jun 9 '14 at 7:47
2

To change or extend the functionality of WordPress Core, WordPress relies heavily on actions and filters. I'll assume you have basic knowledge of this, and if you don't, you will after reading up on it in the Codex.

render_screen_meta is a public method of the WP_Screen object. You can't overwrite is by defining the function somewhere else. public determines the scope of a method or property in class-context. If you would like to read up on this, and on classes and objects, I suggest checking out the PHP manual on them.

There are many filters available to modify behaviour of WordPress Core behaviour, including a filter to change the Screen Options contents. This filter is called screen_settings, and it is located in wp-admin/includes/screen.php:990.

Basically, it allows you to completely modify the contents of the Screen Options. Using it, you can add the switch yourself:

add_filter( 'screen_settings', 'wpse148978_screen_settings', 10, 2 );

function wpse148978_screen_settings( $screen_settings, $screen_instance ) {
    $screen_settings .= 'Wow, a button! <a href="#" class="button button-primary">Switch!</a>';

    return $screen_settings;
}
  • This worked great, but the problem is every time I refresh the page, the value of the switch returns to it's default value. How can I save this value so it does not revert upon page refresh? – davidcondrey Jun 12 '14 at 1:29
  • You could store it in a cookie! wordpress.stackexchange.com/questions/138644/… should get you started. – engelen Jun 12 '14 at 8:05

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.