PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.3.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.3.1
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
insert-php / admin / includes / class.filter.snippet.php

class.filter.snippet.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.3.1, at admin/includes/class.filter.snippet.php

76 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Filter for snippet list
4 *
5 * @author Webcraftic <wordpress.webraftic@gmail.com>
6 * @copyright (c) 16.11.2018, Webcraftic
7 * @version 1.0
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 class WINP_Filter_List {
16
17 /**
18 * WINP_Filter_List constructor.
19 */
20 public function __construct() {
21 add_action( 'restrict_manage_posts', [ $this, 'restrictManagePosts' ] );
22 add_filter( 'parse_query', [ $this, 'parseQuery' ] );
23 }
24
25 /**
26 * Create the dropdown
27 */
28 function restrictManagePosts() {
29 $type = WINP_Plugin::app()->request->get( 'post_type', 'post' );
30
31 $terms = get_terms( [
32 'taxonomy' => WINP_SNIPPETS_TAXONOMY,
33 'hide_empty' => true,
34 ] );
35
36 if ( WINP_SNIPPETS_POST_TYPE == $type && ! empty( $terms ) ) { ?>
37 <select name="winp_filter_tag">
38 <option value=""><?php _e( 'Filter by tag:', 'insert-php' ); ?></option>
39 <?php
40 $current_filter = WINP_Plugin::app()->request->get( 'winp_filter_tag', '' );
41 foreach ( $terms as $term ) {
42 if ( is_object( $term ) && isset( $term->slug ) ) {
43 printf( '<option value="%s"%s>%s</option>', $term->slug, $term->slug == $current_filter ? ' selected="selected"' : '', $term->name );
44 }
45 }
46 ?>
47 </select>
48 <?php
49 }
50 }
51
52 /**
53 * If submitted filter by tag
54 *
55 * @param $query
56 */
57 function parseQuery( $query ) {
58 global $pagenow;
59
60 $type = WINP_Plugin::app()->request->get( 'post_type' );
61
62 if ( WINP_SNIPPETS_POST_TYPE == $type && is_admin() && 'edit.php' == $pagenow && WINP_Plugin::app()->request->get( 'winp_filter_tag', '' ) ) {
63 $taxquery = [
64 [
65 'taxonomy' => WINP_SNIPPETS_TAXONOMY,
66 'field' => 'slug',
67 'terms' => [ WINP_Plugin::app()->request->get( 'winp_filter_tag', '' ) ],
68 'operator' => 'IN',
69 ],
70 ];
71 $query->set( 'tax_query', $taxquery );
72 }
73 }
74
75 }
76