@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | function cmb2_bootstrap() { |
| 19 | 19 | |
| 20 | - if ( is_admin() ) { |
|
| 20 | + if (is_admin()) { |
|
| 21 | 21 | /** |
| 22 | 22 | * Fires on the admin side when CMB2 is included/loaded. |
| 23 | 23 | * |
| 24 | 24 | * In most cases, this should be used to add metaboxes. See example-functions.php |
| 25 | 25 | */ |
| 26 | - do_action( 'cmb2_admin_init' ); |
|
| 26 | + do_action('cmb2_admin_init'); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * Can be used to add metaboxes if needed on the front-end or WP-API (or the front and backend). |
| 33 | 33 | */ |
| 34 | - do_action( 'cmb2_init' ); |
|
| 34 | + do_action('cmb2_init'); |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * For back-compat. Does the dirty-work of instantiating all the |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @since 2.0.2 |
| 41 | 41 | */ |
| 42 | - $cmb_config_arrays = apply_filters( 'cmb2_meta_boxes', array() ); |
|
| 43 | - foreach ( (array) $cmb_config_arrays as $cmb_config ) { |
|
| 44 | - new CMB2( $cmb_config ); |
|
| 42 | + $cmb_config_arrays = apply_filters('cmb2_meta_boxes', array()); |
|
| 43 | + foreach ((array) $cmb_config_arrays as $cmb_config) { |
|
| 44 | + new CMB2($cmb_config); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Fires after all CMB2 instances are created |
| 49 | 49 | */ |
| 50 | - do_action( 'cmb2_init_before_hookup' ); |
|
| 50 | + do_action('cmb2_init_before_hookup'); |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * Get all created metaboxes, and instantiate CMB2_Hookup |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @since 2.0.2 |
| 57 | 57 | */ |
| 58 | - foreach ( CMB2_Boxes::get_all() as $cmb ) { |
|
| 58 | + foreach (CMB2_Boxes::get_all() as $cmb) { |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Initiates the box "hookup" into WordPress. |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param array $cmb The CMB2 object to hookup. |
| 74 | 74 | */ |
| 75 | - do_action( "cmb2_init_hookup_{$cmb->cmb_id}", $cmb ); |
|
| 75 | + do_action("cmb2_init_hookup_{$cmb->cmb_id}", $cmb); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | 79 | * Fires after CMB2 initiation process has been completed |
| 80 | 80 | */ |
| 81 | - do_action( 'cmb2_after_init' ); |
|
| 81 | + do_action('cmb2_after_init'); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /* End. That's it, folks! */ |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -if ( ! class_exists( 'CMB2_Bootstrap_270', false ) ) { |
|
| 7 | +if ( ! class_exists('CMB2_Bootstrap_270', false)) { |
|
| 8 | 8 | |
| 9 | 9 | class CMB2_Bootstrap_270 { |
| 10 | 10 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @return CMB2_Bootstrap_270 Single instance object |
| 40 | 40 | */ |
| 41 | 41 | public static function initiate() { |
| 42 | - if ( null === self::$single_instance ) { |
|
| 42 | + if (null === self::$single_instance) { |
|
| 43 | 43 | self::$single_instance = new self(); |
| 44 | 44 | } |
| 45 | 45 | return self::$single_instance; |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | * A constant you can use to check if CMB2 is loaded |
| 60 | 60 | * for your plugins/themes with CMB2 dependency |
| 61 | 61 | */ |
| 62 | - if ( ! defined( 'CMB2_LOADED' ) ) { |
|
| 63 | - define( 'CMB2_LOADED', self::PRIORITY ); |
|
| 62 | + if ( ! defined('CMB2_LOADED')) { |
|
| 63 | + define('CMB2_LOADED', self::PRIORITY); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ( ! function_exists( 'add_action' ) ) { |
|
| 66 | + if ( ! function_exists('add_action')) { |
|
| 67 | 67 | // We are running outside of the context of WordPress. |
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | - add_action( 'init', array( $this, 'include_cmb' ), self::PRIORITY ); |
|
| 70 | + add_action('init', array($this, 'include_cmb'), self::PRIORITY); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | * @since 2.0.0 |
| 78 | 78 | */ |
| 79 | 79 | public function include_cmb() { |
| 80 | - if ( class_exists( 'CMB2', false ) ) { |
|
| 80 | + if (class_exists('CMB2', false)) { |
|
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ( ! defined( 'CMB2_VERSION' ) ) { |
|
| 85 | - define( 'CMB2_VERSION', self::VERSION ); |
|
| 84 | + if ( ! defined('CMB2_VERSION')) { |
|
| 85 | + define('CMB2_VERSION', self::VERSION); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( ! defined( 'CMB2_DIR' ) ) { |
|
| 89 | - define( 'CMB2_DIR', trailingslashit( dirname( __FILE__ ) ) ); |
|
| 88 | + if ( ! defined('CMB2_DIR')) { |
|
| 89 | + define('CMB2_DIR', trailingslashit(dirname(__FILE__))); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $this->l10ni18n(); |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | require_once CMB2_DIR . 'includes/helper-functions.php'; |
| 98 | 98 | |
| 99 | 99 | // Now kick off the class autoloader. |
| 100 | - spl_autoload_register( 'cmb2_autoload_classes' ); |
|
| 100 | + spl_autoload_register('cmb2_autoload_classes'); |
|
| 101 | 101 | |
| 102 | 102 | // Kick the whole thing off. |
| 103 | - require_once( cmb2_dir( 'bootstrap.php' ) ); |
|
| 103 | + require_once(cmb2_dir('bootstrap.php')); |
|
| 104 | 104 | cmb2_bootstrap(); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -111,20 +111,20 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function l10ni18n() { |
| 113 | 113 | |
| 114 | - $loaded = load_plugin_textdomain( 'cmb2', false, '/languages/' ); |
|
| 114 | + $loaded = load_plugin_textdomain('cmb2', false, '/languages/'); |
|
| 115 | 115 | |
| 116 | - if ( ! $loaded ) { |
|
| 117 | - $loaded = load_muplugin_textdomain( 'cmb2', '/languages/' ); |
|
| 116 | + if ( ! $loaded) { |
|
| 117 | + $loaded = load_muplugin_textdomain('cmb2', '/languages/'); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if ( ! $loaded ) { |
|
| 121 | - $loaded = load_theme_textdomain( 'cmb2', get_stylesheet_directory() . '/languages/' ); |
|
| 120 | + if ( ! $loaded) { |
|
| 121 | + $loaded = load_theme_textdomain('cmb2', get_stylesheet_directory() . '/languages/'); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if ( ! $loaded ) { |
|
| 125 | - $locale = apply_filters( 'plugin_locale', function_exists( 'determine_locale' ) ? determine_locale() : get_locale(), 'cmb2' ); |
|
| 126 | - $mofile = dirname( __FILE__ ) . '/languages/cmb2-' . $locale . '.mo'; |
|
| 127 | - load_textdomain( 'cmb2', $mofile ); |
|
| 124 | + if ( ! $loaded) { |
|
| 125 | + $locale = apply_filters('plugin_locale', function_exists('determine_locale') ? determine_locale() : get_locale(), 'cmb2'); |
|
| 126 | + $mofile = dirname(__FILE__) . '/languages/cmb2-' . $locale . '.mo'; |
|
| 127 | + load_textdomain('cmb2', $mofile); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Class MAG_CMB2_Field_Post_Search_Ajax |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -if ( ! class_exists( 'MAG_CMB2_Field_Post_Search_Ajax' ) ) { |
|
| 6 | +if ( ! class_exists('MAG_CMB2_Field_Post_Search_Ajax')) { |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * The LSX Post Search Field |
@@ -26,37 +26,37 @@ discard block |
||
| 26 | 26 | * Initialize the plugin by hooking into CMB2 |
| 27 | 27 | */ |
| 28 | 28 | public function __construct() { |
| 29 | - add_action( 'cmb2_render_post_search_ajax', array( $this, 'render' ), 10, 5 ); |
|
| 30 | - add_action( 'cmb2_sanitize_post_search_ajax', array( $this, 'sanitize' ), 10, 4 ); |
|
| 31 | - add_action( 'wp_ajax_cmb_post_search_ajax_get_results', array( $this, 'cmb_post_search_ajax_get_results' ) ); |
|
| 29 | + add_action('cmb2_render_post_search_ajax', array($this, 'render'), 10, 5); |
|
| 30 | + add_action('cmb2_sanitize_post_search_ajax', array($this, 'sanitize'), 10, 4); |
|
| 31 | + add_action('wp_ajax_cmb_post_search_ajax_get_results', array($this, 'cmb_post_search_ajax_get_results')); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Render field |
| 36 | 36 | */ |
| 37 | - public function render( $field, $value, $object_id, $object_type, $field_type ) { |
|
| 37 | + public function render($field, $value, $object_id, $object_type, $field_type) { |
|
| 38 | 38 | $this->setup_admin_scripts(); |
| 39 | 39 | $field_name = $field->_name(); |
| 40 | 40 | |
| 41 | - if ( $field->args( 'limit' ) > 1 ) { |
|
| 41 | + if ($field->args('limit') > 1) { |
|
| 42 | 42 | |
| 43 | 43 | echo '<ul class="cmb-post-search-ajax-results" id="' . $field_name . '_results">'; |
| 44 | - if ( isset( $value ) && ! empty( $value ) ) { |
|
| 45 | - if ( ! is_array( $value ) ) { |
|
| 46 | - $value = array( $value ); |
|
| 44 | + if (isset($value) && ! empty($value)) { |
|
| 45 | + if ( ! is_array($value)) { |
|
| 46 | + $value = array($value); |
|
| 47 | 47 | } |
| 48 | - $value = array_unique( $value ); |
|
| 49 | - foreach ( $value as $val ) { |
|
| 50 | - $handle = ( $field->args( 'sortable' ) ) ? '<span class="hndl"></span>' : ''; |
|
| 48 | + $value = array_unique($value); |
|
| 49 | + foreach ($value as $val) { |
|
| 50 | + $handle = ($field->args('sortable')) ? '<span class="hndl"></span>' : ''; |
|
| 51 | 51 | $li_css = ''; |
| 52 | - if ( $field->args( 'object_type' ) == 'user' ) { |
|
| 53 | - $guid = get_edit_user_link( $val ); |
|
| 54 | - $user = get_userdata( $val ); |
|
| 52 | + if ($field->args('object_type') == 'user') { |
|
| 53 | + $guid = get_edit_user_link($val); |
|
| 54 | + $user = get_userdata($val); |
|
| 55 | 55 | $title = $user->display_name; |
| 56 | 56 | } else { |
| 57 | - $guid = get_edit_post_link( $val ); |
|
| 58 | - $title = get_the_title( $val ); |
|
| 59 | - if ( 'trash' === get_post_status( $val ) ) { |
|
| 57 | + $guid = get_edit_post_link($val); |
|
| 58 | + $title = get_the_title($val); |
|
| 59 | + if ('trash' === get_post_status($val)) { |
|
| 60 | 60 | $li_css = 'display:none;'; |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | echo '</ul>'; |
| 67 | 67 | $field_value = ''; |
| 68 | 68 | } else { |
| 69 | - if ( is_array( $value ) ) { |
|
| 69 | + if (is_array($value)) { |
|
| 70 | 70 | $value = $value[0]; |
| 71 | 71 | } |
| 72 | - if ( $field->args( 'object_type' ) == 'user' ) { |
|
| 73 | - $field_value = ( $value ? get_userdata( $value )->display_name : '' ); |
|
| 72 | + if ($field->args('object_type') == 'user') { |
|
| 73 | + $field_value = ($value ? get_userdata($value)->display_name : ''); |
|
| 74 | 74 | } else { |
| 75 | - $field_value = ( $value ? get_the_title( $value ) : '' ); |
|
| 75 | + $field_value = ($value ? get_the_title($value) : ''); |
|
| 76 | 76 | } |
| 77 | 77 | echo $field_type->input( |
| 78 | 78 | array( |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | 'desc' => false, |
| 83 | 83 | ) |
| 84 | 84 | ); |
| 85 | - if ( isset( $field->group ) ) { |
|
| 86 | - $store_name = str_replace( '][', '_', $field_name ); |
|
| 87 | - $store_name = str_replace( ']', '', $store_name ); |
|
| 88 | - $store_name = str_replace( '[', '_', $store_name ); |
|
| 85 | + if (isset($field->group)) { |
|
| 86 | + $store_name = str_replace('][', '_', $field_name); |
|
| 87 | + $store_name = str_replace(']', '', $store_name); |
|
| 88 | + $store_name = str_replace('[', '_', $store_name); |
|
| 89 | 89 | |
| 90 | 90 | echo $field_type->input( |
| 91 | 91 | array( |
@@ -108,59 +108,59 @@ discard block |
||
| 108 | 108 | 'class' => 'cmb-post-search-ajax', |
| 109 | 109 | 'value' => $field_value, |
| 110 | 110 | 'desc' => false, |
| 111 | - 'data-limit' => $field->args( 'limit' ) ? $field->args( 'limit' ) : '1', |
|
| 112 | - 'data-sortable' => $field->args( 'sortable' ) ? $field->args( 'sortable' ) : '0', |
|
| 113 | - 'data-object' => $field->args( 'object_type' ) ? $field->args( 'object_type' ) : 'post', |
|
| 114 | - 'data-queryargs'=> $field->args( 'query_args' ) ? htmlspecialchars( json_encode( $field->args( 'query_args' ) ), ENT_QUOTES, 'UTF-8' ) : '' |
|
| 111 | + 'data-limit' => $field->args('limit') ? $field->args('limit') : '1', |
|
| 112 | + 'data-sortable' => $field->args('sortable') ? $field->args('sortable') : '0', |
|
| 113 | + 'data-object' => $field->args('object_type') ? $field->args('object_type') : 'post', |
|
| 114 | + 'data-queryargs'=> $field->args('query_args') ? htmlspecialchars(json_encode($field->args('query_args')), ENT_QUOTES, 'UTF-8') : '' |
|
| 115 | 115 | ) |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - echo '<img src="' . admin_url( 'images/spinner.gif' ) . '" class="cmb-post-search-ajax-spinner" />'; |
|
| 118 | + echo '<img src="' . admin_url('images/spinner.gif') . '" class="cmb-post-search-ajax-spinner" />'; |
|
| 119 | 119 | |
| 120 | - $field_type->_desc( true, true ); |
|
| 120 | + $field_type->_desc(true, true); |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Optionally save the latitude/longitude values into two custom fields |
| 126 | 126 | */ |
| 127 | - public function sanitize( $override_value, $value, $object_id, $field_args ) { |
|
| 127 | + public function sanitize($override_value, $value, $object_id, $field_args) { |
|
| 128 | 128 | $fid = ''; |
| 129 | - if ( isset( $field_args['id'] ) ) { |
|
| 129 | + if (isset($field_args['id'])) { |
|
| 130 | 130 | $fid = $field_args['id']; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // IF the field is in a repeatable group, then get the info from the post data. |
| 134 | - if ( isset( $field_args['render_row_cb'][0]->group ) && ! empty( $field_args['render_row_cb'][0]->group ) ) { |
|
| 134 | + if (isset($field_args['render_row_cb'][0]->group) && ! empty($field_args['render_row_cb'][0]->group)) { |
|
| 135 | 135 | $new_index = ''; |
| 136 | 136 | |
| 137 | 137 | $data_to_save = $field_args['render_row_cb'][0]->group->args['render_row_cb'][0]->data_to_save; |
| 138 | 138 | $oid = $field_args['_name']; |
| 139 | 139 | $iid = $field_args['_id']; |
| 140 | - $oid = explode( '[', $oid ); |
|
| 141 | - if ( is_array( $oid ) ) { |
|
| 140 | + $oid = explode('[', $oid); |
|
| 141 | + if (is_array($oid)) { |
|
| 142 | 142 | $oid = $oid[0]; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if ( isset( $data_to_save[ $oid ] ) && ! empty( $data_to_save[ $oid ] ) ) { |
|
| 146 | - foreach( $data_to_save[ $oid ] as $index => $svalues ) { |
|
| 147 | - if ( isset( $svalues[ $iid ] ) && $value === $svalues[ $iid ] ) { |
|
| 145 | + if (isset($data_to_save[$oid]) && ! empty($data_to_save[$oid])) { |
|
| 146 | + foreach ($data_to_save[$oid] as $index => $svalues) { |
|
| 147 | + if (isset($svalues[$iid]) && $value === $svalues[$iid]) { |
|
| 148 | 148 | $new_index = $index; |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if ( '' !== $new_index ) { |
|
| 153 | + if ('' !== $new_index) { |
|
| 154 | 154 | $new_index = $oid . '_' . $new_index . '_' . $iid . '_store'; |
| 155 | 155 | |
| 156 | - if ( ! empty( $data_to_save[ $new_index ] ) ) { |
|
| 157 | - $value = $data_to_save[ $new_index ]; |
|
| 156 | + if ( ! empty($data_to_save[$new_index])) { |
|
| 157 | + $value = $data_to_save[$new_index]; |
|
| 158 | 158 | } |
| 159 | 159 | } else { |
| 160 | 160 | $value = false; |
| 161 | 161 | } |
| 162 | - } else if ( ! empty( $field_args['render_row_cb'][0]->data_to_save[ $fid . '_results' ] ) ) { |
|
| 163 | - $value = $field_args['render_row_cb'][0]->data_to_save[ $fid . '_results' ]; |
|
| 162 | + } else if ( ! empty($field_args['render_row_cb'][0]->data_to_save[$fid . '_results'])) { |
|
| 163 | + $value = $field_args['render_row_cb'][0]->data_to_save[$fid . '_results']; |
|
| 164 | 164 | } else { |
| 165 | 165 | $value = false; |
| 166 | 166 | } |
@@ -172,25 +172,25 @@ discard block |
||
| 172 | 172 | * Defines the url which is used to load local resources. Based on, and uses, |
| 173 | 173 | * the CMB2_Utils class from the CMB2 library. |
| 174 | 174 | */ |
| 175 | - public static function url( $path = '' ) { |
|
| 176 | - if ( self::$url ) { |
|
| 175 | + public static function url($path = '') { |
|
| 176 | + if (self::$url) { |
|
| 177 | 177 | return self::$url . $path; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * Set the variable cmb2_fpsa_dir |
| 182 | 182 | */ |
| 183 | - $cmb2_fpsa_dir = trailingslashit( dirname( __FILE__ ) ); |
|
| 183 | + $cmb2_fpsa_dir = trailingslashit(dirname(__FILE__)); |
|
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | 186 | * Use CMB2_Utils to gather the url from cmb2_fpsa_dir |
| 187 | 187 | */ |
| 188 | - $cmb2_fpsa_url = CMB2_Utils::get_url_from_dir( $cmb2_fpsa_dir ); |
|
| 188 | + $cmb2_fpsa_url = CMB2_Utils::get_url_from_dir($cmb2_fpsa_dir); |
|
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * Filter the CMB2 FPSA location url |
| 192 | 192 | */ |
| 193 | - self::$url = trailingslashit( apply_filters( 'cmb2_fpsa_url', $cmb2_fpsa_url, self::VERSION ) ); |
|
| 193 | + self::$url = trailingslashit(apply_filters('cmb2_fpsa_url', $cmb2_fpsa_url, self::VERSION)); |
|
| 194 | 194 | |
| 195 | 195 | return self::$url . $path; |
| 196 | 196 | } |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | public function setup_admin_scripts() { |
| 202 | 202 | |
| 203 | - wp_register_script( 'jquery-autocomplete', self::url( 'js/jquery.autocomplete.min.js' ), array( 'jquery' ), self::VERSION ); |
|
| 204 | - wp_register_script( 'mag-post-search-ajax', self::url( 'js/mag-post-search-ajax.js' ), array( 'jquery', 'jquery-autocomplete', 'jquery-ui-sortable' ), self::VERSION ); |
|
| 205 | - wp_localize_script( 'mag-post-search-ajax', 'psa', array( |
|
| 206 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 207 | - 'nonce' => wp_create_nonce( 'mag_cmb_post_search_ajax_get_results' ) |
|
| 208 | - ) ); |
|
| 209 | - wp_enqueue_script( 'mag-post-search-ajax' ); |
|
| 210 | - wp_enqueue_style( 'mag-post-search-ajax', self::url( 'css/mag-post-search-ajax.css' ), array(), self::VERSION ); |
|
| 203 | + wp_register_script('jquery-autocomplete', self::url('js/jquery.autocomplete.min.js'), array('jquery'), self::VERSION); |
|
| 204 | + wp_register_script('mag-post-search-ajax', self::url('js/mag-post-search-ajax.js'), array('jquery', 'jquery-autocomplete', 'jquery-ui-sortable'), self::VERSION); |
|
| 205 | + wp_localize_script('mag-post-search-ajax', 'psa', array( |
|
| 206 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
| 207 | + 'nonce' => wp_create_nonce('mag_cmb_post_search_ajax_get_results') |
|
| 208 | + )); |
|
| 209 | + wp_enqueue_script('mag-post-search-ajax'); |
|
| 210 | + wp_enqueue_style('mag-post-search-ajax', self::url('css/mag-post-search-ajax.css'), array(), self::VERSION); |
|
| 211 | 211 | |
| 212 | 212 | } |
| 213 | 213 | |
@@ -215,45 +215,45 @@ discard block |
||
| 215 | 215 | * Ajax request : get results |
| 216 | 216 | */ |
| 217 | 217 | public function cmb_post_search_ajax_get_results() { |
| 218 | - $nonce = sanitize_text_field( $_POST['psacheck'] ); |
|
| 219 | - if ( ! wp_verify_nonce( $nonce, 'mag_cmb_post_search_ajax_get_results' ) ) { |
|
| 220 | - die( json_encode( array( 'error' => __( 'Error : Unauthorized action' ) ) ) ); |
|
| 218 | + $nonce = sanitize_text_field($_POST['psacheck']); |
|
| 219 | + if ( ! wp_verify_nonce($nonce, 'mag_cmb_post_search_ajax_get_results')) { |
|
| 220 | + die(json_encode(array('error' => __('Error : Unauthorized action')))); |
|
| 221 | 221 | } else { |
| 222 | - $args = json_decode( stripslashes( htmlspecialchars_decode( sanitize_text_field( $_POST['query_args'] ) ) ), true ); |
|
| 223 | - $args['s'] = sanitize_text_field( $_POST['query'] ); |
|
| 222 | + $args = json_decode(stripslashes(htmlspecialchars_decode(sanitize_text_field($_POST['query_args']))), true); |
|
| 223 | + $args['s'] = sanitize_text_field($_POST['query']); |
|
| 224 | 224 | $datas = array(); |
| 225 | - if ( $_POST['object'] == 'user' ) { |
|
| 225 | + if ($_POST['object'] == 'user') { |
|
| 226 | 226 | |
| 227 | - $args['search'] = '*' . esc_attr( sanitize_text_field( $_POST['query'] ) ) . '*'; |
|
| 228 | - $users = new WP_User_Query( $args ); |
|
| 227 | + $args['search'] = '*' . esc_attr(sanitize_text_field($_POST['query'])) . '*'; |
|
| 228 | + $users = new WP_User_Query($args); |
|
| 229 | 229 | $results = $users->get_results(); |
| 230 | 230 | |
| 231 | - if ( ! empty( $results ) ) { |
|
| 232 | - foreach ( $results as $result ){ |
|
| 233 | - $user_info = get_userdata( $result->ID ); |
|
| 231 | + if ( ! empty($results)) { |
|
| 232 | + foreach ($results as $result) { |
|
| 233 | + $user_info = get_userdata($result->ID); |
|
| 234 | 234 | // Define filter "mag_cmb_post_search_ajax_result" to allow customize ajax results. |
| 235 | - $datas[] = apply_filters( 'mag_cmb_post_search_ajax_result', array( |
|
| 235 | + $datas[] = apply_filters('mag_cmb_post_search_ajax_result', array( |
|
| 236 | 236 | 'value' => $user_info->display_name, |
| 237 | 237 | 'data' => $result->ID, |
| 238 | - 'guid' => get_edit_user_link( $result->ID ), |
|
| 239 | - ) ); |
|
| 238 | + 'guid' => get_edit_user_link($result->ID), |
|
| 239 | + )); |
|
| 240 | 240 | } |
| 241 | 241 | } |
| 242 | 242 | } else { |
| 243 | - $results = new WP_Query( $args ); |
|
| 244 | - if ( $results->have_posts() ) : |
|
| 245 | - while ( $results->have_posts() ) : $results->the_post(); |
|
| 243 | + $results = new WP_Query($args); |
|
| 244 | + if ($results->have_posts()) : |
|
| 245 | + while ($results->have_posts()) : $results->the_post(); |
|
| 246 | 246 | // Define filter "mag_cmb_post_search_ajax_result" to allow customize ajax results. |
| 247 | - $datas[] = apply_filters( 'mag_cmb_post_search_ajax_result', array( |
|
| 247 | + $datas[] = apply_filters('mag_cmb_post_search_ajax_result', array( |
|
| 248 | 248 | 'value' => get_the_title() . ' - ' . '#' . get_the_ID(), |
| 249 | 249 | 'data' => get_the_ID(), |
| 250 | 250 | 'guid' => get_edit_post_link(), |
| 251 | - ) ); |
|
| 251 | + )); |
|
| 252 | 252 | endwhile; |
| 253 | 253 | endif; |
| 254 | 254 | } |
| 255 | 255 | wp_reset_postdata(); |
| 256 | - die( json_encode( $datas ) ); |
|
| 256 | + die(json_encode($datas)); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | } |