开发者

Wordpress External PHP File

I have a newsletter form in my wordpress site which supposed to be used through the shortcode :

<form action="newsletter.php" method="post">
... 
</form>

And the shortcode should look :

[newsletter]

In my theme option i have an input field to enter the email address. That value needs to be stored in newsletter.php in the variable $to

How can i 'connect' the newsletter.php with the wordpress get_option for that input i have?

newslett开发者_JAVA技巧er.php :

<?php
$email = $_POST['news'];

// --- this should be the option from the wordpress panel -------
$to = "mail@mail.com";
// ---------------------------------


$subject = "newsletter request";


$date = date("d-m-Y");


$email_message = " Newsletter request : \r\n";
$email_message .= " ================================================== \r\n ";
$email_message .= "This user wants to be notified about your website launch : ".$email."\r\n";
$email_message .= " ================================================== \r\n";
$email_message .= " Request was sent " .$date. " \r\n";

$headers = 'From: '.$email."\r\n";


if($email != null && $email != ""){

mail($to,$subject,$email_message,$headers);
}

header("location:../index.php");

?>

I tried with REQUIRE_ONCE but, that isn't working...


Well you have to create a plugin, I am giving instruction to create a simple plugin. I say again SIMPLE. And its not the only way to create a plugin, but it will be easy one for you.

Create a file in plugins folder and do code like this

/**
 * @package Simple Plugin
 * @version 0.0.1
 */
/*
Plugin Name: Usman
Author: Muhammad Usman
Version: 0.0.1
*/

function showpage($content)
{
    if(stristr($content,'[myplugin]'))
        {
         if(isset($_POST['your-field']))
         {
          //Write your code
          //Save fields or so

          $content="Form submitted";
         }


    }

    return $content;
}

add_filter("the_content","showpage");

Activate this plugin from admin panel and create a page, write [myplugin] in content. And give your form action to this page's permalink.

More details can be found at http://codex.wordpress.org/Writing_a_Plugin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜