自定义Wordpress插件,他们都只是小资? [关闭]

I am trying my hand at Wordpress plugin development. From all of the getting started examples and tutorials I have seen, it seems as though plugins can do little more than, say, add a "Bookmark This" at the end of a post, add an icon next to external links, or other relatively minor enhancements to existing features.

I would like to develop an extension (might that be the better word?) where a user can go to my-wordpress-site.com/the-extension and access the features of the web application. However, since all extensions must placed within wp-includes/plugins/the-extension, does that mean that is the only way the plugins can be accessed?

How could I design the extension and containing pages to be accessed with a URL like this: my-wordpress-site.com/the-extension?

Here's an example:

// register your rewrite rule
add_action('init', function(){
  add_rewrite_rule('the-extension$', 'index.php?my_plugin_action=do_stuff', 'top');
});

// register your query variable
add_filter('query_vars', function($vars){
  $vars[] = 'my_plugin_action';
  return $vars;
});

// process request
add_action('parse_request', function($wp){

  // check if this is your request; do nothing if not
  if(!isset($wp->query_vars['my_plugin_action']))
    return;

  // otherwise do your stuff
  printf('Hello Pony. You requested "%s"', $wp->query_vars['my_plugin_action']);
  exit;
});

This will only work after you go to your dashboard > settings > permalinks and click the save button to flush rewrite rules, because WP apparently keeps some kind of cache of all rewrite rules.

Then accessing yourwordpresssite.com/the-extension should display the hello message

I have not worked on Wordpress plugins of this scale, but here is the general idea.

Your plugin needs to do the following:

  1. Generate a shortcode.
  2. Generate a page with the shortcode.

Using a shortcode allows users to move the plugin's page anywhere.

Also, you could look into setting up administration pages for the plugin as an option..

Here are some examples of plugins that float outside of the wp-content directory (see installation instructions):