Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I´m developing a theme that include plugins. One of this plugins is a contact form. And this plugin have an asociate code to validate input data. Because I don´t know in what pages contact form was been added... I want to find a right way to detect if a plugin is included in a current page.

Sample: page.php

<?php get_header(); ?>

<?php if( is contact form included ) : ?>
    //include php form valdiation...
<?php endif; ?>

//page content code ...

<?php get_footer(); ?>

Note: I don´t want to check if a plugin is activated. The plugin is included with theme, therefore is active. I want to detect if is current using for example in page.php. The issue should be include php form validation only when page include contact form.

Any suggestion or advice are welcome :)

Thanks.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

If I understand correctly you want to include a php file that validates the form input, but only when you need to actually validate something?

In this case, you don't need to check if the contact form exists on some page - you just need to check if the form data has been posted. All you need to do is add a hidden field to the form, with a unique identifier:

 <input type="hidden" name="my_plugin_contact_form" value="true"/>

This is just to enable us to know when data from your plug-in form has been posted:

<?php if(!empty($_REQUEST['my_plugin_contact_form'])) : ?>
    //perform validation
<?php endif; ?>

I've noticed that you want to include the validation check inside a page template. I would recommend instead that you wrap your validation inside a function and hook it onto something like init.

A final note: this is not a replacement for using nonces. The above check is only so we know that validation is required - you should still check:

  1. Nonces: did the data come from our form?
  2. Permissions: does the user have permission to send this data

No.2 is probably less relevant here.

share|improve this answer
    
It´s so easy following your aproach. Thanks so much :) –  Marcos Feb 9 '12 at 18:44
add comment

You can use get shortcode regex if your plugin uses shortcodes, but honestly it is a hacky solution, the detection should be in the plugin itself or by using Stephen Harris's suggestion.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.