How to call php file in theme directory from plugin

I resolved my issue. My error came from both calling the php file from the wordpress theme and converting the html code to an object value so that jquery ajax interprets it as it should. $tmpdir = get_template_directory() . ‘/ajax_user.php’; $resumeaccount = file_get_contents($tmpdir); So I get Html content inside singles quote (value object) instead of … Read more

jQuery forms & updating info

ahh nvm, sorted it: jQuery(document).ready(function($){ $(‘.addtocart’).submit(function(){ var data = {action: ‘my_special_action’,post:$(‘.addtocart’).serialize() }; $.post(“<?php echo admin_url(‘admin-ajax.php’); ?>”, data, function(response){ $(“.eshopajax”).insertAfter(this).fadeIn(100).html(response).fadeOut(3000); setTimeout (clearCart,200); setTimeout (doRequest,500); setTimeout (clearRequest,3000); }); function doRequest(){ var tdata = {action: ‘my_cart’}; $.post(“<?php echo admin_url(‘admin-ajax.php’); ?>”, tdata, function(response){ $(“.ajaxcart”).insertAfter(this).fadeIn(100).html(response); }); } function clearRequest(){ $(“.eshopajax”).empty(); } function clearCart(){ $(“.ajaxcart”).insert(); } return false; }); });

best way to run a php script away from the template?

Hi @Mild Fuzz: Sounds like what you might be looking for is the template_redirect hook. If you add a function for that hook then you can output whatever you want and end with an exit; statement. add_action( ‘template_redirect’, ‘yoursite_template_redirect’ ); function yoursite_template_redirect() { if (isset($_GET[‘foo’]) && $_GET[‘foo’]==’bar’) { // Do whatever you want when $_GET[‘foo’]==’bar’ … Read more

my example with ajax doesn’t work

Your code is technically correct, though you should be doing ajax calls via the WordPress provided means. Also, your path to ajax-php.php will fail if WP isn’t installed in root. What does ajax-php.php contain and what are you expecting it to return? If you’re trying to use WordPress functions inside of that file, you need … Read more