简体   繁体   中英

Can't Get Wordpress Settings Link To Work

I'm trying to build my first Wordpress plugin and it's giving me a ~LOT~ of grief.

I've got a plugin template I'm using, and I'm following THIS tutorial to turn it into something I can use.

The tutorial says to put a function in [insert plugin name]-admin.php to make 'settings' appear near the plugin on the plugins.php page.

This is what it's supposed to look like:

设置

The thing is, I have tried inserting the function and I just can't get this 'settings' link to appear.

The code the tutorial says to use is this:

public function add_action_links( $links ) {

 $settings_link = array( '<a href="' . admin_url( 'options-general.php?page=' . $this->plugin_name ) . '">' . __('Settings', $this->plugin_name) . '</a>', );
return array_merge( $settings_link, $links );
}

I've tried using this--and similar snippets that I've found on other sites after googling--and none of them work. I know that page= is supposed to link to the page URL, I'm not entirely sure what mine is (is it the plugin slug?). Anyway, I'm currently using the plugin slug after 'page='

If anybody here could help me out with this, it would be greatly appreciated. I know the tutorial I'm using was sloppily written because I have managed to find mistakes in it that were causing errors, and I'm relatively new to PHP and totally new to Wordpress plugins.

Did you also add the beloning add_filter?

Like here:

add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'my_plugin_action_links' );

function my_plugin_action_links( $links ) {
   $links[] = '<a href="'. esc_url( get_admin_url(null, 'options-general.php?page=gpaisr') ) .'">Settings</a>';
   $links[] = '<a href="http://wp-buddy.com" target="_blank">More plugins by WP-Buddy</a>';
   return $links;
}

Also see: https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM