Skip to content

gddrt/wordpress-admin-buttons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gddrt Admin Buttons

Sometimes it is nice, for debugging and development, to have the power to execute arbitrary code in WordPress-land on demand.

You could do that with wp-cli, but that's not always possible or feasible.

This plugin makes it easier to add your own buttons that do stuff. Just supply the function code and don't touch the boilerplate.

When activated, a menu will appear in the wp-admin. The capability for this menu is install_plugins -- if a user can install plugins, they can already run arbitrary code, so don't sweat.

About custom functions

Functions won't execute until rendering has started, so it's fine to call any WordPress function (and too late to use hooks or modify headers.)

Your function does not need to return anything, but if it does:

  • WP_Error instances will have their messages displayed with an error flair.
  • Any other non-null value will be output with print_r and HTML-escaped.

If you want to echo raw HTML you can just do that in the function.

Registering your functions

Registering a function will create a button in the menu that invokes your function. There are two ways to do this:

Method 1: Editing the file

Edit /editable.php. Create a function in that file (say, my_function()). And call register with that callback (eg. register('my_function')). editable.php includes a working example.

Method 2: Using the filter hook

Use the gddrt_admin_buttons filter hook. It takes one argument: an associative array. The key is the label for the function, which will be displayed on the button. The value is the callable you wish to execute.

Here's an example if you wanted to add a button from a different plugin:

// Use the filter to add your button
add_filter( 'gddrt_admin_buttons', 'my_plugin_register_admin_button' );

function my_plugin_register_admin_button( $buttons ) {
    // Adds a new button to the menu that calls your function
    $buttons['do_thing'] = 'my_plugin_do_thing';
    return $buttons;
}

function my_plugin_do_thing() {
    // (Do something)

    // Return a message to display
    return "Did the thing!";
}

About this plugin

Created by Ryan Geddert. Licensed under GPL 2.0.

About

Easy way to add some buttons to your wp-admin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages