WordPress.org

Ready to get started?Download WordPress

Forums

plugin functions and Ajax help (2 posts)

  1. ericcumbee
    Member
    Posted 4 years ago #

    i am trying to write a plugin that processes ajax post requests makes a database request and returns json as the result. right now i am just trying to get the request and response right. the problem that i am running into is that the parse_request function (rmm_add_signature()) is being run on every page load on my site. and when i make an ajax call it returns the entire page.

    my question is, how do i only run that function when it is called via the url, and secondly how do i keep the rest of the theme from loading as well?

    function rmm_add_signature()
    {
    	$fields['pet_id'] = $_POST['pet_id'];
    	$fields['F_Name'] = $_POST['F_Name'];
    	$fields['L_Name'] = $_POST['L_Name'];
    	$fields['Zip_Code'] = $_POST['Zip_Code'];
    	$fields['Email'] = $_POST['Email'];
    	$fields['Comment'] = $_POST['Comment'];
    	$fields['Opt_In'] = $_POST['Opt_In'];
    	//wp_die('');
    	echo json_encode($fields);
    }
    add_action('parse_sig','rmm_add_signature');
    function rmm_query_vars($vars)
    {
    	$vars[] = 'my-plugin';
    	return $vars;
    }
    add_filter('query_vars','rmm_query_vars');
    add_action('parse_request','rmm_add_signature');

    this is my first crack at writing a wordpress plugin. however i have been working with php for the last year or so.

  2. ericcumbee
    Member
    Posted 4 years ago #

    anyone?

Topic Closed

This topic has been closed to new replies.

About this Topic