1

我正在开发一个 wordpress 插件,它需要在某些时候显示和处理用户注册。我已经制作了页面并添加了一个短代码[signup-page],如其内容。

现在,我想做的是将此简码转换为位于插件目录中的实际注册表单。

该插件有一个处理内部工作的类,包括(在类构造函数中添加)之类的操作:

add_action('admin_menu', array(&$this, 'register_menus'));
add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2);

他们工作正常。

我还添加add_filter('the_content', array(&$this, 'load_view'), 100);了相关方法:

function load_view($content){
   if(preg_match('#\[signup-page\]#is', $content))
   {
      return 'REGISTRATION FORM HERE!';
   }
   return $content;
}

但是,这个过滤器不起作用!而且我不知道我在这里缺少什么。

4

1 回答 1

1

我认为[signup-page]是您shortcode在页面/帖子内容中,如果是这样,那么您可以使用

if(stristr($content, '[signup-page]'))
{
    $reg_form="<form action=''>";
    $reg_form.="<input />";
    // ...
    return $reg_form;
}
return $content;

但正确的使用方法shortcode是(基本上在你的functions.php中)

function myShortCodeGenerator($atts)
{
    // ...
}
add_shortcode( 'signup-page', 'msShortCodeGenerator' ); // myShortCodeGenerator function will execute whenever wordpress finds [signup-page]

阅读更多

于 2012-11-10T02:58:52.973 回答