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...
-
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)
-
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:
-
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)
-
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]"