Stephane
Stephane

Reputation: 5078

Properly display content from a php file into a wordpress page

I'm working on a wordpress plugin which needs to show and handle user signups at some point. I already made the page and added a shortcode like [signup-page] as its content.

Now, what I would like to do is turn this shortcode to the actual signup form located in the plugin directory.

The plugin has a class that handles inner workings including actions like (added in the class contructor):

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

and they work fine.

I also added add_filter('the_content', array(&$this, 'load_view'), 100); with the related method:

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

However, this filter is not working! and I don't know what I'm missing here.

Upvotes: 1

Views: 556

Answers (1)

The Alpha
The Alpha

Reputation: 146191

I think [signup-page] is your shortcode in the page/post content and if so then you can use

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

But the proper way to use shortcode is (basically in your functions.php)

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

Read More.

Upvotes: 1

Related Questions