PluginProbe ʕ •ᴥ•ʔ
Strong Testimonials / 3.3.2
Strong Testimonials v3.3.2
3.3.2 3.3.1 trunk 1.0.1 2.30.9 2.31.10 2.32 2.32.1 2.32.2 2.32.3 2.32.4 2.33 2.34 2.35 2.36 2.37 2.38 2.38.1 2.39 2.39.1 2.39.2 2.39.3 2.40.0 2.40.1 2.40.2 2.40.3 2.40.4 2.40.5 2.40.6 2.40.7 2.41.0 2.41.1 2.50.0 2.50.1 2.50.2 2.50.3 2.50.4 2.51.0 2.51.1 2.51.2 2.51.3 2.51.4 2.51.5 2.51.6 2.51.7 2.51.8 2.51.9 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.17 3.2.18 3.2.19 3.2.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0
strong-testimonials / admin / class-strong-testimonials-admin-list.php
strong-testimonials / admin Last commit date
challenge 1 year ago css 1 week ago img 1 year ago js 1 month ago menu 1 month ago partials 2 weeks ago rest-api 1 week ago scss 1 year ago settings 1 week ago uninstall 1 year ago wpchill 1 month ago admin-notices.php 6 months ago admin.php 1 month ago class-strong-testimonials-addons.php 1 month ago class-strong-testimonials-admin-category-list.php 1 year ago class-strong-testimonials-admin-list.php 1 year ago class-strong-testimonials-admin-scripts.php 1 month ago class-strong-testimonials-admin.php 1 month ago class-strong-testimonials-debug.php 6 months ago class-strong-testimonials-exporter.php 1 year ago class-strong-testimonials-help.php 1 year ago class-strong-testimonials-helper.php 1 month ago class-strong-testimonials-list-table.php 1 year ago class-strong-testimonials-lite-vs-pro-page.php 1 month ago class-strong-testimonials-post-editor.php 7 months ago class-strong-testimonials-review.php 1 year ago class-strong-testimonials-updater.php 1 month ago class-strong-testimonials-upsell.php 1 week ago class-strong-views-list-table.php 1 month ago class-walker-strong-category-checklist.php 1 year ago class-walker-strong-form-category-checklist.php 1 year ago class-wpmtst-onboarding.php 1 year ago compat.php 1 year ago custom-fields-ajax.php 1 year ago custom-fields.php 1 week ago form-preview.php 1 year ago view-list-order.php 1 year ago views-ajax.php 1 month ago views-validate.php 1 year ago views.php 1 month ago
class-strong-testimonials-admin-list.php
378 lines
1 <?php
2 /**
3 * Class Strong_Testimonials_Admin_List
4 *
5 * @since 2.28.0
6 */
7 class Strong_Testimonials_Admin_List {
8
9 /**
10 * Strong_Testimonials_Admin_List constructor.
11 */
12 public function __construct() {}
13
14 /**
15 * Initialize.
16 */
17 public static function init() {
18 self::add_actions();
19 }
20
21 /**
22 * Add actions and filters.
23 */
24 public static function add_actions() {
25 add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) );
26 add_filter( 'manage_wpm-testimonial_posts_columns', array( __CLASS__, 'add_thumbnail_column' ) );
27 add_filter( 'manage_edit-wpm-testimonial_columns', array( __CLASS__, 'edit_columns' ) );
28 add_action( 'restrict_manage_posts', array( __CLASS__, 'add_taxonomy_filters' ) );
29 add_filter( 'manage_edit-wpm-testimonial_sortable_columns', array( __CLASS__, 'manage_sortable_columns' ) );
30 add_action( 'manage_wpm-testimonial_posts_custom_column', array( __CLASS__, 'custom_columns' ) );
31 add_filter( 'post_row_actions', array( __CLASS__, 'post_row_actions' ), 10, 2 );
32
33 add_filter( 'manage_wpm-testimonial_posts_columns', array( __CLASS__, 'add_submitted_on_column' ) );
34 }
35
36 /**
37 * Add post ID to post row actions.
38 *
39 * @param $actions
40 * @param $post
41 * @since 2.32.2
42 *
43 * @return array
44 */
45 public static function post_row_actions( $actions, $post ) {
46 if ( 'wpm-testimonial' === $post->post_type ) {
47 $actions = array( 'id' => '<span>ID: ' . $post->ID . '</span>' ) + $actions;
48 }
49
50 return $actions;
51 }
52
53 /**
54 * Add custom columns to the admin list.
55 *
56 * @param $columns
57 *
58 * @since 1.4.0
59 * @since 2.5.1 Added comments column.
60 *
61 * @return array
62 */
63 public static function edit_columns( $columns ) {
64 $fields = wpmtst_get_all_fields();
65
66 $comments = isset( $columns['comments'] ) ? $columns['comments'] : '';
67
68 /*
69 INCOMING COLUMNS = Array (
70 [cb] => <input type="checkbox" />
71 [title] => Title
72 [comments] => <span class="vers comment-grey-bubble" title="Comments"><span class="screen-reader-text">Comments</span></span>
73 [date] => Date
74 [search_exclude] => Search Exclude // other plugin
75 [strong_thumbnail] => Thumbnail
76 )
77 */
78
79 // 1. remove [thumbnail] (may be re-added in custom field loop) and [date]
80 unset( $columns['strong_thumbnail'], $columns['date'] );
81
82 if ( $comments ) {
83 unset( $columns['comments'] );
84 }
85
86 // 2. insert [order] after [cb]
87 if ( ! self::is_column_sorted() && ! self::is_viewing_trash() && class_exists( 'Strong_Testimonials_Order' ) ) {
88 $columns = array_merge(
89 array_slice( $columns, 0, 1 ),
90 array( 'handle' => 'Order' ),
91 array_slice( $columns, 1, null )
92 );
93 }
94
95 // 3. insert [excerpt] after [title]
96 $key = 'title';
97 $offset = array_search( $key, array_keys( $columns ), true ) + 1;
98 $fields_to_add = array( 'post_excerpt' => esc_html__( 'Excerpt', 'strong-testimonials' ) );
99
100 // 4. add custom fields
101 foreach ( $fields as $key => $field ) {
102 if ( isset( $field['admin_table'] ) ) {
103 if ( 'post_title' === $field['name'] ) {
104 continue;
105 } elseif ( 'featured_image' === $field['name'] ) {
106 $fields_to_add['strong_thumbnail'] = esc_html__( 'Thumbnail', 'strong-testimonials' );
107 } elseif ( 'rating' === $field['input_type'] ) {
108 $fields_to_add[ $field['name'] ] = esc_html__( 'Rating', 'strong-testimonials' );
109 } else {
110 $fields_to_add[ $field['name'] ] = apply_filters( 'wpmtst_l10n', $field['label'], 'strong-testimonials-form-fields', $field['name'] . ' : label' );
111 }
112 }
113 }
114
115 // 5. add [category], [comments] and [date]
116 // The slug "categories" slug is reserved by WordPress.
117 if ( wpmtst_get_cat_count() ) {
118 $fields_to_add['category'] = esc_html__( 'Categories', 'strong-testimonials' );
119 }
120
121 if ( $comments ) {
122 $fields_to_add['comments'] = $comments;
123 }
124
125 $fields_to_add['date'] = esc_html__( 'Date', 'strong-testimonials' );
126
127 $options = get_option( 'wpmtst_options' );
128 if ( isset( $options['include_platform'] ) && true === $options['include_platform'] ) {
129 $fields_to_add['platform'] = esc_html__( 'Platform', 'strong-testimonials' );
130 }
131
132 // Push other added columns like [search_exclude] to the end.
133 $columns = array_merge(
134 array_slice( $columns, 0, $offset ),
135 $fields_to_add,
136 array_slice( $columns, $offset, null )
137 );
138
139 return $columns;
140 }
141
142 /**
143 * Show custom values
144 *
145 * @param $column
146 */
147 public static function custom_columns( $column ) {
148 global $post;
149
150 switch ( $column ) {
151 case 'post_id':
152 echo absint( $post->ID );
153 break;
154
155 case 'post_content':
156 $allowed_tags = array(
157 'a' => array(
158 'href' => array(),
159 'title' => array(),
160 ),
161 'p' => array(),
162 'strong' => array(),
163 'em' => array(),
164 'ul' => array(),
165 'ol' => array(),
166 'li' => array(),
167 'br' => array(),
168 'span' => array( 'class' => array() ),
169 );
170 echo wp_kses( substr( $post->post_content, 0, 100 ) . '&hellip;', $allowed_tags );
171 break;
172
173 case 'post_excerpt':
174 echo wp_kses_post( $post->post_excerpt );
175 break;
176
177 case 'strong_thumbnail':
178 echo wp_kses_post( wpmtst_get_thumbnail( array( 60, 60 ) ) );
179 break;
180
181 case 'category':
182 $categories = get_the_terms( 0, 'wpm-testimonial-category' );
183 if ( $categories && ! is_wp_error( $categories ) ) {
184 $list = array();
185 foreach ( $categories as $cat ) {
186 $list[] = $cat->name;
187 }
188 echo esc_html( implode( ', ', $list ) );
189 }
190 break;
191
192 case 'handle':
193 if ( current_user_can( 'edit_post', $post->ID ) && ! self::is_column_sorted() && ! self::is_viewing_trash() ) {
194 echo '<div class="handle"><div class="help"></div><div class="help-in-motion"></div></div>';
195 }
196 break;
197
198 case 'platform':
199 $platform = get_post_meta( $post->ID, 'platform', true );
200
201 if ( $platform ) {
202 $icon_src = apply_filters( 'wpmtst_platform_icon_src', WPMTST_ASSETS_IMG . '/platform_icons/' . $platform . '.svg', $platform, $post );
203 ?>
204 <img title="<?php echo esc_attr( __( 'posted on ', 'strong-testimonials' ) . $platform ); ?>" width="26" height="26" src="<?php echo esc_url( $icon_src ); ?>"/>
205 <?php
206 }
207
208 break;
209
210 case 'submission_date':
211 $submission_date = get_post_meta( $post->ID, 'submit_date', true );
212 if ( $submission_date ) {
213 $timestamp = strtotime( $submission_date );
214 $formatted = date_i18n( 'Y/m/d', $timestamp ) . ' at ' . date_i18n( 'g:i a', $timestamp );
215 echo esc_html( $formatted );
216 } else {
217 echo '';
218 }
219 break;
220
221 default:
222 // custom field?
223 $custom = get_post_custom();
224 $fields = wpmtst_get_custom_fields();
225
226 if ( isset( $custom[ $column ] ) && $custom[ $column ][0] ) {
227 if ( isset( $fields[ $column ] ) ) {
228 switch ( $fields[ $column ]['input_type'] ) {
229 case 'rating':
230 wpmtst_star_rating_display( $custom[ $column ][0], 'in-table-list' );
231 break;
232 case 'checkbox':
233 echo $custom[ $column ][0] ? 'yes' : 'no';
234 break;
235 default:
236 echo wp_kses_post( $custom[ $column ][0] );
237 }
238 }
239 } elseif ( isset( $fields[ $column ] ) ) {
240 if ( 'checkbox' === $fields[ $column ]['input_type'] ) {
241 echo 'no';
242 } else {
243 // display nothing
244 }
245 }
246 }
247 }
248
249 /**
250 * Add thumbnail column to admin list
251 *
252 * @param $columns
253 *
254 * @return array
255 */
256 public static function add_thumbnail_column( $columns ) {
257 $columns['strong_thumbnail'] = esc_html__( 'Thumbnail', 'strong-testimonials' );
258
259 return $columns;
260 }
261
262 /**
263 * Add thumbnail column to admin list
264 *
265 * @param $columns
266 *
267 * @return array
268 */
269 public static function add_submitted_on_column( $columns ) {
270 $columns['submission_date'] = esc_html__( 'Submitted On', 'strong-testimonials' );
271
272 return $columns;
273 }
274
275 /**
276 * Make columns sortable.
277 *
278 * @param $columns
279 *
280 * @since 1.12.0
281 * @since 2.2.0 category
282 *
283 * @return mixed
284 */
285 public static function manage_sortable_columns( $columns ) {
286 $columns['client_name'] = 'client_name';
287 $columns['category'] = 'categories';
288 $columns['date'] = 'date';
289 $columns['submission_date'] = 'submission_date';
290
291 return $columns;
292 }
293
294 /**
295 * Add category filter to testimonial list table.
296 *
297 * @since 2.2.0
298 */
299 public static function add_taxonomy_filters() {
300 global $typenow;
301
302 if ( 'wpm-testimonial' !== $typenow ) {
303 return;
304 }
305
306 $taxonomies = array( 'wpm-testimonial-category' );
307
308 foreach ( $taxonomies as $tax ) {
309 $tax_obj = get_taxonomy( $tax );
310 $args = array(
311 'show_option_all' => $tax_obj->labels->all_items,
312 'show_option_none' => '',
313 'option_none_value' => '-1',
314 'orderby' => 'NAME',
315 'order' => 'ASC',
316 'show_count' => 1,
317 'hide_empty' => 1,
318 'child_of' => 0,
319 'exclude' => '',
320 'echo' => 1,
321 'selected' => isset( $_GET[ $tax ] ) ? sanitize_text_field( wp_unslash( $_GET[ $tax ] ) ) : '',
322 'hierarchical' => 1,
323 'name' => $tax,
324 'id' => $tax,
325 'class' => 'postform',
326 'depth' => 0,
327 'tab_index' => 0,
328 'taxonomy' => $tax,
329 'hide_if_empty' => true,
330 'value_field' => 'slug',
331 );
332
333 wp_dropdown_categories( $args );
334 }
335 }
336
337 /**
338 * Sort columns.
339 *
340 * @since 1.12.0
341 *
342 * @param $query
343 */
344 public static function pre_get_posts( $query ) {
345 // Only in main WP query AND if an orderby query variable is designated.
346 if ( is_admin() && $query->is_main_query() && 'wpm-testimonial' === $query->get( 'post_type' ) ) {
347 if ( 'client_name' === $query->get( 'orderby' ) ) {
348 $query->set( 'meta_key', 'client_name' );
349 $query->set( 'orderby', 'meta_value' );
350 }
351 if ( 'submission_date' === $query->get( 'orderby' ) ) {
352 $query->set( 'meta_key', 'submit_date' );
353 $query->set( 'orderby', 'meta_value' );
354 }
355 }
356 }
357
358 /**
359 * Check if we are viewing the Trash.
360 *
361 * @since 1.16.0
362 */
363 public static function is_viewing_trash() {
364 return isset( $_GET['post_status'] ) && 'trash' === $_GET['post_status'];
365 }
366
367 /**
368 * Check if a column in admin list table is sorted.
369 *
370 * @since 1.16.0
371 */
372 public static function is_column_sorted() {
373 return isset( $_GET['orderby'] ) || ( isset( $_SERVER['REQUEST_URI'] ) && strstr( sanitize_url( $_SERVER['REQUEST_URI'] ), 'action=edit' ) ) || strstr( sanitize_url( $_SERVER['REQUEST_URI'] ), 'wp-admin/post-new.php' );
374 }
375 }
376
377 Strong_Testimonials_Admin_List::init();
378