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 :)


2 Answers 2


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.

  • It´s so easy following your aproach. Thanks so much :)
    – Marcos
    Commented Feb 9, 2012 at 18:44

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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