Wordpress plug-in development-issues with custom URLs

Source: Internet
Author: User
To describe your problem, I refer to the json-api plug-in writing and want to implement some data interfaces by myself, but it does not work during custom routing. (I want to customize a url interface like & #039; api3controlName & #039;) paste the relevant code {code...} template_red...
  1. Describe your problem

I refer to the json-api plug-in writing and want to implement some data interfaces by myself, but it does not work during custom routing. (I want to customize a url interface like '/api3/controlname)

  1. Paste related Code


  flush_rules();}function my_plugin_template_rewrite(){    global $myPluginBase;    if( isset( $_REQUEST[ $myPluginBase ] ) ){        echo $_REQUEST[ $myPluginBase ];        exit;    }}function my_plugin_activation() {    // Add the rewrite rule on activation    global $wp_rewrite;    add_filter('rewrite_rules_array', 'my_plugin_rewrites');    $wp_rewrite->flush_rules();}function my_plugin_deactivation() {    // Remove the rewrite rule on deactivation    global $wp_rewrite;    $wp_rewrite->flush_rules();}function my_plugin_rewrites($wp_rules) {    global $myPluginBase;    if (empty($base)) {        return $wp_rules;    }    $my_plugin_rules = array(        "$myPluginBase\$" => "index.php?{$myPluginBase}=info",        "$myPluginBase/(.+)\$" => "index.php?{$myPluginBase}=\$matches[1]"    );    return array_merge($my_plugin_rules, $wp_rules);}// Add initialization and activation hooksadd_action('init', 'my_plugin_init');register_activation_hook( __FILE__, 'my_plugin_activation');register_deactivation_hook( __FILE__, 'my_plugin_deactivation');?>

template_redirectThis action should take effect, for example, access/api3=helloNormal responsehelloBut if you try to access/api3/helloThe homepage is always returned.

Reply content:
  1. Describe your problem

I refer to the json-api plug-in writing and want to implement some data interfaces by myself, but it does not work during custom routing. (I want to customize a url interface like '/api3/controlname)

  1. Paste related Code


  flush_rules();}function my_plugin_template_rewrite(){    global $myPluginBase;    if( isset( $_REQUEST[ $myPluginBase ] ) ){        echo $_REQUEST[ $myPluginBase ];        exit;    }}function my_plugin_activation() {    // Add the rewrite rule on activation    global $wp_rewrite;    add_filter('rewrite_rules_array', 'my_plugin_rewrites');    $wp_rewrite->flush_rules();}function my_plugin_deactivation() {    // Remove the rewrite rule on deactivation    global $wp_rewrite;    $wp_rewrite->flush_rules();}function my_plugin_rewrites($wp_rules) {    global $myPluginBase;    if (empty($base)) {        return $wp_rules;    }    $my_plugin_rules = array(        "$myPluginBase\$" => "index.php?{$myPluginBase}=info",        "$myPluginBase/(.+)\$" => "index.php?{$myPluginBase}=\$matches[1]"    );    return array_merge($my_plugin_rules, $wp_rules);}// Add initialization and activation hooksadd_action('init', 'my_plugin_init');register_activation_hook( __FILE__, 'my_plugin_activation');register_deactivation_hook( __FILE__, 'my_plugin_deactivation');?>

template_redirectThis action should take effect, for example, access/api3=helloNormal responsehelloBut if you try to access/api3/helloThe homepage is always returned.

My God, what you wrote makes me a little confused.
However, since you mentioned that you can access/api3 = hello, you can return hello normally. What type of address is it first?

Page? Post? Cat? We recommend that you try the following code first.

// Register a link add_action ('init ', 'api3 _ rewrites_init'); function api3_rewrites_init () {add_rewrite_rule ('api3 /(. +) \ $ ', 'index. php? & Api3 = $ matches [1] ', 'top ');}

Your code. I don't know much about it.

"$myPluginBase/(.+)\$" => "index.php?{$myPluginBase}=\$matches[1]"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.