Passed
Push — master ( f066ab...2425ec )
by Chris
02:33
created
includes/class-lsx-team-scpo-engine.php 1 patch
Indentation   +366 added lines, -366 removed lines patch added patch discarded remove patch
@@ -13,133 +13,133 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class LSX_TEAM_SCPO_Engine {
15 15
 
16
-	public function __construct() {
17
-		if ( ! get_option( 'lsx_team_scporder_install' ) )
18
-			$this->lsx_team_scporder_install();
16
+     public function __construct() {
17
+          if ( ! get_option( 'lsx_team_scporder_install' ) )
18
+               $this->lsx_team_scporder_install();
19 19
 
20
-		add_action( 'admin_init', array( $this, 'refresh' ) );
21
-		add_action( 'admin_init', array( $this, 'load_script_css' ) );
20
+          add_action( 'admin_init', array( $this, 'refresh' ) );
21
+          add_action( 'admin_init', array( $this, 'load_script_css' ) );
22 22
 
23
-		add_action( 'wp_ajax_update-menu-order', array( $this, 'update_menu_order' ) );
24
-		add_action( 'wp_ajax_update-menu-order-tags', array( $this, 'update_menu_order_tags' ) );
23
+          add_action( 'wp_ajax_update-menu-order', array( $this, 'update_menu_order' ) );
24
+          add_action( 'wp_ajax_update-menu-order-tags', array( $this, 'update_menu_order_tags' ) );
25 25
 
26
-		add_action( 'pre_get_posts', array( $this, 'lsx_team_scporder_pre_get_posts' ) );
26
+          add_action( 'pre_get_posts', array( $this, 'lsx_team_scporder_pre_get_posts' ) );
27 27
 
28
-		add_filter( 'get_previous_post_where', array( $this, 'lsx_team_scporder_previous_post_where' ) );
29
-		add_filter( 'get_previous_post_sort', array( $this, 'lsx_team_scporder_previous_post_sort' ) );
30
-		add_filter( 'get_next_post_where', array( $this, 'lsx_team_scporder_next_post_where' ) );
31
-		add_filter( 'get_next_post_sort', array( $this, 'lsx_team_scporder_next_post_sort' ) );
28
+          add_filter( 'get_previous_post_where', array( $this, 'lsx_team_scporder_previous_post_where' ) );
29
+          add_filter( 'get_previous_post_sort', array( $this, 'lsx_team_scporder_previous_post_sort' ) );
30
+          add_filter( 'get_next_post_where', array( $this, 'lsx_team_scporder_next_post_where' ) );
31
+          add_filter( 'get_next_post_sort', array( $this, 'lsx_team_scporder_next_post_sort' ) );
32 32
 
33
-		add_filter( 'get_terms_orderby', array( $this, 'lsx_team_scporder_get_terms_orderby' ), 10, 3 );
34
-		add_filter( 'wp_get_object_terms', array( $this, 'lsx_team_scporder_get_object_terms' ), 10, 3 );
35
-		add_filter( 'get_terms', array( $this, 'lsx_team_scporder_get_object_terms' ), 10, 3 );
36
-	}
33
+          add_filter( 'get_terms_orderby', array( $this, 'lsx_team_scporder_get_terms_orderby' ), 10, 3 );
34
+          add_filter( 'wp_get_object_terms', array( $this, 'lsx_team_scporder_get_object_terms' ), 10, 3 );
35
+          add_filter( 'get_terms', array( $this, 'lsx_team_scporder_get_object_terms' ), 10, 3 );
36
+     }
37 37
 
38
-	public function lsx_team_scporder_install() {
39
-		global $wpdb;
40
-		$result = $wpdb->query( "DESCRIBE $wpdb->terms `lsx_team_term_order`" );
38
+     public function lsx_team_scporder_install() {
39
+          global $wpdb;
40
+          $result = $wpdb->query( "DESCRIBE $wpdb->terms `lsx_team_term_order`" );
41 41
 
42
-		if ( ! $result ) {
43
-			$result = $wpdb->query( "ALTER TABLE $wpdb->terms ADD `lsx_team_term_order` INT( 4 ) NULL DEFAULT '0'" );
44
-		}
42
+          if ( ! $result ) {
43
+               $result = $wpdb->query( "ALTER TABLE $wpdb->terms ADD `lsx_team_term_order` INT( 4 ) NULL DEFAULT '0'" );
44
+          }
45 45
 
46
-		update_option( 'lsx_team_scporder_install', 1 );
47
-	}
46
+          update_option( 'lsx_team_scporder_install', 1 );
47
+     }
48 48
 
49
-	public function _check_load_script_css() {
50
-		$active = false;
49
+     public function _check_load_script_css() {
50
+          $active = false;
51 51
 
52
-		$objects = $this->get_lsx_team_scporder_options_objects();
53
-		$tags = $this->get_lsx_team_scporder_options_tags();
52
+          $objects = $this->get_lsx_team_scporder_options_objects();
53
+          $tags = $this->get_lsx_team_scporder_options_tags();
54 54
 
55
-		if ( empty( $objects ) && empty( $tags ) )
56
-			return false;
55
+          if ( empty( $objects ) && empty( $tags ) )
56
+               return false;
57 57
 
58
-		if ( isset( $_GET['orderby'] ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'action=edit' ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/post-new.php' ) )
59
-			return false;
58
+          if ( isset( $_GET['orderby'] ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'action=edit' ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/post-new.php' ) )
59
+               return false;
60 60
 
61
-		if ( ! empty( $objects ) ) {
62
-			if ( isset( $_GET['post_type'] ) && ! isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_GET['post_type'] ) ), $objects ) ) { // if page or custom post types.
63
-				$active = true;
64
-			}
65
-			if ( ! isset( $_GET['post_type'] ) && strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/edit.php' ) && array_key_exists( 'post', $objects ) ) { // if post.
66
-				$active = true;
67
-			}
68
-		}
61
+          if ( ! empty( $objects ) ) {
62
+               if ( isset( $_GET['post_type'] ) && ! isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_GET['post_type'] ) ), $objects ) ) { // if page or custom post types.
63
+                    $active = true;
64
+               }
65
+               if ( ! isset( $_GET['post_type'] ) && strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/edit.php' ) && array_key_exists( 'post', $objects ) ) { // if post.
66
+                    $active = true;
67
+               }
68
+          }
69 69
 
70
-		if ( ! empty( $tags ) ) {
71
-			if ( isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ), $tags ) ) {
72
-				$active = true;
73
-			}
74
-		}
70
+          if ( ! empty( $tags ) ) {
71
+               if ( isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ), $tags ) ) {
72
+                    $active = true;
73
+               }
74
+          }
75 75
 
76
-		return $active;
77
-	}
76
+          return $active;
77
+     }
78 78
 
79
-	public function load_script_css() {
80
-		if ( $this->_check_load_script_css() ) {
81
-			wp_enqueue_script( 'scporderjs', LSX_TEAM_URL . 'assets/js/scporder.min.js', array( 'jquery', 'jquery-ui-sortable' ), null, true );
79
+     public function load_script_css() {
80
+          if ( $this->_check_load_script_css() ) {
81
+               wp_enqueue_script( 'scporderjs', LSX_TEAM_URL . 'assets/js/scporder.min.js', array( 'jquery', 'jquery-ui-sortable' ), null, true );
82 82
 
83
-			$scporderjs_params = array(
84
-				'ajax_url' => admin_url( 'admin-ajax.php' ),
85
-				'ajax_nonce' => wp_create_nonce( 'scporder' ),
86
-			 );
83
+               $scporderjs_params = array(
84
+                    'ajax_url' => admin_url( 'admin-ajax.php' ),
85
+                    'ajax_nonce' => wp_create_nonce( 'scporder' ),
86
+                    );
87 87
 
88
-			wp_localize_script( 'scporderjs', 'scporderjs_params', $scporderjs_params );
88
+               wp_localize_script( 'scporderjs', 'scporderjs_params', $scporderjs_params );
89 89
 
90
-			wp_enqueue_style( 'scporder', LSX_TEAM_URL . 'assets/css/scporder.css', array(), null );
91
-		}
92
-	}
90
+               wp_enqueue_style( 'scporder', LSX_TEAM_URL . 'assets/css/scporder.css', array(), null );
91
+          }
92
+     }
93 93
 
94
-	public function refresh() {
95
-		global $wpdb;
96
-		$objects = $this->get_lsx_team_scporder_options_objects();
97
-		$tags = $this->get_lsx_team_scporder_options_tags();
94
+     public function refresh() {
95
+          global $wpdb;
96
+          $objects = $this->get_lsx_team_scporder_options_objects();
97
+          $tags = $this->get_lsx_team_scporder_options_tags();
98 98
 
99
-		if ( ! empty( $objects ) ) {
100
-			foreach ( $objects as $object => $object_data ) {
101
-				$result = $wpdb->get_results( $wpdb->prepare( "
99
+          if ( ! empty( $objects ) ) {
100
+               foreach ( $objects as $object => $object_data ) {
101
+                    $result = $wpdb->get_results( $wpdb->prepare( "
102 102
 					SELECT count( * ) as cnt, max( menu_order ) as max, min( menu_order ) as min
103 103
 					FROM $wpdb->posts
104 104
 					WHERE post_type = '%s' AND post_status IN ( 'publish', 'pending', 'draft', 'private', 'future' )
105 105
 				", $object ) );
106 106
 
107
-				if ( 0 == $result[0]->cnt || $result[0]->cnt == $result[0]->max )
108
-					continue;
107
+                    if ( 0 == $result[0]->cnt || $result[0]->cnt == $result[0]->max )
108
+                         continue;
109 109
 
110
-				$results = $wpdb->get_results( $wpdb->prepare( "
110
+                    $results = $wpdb->get_results( $wpdb->prepare( "
111 111
 					SELECT ID
112 112
 					FROM $wpdb->posts
113 113
 					WHERE post_type = '%s' AND post_status IN ( 'publish', 'pending', 'draft', 'private', 'future' )
114 114
 					ORDER BY menu_order ASC
115 115
 				", $object ) );
116 116
 
117
-				foreach ( $results as $key => $result ) {
118
-					$wpdb->update( $wpdb->posts,
119
-						array(
120
-							'menu_order' => $key + 1,
121
-						),
122
-						array(
123
-							'ID' => $result->ID,
124
-						)
125
-					);
126
-				}
127
-			}
128
-		}
129
-
130
-		if ( ! empty( $tags ) ) {
131
-			foreach ( $tags as $taxonomy => $taxonomy_data ) {
132
-				$result = $wpdb->get_results( $wpdb->prepare( "
117
+                    foreach ( $results as $key => $result ) {
118
+                         $wpdb->update( $wpdb->posts,
119
+                              array(
120
+                                   'menu_order' => $key + 1,
121
+                              ),
122
+                              array(
123
+                                   'ID' => $result->ID,
124
+                              )
125
+                         );
126
+                    }
127
+               }
128
+          }
129
+
130
+          if ( ! empty( $tags ) ) {
131
+               foreach ( $tags as $taxonomy => $taxonomy_data ) {
132
+                    $result = $wpdb->get_results( $wpdb->prepare( "
133 133
 					SELECT count( * ) as cnt, max( lsx_team_term_order ) as max, min( lsx_team_term_order ) as min
134 134
 					FROM $wpdb->terms AS terms
135 135
 					INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
136 136
 					WHERE term_taxonomy.taxonomy = '%s'
137 137
 				", $taxonomy ) );
138 138
 
139
-				if ( 0 == $result[0]->cnt || $result[0]->cnt == $result[0]->max )
140
-					continue;
139
+                    if ( 0 == $result[0]->cnt || $result[0]->cnt == $result[0]->max )
140
+                         continue;
141 141
 
142
-				$results = $wpdb->get_results( $wpdb->prepare( "
142
+                    $results = $wpdb->get_results( $wpdb->prepare( "
143 143
 					SELECT terms.term_id
144 144
 					FROM $wpdb->terms AS terms
145 145
 					INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id )
@@ -147,270 +147,270 @@  discard block
 block discarded – undo
147 147
 					ORDER BY lsx_team_term_order ASC
148 148
 				", $taxonomy ) );
149 149
 
150
-				foreach ( $results as $key => $result ) {
151
-					$wpdb->update(
152
-						$wpdb->terms,
153
-						array(
154
-							'lsx_team_term_order' => $key + 1,
155
-						),
156
-						array(
157
-							'term_id' => $result->term_id,
158
-						)
159
-					);
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	public function update_menu_order() {
166
-		check_ajax_referer( 'scporder', 'security' );
167
-
168
-		global $wpdb;
169
-
170
-		parse_str( sanitize_text_field( wp_unslash( $_POST['order'] ) ), $data );
171
-
172
-		if ( ! is_array( $data ) )
173
-			return false;
174
-
175
-		$id_arr = array();
176
-
177
-		foreach ( $data as $key => $values ) {
178
-			foreach ( $values as $position => $id ) {
179
-				$id_arr[] = $id;
180
-			}
181
-		}
182
-
183
-		$menu_order_arr = array();
184
-
185
-		foreach ( $id_arr as $key => $id ) {
186
-			$results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = " . intval( $id ) );
187
-			foreach ( $results as $result ) {
188
-				$menu_order_arr[] = $result->menu_order;
189
-			}
190
-		}
191
-
192
-		sort( $menu_order_arr );
193
-
194
-		foreach ( $data as $key => $values ) {
195
-			foreach ( $values as $position => $id ) {
196
-				$wpdb->update( $wpdb->posts,
197
-					array(
198
-						'menu_order' => $menu_order_arr[ $position ],
199
-					),
200
-					array(
201
-						'ID' => intval( $id ),
202
-					)
203
-				);
204
-			}
205
-		}
206
-	}
207
-
208
-	public function update_menu_order_tags() {
209
-		check_ajax_referer( 'scporder', 'security' );
210
-
211
-		global $wpdb;
212
-
213
-		parse_str( sanitize_text_field( wp_unslash( $_POST['order'] ) ), $data );
214
-
215
-		if ( ! is_array( $data ) )
216
-			return false;
217
-
218
-		$id_arr = array();
219
-
220
-		foreach ( $data as $key => $values ) {
221
-			foreach ( $values as $position => $id ) {
222
-				$id_arr[] = $id;
223
-			}
224
-		}
225
-
226
-		$menu_order_arr = array();
227
-
228
-		foreach ( $id_arr as $key => $id ) {
229
-			$results = $wpdb->get_results( "
150
+                    foreach ( $results as $key => $result ) {
151
+                         $wpdb->update(
152
+                              $wpdb->terms,
153
+                              array(
154
+                                   'lsx_team_term_order' => $key + 1,
155
+                              ),
156
+                              array(
157
+                                   'term_id' => $result->term_id,
158
+                              )
159
+                         );
160
+                    }
161
+               }
162
+          }
163
+     }
164
+
165
+     public function update_menu_order() {
166
+          check_ajax_referer( 'scporder', 'security' );
167
+
168
+          global $wpdb;
169
+
170
+          parse_str( sanitize_text_field( wp_unslash( $_POST['order'] ) ), $data );
171
+
172
+          if ( ! is_array( $data ) )
173
+               return false;
174
+
175
+          $id_arr = array();
176
+
177
+          foreach ( $data as $key => $values ) {
178
+               foreach ( $values as $position => $id ) {
179
+                    $id_arr[] = $id;
180
+               }
181
+          }
182
+
183
+          $menu_order_arr = array();
184
+
185
+          foreach ( $id_arr as $key => $id ) {
186
+               $results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = " . intval( $id ) );
187
+               foreach ( $results as $result ) {
188
+                    $menu_order_arr[] = $result->menu_order;
189
+               }
190
+          }
191
+
192
+          sort( $menu_order_arr );
193
+
194
+          foreach ( $data as $key => $values ) {
195
+               foreach ( $values as $position => $id ) {
196
+                    $wpdb->update( $wpdb->posts,
197
+                         array(
198
+                              'menu_order' => $menu_order_arr[ $position ],
199
+                         ),
200
+                         array(
201
+                              'ID' => intval( $id ),
202
+                         )
203
+                    );
204
+               }
205
+          }
206
+     }
207
+
208
+     public function update_menu_order_tags() {
209
+          check_ajax_referer( 'scporder', 'security' );
210
+
211
+          global $wpdb;
212
+
213
+          parse_str( sanitize_text_field( wp_unslash( $_POST['order'] ) ), $data );
214
+
215
+          if ( ! is_array( $data ) )
216
+               return false;
217
+
218
+          $id_arr = array();
219
+
220
+          foreach ( $data as $key => $values ) {
221
+               foreach ( $values as $position => $id ) {
222
+                    $id_arr[] = $id;
223
+               }
224
+          }
225
+
226
+          $menu_order_arr = array();
227
+
228
+          foreach ( $id_arr as $key => $id ) {
229
+               $results = $wpdb->get_results( "
230 230
 				SELECT lsx_team_term_order 
231 231
 				FROM $wpdb->terms 
232 232
 				WHERE term_id = " . intval( $id ) );
233
-			foreach ( $results as $result ) {
234
-				$menu_order_arr[] = $result->lsx_team_term_order;
235
-			}
236
-		}
237
-
238
-		sort( $menu_order_arr );
239
-
240
-		foreach ( $data as $key => $values ) {
241
-			foreach ( $values as $position => $id ) {
242
-				$wpdb->update( $wpdb->terms,
243
-					array(
244
-						'lsx_team_term_order' => $menu_order_arr[ $position ],
245
-					),
246
-					array(
247
-						'term_id' => intval( $id ),
248
-					)
249
-				);
250
-			}
251
-		}
252
-	}
253
-
254
-	public function lsx_team_scporder_previous_post_where( $where ) {
255
-		global $post;
256
-		$objects = $this->get_lsx_team_scporder_options_objects();
257
-
258
-		if ( empty( $objects ) )
259
-			return $where;
260
-
261
-		if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
262
-			$current_menu_order = $post->menu_order;
263
-			$where = "WHERE p.menu_order > '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
264
-		}
265
-
266
-		return $where;
267
-	}
268
-
269
-	public function lsx_team_scporder_previous_post_sort( $orderby ) {
270
-		global $post;
271
-		$objects = $this->get_lsx_team_scporder_options_objects();
272
-
273
-		if ( empty( $objects ) )
274
-			return $orderby;
275
-
276
-		if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
277
-			$orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
278
-		}
279
-
280
-		return $orderby;
281
-	}
282
-
283
-	public function lsx_team_scporder_next_post_where( $where ) {
284
-		global $post;
285
-		$objects = $this->get_lsx_team_scporder_options_objects();
286
-
287
-		if ( empty( $objects ) )
288
-			return $where;
289
-
290
-		if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
291
-			$current_menu_order = $post->menu_order;
292
-			$where = "WHERE p.menu_order < '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
293
-		}
294
-
295
-		return $where;
296
-	}
297
-
298
-	public function lsx_team_scporder_next_post_sort( $orderby ) {
299
-		global $post;
300
-		$objects = $this->get_lsx_team_scporder_options_objects();
301
-
302
-		if ( empty( $objects ) )
303
-			return $orderby;
304
-
305
-		if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
306
-			$orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
307
-		}
308
-
309
-		return $orderby;
310
-	}
311
-
312
-	public function lsx_team_scporder_pre_get_posts( $wp_query ) {
313
-		$objects = $this->get_lsx_team_scporder_options_objects();
314
-
315
-		if ( empty( $objects ) )
316
-			return false;
317
-
318
-		if ( is_admin() ) {
319
-			if ( isset( $wp_query->query['post_type'] ) && ! isset( $_GET['orderby'] ) ) {
320
-				if ( array_key_exists( $wp_query->query['post_type'], $objects ) ) {
321
-					$wp_query->set( 'orderby', 'menu_order' );
322
-					$wp_query->set( 'order', 'ASC' );
323
-				}
324
-			}
325
-		} else {
326
-			$active = false;
327
-
328
-			if ( isset( $wp_query->query['post_type'] ) ) {
329
-				if ( ! is_array( $wp_query->query['post_type'] ) ) {
330
-					if ( array_key_exists( $wp_query->query['post_type'], $objects ) ) {
331
-						$active = true;
332
-					}
333
-				}
334
-			} else {
335
-				if ( array_key_exists( 'post', $objects ) ) {
336
-					$active = true;
337
-				}
338
-			}
339
-
340
-			if ( ! $active )
341
-				return false;
342
-
343
-			if ( isset( $wp_query->query['suppress_filters'] ) ) {
344
-				if ( $wp_query->get( 'orderby' ) == 'date' )
345
-					$wp_query->set( 'orderby', 'menu_order' );
346
-				if ( $wp_query->get( 'order' ) == 'DESC' )
347
-					$wp_query->set( 'order', 'ASC' );
348
-			} else {
349
-				if ( ! $wp_query->get( 'orderby' ) )
350
-					$wp_query->set( 'orderby', 'menu_order' );
351
-				if ( ! $wp_query->get( 'order' ) )
352
-					$wp_query->set( 'order', 'ASC' );
353
-			}
354
-		}
355
-	}
356
-
357
-	public function lsx_team_scporder_get_terms_orderby( $orderby, $args ) {
358
-		if ( is_admin() )
359
-			return $orderby;
360
-
361
-		$tags = $this->get_lsx_team_scporder_options_tags();
362
-
363
-		if ( ! isset( $args['taxonomy'] ) )
364
-			return $orderby;
365
-
366
-		$taxonomy = $args['taxonomy'];
367
-		if ( is_array( $taxonomy ) && count( $taxonomy ) == 1 )
368
-			$taxonomy = $taxonomy[0];
369
-		if ( ! array_key_exists( $taxonomy[0], $tags ) )
370
-			return $orderby;
371
-
372
-		$orderby = 't.lsx_team_term_order';
373
-		return $orderby;
374
-	}
375
-
376
-	public function lsx_team_scporder_get_object_terms( $terms ) {
377
-		$tags = $this->get_lsx_team_scporder_options_tags();
378
-
379
-		if ( is_admin() && isset( $_GET['orderby'] ) )
380
-			return $terms;
381
-
382
-		foreach ( $terms as $key => $term ) {
383
-			if ( is_object( $term ) && isset( $term->taxonomy ) ) {
384
-				$taxonomy = $term->taxonomy;
385
-				if ( ! array_key_exists( $taxonomy, $tags ) )
386
-					return $terms;
387
-			} else {
388
-				return $terms;
389
-			}
390
-		}
391
-
392
-		usort( $terms, array( $this, 'taxcmp' ) );
393
-		return $terms;
394
-	}
395
-
396
-	public function taxcmp( $a, $b ) {
397
-		if ( $a->lsx_team_term_order == $b->lsx_team_term_order )
398
-			return 0;
399
-
400
-		return ( $a->lsx_team_term_order < $b->lsx_team_term_order ) ? -1 : 1;
401
-	}
402
-
403
-	public function get_lsx_team_scporder_options_objects() {
404
-		return array(
405
-			'team' => esc_html_x( 'Team Member', 'post type singular name', 'lsx-team' ),
406
-		);
407
-	}
408
-
409
-	public function get_lsx_team_scporder_options_tags() {
410
-		return array(
411
-			'team_role' => esc_html_x( 'Role', 'taxonomy singular name', 'lsx-team' ),
412
-		);
413
-	}
233
+               foreach ( $results as $result ) {
234
+                    $menu_order_arr[] = $result->lsx_team_term_order;
235
+               }
236
+          }
237
+
238
+          sort( $menu_order_arr );
239
+
240
+          foreach ( $data as $key => $values ) {
241
+               foreach ( $values as $position => $id ) {
242
+                    $wpdb->update( $wpdb->terms,
243
+                         array(
244
+                              'lsx_team_term_order' => $menu_order_arr[ $position ],
245
+                         ),
246
+                         array(
247
+                              'term_id' => intval( $id ),
248
+                         )
249
+                    );
250
+               }
251
+          }
252
+     }
253
+
254
+     public function lsx_team_scporder_previous_post_where( $where ) {
255
+          global $post;
256
+          $objects = $this->get_lsx_team_scporder_options_objects();
257
+
258
+          if ( empty( $objects ) )
259
+               return $where;
260
+
261
+          if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
262
+               $current_menu_order = $post->menu_order;
263
+               $where = "WHERE p.menu_order > '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
264
+          }
265
+
266
+          return $where;
267
+     }
268
+
269
+     public function lsx_team_scporder_previous_post_sort( $orderby ) {
270
+          global $post;
271
+          $objects = $this->get_lsx_team_scporder_options_objects();
272
+
273
+          if ( empty( $objects ) )
274
+               return $orderby;
275
+
276
+          if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
277
+               $orderby = 'ORDER BY p.menu_order ASC LIMIT 1';
278
+          }
279
+
280
+          return $orderby;
281
+     }
282
+
283
+     public function lsx_team_scporder_next_post_where( $where ) {
284
+          global $post;
285
+          $objects = $this->get_lsx_team_scporder_options_objects();
286
+
287
+          if ( empty( $objects ) )
288
+               return $where;
289
+
290
+          if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
291
+               $current_menu_order = $post->menu_order;
292
+               $where = "WHERE p.menu_order < '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'";
293
+          }
294
+
295
+          return $where;
296
+     }
297
+
298
+     public function lsx_team_scporder_next_post_sort( $orderby ) {
299
+          global $post;
300
+          $objects = $this->get_lsx_team_scporder_options_objects();
301
+
302
+          if ( empty( $objects ) )
303
+               return $orderby;
304
+
305
+          if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) {
306
+               $orderby = 'ORDER BY p.menu_order DESC LIMIT 1';
307
+          }
308
+
309
+          return $orderby;
310
+     }
311
+
312
+     public function lsx_team_scporder_pre_get_posts( $wp_query ) {
313
+          $objects = $this->get_lsx_team_scporder_options_objects();
314
+
315
+          if ( empty( $objects ) )
316
+               return false;
317
+
318
+          if ( is_admin() ) {
319
+               if ( isset( $wp_query->query['post_type'] ) && ! isset( $_GET['orderby'] ) ) {
320
+                    if ( array_key_exists( $wp_query->query['post_type'], $objects ) ) {
321
+                         $wp_query->set( 'orderby', 'menu_order' );
322
+                         $wp_query->set( 'order', 'ASC' );
323
+                    }
324
+               }
325
+          } else {
326
+               $active = false;
327
+
328
+               if ( isset( $wp_query->query['post_type'] ) ) {
329
+                    if ( ! is_array( $wp_query->query['post_type'] ) ) {
330
+                         if ( array_key_exists( $wp_query->query['post_type'], $objects ) ) {
331
+                              $active = true;
332
+                         }
333
+                    }
334
+               } else {
335
+                    if ( array_key_exists( 'post', $objects ) ) {
336
+                         $active = true;
337
+                    }
338
+               }
339
+
340
+               if ( ! $active )
341
+                    return false;
342
+
343
+               if ( isset( $wp_query->query['suppress_filters'] ) ) {
344
+                    if ( $wp_query->get( 'orderby' ) == 'date' )
345
+                         $wp_query->set( 'orderby', 'menu_order' );
346
+                    if ( $wp_query->get( 'order' ) == 'DESC' )
347
+                         $wp_query->set( 'order', 'ASC' );
348
+               } else {
349
+                    if ( ! $wp_query->get( 'orderby' ) )
350
+                         $wp_query->set( 'orderby', 'menu_order' );
351
+                    if ( ! $wp_query->get( 'order' ) )
352
+                         $wp_query->set( 'order', 'ASC' );
353
+               }
354
+          }
355
+     }
356
+
357
+     public function lsx_team_scporder_get_terms_orderby( $orderby, $args ) {
358
+          if ( is_admin() )
359
+               return $orderby;
360
+
361
+          $tags = $this->get_lsx_team_scporder_options_tags();
362
+
363
+          if ( ! isset( $args['taxonomy'] ) )
364
+               return $orderby;
365
+
366
+          $taxonomy = $args['taxonomy'];
367
+          if ( is_array( $taxonomy ) && count( $taxonomy ) == 1 )
368
+               $taxonomy = $taxonomy[0];
369
+          if ( ! array_key_exists( $taxonomy[0], $tags ) )
370
+               return $orderby;
371
+
372
+          $orderby = 't.lsx_team_term_order';
373
+          return $orderby;
374
+     }
375
+
376
+     public function lsx_team_scporder_get_object_terms( $terms ) {
377
+          $tags = $this->get_lsx_team_scporder_options_tags();
378
+
379
+          if ( is_admin() && isset( $_GET['orderby'] ) )
380
+               return $terms;
381
+
382
+          foreach ( $terms as $key => $term ) {
383
+               if ( is_object( $term ) && isset( $term->taxonomy ) ) {
384
+                    $taxonomy = $term->taxonomy;
385
+                    if ( ! array_key_exists( $taxonomy, $tags ) )
386
+                         return $terms;
387
+               } else {
388
+                    return $terms;
389
+               }
390
+          }
391
+
392
+          usort( $terms, array( $this, 'taxcmp' ) );
393
+          return $terms;
394
+     }
395
+
396
+     public function taxcmp( $a, $b ) {
397
+          if ( $a->lsx_team_term_order == $b->lsx_team_term_order )
398
+               return 0;
399
+
400
+          return ( $a->lsx_team_term_order < $b->lsx_team_term_order ) ? -1 : 1;
401
+     }
402
+
403
+     public function get_lsx_team_scporder_options_objects() {
404
+          return array(
405
+               'team' => esc_html_x( 'Team Member', 'post type singular name', 'lsx-team' ),
406
+          );
407
+     }
408
+
409
+     public function get_lsx_team_scporder_options_tags() {
410
+          return array(
411
+               'team_role' => esc_html_x( 'Role', 'taxonomy singular name', 'lsx-team' ),
412
+          );
413
+     }
414 414
 
415 415
 }
416 416
 
@@ -420,30 +420,30 @@  discard block
 block discarded – undo
420 420
 register_uninstall_hook( __FILE__, 'lsx_team_scporder_uninstall' );
421 421
 
422 422
 function lsx_team_scporder_uninstall() {
423
-	global $wpdb;
423
+     global $wpdb;
424 424
 
425
-	if ( function_exists( 'is_multisite' ) && is_multisite() ) {
426
-		$curr_blog = $wpdb->blogid;
427
-		$blogids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
425
+     if ( function_exists( 'is_multisite' ) && is_multisite() ) {
426
+          $curr_blog = $wpdb->blogid;
427
+          $blogids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
428 428
 
429
-		foreach ( $blogids as $blog_id ) {
430
-			switch_to_blog( $blog_id );
431
-			lsx_team_scporder_uninstall_db();
432
-		}
429
+          foreach ( $blogids as $blog_id ) {
430
+               switch_to_blog( $blog_id );
431
+               lsx_team_scporder_uninstall_db();
432
+          }
433 433
 
434
-		switch_to_blog( $curr_blog );
435
-	} else {
436
-		lsx_team_scporder_uninstall_db();
437
-	}
434
+          switch_to_blog( $curr_blog );
435
+     } else {
436
+          lsx_team_scporder_uninstall_db();
437
+     }
438 438
 }
439 439
 
440 440
 function lsx_team_scporder_uninstall_db() {
441
-	global $wpdb;
442
-	$result = $wpdb->query( "DESCRIBE $wpdb->terms `lsx_team_term_order`" );
441
+     global $wpdb;
442
+     $result = $wpdb->query( "DESCRIBE $wpdb->terms `lsx_team_term_order`" );
443 443
 
444
-	if ( $result ) {
445
-		$result = $wpdb->query( "ALTER TABLE $wpdb->terms DROP `lsx_team_term_order`" );
446
-	}
444
+     if ( $result ) {
445
+          $result = $wpdb->query( "ALTER TABLE $wpdb->terms DROP `lsx_team_term_order`" );
446
+     }
447 447
 
448
-	delete_option( 'lsx_team_scporder_install' );
448
+     delete_option( 'lsx_team_scporder_install' );
449 449
 }
Please login to merge, or discard this patch.
includes/functions.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Add our action to init to set up our vars first.
14 14
  */
15 15
 function lsx_team_load_plugin_textdomain() {
16
-	load_plugin_textdomain( 'lsx-team', false, basename( LSX_TEAM_PATH ) . '/languages' );
16
+     load_plugin_textdomain( 'lsx-team', false, basename( LSX_TEAM_PATH ) . '/languages' );
17 17
 }
18 18
 add_action( 'init', 'lsx_team_load_plugin_textdomain' );
19 19
 
@@ -25,23 +25,23 @@  discard block
 block discarded – undo
25 25
  * @return mixed           Option value
26 26
  */
27 27
 function team_get_options() {
28
-	$options = array();
29
-	if ( function_exists( 'tour_operator' ) ) {
30
-		$options = get_option( '_lsx-to_settings', false );
31
-	} else {
32
-		$options = get_option( '_lsx_settings', false );
33
-
34
-		if ( false === $options ) {
35
-			$options = get_option( '_lsx_lsx-settings', false );
36
-		}
37
-	}
38
-
39
-	// If there are new CMB2 options available, then use those.
40
-	$new_options = get_option( 'lsx_team_options', false );
41
-	if ( false !== $new_options ) {
42
-		$options['display'] = $new_options;
43
-	}
44
-	return $options;
28
+     $options = array();
29
+     if ( function_exists( 'tour_operator' ) ) {
30
+          $options = get_option( '_lsx-to_settings', false );
31
+     } else {
32
+          $options = get_option( '_lsx_settings', false );
33
+
34
+          if ( false === $options ) {
35
+               $options = get_option( '_lsx_lsx-settings', false );
36
+          }
37
+     }
38
+
39
+     // If there are new CMB2 options available, then use those.
40
+     $new_options = get_option( 'lsx_team_options', false );
41
+     if ( false !== $new_options ) {
42
+          $options['display'] = $new_options;
43
+     }
44
+     return $options;
45 45
 }
46 46
 
47 47
 /**
@@ -52,44 +52,44 @@  discard block
 block discarded – undo
52 52
  * @return mixed           Option value
53 53
  */
54 54
 function team_get_option( $key = '', $default = false ) {
55
-	$options = array();
56
-	$value   = $default;
57
-	if ( function_exists( 'tour_operator' ) ) {
58
-		$options = get_option( '_lsx-to_settings', false );
59
-	} else {
60
-		$options = get_option( '_lsx_settings', false );
61
-
62
-		if ( false === $options ) {
63
-			$options = get_option( '_lsx_lsx-settings', false );
64
-		}
65
-	}
66
-
67
-	// If there are new CMB2 options available, then use those.
68
-	$new_options = get_option( 'lsx_team_options', false );
69
-	if ( false !== $new_options ) {
70
-		$options['display'] = $new_options;
71
-	}
72
-
73
-	if ( isset( $options['display'] ) && isset( $options['display'][ $key ] ) ) {
74
-		$value = $options['display'][ $key ];
75
-	}
76
-	return $value;
55
+     $options = array();
56
+     $value   = $default;
57
+     if ( function_exists( 'tour_operator' ) ) {
58
+          $options = get_option( '_lsx-to_settings', false );
59
+     } else {
60
+          $options = get_option( '_lsx_settings', false );
61
+
62
+          if ( false === $options ) {
63
+               $options = get_option( '_lsx_lsx-settings', false );
64
+          }
65
+     }
66
+
67
+     // If there are new CMB2 options available, then use those.
68
+     $new_options = get_option( 'lsx_team_options', false );
69
+     if ( false !== $new_options ) {
70
+          $options['display'] = $new_options;
71
+     }
72
+
73
+     if ( isset( $options['display'] ) && isset( $options['display'][ $key ] ) ) {
74
+          $value = $options['display'][ $key ];
75
+     }
76
+     return $value;
77 77
 }
78 78
 
79 79
 /**
80 80
  * Wraps the output class in a function to be called in templates
81 81
  */
82 82
 function lsx_team( $args ) {
83
-	$lsx_team = new LSX_Team;
84
-	echo wp_kses_post( $lsx_team->output( $args ) );
83
+     $lsx_team = new LSX_Team;
84
+     echo wp_kses_post( $lsx_team->output( $args ) );
85 85
 }
86 86
 
87 87
 /**
88 88
  * Shortcode
89 89
  */
90 90
 function lsx_team_shortcode( $atts ) {
91
-	$lsx_team = new LSX_Team;
92
-	return $lsx_team->output( $atts );
91
+     $lsx_team = new LSX_Team;
92
+     return $lsx_team->output( $atts );
93 93
 }
94 94
 add_shortcode( 'lsx_team', 'lsx_team_shortcode' );
95 95
 
@@ -101,16 +101,16 @@  discard block
 block discarded – undo
101 101
  * @param [type] $request request.
102 102
  */
103 103
 function lsx_team_get_images_urls( $object, $field_name, $request ) {
104
-	$medium     = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'medium' );
105
-	$medium_url = $medium['0'];
104
+     $medium     = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'medium' );
105
+     $medium_url = $medium['0'];
106 106
 
107
-	$large     = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'large' );
108
-	$large_url = $large['0'];
107
+     $large     = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'large' );
108
+     $large_url = $large['0'];
109 109
 
110
-	return array(
111
-		'medium' => $medium_url,
112
-		'large'  => $large_url,
113
-	);
110
+     return array(
111
+          'medium' => $medium_url,
112
+          'large'  => $large_url,
113
+     );
114 114
 }
115 115
 
116 116
 /**
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
  * @return void
120 120
  */
121 121
 function lsx_team_register_images_field() {
122
-	register_rest_field(
123
-		'team',
124
-		'images',
125
-		array(
126
-			'get_callback'    => 'lsx_team_get_images_urls',
127
-			'update_callback' => null,
128
-			'schema'          => null,
129
-		)
130
-	);
122
+     register_rest_field(
123
+          'team',
124
+          'images',
125
+          array(
126
+               'get_callback'    => 'lsx_team_get_images_urls',
127
+               'update_callback' => null,
128
+               'schema'          => null,
129
+          )
130
+     );
131 131
 }
132 132
 add_action( 'rest_api_init', 'lsx_team_register_images_field' );
133 133
 
@@ -139,25 +139,25 @@  discard block
 block discarded – undo
139 139
  * @param [type] $request request.
140 140
  */
141 141
 function lsx_team_get_additional_meta( $object, $field_name, $request ) {
142
-	$role      = get_the_terms( get_the_ID(), 'team_role' );
143
-	$job_title = get_post_meta( get_the_ID(), 'lsx_job_title', true );
144
-	$email     = get_post_meta( get_the_ID(), 'lsx_email_contact', true );
145
-	$phone     = get_post_meta( get_the_ID(), 'lsx_tel', true );
146
-	$skype     = get_post_meta( get_the_ID(), 'lsx_skype', true );
147
-	$facebook  = get_post_meta( get_the_ID(), 'lsx_facebook', true );
148
-	$twitter   = get_post_meta( get_the_ID(), 'lsx_twitter', true );
149
-	$linkedin  = get_post_meta( get_the_ID(), 'lsx_linkedin', true );
150
-
151
-	return array(
152
-		'role'      => $role,
153
-		'job_title' => $job_title,
154
-		'email'     => $email,
155
-		'phone'     => $phone,
156
-		'skype'     => $skype,
157
-		'facebook'  => $facebook,
158
-		'twitter'   => $twitter,
159
-		'linkedin'  => $linkedin,
160
-	);
142
+     $role      = get_the_terms( get_the_ID(), 'team_role' );
143
+     $job_title = get_post_meta( get_the_ID(), 'lsx_job_title', true );
144
+     $email     = get_post_meta( get_the_ID(), 'lsx_email_contact', true );
145
+     $phone     = get_post_meta( get_the_ID(), 'lsx_tel', true );
146
+     $skype     = get_post_meta( get_the_ID(), 'lsx_skype', true );
147
+     $facebook  = get_post_meta( get_the_ID(), 'lsx_facebook', true );
148
+     $twitter   = get_post_meta( get_the_ID(), 'lsx_twitter', true );
149
+     $linkedin  = get_post_meta( get_the_ID(), 'lsx_linkedin', true );
150
+
151
+     return array(
152
+          'role'      => $role,
153
+          'job_title' => $job_title,
154
+          'email'     => $email,
155
+          'phone'     => $phone,
156
+          'skype'     => $skype,
157
+          'facebook'  => $facebook,
158
+          'twitter'   => $twitter,
159
+          'linkedin'  => $linkedin,
160
+     );
161 161
 }
162 162
 
163 163
 /**
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
  * @return void
167 167
  */
168 168
 function lsx_team_register_additional_meta() {
169
-	register_rest_field(
170
-		'team',
171
-		'additional_meta',
172
-		array(
173
-			'get_callback'    => 'lsx_team_get_additional_meta',
174
-			'update_callback' => null,
175
-			'schema'          => null,
176
-		)
177
-	);
169
+     register_rest_field(
170
+          'team',
171
+          'additional_meta',
172
+          array(
173
+               'get_callback'    => 'lsx_team_get_additional_meta',
174
+               'update_callback' => null,
175
+               'schema'          => null,
176
+          )
177
+     );
178 178
 }
179 179
 add_action( 'rest_api_init', 'lsx_team_register_additional_meta' );
Please login to merge, or discard this patch.
lsx-team.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 // If this file is called directly, abort.
16 16
 if ( ! defined( 'WPINC' ) ) {
17
-	die;
17
+     die;
18 18
 }
19 19
 
20 20
 define( 'LSX_TEAM_PATH', plugin_dir_path( __FILE__ ) );
Please login to merge, or discard this patch.
templates/content-single-team.php 1 patch
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -5,137 +5,137 @@
 block discarded – undo
5 5
 ?>
6 6
 
7 7
 <?php
8
-	global $lsx_team;
9
-
10
-	$thumbnail = $lsx_team->get_thumbnail( get_the_ID(), 'lsx-team-single' );
11
-
12
-	$job_title = get_post_meta( get_the_ID(), 'lsx_job_title', true );
13
-
14
-	$links = array(
15
-		'facebook'  => get_post_meta( get_the_ID(), 'lsx_facebook', true ),
16
-		'twitter'   => get_post_meta( get_the_ID(), 'lsx_twitter', true ),
17
-		'linkedin'  => get_post_meta( get_the_ID(), 'lsx_linkedin', true ),
18
-		'github'    => get_post_meta( get_the_ID(), 'lsx_github', true ),
19
-		'wordpress' => get_post_meta( get_the_ID(), 'lsx_wordpress', true ),
20
-	);
21
-
22
-	foreach ( $links as $service => $link ) {
23
-		if ( empty( $link ) ) {
24
-			unset( $links[ $service ] );
25
-		}
26
-	}
27
-
28
-	$email = get_post_meta( get_the_ID(), 'lsx_email_contact', true );
29
-	$phone = get_post_meta( get_the_ID(), 'lsx_tel', true );
30
-	$skype = get_post_meta( get_the_ID(), 'lsx_skype', true );
31
-
32
-	$phone_attr = $phone;
33
-	$phone_attr = str_replace( ' ', '', $phone_attr );
34
-	$phone_attr = str_replace( '+', '', $phone_attr );
35
-	$phone_attr = str_replace( '(', '', $phone_attr );
36
-	$phone_attr = str_replace( ')', '', $phone_attr );
37
-	$phone_attr = str_replace( '.', '', $phone_attr );
38
-
39
-	// Tabs
40
-
41
-	$tabs = array();
42
-
43
-	// Tab Posts
44
-
45
-	$site_user = get_post_meta( get_the_ID(), 'lsx_site_user', true );
46
-
47
-	if ( ! empty( $site_user ) ) {
48
-		if ( is_user_member_of_blog( $site_user ) ) {
49
-			$user_posts = count_user_posts( $site_user, 'post' );
50
-
51
-			if ( $user_posts > 0 ) {
52
-				$params = array(
53
-					'post_type' => 'post',
54
-					'author' => $site_user,
55
-					'posts_per_page' => 9,
56
-					'order' => 'DESC',
57
-					'orderby' => 'date',
58
-					'fields' => 'ids',
59
-					'tax_query' => array(
60
-						array(
61
-							'taxonomy' => 'post_format',
62
-							'field' => 'slug',
63
-							'terms' => array(
64
-								'post-format-aside',
65
-								'post-format-audio',
66
-								'post-format-chat',
67
-								'post-format-gallery',
68
-								'post-format-image',
69
-								'post-format-link',
70
-								'post-format-quote',
71
-								'post-format-status',
72
-								'post-format-video',
73
-							),
74
-							'operator' => 'NOT IN',
75
-						),
76
-					),
77
-				);
78
-
79
-				$posts_query = new \WP_Query( $params );
80
-
81
-				if ( $posts_query->have_posts() ) {
82
-					$tab_post['post_type'] = 'post';
83
-					$tab_post['title'] = esc_html__( 'Posts', 'lsx-team' );
84
-					$tab_post['posts'] = $posts_query->posts;
85
-
86
-					if ( ! empty( $tab_post['posts'] ) ) {
87
-						$post_ids = join( ',', $tab_post['posts'] );
88
-						$tab_post['shortcode'] = '[lsx_posts columns="3" include="' . $post_ids . '"]';
89
-						$tabs[] = $tab_post;
90
-					}
91
-				}
92
-			}
93
-		}
94
-	}
95
-
96
-	// Tab Projects
97
-
98
-	$tab_project['post_type'] = 'project';
99
-	$tab_project['title'] = esc_html__( 'Projects', 'lsx-team' );
100
-	$tab_project['posts'] = get_post_meta( get_the_ID(), 'project_to_team', false );
101
-
102
-	if ( is_plugin_active( 'lsx-projects/lsx-projects.php' ) && ( ! empty( $tab_project['posts'] ) ) ) {
103
-		$post_ids = join( ',', $tab_project['posts'] );
104
-		$tab_project['shortcode'] = '[lsx_projects columns="3" include="' . $post_ids . '"]';
105
-		$tabs[] = $tab_project;
106
-	}
107
-
108
-	// Tab Services
109
-
110
-	if ( is_plugin_active( 'lsx-services/lsx-services.php' ) ) {
111
-		$tab_service['post_type'] = 'service';
112
-		$tab_service['title'] = esc_html__( 'Services', 'lsx-team' );
113
-		$tab_service['posts'] = get_post_meta( get_the_ID(), 'service_to_team', false );
114
-
115
-		if ( ! empty( $tab_service['posts'] ) ) {
116
-			$post_ids = join( ',', $tab_service['posts'] );
117
-			$tab_service['shortcode'] = '[lsx_services columns="3" include="' . $post_ids . '"]';
118
-			$tabs[] = $tab_service;
119
-		}
120
-	}
121
-
122
-	// Tab Testimonials
123
-
124
-	$tab_testimonial['post_type'] = 'testimonial';
125
-	$tab_testimonial['title'] = esc_html__( 'Testimonials', 'lsx-team' );
126
-	$tab_testimonial['posts'] = get_post_meta( get_the_ID(), 'testimonial_to_team', false );
127
-
128
-	if ( is_plugin_active( 'lsx-testimonials/lsx-testimonials.php' ) && ( ! empty( $tab_testimonial['posts'] ) ) ) {
129
-		if ( count( $tab_testimonial['posts'] ) <= 2 ) {
130
-			$columns = count( $tab_testimonial['posts'] );
131
-		} else {
132
-			$columns = 2;
133
-		}
134
-
135
-		$post_ids = join( ',', $tab_testimonial['posts'] );
136
-		$tab_testimonial['shortcode'] = '[lsx_testimonials columns="' . $columns . '" include="' . $post_ids . '" orderby="date" order="DESC" display="excerpt"]';
137
-		$tabs[] = $tab_testimonial;
138
-	}
8
+     global $lsx_team;
9
+
10
+     $thumbnail = $lsx_team->get_thumbnail( get_the_ID(), 'lsx-team-single' );
11
+
12
+     $job_title = get_post_meta( get_the_ID(), 'lsx_job_title', true );
13
+
14
+     $links = array(
15
+          'facebook'  => get_post_meta( get_the_ID(), 'lsx_facebook', true ),
16
+          'twitter'   => get_post_meta( get_the_ID(), 'lsx_twitter', true ),
17
+          'linkedin'  => get_post_meta( get_the_ID(), 'lsx_linkedin', true ),
18
+          'github'    => get_post_meta( get_the_ID(), 'lsx_github', true ),
19
+          'wordpress' => get_post_meta( get_the_ID(), 'lsx_wordpress', true ),
20
+     );
21
+
22
+     foreach ( $links as $service => $link ) {
23
+          if ( empty( $link ) ) {
24
+               unset( $links[ $service ] );
25
+          }
26
+     }
27
+
28
+     $email = get_post_meta( get_the_ID(), 'lsx_email_contact', true );
29
+     $phone = get_post_meta( get_the_ID(), 'lsx_tel', true );
30
+     $skype = get_post_meta( get_the_ID(), 'lsx_skype', true );
31
+
32
+     $phone_attr = $phone;
33
+     $phone_attr = str_replace( ' ', '', $phone_attr );
34
+     $phone_attr = str_replace( '+', '', $phone_attr );
35
+     $phone_attr = str_replace( '(', '', $phone_attr );
36
+     $phone_attr = str_replace( ')', '', $phone_attr );
37
+     $phone_attr = str_replace( '.', '', $phone_attr );
38
+
39
+     // Tabs
40
+
41
+     $tabs = array();
42
+
43
+     // Tab Posts
44
+
45
+     $site_user = get_post_meta( get_the_ID(), 'lsx_site_user', true );
46
+
47
+     if ( ! empty( $site_user ) ) {
48
+          if ( is_user_member_of_blog( $site_user ) ) {
49
+               $user_posts = count_user_posts( $site_user, 'post' );
50
+
51
+               if ( $user_posts > 0 ) {
52
+                    $params = array(
53
+                         'post_type' => 'post',
54
+                         'author' => $site_user,
55
+                         'posts_per_page' => 9,
56
+                         'order' => 'DESC',
57
+                         'orderby' => 'date',
58
+                         'fields' => 'ids',
59
+                         'tax_query' => array(
60
+                              array(
61
+                                   'taxonomy' => 'post_format',
62
+                                   'field' => 'slug',
63
+                                   'terms' => array(
64
+                                        'post-format-aside',
65
+                                        'post-format-audio',
66
+                                        'post-format-chat',
67
+                                        'post-format-gallery',
68
+                                        'post-format-image',
69
+                                        'post-format-link',
70
+                                        'post-format-quote',
71
+                                        'post-format-status',
72
+                                        'post-format-video',
73
+                                   ),
74
+                                   'operator' => 'NOT IN',
75
+                              ),
76
+                         ),
77
+                    );
78
+
79
+                    $posts_query = new \WP_Query( $params );
80
+
81
+                    if ( $posts_query->have_posts() ) {
82
+                         $tab_post['post_type'] = 'post';
83
+                         $tab_post['title'] = esc_html__( 'Posts', 'lsx-team' );
84
+                         $tab_post['posts'] = $posts_query->posts;
85
+
86
+                         if ( ! empty( $tab_post['posts'] ) ) {
87
+                              $post_ids = join( ',', $tab_post['posts'] );
88
+                              $tab_post['shortcode'] = '[lsx_posts columns="3" include="' . $post_ids . '"]';
89
+                              $tabs[] = $tab_post;
90
+                         }
91
+                    }
92
+               }
93
+          }
94
+     }
95
+
96
+     // Tab Projects
97
+
98
+     $tab_project['post_type'] = 'project';
99
+     $tab_project['title'] = esc_html__( 'Projects', 'lsx-team' );
100
+     $tab_project['posts'] = get_post_meta( get_the_ID(), 'project_to_team', false );
101
+
102
+     if ( is_plugin_active( 'lsx-projects/lsx-projects.php' ) && ( ! empty( $tab_project['posts'] ) ) ) {
103
+          $post_ids = join( ',', $tab_project['posts'] );
104
+          $tab_project['shortcode'] = '[lsx_projects columns="3" include="' . $post_ids . '"]';
105
+          $tabs[] = $tab_project;
106
+     }
107
+
108
+     // Tab Services
109
+
110
+     if ( is_plugin_active( 'lsx-services/lsx-services.php' ) ) {
111
+          $tab_service['post_type'] = 'service';
112
+          $tab_service['title'] = esc_html__( 'Services', 'lsx-team' );
113
+          $tab_service['posts'] = get_post_meta( get_the_ID(), 'service_to_team', false );
114
+
115
+          if ( ! empty( $tab_service['posts'] ) ) {
116
+               $post_ids = join( ',', $tab_service['posts'] );
117
+               $tab_service['shortcode'] = '[lsx_services columns="3" include="' . $post_ids . '"]';
118
+               $tabs[] = $tab_service;
119
+          }
120
+     }
121
+
122
+     // Tab Testimonials
123
+
124
+     $tab_testimonial['post_type'] = 'testimonial';
125
+     $tab_testimonial['title'] = esc_html__( 'Testimonials', 'lsx-team' );
126
+     $tab_testimonial['posts'] = get_post_meta( get_the_ID(), 'testimonial_to_team', false );
127
+
128
+     if ( is_plugin_active( 'lsx-testimonials/lsx-testimonials.php' ) && ( ! empty( $tab_testimonial['posts'] ) ) ) {
129
+          if ( count( $tab_testimonial['posts'] ) <= 2 ) {
130
+               $columns = count( $tab_testimonial['posts'] );
131
+          } else {
132
+               $columns = 2;
133
+          }
134
+
135
+          $post_ids = join( ',', $tab_testimonial['posts'] );
136
+          $tab_testimonial['shortcode'] = '[lsx_testimonials columns="' . $columns . '" include="' . $post_ids . '" orderby="date" order="DESC" display="excerpt"]';
137
+          $tabs[] = $tab_testimonial;
138
+     }
139 139
 ?>
140 140
 
141 141
 <?php lsx_entry_before(); ?>
Please login to merge, or discard this patch.
templates/content-archive-team-careers-cta.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -6,12 +6,12 @@
 block discarded – undo
6 6
 
7 7
 <?php if ( ! empty( team_get_option( 'team_careers_cta_enable' ) ) ) : ?>
8 8
 	<?php
9
-		$thumbnail = '<img loading="lazy" class="img-responsive wp-post-image" src="https://www.gravatar.com/avatar/none?d=mm&s=170" width="170" />';
10
-		$title     = team_get_option( 'team_careers_cta_title' );
11
-		$tagline   = team_get_option( 'team_careers_cta_tagline' );
12
-		$link_text = team_get_option( 'team_careers_cta_link_text' );
13
-		$link      = team_get_option( 'team_careers_cta_link' );
14
-	?>
9
+          $thumbnail = '<img loading="lazy" class="img-responsive wp-post-image" src="https://www.gravatar.com/avatar/none?d=mm&s=170" width="170" />';
10
+          $title     = team_get_option( 'team_careers_cta_title' );
11
+          $tagline   = team_get_option( 'team_careers_cta_tagline' );
12
+          $link_text = team_get_option( 'team_careers_cta_link_text' );
13
+          $link      = team_get_option( 'team_careers_cta_link' );
14
+     ?>
15 15
 
16 16
 	<div class="col-xs-12 col-sm-6 col-md-3">
17 17
 		<article class="lsx-team-slot">
Please login to merge, or discard this patch.
templates/content-archive-team.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@  discard block
 block discarded – undo
5 5
 ?>
6 6
 
7 7
 <?php
8
-	global $lsx_team;
8
+     global $lsx_team;
9 9
 
10
-	$thumbnail = $lsx_team->get_thumbnail( get_the_ID(), 'lsx-team-archive' );
10
+     $thumbnail = $lsx_team->get_thumbnail( get_the_ID(), 'lsx-team-archive' );
11 11
 
12
-	$job_title = get_post_meta( get_the_ID(), 'lsx_job_title', true );
12
+     $job_title = get_post_meta( get_the_ID(), 'lsx_job_title', true );
13 13
 ?>
14 14
 
15 15
 <?php lsx_entry_before(); ?>
@@ -44,4 +44,4 @@  discard block
 block discarded – undo
44 44
 </div>
45 45
 
46 46
 <?php
47
-	lsx_entry_after();
47
+     lsx_entry_after();
Please login to merge, or discard this patch.
templates/archive-team.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,13 +23,13 @@
 block discarded – undo
23 23
 				<div class="row row-flex">
24 24
 
25 25
 					<?php
26
-						while ( have_posts() ) {
27
-							the_post();
28
-							include( LSX_TEAM_PATH . '/templates/content-archive-team.php' );
29
-						}
26
+                              while ( have_posts() ) {
27
+                                   the_post();
28
+                                   include( LSX_TEAM_PATH . '/templates/content-archive-team.php' );
29
+                              }
30 30
 
31
-						include( LSX_TEAM_PATH . '/templates/content-archive-team-careers-cta.php' );
32
-					?>
31
+                              include( LSX_TEAM_PATH . '/templates/content-archive-team-careers-cta.php' );
32
+                         ?>
33 33
 
34 34
 				</div>
35 35
 			</div>
Please login to merge, or discard this patch.
classes/class-lsx-team-admin.php 1 patch
Indentation   +445 added lines, -445 removed lines patch added patch discarded remove patch
@@ -11,451 +11,451 @@
 block discarded – undo
11 11
 
12 12
 class LSX_Team_Admin {
13 13
 
14
-	public function __construct() {
15
-		$this->load_classes();
16
-
17
-		add_action( 'init', array( $this, 'post_type_setup' ) );
18
-		add_action( 'init', array( $this, 'taxonomy_setup' ) );
19
-
20
-		add_action( 'cmb2_admin_init', array( $this, 'details_metabox' ) );
21
-		add_action( 'cmb2_admin_init', array( $this, 'projects_details_metabox' ) );
22
-		add_action( 'cmb2_admin_init', array( $this, 'services_details_metabox' ) );
23
-		add_action( 'cmb2_admin_init', array( $this, 'testimonials_details_metabox' ) );
24
-
25
-		add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) );
26
-
27
-		add_filter( 'type_url_form_media', array( $this, 'change_attachment_field_button' ), 20, 1 );
28
-		add_filter( 'enter_title_here', array( $this, 'change_title_text' ) );
29
-	}
30
-
31
-	/**
32
-	 * Loads the admin subclasses
33
-	 */
34
-	private function load_classes() {
35
-		require_once LSX_TEAM_PATH . 'classes/admin/class-settings.php';
36
-		$this->settings = \lsx\team\classes\admin\Settings::get_instance();
37
-
38
-		require_once LSX_TEAM_PATH . 'classes/admin/class-settings-theme.php';
39
-		$this->settings_theme = \lsx\team\classes\admin\Settings_Theme::get_instance();
40
-	}
41
-
42
-	public function post_type_setup() {
43
-		$labels = array(
44
-			'name'               => esc_html_x( 'Team Members', 'post type general name', 'lsx-team' ),
45
-			'singular_name'      => esc_html_x( 'Team Member', 'post type singular name', 'lsx-team' ),
46
-			'add_new'            => esc_html_x( 'Add New', 'post type general name', 'lsx-team' ),
47
-			'add_new_item'       => esc_html__( 'Add New Team Member', 'lsx-team' ),
48
-			'edit_item'          => esc_html__( 'Edit Team Member', 'lsx-team' ),
49
-			'new_item'           => esc_html__( 'New Team Member', 'lsx-team' ),
50
-			'all_items'          => esc_html__( 'All Team Members', 'lsx-team' ),
51
-			'view_item'          => esc_html__( 'View Team Member', 'lsx-team' ),
52
-			'search_items'       => esc_html__( 'Search Team Members', 'lsx-team' ),
53
-			'not_found'          => esc_html__( 'No team members found', 'lsx-team' ),
54
-			'not_found_in_trash' => esc_html__( 'No team members found in Trash', 'lsx-team' ),
55
-			'parent_item_colon'  => '',
56
-			'menu_name'          => esc_html_x( 'Team Members', 'admin menu', 'lsx-team' ),
57
-		);
58
-
59
-		$args = array(
60
-			'labels'             => $labels,
61
-			'public'             => true,
62
-			'publicly_queryable' => true,
63
-			'show_ui'            => true,
64
-			'show_in_menu'       => true,
65
-			'menu_icon'          => 'dashicons-groups',
66
-			'query_var'          => true,
67
-			'rewrite'            => array(
68
-				'slug' => 'team',
69
-			),
70
-			'capability_type'    => 'post',
71
-			'has_archive'        => 'team',
72
-			'hierarchical'       => false,
73
-			'menu_position'      => null,
74
-			'supports'           => array(
75
-				'title',
76
-				'editor',
77
-				'excerpt',
78
-				'thumbnail',
79
-			),
80
-			'show_in_rest'          => true,
81
-			'rest_base'             => 'team',
82
-			'rest_controller_class' => 'WP_REST_Posts_Controller',
83
-		);
84
-
85
-		register_post_type( 'team', $args );
86
-	}
87
-
88
-	public function taxonomy_setup() {
89
-		$labels = array(
90
-			'name'              => esc_html_x( 'Roles', 'taxonomy general name', 'lsx-team' ),
91
-			'singular_name'     => esc_html_x( 'Role', 'taxonomy singular name', 'lsx-team' ),
92
-			'search_items'      => esc_html__( 'Search Roles', 'lsx-team' ),
93
-			'all_items'         => esc_html__( 'All Roles', 'lsx-team' ),
94
-			'parent_item'       => esc_html__( 'Parent Role', 'lsx-team' ),
95
-			'parent_item_colon' => esc_html__( 'Parent Role:', 'lsx-team' ),
96
-			'edit_item'         => esc_html__( 'Edit Role', 'lsx-team' ),
97
-			'update_item'       => esc_html__( 'Update Role', 'lsx-team' ),
98
-			'add_new_item'      => esc_html__( 'Add New Role', 'lsx-team' ),
99
-			'new_item_name'     => esc_html__( 'New Role Name', 'lsx-team' ),
100
-			'menu_name'         => esc_html__( 'Roles', 'lsx-team' ),
101
-		);
102
-
103
-		$args = array(
104
-			'hierarchical'      => true,
105
-			'labels'            => $labels,
106
-			'show_ui'           => true,
107
-			'show_admin_column' => true,
108
-			'query_var'         => true,
109
-			'rewrite'           => array(
110
-				'slug' => 'team-role',
111
-			),
112
-			'show_in_rest'          => true,
113
-			'rest_base'             => 'teamrole',
114
-			'rest_controller_class' => 'WP_REST_Terms_Controller',
115
-		);
116
-
117
-		register_taxonomy( 'team_role', array( 'team' ), $args );
118
-	}
119
-
120
-	/**
121
-	 * Define the metabox and field configurations.
122
-	 */
123
-	public function details_metabox() {
124
-
125
-		$prefix = 'lsx_';
126
-
127
-		$users = get_transient( 'lsx_team_users' );
128
-
129
-		if ( false === $users || '' === $users ) {
130
-			$users = get_users( array(
131
-				'role__in' => array( 'administrator', 'editor', 'author' ),
132
-			) );
133
-			set_transient( 'lsx_team_users', $users, 5 * 60 );
134
-		}
135
-
136
-		foreach ( $users as $user ) {
137
-			$user_array[] = array(
138
-				'name'  => $user->display_name,
139
-				'value' => $user->ID,
140
-			);
141
-		}
142
-
143
-		$cmb = new_cmb2_box(
144
-			array(
145
-				'id'           => $prefix . '_team',
146
-				'title'        => esc_html__( 'Team Member Details', 'lsx-team' ),
147
-				'object_types' => 'team',
148
-				'context'      => 'normal',
149
-				'priority'     => 'low',
150
-				'show_names'   => true,
151
-			)
152
-		);
153
-
154
-		$cmb->add_field(
155
-			array(
156
-				'name'         => esc_html__( 'Featured:', 'lsx-team' ),
157
-				'id'           => $prefix . 'featured',
158
-				'type'         => 'checkbox',
159
-				'value'        => 1,
160
-				'default'      => 0,
161
-				'show_in_rest' => true,
162
-			)
163
-		);
164
-
165
-		$cmb->add_field(
166
-			array(
167
-				'name'         => esc_html__( 'Site User', 'lsx-team' ),
168
-				'id'           => $prefix . 'site_user',
169
-				'allow_none'   => true,
170
-				'type'         => 'select',
171
-				'options'      => $user_array,
172
-				'show_in_rest' => true,
173
-			)
174
-		);
175
-
176
-		$cmb->add_field(
177
-			array(
178
-				'name'         => esc_html__( 'Job Title:', 'lsx-team' ),
179
-				'id'           => $prefix . 'job_title',
180
-				'type'         => 'text',
181
-				'show_in_rest' => true,
182
-			)
183
-		);
184
-
185
-		$cmb->add_field(
186
-			array(
187
-				'name'         => esc_html__( 'Location:', 'lsx-team' ),
188
-				'id'           => $prefix . 'location',
189
-				'type'         => 'text',
190
-				'show_in_rest' => true,
191
-			)
192
-		);
193
-
194
-		$cmb->add_field(
195
-			array(
196
-				'name'         => esc_html__( 'Contact Email Address:', 'lsx-team' ),
197
-				'id'           => $prefix . 'email_contact',
198
-				'type'         => 'text',
199
-				'show_in_rest' => true,
200
-			)
201
-		);
202
-
203
-		$cmb->add_field(
204
-			array(
205
-				'name'         => esc_html__( 'Gravatar Email Address:', 'lsx-team' ),
206
-				'desc'         => esc_html__( 'Used for Gravatar if a featured image is not set', 'lsx-team' ),
207
-				'id'           => $prefix . 'email_gravatar',
208
-				'type'         => 'text',
209
-				'show_in_rest' => true,
210
-			)
211
-		);
212
-
213
-		$cmb->add_field(
214
-			array(
215
-				'name'         => esc_html__( 'Telephone Number:', 'lsx-team' ),
216
-				'id'           => $prefix . 'tel',
217
-				'type'         => 'text',
218
-				'show_in_rest' => true,
219
-			)
220
-		);
221
-
222
-		$cmb->add_field(
223
-			array(
224
-				'name'         => esc_html__( 'Skype Name:', 'lsx-team' ),
225
-				'id'           => $prefix . 'skype',
226
-				'type'         => 'text',
227
-				'show_in_rest' => true,
228
-			)
229
-		);
230
-
231
-		$cmb->add_field(
232
-			array(
233
-				'name'         => esc_html__( 'Facebook URL', 'lsx-team' ),
234
-				'id'           => $prefix . 'facebook',
235
-				'type'         => 'text_url',
236
-				'show_in_rest' => true,
237
-			)
238
-		);
239
-
240
-		$cmb->add_field(
241
-			array(
242
-				'name'         => esc_html__( 'Twitter URL', 'lsx-team' ),
243
-				'id'           => $prefix . 'twitter',
244
-				'type'         => 'text_url',
245
-				'show_in_rest' => true,
246
-			)
247
-		);
248
-
249
-		$cmb->add_field(
250
-			array(
251
-				'name'         => esc_html__( 'LinkedIn URL', 'lsx-team' ),
252
-				'id'           => $prefix . 'linkedin',
253
-				'type'         => 'text_url',
254
-				'show_in_rest' => true,
255
-			)
256
-		);
257
-
258
-		$cmb->add_field(
259
-			array(
260
-				'name'         => esc_html__( 'Github URL', 'lsx-team' ),
261
-				'id'           => $prefix . 'github',
262
-				'type'         => 'text_url',
263
-				'show_in_rest' => true,
264
-			)
265
-		);
266
-
267
-		$cmb->add_field(
268
-			array(
269
-				'name'         => esc_html__( 'WordPress URL', 'lsx-team' ),
270
-				'id'           => $prefix . 'wordpress',
271
-				'type'         => 'text_url',
272
-				'show_in_rest' => true,
273
-			)
274
-		);
275
-	}
276
-
277
-	/**
278
-	 * Define the metabox and field configurations.
279
-	 */
280
-	public function projects_details_metabox() {
281
-
282
-		if ( class_exists( 'LSX_Projects' ) ) {
283
-
284
-			$prefix = 'lsx_';
285
-
286
-			$cmb = new_cmb2_box(
287
-				array(
288
-					'id'           => $prefix . '_team',
289
-					'context'      => 'normal',
290
-					'priority'     => 'low',
291
-					'show_names'   => true,
292
-					'object_types' => array( 'team' ),
293
-				)
294
-			);
295
-			$cmb->add_field(
296
-				array(
297
-					'name'       => __( 'Projects:', 'lsx-team' ),
298
-					'id'         => 'project_to_team',
299
-					'type'       => 'post_search_ajax',
300
-					'limit'      => 15,
301
-					'sortable'   => true,
302
-					'query_args' => array(
303
-						'post_type'      => array( 'project' ),
304
-						'post_status'    => array( 'publish' ),
305
-						'posts_per_page' => -1,
306
-					),
307
-				)
308
-			);
309
-		}
310
-	}
311
-
312
-	/**
313
-	 * Define the metabox and field configurations.
314
-	 */
315
-	public function services_details_metabox() {
316
-
317
-		if ( class_exists( 'LSX_Services' ) ) {
318
-
319
-			$prefix = 'lsx_';
320
-
321
-			$cmb = new_cmb2_box(
322
-				array(
323
-					'id'           => $prefix . '_team',
324
-					'context'      => 'normal',
325
-					'priority'     => 'low',
326
-					'show_names'   => true,
327
-					'object_types' => array( 'team' ),
328
-				)
329
-			);
330
-			$cmb->add_field(
331
-				array(
332
-					'name'       => __( 'Services:', 'lsx-team' ),
333
-					'id'         => 'service_to_team',
334
-					'type'       => 'post_search_ajax',
335
-					'limit'      => 15,
336
-					'sortable'   => true,
337
-					'query_args' => array(
338
-						'post_type'      => array( 'service' ),
339
-						'post_status'    => array( 'publish' ),
340
-						'posts_per_page' => -1,
341
-					),
342
-				)
343
-			);
344
-		}
345
-	}
346
-
347
-	/**
348
-	 * Define the metabox and field configurations.
349
-	 */
350
-	public function testimonials_details_metabox() {
351
-
352
-		if ( class_exists( 'LSX_Testimonials' ) ) {
353
-
354
-			$prefix = 'lsx_';
355
-
356
-			$cmb = new_cmb2_box(
357
-				array(
358
-					'id'           => $prefix . '_team',
359
-					'context'      => 'normal',
360
-					'priority'     => 'low',
361
-					'show_names'   => true,
362
-					'object_types' => array( 'team' ),
363
-				)
364
-			);
365
-			$cmb->add_field(
366
-				array(
367
-					'name'       => __( 'Testimonials:', 'lsx-team' ),
368
-					'id'         => 'testimonial_to_team',
369
-					'type'       => 'post_search_ajax',
370
-					'limit'      => 15,
371
-					'sortable'   => true,
372
-					'query_args' => array(
373
-						'post_type'      => array( 'testimonial' ),
374
-						'post_status'    => array( 'publish' ),
375
-						'posts_per_page' => -1,
376
-					),
377
-				)
378
-			);
379
-		}
380
-
381
-	}
382
-
383
-	/**
384
-	 * Sets up the "post relations".
385
-	 */
386
-	public function post_relations( $post_id, $field, $value ) {
387
-		$connections = array(
388
-			'team_to_testimonial',
389
-			'testimonial_to_team',
390
-
391
-			'team_to_project',
392
-			'project_to_team',
393
-
394
-			'team_to_service',
395
-			'service_to_team',
396
-		);
397
-
398
-		if ( in_array( $field['id'], $connections ) ) {
399
-			$this->save_related_post( $connections, $post_id, $field, $value );
400
-		}
401
-	}
402
-
403
-	/**
404
-	 * Save the reverse post relation.
405
-	 */
406
-	public function save_related_post( $connections, $post_id, $field, $value ) {
407
-		$ids = explode( '_to_', $field['id'] );
408
-		$relation = $ids[1] . '_to_' . $ids[0];
409
-
410
-		if ( in_array( $relation, $connections ) ) {
411
-			$previous_values = get_post_meta( $post_id, $field['id'], false );
412
-
413
-			if ( ! empty( $previous_values ) ) {
414
-				foreach ( $previous_values as $v ) {
415
-					delete_post_meta( $v, $relation, $post_id );
416
-				}
417
-			}
418
-
419
-			if ( is_array( $value ) ) {
420
-				foreach ( $value as $v ) {
421
-					if ( ! empty( $v ) ) {
422
-						add_post_meta( $v, $relation, $post_id );
423
-					}
424
-				}
425
-			}
426
-		}
427
-	}
428
-
429
-	public function assets() {
430
-		//wp_enqueue_media();
431
-		wp_enqueue_script( 'media-upload' );
432
-		wp_enqueue_script( 'thickbox' );
433
-		wp_enqueue_style( 'thickbox' );
434
-
435
-		wp_enqueue_script( 'lsx-team-admin', LSX_TEAM_URL . 'assets/js/lsx-team-admin.min.js', array( 'jquery' ), LSX_TEAM_VER );
436
-		wp_enqueue_style( 'lsx-team-admin', LSX_TEAM_URL . 'assets/css/lsx-team-admin.css', array(), LSX_TEAM_VER );
437
-	}
438
-
439
-	/**
440
-	 * Change the "Insert into Post" button text when media modal is used for feature images
441
-	 */
442
-	public function change_attachment_field_button( $html ) {
443
-		if ( isset( $_GET['feature_image_text_button'] ) ) {
444
-			$html = str_replace( 'value="Insert into Post"', sprintf( 'value="%s"', esc_html__( 'Select featured image', 'lsx-team' ) ), $html );
445
-		}
446
-
447
-		return $html;
448
-	}
449
-
450
-	public function change_title_text( $title ) {
451
-		$screen = get_current_screen();
452
-
453
-		if ( 'team' === $screen->post_type ) {
454
-			$title = esc_attr__( 'Enter team member name', 'lsx-team' );
455
-		}
456
-
457
-		return $title;
458
-	}
14
+     public function __construct() {
15
+          $this->load_classes();
16
+
17
+          add_action( 'init', array( $this, 'post_type_setup' ) );
18
+          add_action( 'init', array( $this, 'taxonomy_setup' ) );
19
+
20
+          add_action( 'cmb2_admin_init', array( $this, 'details_metabox' ) );
21
+          add_action( 'cmb2_admin_init', array( $this, 'projects_details_metabox' ) );
22
+          add_action( 'cmb2_admin_init', array( $this, 'services_details_metabox' ) );
23
+          add_action( 'cmb2_admin_init', array( $this, 'testimonials_details_metabox' ) );
24
+
25
+          add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) );
26
+
27
+          add_filter( 'type_url_form_media', array( $this, 'change_attachment_field_button' ), 20, 1 );
28
+          add_filter( 'enter_title_here', array( $this, 'change_title_text' ) );
29
+     }
30
+
31
+     /**
32
+      * Loads the admin subclasses
33
+      */
34
+     private function load_classes() {
35
+          require_once LSX_TEAM_PATH . 'classes/admin/class-settings.php';
36
+          $this->settings = \lsx\team\classes\admin\Settings::get_instance();
37
+
38
+          require_once LSX_TEAM_PATH . 'classes/admin/class-settings-theme.php';
39
+          $this->settings_theme = \lsx\team\classes\admin\Settings_Theme::get_instance();
40
+     }
41
+
42
+     public function post_type_setup() {
43
+          $labels = array(
44
+               'name'               => esc_html_x( 'Team Members', 'post type general name', 'lsx-team' ),
45
+               'singular_name'      => esc_html_x( 'Team Member', 'post type singular name', 'lsx-team' ),
46
+               'add_new'            => esc_html_x( 'Add New', 'post type general name', 'lsx-team' ),
47
+               'add_new_item'       => esc_html__( 'Add New Team Member', 'lsx-team' ),
48
+               'edit_item'          => esc_html__( 'Edit Team Member', 'lsx-team' ),
49
+               'new_item'           => esc_html__( 'New Team Member', 'lsx-team' ),
50
+               'all_items'          => esc_html__( 'All Team Members', 'lsx-team' ),
51
+               'view_item'          => esc_html__( 'View Team Member', 'lsx-team' ),
52
+               'search_items'       => esc_html__( 'Search Team Members', 'lsx-team' ),
53
+               'not_found'          => esc_html__( 'No team members found', 'lsx-team' ),
54
+               'not_found_in_trash' => esc_html__( 'No team members found in Trash', 'lsx-team' ),
55
+               'parent_item_colon'  => '',
56
+               'menu_name'          => esc_html_x( 'Team Members', 'admin menu', 'lsx-team' ),
57
+          );
58
+
59
+          $args = array(
60
+               'labels'             => $labels,
61
+               'public'             => true,
62
+               'publicly_queryable' => true,
63
+               'show_ui'            => true,
64
+               'show_in_menu'       => true,
65
+               'menu_icon'          => 'dashicons-groups',
66
+               'query_var'          => true,
67
+               'rewrite'            => array(
68
+                    'slug' => 'team',
69
+               ),
70
+               'capability_type'    => 'post',
71
+               'has_archive'        => 'team',
72
+               'hierarchical'       => false,
73
+               'menu_position'      => null,
74
+               'supports'           => array(
75
+                    'title',
76
+                    'editor',
77
+                    'excerpt',
78
+                    'thumbnail',
79
+               ),
80
+               'show_in_rest'          => true,
81
+               'rest_base'             => 'team',
82
+               'rest_controller_class' => 'WP_REST_Posts_Controller',
83
+          );
84
+
85
+          register_post_type( 'team', $args );
86
+     }
87
+
88
+     public function taxonomy_setup() {
89
+          $labels = array(
90
+               'name'              => esc_html_x( 'Roles', 'taxonomy general name', 'lsx-team' ),
91
+               'singular_name'     => esc_html_x( 'Role', 'taxonomy singular name', 'lsx-team' ),
92
+               'search_items'      => esc_html__( 'Search Roles', 'lsx-team' ),
93
+               'all_items'         => esc_html__( 'All Roles', 'lsx-team' ),
94
+               'parent_item'       => esc_html__( 'Parent Role', 'lsx-team' ),
95
+               'parent_item_colon' => esc_html__( 'Parent Role:', 'lsx-team' ),
96
+               'edit_item'         => esc_html__( 'Edit Role', 'lsx-team' ),
97
+               'update_item'       => esc_html__( 'Update Role', 'lsx-team' ),
98
+               'add_new_item'      => esc_html__( 'Add New Role', 'lsx-team' ),
99
+               'new_item_name'     => esc_html__( 'New Role Name', 'lsx-team' ),
100
+               'menu_name'         => esc_html__( 'Roles', 'lsx-team' ),
101
+          );
102
+
103
+          $args = array(
104
+               'hierarchical'      => true,
105
+               'labels'            => $labels,
106
+               'show_ui'           => true,
107
+               'show_admin_column' => true,
108
+               'query_var'         => true,
109
+               'rewrite'           => array(
110
+                    'slug' => 'team-role',
111
+               ),
112
+               'show_in_rest'          => true,
113
+               'rest_base'             => 'teamrole',
114
+               'rest_controller_class' => 'WP_REST_Terms_Controller',
115
+          );
116
+
117
+          register_taxonomy( 'team_role', array( 'team' ), $args );
118
+     }
119
+
120
+     /**
121
+      * Define the metabox and field configurations.
122
+      */
123
+     public function details_metabox() {
124
+
125
+          $prefix = 'lsx_';
126
+
127
+          $users = get_transient( 'lsx_team_users' );
128
+
129
+          if ( false === $users || '' === $users ) {
130
+               $users = get_users( array(
131
+                    'role__in' => array( 'administrator', 'editor', 'author' ),
132
+               ) );
133
+               set_transient( 'lsx_team_users', $users, 5 * 60 );
134
+          }
135
+
136
+          foreach ( $users as $user ) {
137
+               $user_array[] = array(
138
+                    'name'  => $user->display_name,
139
+                    'value' => $user->ID,
140
+               );
141
+          }
142
+
143
+          $cmb = new_cmb2_box(
144
+               array(
145
+                    'id'           => $prefix . '_team',
146
+                    'title'        => esc_html__( 'Team Member Details', 'lsx-team' ),
147
+                    'object_types' => 'team',
148
+                    'context'      => 'normal',
149
+                    'priority'     => 'low',
150
+                    'show_names'   => true,
151
+               )
152
+          );
153
+
154
+          $cmb->add_field(
155
+               array(
156
+                    'name'         => esc_html__( 'Featured:', 'lsx-team' ),
157
+                    'id'           => $prefix . 'featured',
158
+                    'type'         => 'checkbox',
159
+                    'value'        => 1,
160
+                    'default'      => 0,
161
+                    'show_in_rest' => true,
162
+               )
163
+          );
164
+
165
+          $cmb->add_field(
166
+               array(
167
+                    'name'         => esc_html__( 'Site User', 'lsx-team' ),
168
+                    'id'           => $prefix . 'site_user',
169
+                    'allow_none'   => true,
170
+                    'type'         => 'select',
171
+                    'options'      => $user_array,
172
+                    'show_in_rest' => true,
173
+               )
174
+          );
175
+
176
+          $cmb->add_field(
177
+               array(
178
+                    'name'         => esc_html__( 'Job Title:', 'lsx-team' ),
179
+                    'id'           => $prefix . 'job_title',
180
+                    'type'         => 'text',
181
+                    'show_in_rest' => true,
182
+               )
183
+          );
184
+
185
+          $cmb->add_field(
186
+               array(
187
+                    'name'         => esc_html__( 'Location:', 'lsx-team' ),
188
+                    'id'           => $prefix . 'location',
189
+                    'type'         => 'text',
190
+                    'show_in_rest' => true,
191
+               )
192
+          );
193
+
194
+          $cmb->add_field(
195
+               array(
196
+                    'name'         => esc_html__( 'Contact Email Address:', 'lsx-team' ),
197
+                    'id'           => $prefix . 'email_contact',
198
+                    'type'         => 'text',
199
+                    'show_in_rest' => true,
200
+               )
201
+          );
202
+
203
+          $cmb->add_field(
204
+               array(
205
+                    'name'         => esc_html__( 'Gravatar Email Address:', 'lsx-team' ),
206
+                    'desc'         => esc_html__( 'Used for Gravatar if a featured image is not set', 'lsx-team' ),
207
+                    'id'           => $prefix . 'email_gravatar',
208
+                    'type'         => 'text',
209
+                    'show_in_rest' => true,
210
+               )
211
+          );
212
+
213
+          $cmb->add_field(
214
+               array(
215
+                    'name'         => esc_html__( 'Telephone Number:', 'lsx-team' ),
216
+                    'id'           => $prefix . 'tel',
217
+                    'type'         => 'text',
218
+                    'show_in_rest' => true,
219
+               )
220
+          );
221
+
222
+          $cmb->add_field(
223
+               array(
224
+                    'name'         => esc_html__( 'Skype Name:', 'lsx-team' ),
225
+                    'id'           => $prefix . 'skype',
226
+                    'type'         => 'text',
227
+                    'show_in_rest' => true,
228
+               )
229
+          );
230
+
231
+          $cmb->add_field(
232
+               array(
233
+                    'name'         => esc_html__( 'Facebook URL', 'lsx-team' ),
234
+                    'id'           => $prefix . 'facebook',
235
+                    'type'         => 'text_url',
236
+                    'show_in_rest' => true,
237
+               )
238
+          );
239
+
240
+          $cmb->add_field(
241
+               array(
242
+                    'name'         => esc_html__( 'Twitter URL', 'lsx-team' ),
243
+                    'id'           => $prefix . 'twitter',
244
+                    'type'         => 'text_url',
245
+                    'show_in_rest' => true,
246
+               )
247
+          );
248
+
249
+          $cmb->add_field(
250
+               array(
251
+                    'name'         => esc_html__( 'LinkedIn URL', 'lsx-team' ),
252
+                    'id'           => $prefix . 'linkedin',
253
+                    'type'         => 'text_url',
254
+                    'show_in_rest' => true,
255
+               )
256
+          );
257
+
258
+          $cmb->add_field(
259
+               array(
260
+                    'name'         => esc_html__( 'Github URL', 'lsx-team' ),
261
+                    'id'           => $prefix . 'github',
262
+                    'type'         => 'text_url',
263
+                    'show_in_rest' => true,
264
+               )
265
+          );
266
+
267
+          $cmb->add_field(
268
+               array(
269
+                    'name'         => esc_html__( 'WordPress URL', 'lsx-team' ),
270
+                    'id'           => $prefix . 'wordpress',
271
+                    'type'         => 'text_url',
272
+                    'show_in_rest' => true,
273
+               )
274
+          );
275
+     }
276
+
277
+     /**
278
+      * Define the metabox and field configurations.
279
+      */
280
+     public function projects_details_metabox() {
281
+
282
+          if ( class_exists( 'LSX_Projects' ) ) {
283
+
284
+               $prefix = 'lsx_';
285
+
286
+               $cmb = new_cmb2_box(
287
+                    array(
288
+                         'id'           => $prefix . '_team',
289
+                         'context'      => 'normal',
290
+                         'priority'     => 'low',
291
+                         'show_names'   => true,
292
+                         'object_types' => array( 'team' ),
293
+                    )
294
+               );
295
+               $cmb->add_field(
296
+                    array(
297
+                         'name'       => __( 'Projects:', 'lsx-team' ),
298
+                         'id'         => 'project_to_team',
299
+                         'type'       => 'post_search_ajax',
300
+                         'limit'      => 15,
301
+                         'sortable'   => true,
302
+                         'query_args' => array(
303
+                              'post_type'      => array( 'project' ),
304
+                              'post_status'    => array( 'publish' ),
305
+                              'posts_per_page' => -1,
306
+                         ),
307
+                    )
308
+               );
309
+          }
310
+     }
311
+
312
+     /**
313
+      * Define the metabox and field configurations.
314
+      */
315
+     public function services_details_metabox() {
316
+
317
+          if ( class_exists( 'LSX_Services' ) ) {
318
+
319
+               $prefix = 'lsx_';
320
+
321
+               $cmb = new_cmb2_box(
322
+                    array(
323
+                         'id'           => $prefix . '_team',
324
+                         'context'      => 'normal',
325
+                         'priority'     => 'low',
326
+                         'show_names'   => true,
327
+                         'object_types' => array( 'team' ),
328
+                    )
329
+               );
330
+               $cmb->add_field(
331
+                    array(
332
+                         'name'       => __( 'Services:', 'lsx-team' ),
333
+                         'id'         => 'service_to_team',
334
+                         'type'       => 'post_search_ajax',
335
+                         'limit'      => 15,
336
+                         'sortable'   => true,
337
+                         'query_args' => array(
338
+                              'post_type'      => array( 'service' ),
339
+                              'post_status'    => array( 'publish' ),
340
+                              'posts_per_page' => -1,
341
+                         ),
342
+                    )
343
+               );
344
+          }
345
+     }
346
+
347
+     /**
348
+      * Define the metabox and field configurations.
349
+      */
350
+     public function testimonials_details_metabox() {
351
+
352
+          if ( class_exists( 'LSX_Testimonials' ) ) {
353
+
354
+               $prefix = 'lsx_';
355
+
356
+               $cmb = new_cmb2_box(
357
+                    array(
358
+                         'id'           => $prefix . '_team',
359
+                         'context'      => 'normal',
360
+                         'priority'     => 'low',
361
+                         'show_names'   => true,
362
+                         'object_types' => array( 'team' ),
363
+                    )
364
+               );
365
+               $cmb->add_field(
366
+                    array(
367
+                         'name'       => __( 'Testimonials:', 'lsx-team' ),
368
+                         'id'         => 'testimonial_to_team',
369
+                         'type'       => 'post_search_ajax',
370
+                         'limit'      => 15,
371
+                         'sortable'   => true,
372
+                         'query_args' => array(
373
+                              'post_type'      => array( 'testimonial' ),
374
+                              'post_status'    => array( 'publish' ),
375
+                              'posts_per_page' => -1,
376
+                         ),
377
+                    )
378
+               );
379
+          }
380
+
381
+     }
382
+
383
+     /**
384
+      * Sets up the "post relations".
385
+      */
386
+     public function post_relations( $post_id, $field, $value ) {
387
+          $connections = array(
388
+               'team_to_testimonial',
389
+               'testimonial_to_team',
390
+
391
+               'team_to_project',
392
+               'project_to_team',
393
+
394
+               'team_to_service',
395
+               'service_to_team',
396
+          );
397
+
398
+          if ( in_array( $field['id'], $connections ) ) {
399
+               $this->save_related_post( $connections, $post_id, $field, $value );
400
+          }
401
+     }
402
+
403
+     /**
404
+      * Save the reverse post relation.
405
+      */
406
+     public function save_related_post( $connections, $post_id, $field, $value ) {
407
+          $ids = explode( '_to_', $field['id'] );
408
+          $relation = $ids[1] . '_to_' . $ids[0];
409
+
410
+          if ( in_array( $relation, $connections ) ) {
411
+               $previous_values = get_post_meta( $post_id, $field['id'], false );
412
+
413
+               if ( ! empty( $previous_values ) ) {
414
+                    foreach ( $previous_values as $v ) {
415
+                         delete_post_meta( $v, $relation, $post_id );
416
+                    }
417
+               }
418
+
419
+               if ( is_array( $value ) ) {
420
+                    foreach ( $value as $v ) {
421
+                         if ( ! empty( $v ) ) {
422
+                              add_post_meta( $v, $relation, $post_id );
423
+                         }
424
+                    }
425
+               }
426
+          }
427
+     }
428
+
429
+     public function assets() {
430
+          //wp_enqueue_media();
431
+          wp_enqueue_script( 'media-upload' );
432
+          wp_enqueue_script( 'thickbox' );
433
+          wp_enqueue_style( 'thickbox' );
434
+
435
+          wp_enqueue_script( 'lsx-team-admin', LSX_TEAM_URL . 'assets/js/lsx-team-admin.min.js', array( 'jquery' ), LSX_TEAM_VER );
436
+          wp_enqueue_style( 'lsx-team-admin', LSX_TEAM_URL . 'assets/css/lsx-team-admin.css', array(), LSX_TEAM_VER );
437
+     }
438
+
439
+     /**
440
+      * Change the "Insert into Post" button text when media modal is used for feature images
441
+      */
442
+     public function change_attachment_field_button( $html ) {
443
+          if ( isset( $_GET['feature_image_text_button'] ) ) {
444
+               $html = str_replace( 'value="Insert into Post"', sprintf( 'value="%s"', esc_html__( 'Select featured image', 'lsx-team' ) ), $html );
445
+          }
446
+
447
+          return $html;
448
+     }
449
+
450
+     public function change_title_text( $title ) {
451
+          $screen = get_current_screen();
452
+
453
+          if ( 'team' === $screen->post_type ) {
454
+               $title = esc_attr__( 'Enter team member name', 'lsx-team' );
455
+          }
456
+
457
+          return $title;
458
+     }
459 459
 }
460 460
 
461 461
 $lsx_team_admin = new LSX_Team_Admin();
Please login to merge, or discard this patch.
classes/admin/class-settings.php 1 patch
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -9,184 +9,184 @@
 block discarded – undo
9 9
 
10 10
 class Settings {
11 11
 
12
-	/**
13
-	 * Holds class instance
14
-	 *
15
-	 * @since 1.0.0
16
-	 *
17
-	 * @var      object \lsx_team\classes\admin\Settings()
18
-	 */
19
-	protected static $instance = null;
20
-
21
-	/**
22
-	 * Option key, and option page slug
23
-	 *
24
-	 * @var string
25
-	 */
26
-	protected $screen_id = 'lsx_team_settings';
27
-
28
-	/**
29
-	 * Contructor
30
-	 */
31
-	public function __construct() {
32
-		add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) );
33
-		add_action( 'lsx_team_settings_page', array( $this, 'general_settings' ), 1, 1 );
34
-		add_action( 'lsx_team_settings_page', array( $this, 'global_defaults' ), 3, 1 );
35
-	}
36
-
37
-	/**
38
-	 * Return an instance of this class.
39
-	 *
40
-	 * @since 1.0.0
41
-	 *
42
-	 * @return    object Settings()    A single instance of this class.
43
-	 */
44
-	public static function get_instance() {
45
-		// If the single instance hasn't been set, set it now.
46
-		if ( null === self::$instance ) {
47
-			self::$instance = new self();
48
-		}
49
-		return self::$instance;
50
-	}
51
-
52
-	/**
53
-	 * Hook in and register a submenu options page for the Page post-type menu.
54
-	 */
55
-	public function register_settings_page() {
56
-		$cmb = new_cmb2_box(
57
-			array(
58
-				'id'           => $this->screen_id,
59
-				'title'        => esc_html__( 'Settings', 'lsx-team' ),
60
-				'object_types' => array( 'options-page' ),
61
-				'option_key'   => 'lsx_team_options', // The option key and admin menu page slug.
62
-				'parent_slug'  => 'edit.php?post_type=team', // Make options page a submenu item of the themes menu.
63
-				'capability'   => 'manage_options', // Cap required to view options-page.
64
-			)
65
-		);
66
-		do_action( 'lsx_team_settings_page', $cmb );
67
-	}
68
-
69
-	/**
70
-	 * Registers the general settings.
71
-	 *
72
-	 * @param object $cmb new_cmb2_box().
73
-	 * @return void
74
-	 */
75
-	public function general_settings( $cmb ) {
76
-		$cmb->add_field(
77
-			array(
78
-				'id'      => 'settings_general_title',
79
-				'type'    => 'title',
80
-				'name'    => __( 'General', 'lsx-team' ),
81
-				'default' => __( 'General', 'lsx-team' ),
82
-			)
83
-		);
84
-		$cmb->add_field(
85
-			array(
86
-				'name'        => __( 'Disable Single Posts', 'lsx-team' ),
87
-				'id'          => 'team_disable_single',
88
-				'type'        => 'checkbox',
89
-				'value'       => 1,
90
-				'default'     => 0,
91
-				'description' => __( 'Disable Single Posts.', 'lsx-health-plan' ),
92
-			)
93
-		);
94
-
95
-		$cmb->add_field(
96
-			array(
97
-				'name'        => __( 'Group By Role', 'lsx-team' ),
98
-				'id'          => 'group_by_role',
99
-				'type'        => 'checkbox',
100
-				'value'       => 1,
101
-				'default'     => 0,
102
-				'description' => __( 'Groups the Team on the Team archive by the role assigned.', 'lsx-health-plan' ),
103
-			)
104
-		);
105
-		$cmb->add_field( array(
106
-			'name'    => 'Placeholder',
107
-			'desc'    => __( 'Upload an image.', 'lsx-health-plan' ),
108
-			'id'      => 'team_placeholder',
109
-			'type'    => 'file',
110
-			'options' => array(
111
-				'url' => false, // Hide the text input for the url.
112
-			),
113
-			'text'    => array(
114
-				'add_upload_file_text' => 'Choose Image',
115
-			),
116
-		) );
117
-		$cmb->add_field(
118
-			array(
119
-				'id'   => 'settings_general_closing',
120
-				'type' => 'tab_closing',
121
-			)
122
-		);
123
-	}
124
-
125
-	/**
126
-	 * Registers the global default settings.
127
-	 *
128
-	 * @param object $cmb new_cmb2_box().
129
-	 * @return void
130
-	 */
131
-	public function global_defaults( $cmb ) {
132
-		$cmb->add_field(
133
-			array(
134
-				'id'      => 'global_defaults_title',
135
-				'type'    => 'title',
136
-				'name'    => __( 'Careers CTA', 'lsx-team' ),
137
-				'default' => __( 'Careers CTA', 'lsx-team' ),
138
-			)
139
-		);
140
-
141
-		$cmb->add_field(
142
-			array(
143
-				'name'        => __( 'Enable careers CTA', 'lsx-team' ),
144
-				'id'          => 'team_careers_cta_enable',
145
-				'type'        => 'checkbox',
146
-				'value'       => 1,
147
-				'default'     => 0,
148
-				'description' => __( 'Displays careers CTA mystery man on team archive.', 'lsx-health-plan' ),
149
-			)
150
-		);
151
-
152
-		$cmb->add_field(
153
-			array(
154
-				'name' => __( 'Title', 'lsx-team' ),
155
-				'id'   => 'team_careers_cta_title',
156
-				'type' => 'text',
157
-			)
158
-		);
159
-
160
-		$cmb->add_field(
161
-			array(
162
-				'name' => __( 'Tagline', 'lsx-team' ),
163
-				'id'   => 'team_careers_cta_tagline',
164
-				'type' => 'text',
165
-			)
166
-		);
167
-
168
-		$cmb->add_field(
169
-			array(
170
-				'name' => __( 'Link Text', 'lsx-team' ),
171
-				'id'   => 'team_careers_cta_link_text',
172
-				'type' => 'text',
173
-			)
174
-		);
175
-
176
-		$cmb->add_field(
177
-			array(
178
-				'name' => __( 'Careers page link', 'lsx-team' ),
179
-				'id'   => 'team_careers_cta_link',
180
-				'type' => 'text',
181
-			)
182
-		);
183
-
184
-		$cmb->add_field(
185
-			array(
186
-				'id'   => 'settings_global_defaults_closing',
187
-				'type' => 'tab_closing',
188
-			)
189
-		);
190
-	}
12
+     /**
13
+      * Holds class instance
14
+      *
15
+      * @since 1.0.0
16
+      *
17
+      * @var      object \lsx_team\classes\admin\Settings()
18
+      */
19
+     protected static $instance = null;
20
+
21
+     /**
22
+      * Option key, and option page slug
23
+      *
24
+      * @var string
25
+      */
26
+     protected $screen_id = 'lsx_team_settings';
27
+
28
+     /**
29
+      * Contructor
30
+      */
31
+     public function __construct() {
32
+          add_action( 'cmb2_admin_init', array( $this, 'register_settings_page' ) );
33
+          add_action( 'lsx_team_settings_page', array( $this, 'general_settings' ), 1, 1 );
34
+          add_action( 'lsx_team_settings_page', array( $this, 'global_defaults' ), 3, 1 );
35
+     }
36
+
37
+     /**
38
+      * Return an instance of this class.
39
+      *
40
+      * @since 1.0.0
41
+      *
42
+      * @return    object Settings()    A single instance of this class.
43
+      */
44
+     public static function get_instance() {
45
+          // If the single instance hasn't been set, set it now.
46
+          if ( null === self::$instance ) {
47
+               self::$instance = new self();
48
+          }
49
+          return self::$instance;
50
+     }
51
+
52
+     /**
53
+      * Hook in and register a submenu options page for the Page post-type menu.
54
+      */
55
+     public function register_settings_page() {
56
+          $cmb = new_cmb2_box(
57
+               array(
58
+                    'id'           => $this->screen_id,
59
+                    'title'        => esc_html__( 'Settings', 'lsx-team' ),
60
+                    'object_types' => array( 'options-page' ),
61
+                    'option_key'   => 'lsx_team_options', // The option key and admin menu page slug.
62
+                    'parent_slug'  => 'edit.php?post_type=team', // Make options page a submenu item of the themes menu.
63
+                    'capability'   => 'manage_options', // Cap required to view options-page.
64
+               )
65
+          );
66
+          do_action( 'lsx_team_settings_page', $cmb );
67
+     }
68
+
69
+     /**
70
+      * Registers the general settings.
71
+      *
72
+      * @param object $cmb new_cmb2_box().
73
+      * @return void
74
+      */
75
+     public function general_settings( $cmb ) {
76
+          $cmb->add_field(
77
+               array(
78
+                    'id'      => 'settings_general_title',
79
+                    'type'    => 'title',
80
+                    'name'    => __( 'General', 'lsx-team' ),
81
+                    'default' => __( 'General', 'lsx-team' ),
82
+               )
83
+          );
84
+          $cmb->add_field(
85
+               array(
86
+                    'name'        => __( 'Disable Single Posts', 'lsx-team' ),
87
+                    'id'          => 'team_disable_single',
88
+                    'type'        => 'checkbox',
89
+                    'value'       => 1,
90
+                    'default'     => 0,
91
+                    'description' => __( 'Disable Single Posts.', 'lsx-health-plan' ),
92
+               )
93
+          );
94
+
95
+          $cmb->add_field(
96
+               array(
97
+                    'name'        => __( 'Group By Role', 'lsx-team' ),
98
+                    'id'          => 'group_by_role',
99
+                    'type'        => 'checkbox',
100
+                    'value'       => 1,
101
+                    'default'     => 0,
102
+                    'description' => __( 'Groups the Team on the Team archive by the role assigned.', 'lsx-health-plan' ),
103
+               )
104
+          );
105
+          $cmb->add_field( array(
106
+               'name'    => 'Placeholder',
107
+               'desc'    => __( 'Upload an image.', 'lsx-health-plan' ),
108
+               'id'      => 'team_placeholder',
109
+               'type'    => 'file',
110
+               'options' => array(
111
+                    'url' => false, // Hide the text input for the url.
112
+               ),
113
+               'text'    => array(
114
+                    'add_upload_file_text' => 'Choose Image',
115
+               ),
116
+          ) );
117
+          $cmb->add_field(
118
+               array(
119
+                    'id'   => 'settings_general_closing',
120
+                    'type' => 'tab_closing',
121
+               )
122
+          );
123
+     }
124
+
125
+     /**
126
+      * Registers the global default settings.
127
+      *
128
+      * @param object $cmb new_cmb2_box().
129
+      * @return void
130
+      */
131
+     public function global_defaults( $cmb ) {
132
+          $cmb->add_field(
133
+               array(
134
+                    'id'      => 'global_defaults_title',
135
+                    'type'    => 'title',
136
+                    'name'    => __( 'Careers CTA', 'lsx-team' ),
137
+                    'default' => __( 'Careers CTA', 'lsx-team' ),
138
+               )
139
+          );
140
+
141
+          $cmb->add_field(
142
+               array(
143
+                    'name'        => __( 'Enable careers CTA', 'lsx-team' ),
144
+                    'id'          => 'team_careers_cta_enable',
145
+                    'type'        => 'checkbox',
146
+                    'value'       => 1,
147
+                    'default'     => 0,
148
+                    'description' => __( 'Displays careers CTA mystery man on team archive.', 'lsx-health-plan' ),
149
+               )
150
+          );
151
+
152
+          $cmb->add_field(
153
+               array(
154
+                    'name' => __( 'Title', 'lsx-team' ),
155
+                    'id'   => 'team_careers_cta_title',
156
+                    'type' => 'text',
157
+               )
158
+          );
159
+
160
+          $cmb->add_field(
161
+               array(
162
+                    'name' => __( 'Tagline', 'lsx-team' ),
163
+                    'id'   => 'team_careers_cta_tagline',
164
+                    'type' => 'text',
165
+               )
166
+          );
167
+
168
+          $cmb->add_field(
169
+               array(
170
+                    'name' => __( 'Link Text', 'lsx-team' ),
171
+                    'id'   => 'team_careers_cta_link_text',
172
+                    'type' => 'text',
173
+               )
174
+          );
175
+
176
+          $cmb->add_field(
177
+               array(
178
+                    'name' => __( 'Careers page link', 'lsx-team' ),
179
+                    'id'   => 'team_careers_cta_link',
180
+                    'type' => 'text',
181
+               )
182
+          );
183
+
184
+          $cmb->add_field(
185
+               array(
186
+                    'id'   => 'settings_global_defaults_closing',
187
+                    'type' => 'tab_closing',
188
+               )
189
+          );
190
+     }
191 191
 
192 192
 }
Please login to merge, or discard this patch.