我正在开发一个需要一些重写规则的自定义插件。我遵循了文档,但没有执行规则。我尝试了一些变化,但不断出错。这是代码的摘录:
if (!class_exists(\'CC_Forms\'))
{
class CC_Forms
{
private $options;
/**
*
* Assign everything as a call from within the constructor
*/
function __construct()
{
add_action(\'wp_enqueue_scripts\',array(&$this,\'cc_add_CSS\'));
// register admin pages for the plugin
add_action(\'admin_menu\',array(&$this,\'cc_admin_pages_callback\'));
add_action(\'admin_init\',array($this,\'page_init\'));
add_action(\'admin_footer\',array($this,\'my_action_javascript\'));
// rewrite tags
/*add_action(\'init\', function()
{
add_rewrite_tag(\'%sign1%\', \'([^&]+)\');
add_rewrite_tag(\'%sign2%\', \'([^&]+)\');
});*/
// rewrite rules
add_action(\'init\',array($this,\'cc_rewrite_rules\'));
/*, function()
{
cc_rewrite_rules();
});*/
}
// Rewrite Rules
function cc_rewrite_rules()
{
add_rewrite_rule(\'^page/form/([^/]*)-([^/]*)?$\',
\'/wp-content/plugins/cc-plugin/pages/form.php?sign1=$matches[1]&sign2=$matches[2]\',
\'top\'
);
}
}
}
if (class_exists(\'CC_Forms\'))
{
// Register activation and deactivation hooks
register_activation_hook(__FILE__,array( \'CC_Forms\', \'cc_activate\' ));
register_deactivation_hook(__FILE__,array( \'CC_Forms\', \'cc_deactivate\' ));
register_uninstall_hook(__FILE__,array( \'CC_Forms\', \'cc_uninstall\' ));
// Shortcodes
add_shortcode(\'form_selector\',array( \'CC_Forms\', \'cc_shortcode\' ));
add_shortcode(\'form_compatibility\',array( \'CC_Forms\', \'cc_compatibility_shortcode\' ));
// add_filter(\'admin_init\', array(\'CC_Forms\', \'cc_rewrite_rules\'));
// Initialize everything
$cc_plugin_base = new CC_Forms();
}
非常感谢您对这些重写规则的任何帮助!