creatings wordpress plugins settings Menu upon activation
Here I want to have upon activation of my wordpress plugins activ开发者_如何学JAVAation
Before Activation
Activate | Edit | Delete
After Activation
Settings | Edit | Delete
How can this be done in code to add this Menu?
I personally use the following snippet of code to add new action links. I found this elsewhere and modified as needed.
function my_plugin_admin_action_links($links, $file) {
static $my_plugin;
if (!$my_plugin) {
$my_plugin = plugin_basename(__FILE__);
}
if ($file == $my_plugin) {
$settings_link = '<a href="options-general.php?page=my_admin">Settings</a>';
array_unshift($links, $settings_link);
}
return $links;
}
add_filter('plugin_action_links', 'my_plugin_admin_action_links', 10, 2);
There's a filter for plugin_action_links
that you can set specifically for your plugin to add action links for your plugin on the Plugins page
Check out these blogs for more detail:
- http://adambrown.info/p/wp_hooks/hook/%7B$prefix%7Dplugin_action_links
- http://www.wpmods.com/adding-plugin-action-links/
There are two types of links in plugin list.Taken from
http://atiblog.com/wordpress-plugin-development/
Use the following code in your Class.
For Type 1:
add_action( 'plugin_action_links_' . plugin_basename( FILE ),array($this,'plugin_links') );
function plugin_links( $links ) {
$links = array_merge( array('' . __( 'Settings', 'textdomain' ) . ''), $links );
return $links;
}
For Type 2 : use filter.
add_filter( 'plugin_row_meta', array($this,'plugin_row_meta_links'), 10, 2 );
function plugin_row_meta_links( $links, $file ) {
$base = plugin_basename( FILE );
if ($file == $base ) {
$new_links = array(
'donate' => 'Donate',
'doc' => 'Documentation'
);
$links = array_merge( $links, $new_links ); }
return $links;
}
精彩评论