Forums

How to add action to plugin (2 posts)

  1. maheshstiwari
    Member
    Posted 2 years ago #

    I have created my plugin(simple mail).
    Which sends mail to administrator whenever a user gives a feedback.

    I have added a feedback page on site which collects user info as name, contact no. , email-address and feedback.

    I want to trigger my plugin when the user submits (clicks on Submit button).

    I mean when user enters all info and submits it , the plugin should send mail to administrator.

    normally to hook to wordpress we write:

    add_action('action_hook', 'action_function_name');

    What should i use in place of action_hook.

    Myplugin: hremail
    ----------------------
    function hremail(){

    if(isset($_REQUEST['email']))
    //if email is filled out ,send email
    {
    //send email
    $name = $_REQUEST['name'];
    $contact = $_REQUEST['contact'];
    $email = $_REQUEST['email'];
    $subject = $_REQUEST['subject'];
    $comments = $_REQUEST['comments'];
    $list = 'maheshstiwari@gmail.com,harsh@gmail.com';
    mail( $list, "Subject: $subject", $comments, "From: $email" );
    echo "Thank you for using our mail form";
    }
    else
    //if "email" is not filled out, display the error messsage
    {

    echo "Please enter the email";
    }
    }

    add_action('post_comment','hremail');
    ?>

    i have added post_comment as action hook but its not working.

  2. s_ha_dum (was apljdi)
    Member
    Posted 2 years ago #

    So this should run when a user posts a comment from the usual WP comment box?

    If you put print_r($_REQUEST); die; just inside your hremail function, do you get any output? If I remember right you need to pull that $_REQUEST into the function with global $_REQUEST; before you have access to it. Try that.

Topic Closed

This topic has been closed to new replies.

About this Topic