@@ -31,34 +31,34 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct() { |
33 | 33 | |
34 | - add_action( 'init', array( $this, 'register_post_type' ) ); |
|
35 | - add_action( 'init', array( $this, 'plan_type_taxonomy_setup' ) ); |
|
36 | - add_action( 'init', array( $this, 'week_taxonomy_setup' ) ); |
|
34 | + add_action('init', array($this, 'register_post_type')); |
|
35 | + add_action('init', array($this, 'plan_type_taxonomy_setup')); |
|
36 | + add_action('init', array($this, 'week_taxonomy_setup')); |
|
37 | 37 | |
38 | 38 | // Icons for the plan types. |
39 | - add_action( 'create_term', array( $this, 'save_meta' ), 10, 2 ); |
|
40 | - add_action( 'edit_term', array( $this, 'save_meta' ), 10, 2 ); |
|
39 | + add_action('create_term', array($this, 'save_meta'), 10, 2); |
|
40 | + add_action('edit_term', array($this, 'save_meta'), 10, 2); |
|
41 | 41 | $prefix_taxonomy = 'plan-type'; |
42 | - add_action( sprintf( '%s_edit_form_fields', $prefix_taxonomy ), array( $this, 'add_thumbnail_form_field' ), 3, 1 ); |
|
42 | + add_action(sprintf('%s_edit_form_fields', $prefix_taxonomy), array($this, 'add_thumbnail_form_field'), 3, 1); |
|
43 | 43 | |
44 | 44 | // Register the Metaboxes. |
45 | - add_action( 'cmb2_admin_init', array( $this, 'featured_metabox' ), 5 ); |
|
46 | - add_action( 'cmb2_admin_init', array( $this, 'details_metaboxes' ), 5 ); |
|
47 | - add_action( 'cmb2_admin_init', array( $this, 'plan_connections' ), 5 ); |
|
48 | - add_action( 'cmb2_admin_init', array( $this, 'sections_metabox_loop' ), 1 ); |
|
45 | + add_action('cmb2_admin_init', array($this, 'featured_metabox'), 5); |
|
46 | + add_action('cmb2_admin_init', array($this, 'details_metaboxes'), 5); |
|
47 | + add_action('cmb2_admin_init', array($this, 'plan_connections'), 5); |
|
48 | + add_action('cmb2_admin_init', array($this, 'sections_metabox_loop'), 1); |
|
49 | 49 | |
50 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
51 | - add_filter( 'lsx_global_header_title', array( $this, 'hp_recipe_header_title' ), 200, 1 ); |
|
50 | + add_filter('get_the_archive_title', array($this, 'get_the_archive_title'), 100); |
|
51 | + add_filter('lsx_global_header_title', array($this, 'hp_recipe_header_title'), 200, 1); |
|
52 | 52 | |
53 | 53 | // Template Redirects. |
54 | - add_filter( 'lsx_health_plan_archive_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
55 | - add_filter( 'lsx_health_plan_single_template', array( $this, 'enable_post_type' ), 10, 1 ); |
|
54 | + add_filter('lsx_health_plan_archive_template', array($this, 'enable_post_type'), 10, 1); |
|
55 | + add_filter('lsx_health_plan_single_template', array($this, 'enable_post_type'), 10, 1); |
|
56 | 56 | |
57 | 57 | // Plan Archive Actions. |
58 | - add_action( 'pre_get_posts', array( $this, 'set_parent_only' ), 10, 1 ); |
|
59 | - add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 100 ); |
|
60 | - add_action( 'lsx_content_top', 'lsx_hp_plan_archive_filters', 10, 1 ); |
|
61 | - add_filter( 'lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_search_enabled', 10, 1 ); |
|
58 | + add_action('pre_get_posts', array($this, 'set_parent_only'), 10, 1); |
|
59 | + add_filter('get_the_archive_title', array($this, 'get_the_archive_title'), 100); |
|
60 | + add_action('lsx_content_top', 'lsx_hp_plan_archive_filters', 10, 1); |
|
61 | + add_filter('lsx_hp_disable_plan_archive_filters', '\lsx_health_plan\functions\plan\is_search_enabled', 10, 1); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public static function get_instance() { |
72 | 72 | // If the single instance hasn't been set, set it now. |
73 | - if ( null === self::$instance ) { |
|
73 | + if (null === self::$instance) { |
|
74 | 74 | self::$instance = new self(); |
75 | 75 | } |
76 | 76 | return self::$instance; |
@@ -80,21 +80,21 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function register_post_type() { |
82 | 82 | $labels = array( |
83 | - 'name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
|
84 | - 'singular_name' => esc_html__( 'Plan', 'lsx-health-plan' ), |
|
85 | - 'add_new' => esc_html_x( 'Add New', 'post type general name', 'lsx-health-plan' ), |
|
86 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
87 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
88 | - 'new_item' => esc_html__( 'New', 'lsx-health-plan' ), |
|
89 | - 'all_items' => esc_html__( 'All Plans', 'lsx-health-plan' ), |
|
90 | - 'view_item' => esc_html__( 'View', 'lsx-health-plan' ), |
|
91 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
92 | - 'not_found' => esc_html__( 'None found', 'lsx-health-plan' ), |
|
93 | - 'not_found_in_trash' => esc_html__( 'None found in Trash', 'lsx-health-plan' ), |
|
83 | + 'name' => esc_html__('Plans', 'lsx-health-plan'), |
|
84 | + 'singular_name' => esc_html__('Plan', 'lsx-health-plan'), |
|
85 | + 'add_new' => esc_html_x('Add New', 'post type general name', 'lsx-health-plan'), |
|
86 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
87 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
88 | + 'new_item' => esc_html__('New', 'lsx-health-plan'), |
|
89 | + 'all_items' => esc_html__('All Plans', 'lsx-health-plan'), |
|
90 | + 'view_item' => esc_html__('View', 'lsx-health-plan'), |
|
91 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
92 | + 'not_found' => esc_html__('None found', 'lsx-health-plan'), |
|
93 | + 'not_found_in_trash' => esc_html__('None found in Trash', 'lsx-health-plan'), |
|
94 | 94 | 'parent_item_colon' => '', |
95 | - 'menu_name' => esc_html__( 'Plans', 'lsx-health-plan' ), |
|
95 | + 'menu_name' => esc_html__('Plans', 'lsx-health-plan'), |
|
96 | 96 | ); |
97 | - $args = array( |
|
97 | + $args = array( |
|
98 | 98 | 'labels' => $labels, |
99 | 99 | 'public' => true, |
100 | 100 | 'publicly_queryable' => true, |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | 'menu_icon' => 'dashicons-welcome-write-blog', |
105 | 105 | 'query_var' => true, |
106 | 106 | 'rewrite' => array( |
107 | - 'slug' => \lsx_health_plan\functions\get_option( 'plan_single_slug', 'plan' ), |
|
107 | + 'slug' => \lsx_health_plan\functions\get_option('plan_single_slug', 'plan'), |
|
108 | 108 | ), |
109 | 109 | 'capability_type' => 'page', |
110 | - 'has_archive' => \lsx_health_plan\functions\get_option( 'endpoint_plan_archive', 'plans' ), |
|
110 | + 'has_archive' => \lsx_health_plan\functions\get_option('endpoint_plan_archive', 'plans'), |
|
111 | 111 | 'hierarchical' => true, |
112 | 112 | 'menu_position' => null, |
113 | 113 | 'supports' => array( |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | 'custom-fields', |
119 | 119 | ), |
120 | 120 | ); |
121 | - register_post_type( 'plan', $args ); |
|
121 | + register_post_type('plan', $args); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function plan_type_taxonomy_setup() { |
128 | 128 | $labels = array( |
129 | - 'name' => esc_html_x( 'Plan Type', 'taxonomy general name', 'lsx-health-plan' ), |
|
130 | - 'singular_name' => esc_html_x( 'Plan Type', 'taxonomy singular name', 'lsx-health-plan' ), |
|
131 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
132 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
133 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
134 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
135 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
136 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
137 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
138 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
139 | - 'menu_name' => esc_html__( 'Plan Types', 'lsx-health-plan' ), |
|
129 | + 'name' => esc_html_x('Plan Type', 'taxonomy general name', 'lsx-health-plan'), |
|
130 | + 'singular_name' => esc_html_x('Plan Type', 'taxonomy singular name', 'lsx-health-plan'), |
|
131 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
132 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
133 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
134 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
135 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
136 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
137 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
138 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
139 | + 'menu_name' => esc_html__('Plan Types', 'lsx-health-plan'), |
|
140 | 140 | ); |
141 | 141 | |
142 | 142 | $args = array( |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ), |
151 | 151 | ); |
152 | 152 | |
153 | - register_taxonomy( 'plan-type', array( 'plan' ), $args ); |
|
153 | + register_taxonomy('plan-type', array('plan'), $args); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function week_taxonomy_setup() { |
160 | 160 | $labels = array( |
161 | - 'name' => esc_html_x( 'Week', 'taxonomy general name', 'lsx-health-plan' ), |
|
162 | - 'singular_name' => esc_html_x( 'Week', 'taxonomy singular name', 'lsx-health-plan' ), |
|
163 | - 'search_items' => esc_html__( 'Search', 'lsx-health-plan' ), |
|
164 | - 'all_items' => esc_html__( 'All', 'lsx-health-plan' ), |
|
165 | - 'parent_item' => esc_html__( 'Parent', 'lsx-health-plan' ), |
|
166 | - 'parent_item_colon' => esc_html__( 'Parent:', 'lsx-health-plan' ), |
|
167 | - 'edit_item' => esc_html__( 'Edit', 'lsx-health-plan' ), |
|
168 | - 'update_item' => esc_html__( 'Update', 'lsx-health-plan' ), |
|
169 | - 'add_new_item' => esc_html__( 'Add New', 'lsx-health-plan' ), |
|
170 | - 'new_item_name' => esc_html__( 'New Name', 'lsx-health-plan' ), |
|
171 | - 'menu_name' => esc_html__( 'Weeks', 'lsx-health-plan' ), |
|
161 | + 'name' => esc_html_x('Week', 'taxonomy general name', 'lsx-health-plan'), |
|
162 | + 'singular_name' => esc_html_x('Week', 'taxonomy singular name', 'lsx-health-plan'), |
|
163 | + 'search_items' => esc_html__('Search', 'lsx-health-plan'), |
|
164 | + 'all_items' => esc_html__('All', 'lsx-health-plan'), |
|
165 | + 'parent_item' => esc_html__('Parent', 'lsx-health-plan'), |
|
166 | + 'parent_item_colon' => esc_html__('Parent:', 'lsx-health-plan'), |
|
167 | + 'edit_item' => esc_html__('Edit', 'lsx-health-plan'), |
|
168 | + 'update_item' => esc_html__('Update', 'lsx-health-plan'), |
|
169 | + 'add_new_item' => esc_html__('Add New', 'lsx-health-plan'), |
|
170 | + 'new_item_name' => esc_html__('New Name', 'lsx-health-plan'), |
|
171 | + 'menu_name' => esc_html__('Weeks', 'lsx-health-plan'), |
|
172 | 172 | ); |
173 | 173 | |
174 | 174 | $args = array( |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | ), |
184 | 184 | ); |
185 | 185 | |
186 | - register_taxonomy( 'week', array( 'plan' ), $args ); |
|
186 | + register_taxonomy('week', array('plan'), $args); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @since 0.1.0 |
193 | 193 | */ |
194 | - public function add_thumbnail_form_field( $term = false ) { |
|
195 | - if ( is_object( $term ) ) { |
|
196 | - $value = get_term_meta( $term->term_id, 'thumbnail', true ); |
|
197 | - $image_preview = wp_get_attachment_image_src( $value, 'thumbnail' ); |
|
194 | + public function add_thumbnail_form_field($term = false) { |
|
195 | + if (is_object($term)) { |
|
196 | + $value = get_term_meta($term->term_id, 'thumbnail', true); |
|
197 | + $image_preview = wp_get_attachment_image_src($value, 'thumbnail'); |
|
198 | 198 | |
199 | - if ( is_array( $image_preview ) ) { |
|
200 | - $image_preview = '<img style="height: 50px; width: 50px;" src="' . esc_url( $image_preview[0] ) . '" width="' . $image_preview[1] . '" height="' . $image_preview[2] . '" class="alignnone size-thumbnail d wp-image-' . $value . '" />'; |
|
199 | + if (is_array($image_preview)) { |
|
200 | + $image_preview = '<img style="height: 50px; width: 50px;" src="' . esc_url($image_preview[0]) . '" width="' . $image_preview[1] . '" height="' . $image_preview[2] . '" class="alignnone size-thumbnail d wp-image-' . $value . '" />'; |
|
201 | 201 | } |
202 | 202 | } else { |
203 | 203 | $image_preview = false; |
@@ -205,15 +205,15 @@ discard block |
||
205 | 205 | } |
206 | 206 | ?> |
207 | 207 | <tr class="form-field form-required term-thumbnail-wrap"> |
208 | - <th scope="row"><label for="thumbnail"><?php esc_html_e( 'Icon Image', 'lsx-health-plan' ); ?></label></th> |
|
208 | + <th scope="row"><label for="thumbnail"><?php esc_html_e('Icon Image', 'lsx-health-plan'); ?></label></th> |
|
209 | 209 | <td> |
210 | - <input class="input_image_id" type="hidden" name="thumbnail" value="<?php echo wp_kses_post( $value ); ?>"> |
|
210 | + <input class="input_image_id" type="hidden" name="thumbnail" value="<?php echo wp_kses_post($value); ?>"> |
|
211 | 211 | <div class="thumbnail-preview"> |
212 | - <?php echo wp_kses_post( $image_preview ); ?> |
|
212 | + <?php echo wp_kses_post($image_preview); ?> |
|
213 | 213 | </div> |
214 | - <a style="<?php if ( '' !== $value && false !== $value ) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-add"><?php esc_html_e( 'Choose Image', 'lsx-health-plan' ); ?></a> |
|
215 | - <a style="<?php if ( '' === $value || false === $value ) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-remove"><?php esc_html_e( 'Remove Image', 'lsx-health-plan' ); ?></a> |
|
216 | - <?php wp_nonce_field( 'lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce' ); ?> |
|
214 | + <a style="<?php if ('' !== $value && false !== $value) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-add"><?php esc_html_e('Choose Image', 'lsx-health-plan'); ?></a> |
|
215 | + <a style="<?php if ('' === $value || false === $value) { ?>display:none;<?php } ?>" class="button-secondary lsx-thumbnail-image-remove"><?php esc_html_e('Remove Image', 'lsx-health-plan'); ?></a> |
|
216 | + <?php wp_nonce_field('lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce'); ?> |
|
217 | 217 | </td> |
218 | 218 | </tr> |
219 | 219 | <?php |
@@ -227,27 +227,27 @@ discard block |
||
227 | 227 | * @param int $term_id |
228 | 228 | * @param string $taxonomy |
229 | 229 | */ |
230 | - public function save_meta( $term_id = 0, $taxonomy = '' ) { |
|
231 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
230 | + public function save_meta($term_id = 0, $taxonomy = '') { |
|
231 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - if ( ! isset( $_POST['thumbnail'] ) ) { |
|
235 | + if ( ! isset($_POST['thumbnail'])) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
239 | - if ( check_admin_referer( 'lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce' ) ) { |
|
240 | - if ( ! isset( $_POST['thumbnail'] ) ) { |
|
239 | + if (check_admin_referer('lsx_hp_term_thumbnail_nonce', 'lsx_hp_term_thumbnail_nonce')) { |
|
240 | + if ( ! isset($_POST['thumbnail'])) { |
|
241 | 241 | return; |
242 | 242 | } |
243 | 243 | |
244 | - $thumbnail_meta = sanitize_text_field( $_POST['thumbnail'] ); |
|
245 | - $thumbnail_meta = ! empty( $thumbnail_meta ) ? $thumbnail_meta : ''; |
|
244 | + $thumbnail_meta = sanitize_text_field($_POST['thumbnail']); |
|
245 | + $thumbnail_meta = ! empty($thumbnail_meta) ? $thumbnail_meta : ''; |
|
246 | 246 | |
247 | - if ( empty( $thumbnail_meta ) ) { |
|
248 | - delete_term_meta( $term_id, 'thumbnail' ); |
|
247 | + if (empty($thumbnail_meta)) { |
|
248 | + delete_term_meta($term_id, 'thumbnail'); |
|
249 | 249 | } else { |
250 | - update_term_meta( $term_id, 'thumbnail', $thumbnail_meta ); |
|
250 | + update_term_meta($term_id, 'thumbnail', $thumbnail_meta); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | } |
@@ -256,33 +256,33 @@ discard block |
||
256 | 256 | * Define the metabox and field configurations. |
257 | 257 | */ |
258 | 258 | public function details_metaboxes() { |
259 | - $cmb = new_cmb2_box( array( |
|
259 | + $cmb = new_cmb2_box(array( |
|
260 | 260 | 'id' => $this->slug . '_details_metabox', |
261 | - 'title' => __( 'Details', 'lsx-health-plan' ), |
|
262 | - 'object_types' => array( $this->slug ), // Post type |
|
261 | + 'title' => __('Details', 'lsx-health-plan'), |
|
262 | + 'object_types' => array($this->slug), // Post type |
|
263 | 263 | 'context' => 'normal', |
264 | 264 | 'priority' => 'high', |
265 | 265 | 'show_names' => true, |
266 | - ) ); |
|
266 | + )); |
|
267 | 267 | |
268 | 268 | $warmup_type = 'page'; |
269 | - if ( false !== \lsx_health_plan\functions\get_option( 'exercise_enabled', false ) ) { |
|
270 | - $warmup_type = array( 'page', 'workout' ); |
|
269 | + if (false !== \lsx_health_plan\functions\get_option('exercise_enabled', false)) { |
|
270 | + $warmup_type = array('page', 'workout'); |
|
271 | 271 | } |
272 | - $cmb->add_field( array( |
|
273 | - 'name' => __( 'Warmup', 'lsx-health-plan' ), |
|
274 | - 'desc' => __( 'Connect the warm up page that applies to this day plan using the field provided.', 'lsx-health-plan' ), |
|
272 | + $cmb->add_field(array( |
|
273 | + 'name' => __('Warmup', 'lsx-health-plan'), |
|
274 | + 'desc' => __('Connect the warm up page that applies to this day plan using the field provided.', 'lsx-health-plan'), |
|
275 | 275 | 'id' => $this->slug . '_warmup', |
276 | 276 | 'type' => 'post_search_ajax', |
277 | 277 | // Optional : |
278 | - 'limit' => 3, // Limit selection to X items only (default 1) |
|
278 | + 'limit' => 3, // Limit selection to X items only (default 1) |
|
279 | 279 | 'sortable' => true, // Allow selected items to be sortable (default false) |
280 | 280 | 'query_args' => array( |
281 | 281 | 'post_type' => $warmup_type, |
282 | - 'post_status' => array( 'publish' ), |
|
282 | + 'post_status' => array('publish'), |
|
283 | 283 | 'posts_per_page' => -1, |
284 | 284 | ), |
285 | - ) ); |
|
285 | + )); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @param array $post_types |
292 | 292 | * @return array |
293 | 293 | */ |
294 | - public function enable_post_type( $post_types = array() ) { |
|
294 | + public function enable_post_type($post_types = array()) { |
|
295 | 295 | $post_types[] = $this->slug; |
296 | 296 | return $post_types; |
297 | 297 | } |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | $cmb = new_cmb2_box( |
306 | 306 | array( |
307 | 307 | 'id' => $this->slug . '_connections_metabox', |
308 | - 'title' => __( 'Plans', 'lsx-health-plan' ), |
|
309 | - 'object_types' => array( 'workout', 'meal', 'tip', 'recipe' ), |
|
308 | + 'title' => __('Plans', 'lsx-health-plan'), |
|
309 | + 'object_types' => array('workout', 'meal', 'tip', 'recipe'), |
|
310 | 310 | 'context' => 'normal', |
311 | 311 | 'priority' => 'high', |
312 | 312 | 'show_names' => true, |
@@ -314,15 +314,15 @@ discard block |
||
314 | 314 | ); |
315 | 315 | $cmb->add_field( |
316 | 316 | array( |
317 | - 'name' => __( 'Plan', 'lsx-health-plan' ), |
|
317 | + 'name' => __('Plan', 'lsx-health-plan'), |
|
318 | 318 | 'id' => 'connected_plans', |
319 | - 'desc' => __( 'Connect this to the day plan it applies to, using the field provided.', 'lsx-health-plan' ), |
|
319 | + 'desc' => __('Connect this to the day plan it applies to, using the field provided.', 'lsx-health-plan'), |
|
320 | 320 | 'type' => 'post_search_ajax', |
321 | 321 | 'limit' => 15, |
322 | 322 | 'sortable' => true, |
323 | 323 | 'query_args' => array( |
324 | - 'post_type' => array( 'plan' ), |
|
325 | - 'post_status' => array( 'publish' ), |
|
324 | + 'post_type' => array('plan'), |
|
325 | + 'post_status' => array('publish'), |
|
326 | 326 | 'posts_per_page' => -1, |
327 | 327 | ), |
328 | 328 | ) |
@@ -335,9 +335,9 @@ discard block |
||
335 | 335 | * @param string $title the term title. |
336 | 336 | * @return string |
337 | 337 | */ |
338 | - public function get_the_archive_title( $title ) { |
|
339 | - if ( is_post_type_archive( 'plan' ) ) { |
|
340 | - $title = __( 'Our health plans', 'lsx-health-plan' ); |
|
338 | + public function get_the_archive_title($title) { |
|
339 | + if (is_post_type_archive('plan')) { |
|
340 | + $title = __('Our health plans', 'lsx-health-plan'); |
|
341 | 341 | } |
342 | 342 | return $title; |
343 | 343 | } |
@@ -348,9 +348,9 @@ discard block |
||
348 | 348 | * @param object $wp_query |
349 | 349 | * @return array |
350 | 350 | */ |
351 | - public function set_parent_only( $wp_query ) { |
|
352 | - if ( ! is_admin() && $wp_query->is_main_query() && ( $wp_query->is_post_type_archive( 'plan' ) || $wp_query->is_tax( 'plan-type' ) ) ) { |
|
353 | - $wp_query->set( 'post_parent', '0' ); |
|
351 | + public function set_parent_only($wp_query) { |
|
352 | + if ( ! is_admin() && $wp_query->is_main_query() && ($wp_query->is_post_type_archive('plan') || $wp_query->is_tax('plan-type'))) { |
|
353 | + $wp_query->set('post_parent', '0'); |
|
354 | 354 | } |
355 | 355 | } |
356 | 356 | |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | $cmb = new_cmb2_box( |
362 | 362 | array( |
363 | 363 | 'id' => $this->slug . '_featured_metabox_plan', |
364 | - 'title' => __( 'Featured Plan', 'lsx-health-plan' ), |
|
365 | - 'object_types' => array( $this->slug ), // Post type |
|
364 | + 'title' => __('Featured Plan', 'lsx-health-plan'), |
|
365 | + 'object_types' => array($this->slug), // Post type |
|
366 | 366 | 'context' => 'side', |
367 | 367 | 'priority' => 'high', |
368 | 368 | 'show_names' => true, |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | ); |
371 | 371 | $cmb->add_field( |
372 | 372 | array( |
373 | - 'name' => __( 'Featured Plan', 'lsx-health-plan' ), |
|
374 | - 'desc' => __( 'Enable a featured plan' ), |
|
373 | + 'name' => __('Featured Plan', 'lsx-health-plan'), |
|
374 | + 'desc' => __('Enable a featured plan'), |
|
375 | 375 | 'id' => $this->slug . '_featured_plan', |
376 | 376 | 'type' => 'checkbox', |
377 | 377 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | $cmb = new_cmb2_box( |
387 | 387 | array( |
388 | 388 | 'id' => $this->slug . '_sections_metabox', |
389 | - 'title' => __( 'Sections', 'lsx-health-plan' ), |
|
390 | - 'object_types' => array( $this->slug ), // Post type. |
|
389 | + 'title' => __('Sections', 'lsx-health-plan'), |
|
390 | + 'object_types' => array($this->slug), // Post type. |
|
391 | 391 | 'context' => 'normal', |
392 | 392 | 'priority' => 'low', |
393 | 393 | 'show_names' => true, |
@@ -403,9 +403,9 @@ discard block |
||
403 | 403 | 'id' => $this->slug . '_sections', |
404 | 404 | 'type' => 'group', |
405 | 405 | 'options' => array( |
406 | - 'group_title' => __( 'Section', 'lsx-health-plan' ) . ' {#}', // {#} gets replaced by row number |
|
407 | - 'add_button' => __( 'Add section', 'lsx-health-plan' ), |
|
408 | - 'remove_button' => __( 'Remove section', 'lsx-health-plan' ), |
|
406 | + 'group_title' => __('Section', 'lsx-health-plan') . ' {#}', // {#} gets replaced by row number |
|
407 | + 'add_button' => __('Add section', 'lsx-health-plan'), |
|
408 | + 'remove_button' => __('Remove section', 'lsx-health-plan'), |
|
409 | 409 | 'sortable' => true, |
410 | 410 | ), |
411 | 411 | 'classes' => 'lsx-admin-row', |
@@ -415,10 +415,10 @@ discard block |
||
415 | 415 | $cmb->add_group_field( |
416 | 416 | $group, |
417 | 417 | array( |
418 | - 'name' => __( 'Title', 'lsx-health-plan' ), |
|
418 | + 'name' => __('Title', 'lsx-health-plan'), |
|
419 | 419 | 'id' => 'title', |
420 | 420 | 'type' => 'text', |
421 | - 'desc' => __( 'e.g Day 1 / Week 1', 'lsx-health-plan' ), |
|
421 | + 'desc' => __('e.g Day 1 / Week 1', 'lsx-health-plan'), |
|
422 | 422 | 'classes' => 'lsx-field-col lsx-field-col-50', |
423 | 423 | ) |
424 | 424 | ); |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | $cmb->add_group_field( |
427 | 427 | $group, |
428 | 428 | array( |
429 | - 'name' => __( 'Group', 'lsx-health-plan' ), |
|
429 | + 'name' => __('Group', 'lsx-health-plan'), |
|
430 | 430 | 'id' => 'group', |
431 | 431 | 'type' => 'text', |
432 | - 'desc' => __( 'e.g Week 1 / January', 'lsx-health-plan' ), |
|
432 | + 'desc' => __('e.g Week 1 / January', 'lsx-health-plan'), |
|
433 | 433 | 'classes' => 'lsx-field-col lsx-field-col-50', |
434 | 434 | ) |
435 | 435 | ); |
@@ -437,25 +437,25 @@ discard block |
||
437 | 437 | $cmb->add_group_field( |
438 | 438 | $group, |
439 | 439 | array( |
440 | - 'name' => __( 'Overview', 'lsx-health-plan' ), |
|
440 | + 'name' => __('Overview', 'lsx-health-plan'), |
|
441 | 441 | 'id' => 'description', |
442 | 442 | 'type' => 'wysiwyg', |
443 | 443 | ) |
444 | 444 | ); |
445 | 445 | |
446 | - if ( post_type_exists( 'workout' ) ) { |
|
446 | + if (post_type_exists('workout')) { |
|
447 | 447 | $cmb->add_group_field( |
448 | 448 | $group, |
449 | 449 | array( |
450 | - 'name' => __( 'Workouts', 'lsx-health-plan' ), |
|
450 | + 'name' => __('Workouts', 'lsx-health-plan'), |
|
451 | 451 | 'id' => 'connected_workouts', |
452 | - 'desc' => __( 'Connect the workout(s) that apply to this section.', 'lsx-health-plan' ), |
|
452 | + 'desc' => __('Connect the workout(s) that apply to this section.', 'lsx-health-plan'), |
|
453 | 453 | 'type' => 'post_search_ajax', |
454 | 454 | 'limit' => 15, |
455 | 455 | 'sortable' => true, |
456 | 456 | 'query_args' => array( |
457 | - 'post_type' => array( 'workout' ), |
|
458 | - 'post_status' => array( 'publish' ), |
|
457 | + 'post_type' => array('workout'), |
|
458 | + 'post_status' => array('publish'), |
|
459 | 459 | 'posts_per_page' => -1, |
460 | 460 | ), |
461 | 461 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-33', |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | $cmb->add_group_field( |
466 | 466 | $group, |
467 | 467 | array( |
468 | - 'name' => __( 'Pre Workout Snack', 'lsx-health-plan' ), |
|
468 | + 'name' => __('Pre Workout Snack', 'lsx-health-plan'), |
|
469 | 469 | 'id' => 'pre_workout_snack', |
470 | 470 | 'type' => 'wysiwyg', |
471 | 471 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | $cmb->add_group_field( |
480 | 480 | $group, |
481 | 481 | array( |
482 | - 'name' => __( 'Post Workout Snack', 'lsx-health-plan' ), |
|
482 | + 'name' => __('Post Workout Snack', 'lsx-health-plan'), |
|
483 | 483 | 'id' => 'post_workout_snack', |
484 | 484 | 'type' => 'wysiwyg', |
485 | 485 | 'show_on_cb' => 'cmb2_hide_if_no_cats', |
@@ -491,60 +491,60 @@ discard block |
||
491 | 491 | ); |
492 | 492 | } |
493 | 493 | |
494 | - if ( post_type_exists( 'meal' ) ) { |
|
494 | + if (post_type_exists('meal')) { |
|
495 | 495 | $cmb->add_group_field( |
496 | 496 | $group, |
497 | 497 | array( |
498 | - 'name' => __( 'Meals', 'lsx-health-plan' ), |
|
499 | - 'desc' => __( 'Connect the meal(s) that apply to this section.', 'lsx-health-plan' ), |
|
498 | + 'name' => __('Meals', 'lsx-health-plan'), |
|
499 | + 'desc' => __('Connect the meal(s) that apply to this section.', 'lsx-health-plan'), |
|
500 | 500 | 'id' => 'connected_meals', |
501 | 501 | 'type' => 'post_search_ajax', |
502 | 502 | // Optional : |
503 | 503 | 'limit' => 15, // Limit selection to X items only (default 1) |
504 | 504 | 'sortable' => true, // Allow selected items to be sortable (default false) |
505 | 505 | 'query_args' => array( |
506 | - 'post_type' => array( 'meal' ), |
|
507 | - 'post_status' => array( 'publish' ), |
|
506 | + 'post_type' => array('meal'), |
|
507 | + 'post_status' => array('publish'), |
|
508 | 508 | 'posts_per_page' => -1, |
509 | 509 | ), |
510 | 510 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-33', |
511 | 511 | ) |
512 | 512 | ); |
513 | 513 | } |
514 | - if ( post_type_exists( 'recipe' ) ) { |
|
514 | + if (post_type_exists('recipe')) { |
|
515 | 515 | $cmb->add_group_field( |
516 | 516 | $group, |
517 | 517 | array( |
518 | - 'name' => __( 'Recipes', 'lsx-health-plan' ), |
|
519 | - 'desc' => __( 'Connect the recipe(s) that apply to this section.', 'lsx-health-plan' ), |
|
518 | + 'name' => __('Recipes', 'lsx-health-plan'), |
|
519 | + 'desc' => __('Connect the recipe(s) that apply to this section.', 'lsx-health-plan'), |
|
520 | 520 | 'id' => 'connected_recipes', |
521 | 521 | 'type' => 'post_search_ajax', |
522 | 522 | // Optional : |
523 | - 'limit' => 15, // Limit selection to X items only (default 1) |
|
523 | + 'limit' => 15, // Limit selection to X items only (default 1) |
|
524 | 524 | 'sortable' => true, // Allow selected items to be sortable (default false) |
525 | 525 | 'query_args' => array( |
526 | - 'post_type' => array( 'recipe' ), |
|
527 | - 'post_status' => array( 'publish' ), |
|
526 | + 'post_type' => array('recipe'), |
|
527 | + 'post_status' => array('publish'), |
|
528 | 528 | 'posts_per_page' => -1, |
529 | 529 | ), |
530 | 530 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-33', |
531 | 531 | ) |
532 | 532 | ); |
533 | 533 | } |
534 | - if ( post_type_exists( 'tip' ) ) { |
|
534 | + if (post_type_exists('tip')) { |
|
535 | 535 | $cmb->add_group_field( |
536 | 536 | $group, |
537 | 537 | array( |
538 | - 'name' => __( 'Tips', 'lsx-health-plan' ), |
|
538 | + 'name' => __('Tips', 'lsx-health-plan'), |
|
539 | 539 | 'id' => 'connected_tips', |
540 | - 'desc' => __( 'Connect the tip(s) that apply to this section.', 'lsx-health-plan' ), |
|
540 | + 'desc' => __('Connect the tip(s) that apply to this section.', 'lsx-health-plan'), |
|
541 | 541 | 'type' => 'post_search_ajax', |
542 | 542 | // Optional : |
543 | - 'limit' => 15, // Limit selection to X items only (default 1) |
|
544 | - 'sortable' => true, // Allow selected items to be sortable (default false) |
|
543 | + 'limit' => 15, // Limit selection to X items only (default 1) |
|
544 | + 'sortable' => true, // Allow selected items to be sortable (default false) |
|
545 | 545 | 'query_args' => array( |
546 | - 'post_type' => array( 'tip' ), |
|
547 | - 'post_status' => array( 'publish' ), |
|
546 | + 'post_type' => array('tip'), |
|
547 | + 'post_status' => array('publish'), |
|
548 | 548 | 'posts_per_page' => -1, |
549 | 549 | ), |
550 | 550 | 'classes' => 'lsx-field-col lsx-field-add-field lsx-field-col-33', |
@@ -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 |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * Initialize the plugin by hooking into CMB2 |
36 | 36 | */ |
37 | 37 | public function __construct() { |
38 | - add_action( 'cmb2_render_post_search_ajax', array( $this, 'render' ), 10, 5 ); |
|
39 | - add_action( 'cmb2_sanitize_post_search_ajax', array( $this, 'sanitize' ), 10, 4 ); |
|
40 | - add_action( 'wp_ajax_cmb_post_search_ajax_get_results', array( $this, 'cmb_post_search_ajax_get_results' ) ); |
|
38 | + add_action('cmb2_render_post_search_ajax', array($this, 'render'), 10, 5); |
|
39 | + add_action('cmb2_sanitize_post_search_ajax', array($this, 'sanitize'), 10, 4); |
|
40 | + add_action('wp_ajax_cmb_post_search_ajax_get_results', array($this, 'cmb_post_search_ajax_get_results')); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public static function get_instance() { |
51 | 51 | // If the single instance hasn't been set, set it now. |
52 | - if ( null === self::$instance ) { |
|
52 | + if (null === self::$instance) { |
|
53 | 53 | self::$instance = new self(); |
54 | 54 | } |
55 | 55 | return self::$instance; |
@@ -58,37 +58,37 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * Render field |
60 | 60 | */ |
61 | - public function render( $field, $value, $object_id, $object_type, $field_type ) { |
|
61 | + public function render($field, $value, $object_id, $object_type, $field_type) { |
|
62 | 62 | $this->setup_admin_scripts(); |
63 | 63 | $field_name = $field->_name(); |
64 | 64 | |
65 | - if ( $field->args( 'limit' ) > 1 ) { |
|
65 | + if ($field->args('limit') > 1) { |
|
66 | 66 | echo '<ul class="cmb-post-search-ajax-results" id="' . $field_name . '_results">'; |
67 | - if ( isset( $value ) && ! empty( $value ) ) { |
|
67 | + if (isset($value) && ! empty($value)) { |
|
68 | 68 | |
69 | - if ( ! is_array( $value ) ) { |
|
70 | - $value = explode( ',', $value ); |
|
69 | + if ( ! is_array($value)) { |
|
70 | + $value = explode(',', $value); |
|
71 | 71 | } |
72 | - if ( ! is_array( $value ) ) { |
|
73 | - $value = array( $value ); |
|
72 | + if ( ! is_array($value)) { |
|
73 | + $value = array($value); |
|
74 | 74 | } |
75 | - $value = array_unique( $value ); |
|
76 | - foreach ( $value as $val ) { |
|
77 | - $handle = ( $field->args( 'sortable' ) ) ? '<span class="hndl"></span>' : ''; |
|
75 | + $value = array_unique($value); |
|
76 | + foreach ($value as $val) { |
|
77 | + $handle = ($field->args('sortable')) ? '<span class="hndl"></span>' : ''; |
|
78 | 78 | $li_css = ''; |
79 | - if ( $field->args( 'object_type' ) == 'user' ) { |
|
80 | - $guid = get_edit_user_link( $val ); |
|
81 | - $user = get_userdata( $val ); |
|
79 | + if ($field->args('object_type') == 'user') { |
|
80 | + $guid = get_edit_user_link($val); |
|
81 | + $user = get_userdata($val); |
|
82 | 82 | $title = $user->display_name; |
83 | 83 | } else { |
84 | - $guid = get_edit_post_link( $val ); |
|
85 | - $title = get_the_title( $val ) . ' - ' . '#' . $val; |
|
86 | - if ( 'trash' === get_post_status( $val ) ) { |
|
84 | + $guid = get_edit_post_link($val); |
|
85 | + $title = get_the_title($val) . ' - ' . '#' . $val; |
|
86 | + if ('trash' === get_post_status($val)) { |
|
87 | 87 | $li_css = 'display:none;'; |
88 | 88 | } |
89 | - $post_parent = wp_get_post_parent_id( $val ); |
|
90 | - if ( 0 !== $post_parent && false !== $post_parent ) { |
|
91 | - $title = get_the_title( $post_parent ) . ' -> ' . $title; |
|
89 | + $post_parent = wp_get_post_parent_id($val); |
|
90 | + if (0 !== $post_parent && false !== $post_parent) { |
|
91 | + $title = get_the_title($post_parent) . ' -> ' . $title; |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | echo '<li style="' . $li_css . '">' . $handle . '<input type="hidden" name="' . $field_name . '_results[]" value="' . $val . '"><a href="' . $guid . '" target="_blank" class="edit-link">' . $title . '</a><a class="remover"><span class="dashicons dashicons-no"></span><span class="dashicons dashicons-dismiss"></span></a></li>'; |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | } |
97 | 97 | echo '</ul>'; |
98 | 98 | $field_value = ''; |
99 | - if ( isset( $field->group ) ) { |
|
100 | - $store_name = str_replace( '][', '_', $field_name ); |
|
101 | - $store_name = str_replace( ']', '', $store_name ); |
|
102 | - $store_name = str_replace( '[', '_', $store_name ); |
|
99 | + if (isset($field->group)) { |
|
100 | + $store_name = str_replace('][', '_', $field_name); |
|
101 | + $store_name = str_replace(']', '', $store_name); |
|
102 | + $store_name = str_replace('[', '_', $store_name); |
|
103 | 103 | |
104 | 104 | echo $field_type->input( |
105 | 105 | array( |
@@ -107,19 +107,19 @@ discard block |
||
107 | 107 | 'id' => $field_name . '_store', |
108 | 108 | 'name' => $store_name . '_store', |
109 | 109 | 'class' => 'cmb-post-search-ajax-store', |
110 | - 'value' => implode( ',', $value ), |
|
110 | + 'value' => implode(',', $value), |
|
111 | 111 | 'desc' => false, |
112 | 112 | ) |
113 | 113 | ); |
114 | 114 | } |
115 | 115 | } else { |
116 | - if ( is_array( $value ) ) { |
|
116 | + if (is_array($value)) { |
|
117 | 117 | $value = $value[0]; |
118 | 118 | } |
119 | - if ( $field->args( 'object_type' ) == 'user' ) { |
|
120 | - $field_value = ( $value ? get_userdata( $value )->display_name : '' ); |
|
119 | + if ($field->args('object_type') == 'user') { |
|
120 | + $field_value = ($value ? get_userdata($value)->display_name : ''); |
|
121 | 121 | } else { |
122 | - $field_value = ( $value ? get_the_title( $value ) : '' ); |
|
122 | + $field_value = ($value ? get_the_title($value) : ''); |
|
123 | 123 | } |
124 | 124 | echo $field_type->input( |
125 | 125 | array( |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | 'desc' => false, |
130 | 130 | ) |
131 | 131 | ); |
132 | - if ( isset( $field->group ) ) { |
|
133 | - $store_name = str_replace( '][', '_', $field_name ); |
|
134 | - $store_name = str_replace( ']', '', $store_name ); |
|
135 | - $store_name = str_replace( '[', '_', $store_name ); |
|
132 | + if (isset($field->group)) { |
|
133 | + $store_name = str_replace('][', '_', $field_name); |
|
134 | + $store_name = str_replace(']', '', $store_name); |
|
135 | + $store_name = str_replace('[', '_', $store_name); |
|
136 | 136 | |
137 | 137 | echo $field_type->input( |
138 | 138 | array( |
@@ -155,64 +155,64 @@ discard block |
||
155 | 155 | 'class' => 'cmb-post-search-ajax', |
156 | 156 | 'value' => $field_value, |
157 | 157 | 'desc' => false, |
158 | - 'data-limit' => $field->args( 'limit' ) ? $field->args( 'limit' ) : '1', |
|
159 | - 'data-sortable' => $field->args( 'sortable' ) ? $field->args( 'sortable' ) : '0', |
|
160 | - 'data-object' => $field->args( 'object_type' ) ? $field->args( 'object_type' ) : 'post', |
|
161 | - 'data-queryargs'=> $field->args( 'query_args' ) ? htmlspecialchars( json_encode( $field->args( 'query_args' ) ), ENT_QUOTES, 'UTF-8' ) : '' |
|
158 | + 'data-limit' => $field->args('limit') ? $field->args('limit') : '1', |
|
159 | + 'data-sortable' => $field->args('sortable') ? $field->args('sortable') : '0', |
|
160 | + 'data-object' => $field->args('object_type') ? $field->args('object_type') : 'post', |
|
161 | + 'data-queryargs'=> $field->args('query_args') ? htmlspecialchars(json_encode($field->args('query_args')), ENT_QUOTES, 'UTF-8') : '' |
|
162 | 162 | ) |
163 | 163 | ); |
164 | 164 | |
165 | - echo '<img src="' . admin_url( 'images/spinner.gif' ) . '" class="cmb-post-search-ajax-spinner" />'; |
|
165 | + echo '<img src="' . admin_url('images/spinner.gif') . '" class="cmb-post-search-ajax-spinner" />'; |
|
166 | 166 | |
167 | - $field_type->_desc( true, true ); |
|
167 | + $field_type->_desc(true, true); |
|
168 | 168 | |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | 172 | * Optionally save the latitude/longitude values into two custom fields |
173 | 173 | */ |
174 | - public function sanitize( $override_value, $value, $object_id, $field_args ) { |
|
174 | + public function sanitize($override_value, $value, $object_id, $field_args) { |
|
175 | 175 | $fid = ''; |
176 | - if ( isset( $field_args['id'] ) ) { |
|
176 | + if (isset($field_args['id'])) { |
|
177 | 177 | $fid = $field_args['id']; |
178 | 178 | } |
179 | 179 | |
180 | 180 | // IF the field is in a repeatable group, then get the info from the post data. |
181 | - if ( isset( $field_args['render_row_cb'][0]->group ) && ! empty( $field_args['render_row_cb'][0]->group ) ) { |
|
181 | + if (isset($field_args['render_row_cb'][0]->group) && ! empty($field_args['render_row_cb'][0]->group)) { |
|
182 | 182 | $new_index = ''; |
183 | 183 | $data_to_save = $field_args['render_row_cb'][0]->group->args['render_row_cb'][0]->data_to_save; |
184 | 184 | $oid = $field_args['_name']; |
185 | 185 | $iid = $field_args['_id']; |
186 | - $oid = explode( '[', $oid ); |
|
186 | + $oid = explode('[', $oid); |
|
187 | 187 | |
188 | - if ( is_array( $oid ) ) { |
|
188 | + if (is_array($oid)) { |
|
189 | 189 | $oid = $oid[0]; |
190 | 190 | } |
191 | 191 | |
192 | - if ( isset( $data_to_save[ $oid ] ) && ! empty( $data_to_save[ $oid ] ) ) { |
|
193 | - foreach( $data_to_save[ $oid ] as $index => $svalues ) { |
|
194 | - if ( isset( $svalues[ $iid ] ) && $value === $svalues[ $iid ] ) { |
|
192 | + if (isset($data_to_save[$oid]) && ! empty($data_to_save[$oid])) { |
|
193 | + foreach ($data_to_save[$oid] as $index => $svalues) { |
|
194 | + if (isset($svalues[$iid]) && $value === $svalues[$iid]) { |
|
195 | 195 | $new_index = $index; |
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - if ( isset( $field_args['render_row_cb'][0]->group->index ) ) { |
|
200 | + if (isset($field_args['render_row_cb'][0]->group->index)) { |
|
201 | 201 | $new_index = $field_args['render_row_cb'][0]->group->index; |
202 | 202 | } |
203 | 203 | |
204 | - if ( '' !== $new_index ) { |
|
204 | + if ('' !== $new_index) { |
|
205 | 205 | $new_index = $oid . '_' . $new_index . '_' . $iid . '_store'; |
206 | - if ( ! empty( $data_to_save[ $new_index ] ) ) { |
|
207 | - $value = $data_to_save[ $new_index ]; |
|
206 | + if ( ! empty($data_to_save[$new_index])) { |
|
207 | + $value = $data_to_save[$new_index]; |
|
208 | 208 | } |
209 | 209 | } else { |
210 | 210 | $value = false; |
211 | 211 | } |
212 | - } else if ( ! empty( $field_args['render_row_cb'][0]->data_to_save[ $fid . '_results' ] ) ) { |
|
213 | - $value = $field_args['render_row_cb'][0]->data_to_save[ $fid . '_results' ]; |
|
214 | - } else if ( ! empty( $field_args['render_row_cb'][0]->data_to_save[ $fid . '_store' ] ) ) { |
|
215 | - $value = $field_args['render_row_cb'][0]->data_to_save[ $fid . '_store' ]; |
|
212 | + } else if ( ! empty($field_args['render_row_cb'][0]->data_to_save[$fid . '_results'])) { |
|
213 | + $value = $field_args['render_row_cb'][0]->data_to_save[$fid . '_results']; |
|
214 | + } else if ( ! empty($field_args['render_row_cb'][0]->data_to_save[$fid . '_store'])) { |
|
215 | + $value = $field_args['render_row_cb'][0]->data_to_save[$fid . '_store']; |
|
216 | 216 | } else { |
217 | 217 | $value = false; |
218 | 218 | } |
@@ -241,25 +241,25 @@ discard block |
||
241 | 241 | * Defines the url which is used to load local resources. Based on, and uses, |
242 | 242 | * the CMB2_Utils class from the CMB2 library. |
243 | 243 | */ |
244 | - public static function url( $path = '' ) { |
|
245 | - if ( self::$url ) { |
|
244 | + public static function url($path = '') { |
|
245 | + if (self::$url) { |
|
246 | 246 | return self::$url . $path; |
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
250 | 250 | * Set the variable cmb2_fpsa_dir |
251 | 251 | */ |
252 | - $cmb2_fpsa_dir = trailingslashit( dirname( __FILE__ ) ); |
|
252 | + $cmb2_fpsa_dir = trailingslashit(dirname(__FILE__)); |
|
253 | 253 | |
254 | 254 | /** |
255 | 255 | * Use CMB2_Utils to gather the url from cmb2_fpsa_dir |
256 | 256 | */ |
257 | - $cmb2_fpsa_url = CMB2_Utils::get_url_from_dir( $cmb2_fpsa_dir ); |
|
257 | + $cmb2_fpsa_url = CMB2_Utils::get_url_from_dir($cmb2_fpsa_dir); |
|
258 | 258 | |
259 | 259 | /** |
260 | 260 | * Filter the CMB2 FPSA location url |
261 | 261 | */ |
262 | - self::$url = trailingslashit( apply_filters( 'cmb2_fpsa_url', $cmb2_fpsa_url, self::VERSION ) ); |
|
262 | + self::$url = trailingslashit(apply_filters('cmb2_fpsa_url', $cmb2_fpsa_url, self::VERSION)); |
|
263 | 263 | |
264 | 264 | return self::$url . $path; |
265 | 265 | } |
@@ -269,14 +269,14 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function setup_admin_scripts() { |
271 | 271 | |
272 | - wp_register_script( 'jquery-devautocomplete', self::url( 'js/jquery.autocomplete.min.js' ), array( 'jquery' ), self::VERSION ); |
|
273 | - wp_register_script( 'mag-post-search-ajax', self::url( 'js/mag-post-search-ajax.js' ), array( 'jquery', 'jquery-devautocomplete', 'jquery-ui-sortable' ), self::VERSION ); |
|
274 | - wp_localize_script( 'mag-post-search-ajax', 'psa', array( |
|
275 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
276 | - 'nonce' => wp_create_nonce( 'mag_cmb_post_search_ajax_get_results' ) |
|
277 | - ) ); |
|
278 | - wp_enqueue_script( 'mag-post-search-ajax' ); |
|
279 | - wp_enqueue_style( 'mag-post-search-ajax', self::url( 'css/mag-post-search-ajax.css' ), array(), self::VERSION ); |
|
272 | + wp_register_script('jquery-devautocomplete', self::url('js/jquery.autocomplete.min.js'), array('jquery'), self::VERSION); |
|
273 | + wp_register_script('mag-post-search-ajax', self::url('js/mag-post-search-ajax.js'), array('jquery', 'jquery-devautocomplete', 'jquery-ui-sortable'), self::VERSION); |
|
274 | + wp_localize_script('mag-post-search-ajax', 'psa', array( |
|
275 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
276 | + 'nonce' => wp_create_nonce('mag_cmb_post_search_ajax_get_results') |
|
277 | + )); |
|
278 | + wp_enqueue_script('mag-post-search-ajax'); |
|
279 | + wp_enqueue_style('mag-post-search-ajax', self::url('css/mag-post-search-ajax.css'), array(), self::VERSION); |
|
280 | 280 | |
281 | 281 | } |
282 | 282 | |
@@ -284,52 +284,52 @@ discard block |
||
284 | 284 | * Ajax request : get results |
285 | 285 | */ |
286 | 286 | public function cmb_post_search_ajax_get_results() { |
287 | - $nonce = sanitize_text_field( $_POST['psacheck'] ); |
|
288 | - if ( ! wp_verify_nonce( $nonce, 'mag_cmb_post_search_ajax_get_results' ) ) { |
|
289 | - die( json_encode( array( 'error' => __( 'Error : Unauthorized action' ) ) ) ); |
|
287 | + $nonce = sanitize_text_field($_POST['psacheck']); |
|
288 | + if ( ! wp_verify_nonce($nonce, 'mag_cmb_post_search_ajax_get_results')) { |
|
289 | + die(json_encode(array('error' => __('Error : Unauthorized action')))); |
|
290 | 290 | } else { |
291 | - $args = json_decode( stripslashes( htmlspecialchars_decode( sanitize_text_field( $_POST['query_args'] ) ) ), true ); |
|
292 | - $args['s'] = sanitize_text_field( $_POST['query'] ); |
|
291 | + $args = json_decode(stripslashes(htmlspecialchars_decode(sanitize_text_field($_POST['query_args']))), true); |
|
292 | + $args['s'] = sanitize_text_field($_POST['query']); |
|
293 | 293 | $datas = array(); |
294 | - if ( $_POST['object'] == 'user' ) { |
|
294 | + if ($_POST['object'] == 'user') { |
|
295 | 295 | |
296 | - $args['search'] = '*' . esc_attr( sanitize_text_field( $_POST['query'] ) ) . '*'; |
|
297 | - $users = new WP_User_Query( $args ); |
|
296 | + $args['search'] = '*' . esc_attr(sanitize_text_field($_POST['query'])) . '*'; |
|
297 | + $users = new WP_User_Query($args); |
|
298 | 298 | $results = $users->get_results(); |
299 | 299 | |
300 | - if ( ! empty( $results ) ) { |
|
301 | - foreach ( $results as $result ){ |
|
302 | - $user_info = get_userdata( $result->ID ); |
|
300 | + if ( ! empty($results)) { |
|
301 | + foreach ($results as $result) { |
|
302 | + $user_info = get_userdata($result->ID); |
|
303 | 303 | // Define filter "mag_cmb_post_search_ajax_result" to allow customize ajax results. |
304 | - $datas[] = apply_filters( 'mag_cmb_post_search_ajax_result', array( |
|
304 | + $datas[] = apply_filters('mag_cmb_post_search_ajax_result', array( |
|
305 | 305 | 'value' => $user_info->display_name, |
306 | 306 | 'data' => $result->ID, |
307 | - 'guid' => get_edit_user_link( $result->ID ), |
|
308 | - ) ); |
|
307 | + 'guid' => get_edit_user_link($result->ID), |
|
308 | + )); |
|
309 | 309 | } |
310 | 310 | } |
311 | 311 | } else { |
312 | - $results = new WP_Query( $args ); |
|
313 | - if ( $results->have_posts() ) : |
|
314 | - while ( $results->have_posts() ) : $results->the_post(); |
|
312 | + $results = new WP_Query($args); |
|
313 | + if ($results->have_posts()) : |
|
314 | + while ($results->have_posts()) : $results->the_post(); |
|
315 | 315 | // Define filter "mag_cmb_post_search_ajax_result" to allow customize ajax results. |
316 | 316 | |
317 | 317 | $title = get_the_title() . ' - ' . '#' . get_the_ID(); |
318 | - $post_parent = wp_get_post_parent_id( get_the_ID() ); |
|
319 | - if ( 0 !== $post_parent && false !== $post_parent ) { |
|
320 | - $title = get_the_title( $post_parent ) . ' -> ' . $title; |
|
318 | + $post_parent = wp_get_post_parent_id(get_the_ID()); |
|
319 | + if (0 !== $post_parent && false !== $post_parent) { |
|
320 | + $title = get_the_title($post_parent) . ' -> ' . $title; |
|
321 | 321 | } |
322 | 322 | |
323 | - $datas[] = apply_filters( 'mag_cmb_post_search_ajax_result', array( |
|
323 | + $datas[] = apply_filters('mag_cmb_post_search_ajax_result', array( |
|
324 | 324 | 'value' => $title, |
325 | 325 | 'data' => get_the_ID(), |
326 | 326 | 'guid' => get_edit_post_link(), |
327 | - ) ); |
|
327 | + )); |
|
328 | 328 | endwhile; |
329 | 329 | endif; |
330 | 330 | } |
331 | 331 | wp_reset_postdata(); |
332 | - die( json_encode( $datas ) ); |
|
332 | + die(json_encode($datas)); |
|
333 | 333 | } |
334 | 334 | } |
335 | 335 | } |