Last active
April 29, 2022 21:03
-
-
Save alanef/9066a81759f79ccafccbbdaf27a1ed81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Plugin Name: Test Ajax | |
| Plugin URI: https://fullworks.net | |
| Description: A demo of ajax calls to the Widget for Eventbrite plugin shortcode | |
| Version: 1.0 | |
| Author: Alan Fuller | |
| Author URI: https://fullworks.net | |
| License: GPL3 | |
| */ | |
| add_action( 'wp_enqueue_scripts', 'ajax_test_enqueue_scripts' ); | |
| function ajax_test_enqueue_scripts() { | |
| wp_enqueue_script( 'test', plugins_url( '/test.js', __FILE__ ), array( 'jquery' ), '1.0', true ); | |
| wp_localize_script( 'test', 'test', array( | |
| 'ajax_url' => admin_url( 'admin-ajax.php' ) | |
| ) ); | |
| } | |
| add_action( 'wp_ajax_nopriv_test_wfea', 'test_wfea' ); | |
| add_action( 'wp_ajax_test_wfea', 'test_wfea' ); | |
| function test_wfea() { | |
| if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | |
| $atts=array(); | |
| $atts['layout']='grid'; | |
| if (!empty($_POST['filter'])) { | |
| $atts['filter_title']= '/'.$_POST['filter'].'/i'; // the filter is extended to add regex ignore case | |
| } | |
| $wfea = new WidgetForEventbriteAPI/FrontEnd/FrontEnd('widget-for-eventbrite-api','1.4'); | |
| $out = $wfea->build_shortcode( $atts ); | |
| echo (empty($out))?'... nothing found try again ...':$out; | |
| } | |
| die(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment