Using Javascript Callback from plugin in a theme

Ok, I found out here how to procede. It was so simple I could not believe: 1) include in theme a custom script with a dependency on the favorite plugin. example: wp_enqueue_script(‘script’, get_stylesheet_directory_uri() . ‘/js/myscript.js’, ‘simple-favorite’, ‘1.0.0’, true); 2) in myscript.js just define again the function, and make it do something: function favorites_after_button_submit(favorites, post_id, site_id, … Read more

Static var overwritten with WP AJAX action, works fine without AJAX

Instead of a static class property, you could use a PHP session: class progress { public function __construct() { session_start(); } public function getTotal() { return $_SESSION[ ‘total’ ]; } public static function setTotal() { $_SESSION[ ‘total’ ] = ‘123’; } } If you’re doing more complex stuff, a session wrapper like Symfony’s might be … Read more

Bad Request when adding new post via ajax form

Finally found the problem. The action: save_post was missing from data in ajax call. This code works: <script> jQuery( document ).ready(function() { jQuery(‘input[type=button]’).on(‘click’, function() { var ajaxurl = “<?php echo admin_url(‘admin-ajax.php’); ?>”; jQuery.ajax({ type: “POST”, data: { data:jQuery(‘.event-form’).serialize(), action: ‘save_post’ }, url: ajaxurl, success: function(result) { console.log(‘data sent!’); console.log(‘sent to: ‘ + templateDir + loadUrl … Read more

How to change response of admin-ajax request?

WP_Fullcalendar::ajax overrided by WP_EventsManager plugin in file em-wpfc.php, if wpfc and wpem used in combination. Here is my final code in functions.php /** * Translate WP_Fullcalendar titles for events * @param $items * @return array */ function wp_fc_translate($items) { foreach ($items as &$item) { $item[‘title’] = apply_filters(‘the_title’, $item[‘title’]); } return $items; } add_action(‘wpfc_events’, ‘wp_fc_translate’);