| @@ -1,111 +1,111 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Filter for snippet list | |
| 4 | - * | |
| 5 | - * @package Woody_Code_Snippets | |
| 6 | - */ | |
| 7 | - | |
| 8 | -// Exit if accessed directly | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - exit; | |
| 11 | -} | |
| 12 | - | |
| 13 | -class WINP_Filter_List { | |
| 14 | - | |
| 15 | - /** | |
| 16 | - * WINP_Filter_List constructor. | |
| 17 | - */ | |
| 18 | - public function __construct() { | |
| 19 | - add_action( 'restrict_manage_posts', [ $this, 'restrictManagePosts' ] ); | |
| 20 | - add_filter( 'parse_query', [ $this, 'parseQuery' ] ); | |
| 21 | - } | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * Create the dropdown | |
| 25 | - */ | |
| 26 | - function restrictManagePosts() { | |
| 27 | - $type = WINP_HTTP::get( 'post_type', 'post' ); | |
| 28 | - | |
| 29 | - $terms = get_terms( | |
| 30 | - [ | |
| 31 | - 'taxonomy' => WINP_SNIPPETS_TAXONOMY, | |
| 32 | - 'hide_empty' => true, | |
| 33 | - ] | |
| 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_HTTP::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 | - $types = [ | |
| 52 | - 'PHP', | |
| 53 | - 'HTML', | |
| 54 | - 'CSS', | |
| 55 | - 'JS', | |
| 56 | - 'Universal', | |
| 57 | - 'Text', | |
| 58 | - 'Advertisement', | |
| 59 | - ]; | |
| 60 | - | |
| 61 | - if ( WINP_SNIPPETS_POST_TYPE == $type && ! empty( $types ) ) { | |
| 62 | - ?> | |
| 63 | - <select name="winp_filter_type"> | |
| 64 | - <option value=""><?php _e( 'Filter by type:', 'insert-php' ); ?></option> | |
| 65 | - <?php | |
| 66 | - $current_type = WINP_HTTP::get( 'winp_filter_type', '' ); | |
| 67 | - foreach ( $types as $t ) { | |
| 68 | - if ( is_string( $t ) ) { | |
| 69 | - printf( '<option value="%s"%s>%s</option>', strtolower( $t ), strtolower( $t ) == $current_type ? ' selected="selected"' : '', $t ); | |
| 70 | - } | |
| 71 | - } | |
| 72 | - ?> | |
| 73 | - </select> | |
| 74 | - <?php | |
| 75 | - } | |
| 76 | - } | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * If submitted filter by tag | |
| 80 | - * | |
| 81 | - * @param $query WP_Query | |
| 82 | - */ | |
| 83 | - function parseQuery( $query ) { | |
| 84 | - global $pagenow; | |
| 85 | - | |
| 86 | - $type = WINP_HTTP::get( 'post_type' ); | |
| 87 | - | |
| 88 | - if ( WINP_SNIPPETS_POST_TYPE == $type && is_admin() && 'edit.php' == $pagenow && WINP_HTTP::get( 'winp_filter_tag', '' ) ) { | |
| 89 | - $taxquery = [ | |
| 90 | - [ | |
| 91 | - 'taxonomy' => WINP_SNIPPETS_TAXONOMY, | |
| 92 | - 'field' => 'slug', | |
| 93 | - 'terms' => [ WINP_HTTP::get( 'winp_filter_tag', '' ) ], | |
| 94 | - 'operator' => 'IN', | |
| 95 | - ], | |
| 96 | - ]; | |
| 97 | - $query->set( 'tax_query', $taxquery ); | |
| 98 | - } | |
| 99 | - | |
| 100 | - if ( WINP_SNIPPETS_POST_TYPE == $type && is_admin() && 'edit.php' == $pagenow && WINP_HTTP::get( 'winp_filter_type', '' ) ) { | |
| 101 | - $meta_query = [ | |
| 102 | - [ | |
| 103 | - 'key' => 'wbcr_inp_snippet_type', | |
| 104 | - 'value' => WINP_HTTP::get( 'winp_filter_type', '' ), | |
| 105 | - 'compare' => '=', | |
| 106 | - ], | |
| 107 | - ]; | |
| 108 | - $query->set( 'meta_query', $meta_query ); | |
| 109 | - } | |
| 110 | - } | |
| 111 | -} | |
| 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 | + $types = [ | |
| 52 | + 'PHP', | |
| 53 | + 'HTML', | |
| 54 | + 'CSS', | |
| 55 | + 'JS', | |
| 56 | + 'Universal', | |
| 57 | + 'Text', | |
| 58 | + 'Advertisement', | |
| 59 | + ]; | |
| 60 | + | |
| 61 | + if ( WINP_SNIPPETS_POST_TYPE == $type && ! empty( $types ) ) { ?> | |
| 62 | + <select name="winp_filter_type"> | |
| 63 | + <option value=""><?php _e( 'Filter by type:', 'insert-php' ); ?></option> | |
| 64 | + <?php | |
| 65 | + $current_type = WINP_Plugin::app()->request->get( 'winp_filter_type', '' ); | |
| 66 | + foreach ( $types as $t ) { | |
| 67 | + if ( is_string( $t ) ) { | |
| 68 | + printf( '<option value="%s"%s>%s</option>', strtolower( $t ), strtolower( $t ) == $current_type ? ' selected="selected"' : '', $t ); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + ?> | |
| 72 | + </select> | |
| 73 | + <?php | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * If submitted filter by tag | |
| 79 | + * | |
| 80 | + * @param $query WP_Query | |
| 81 | + */ | |
| 82 | + function parseQuery( $query ) { | |
| 83 | + global $pagenow; | |
| 84 | + | |
| 85 | + $type = WINP_Plugin::app()->request->get( 'post_type' ); | |
| 86 | + | |
| 87 | + if ( WINP_SNIPPETS_POST_TYPE == $type && is_admin() && 'edit.php' == $pagenow && WINP_Plugin::app()->request->get( 'winp_filter_tag', '' ) ) { | |
| 88 | + $taxquery = [ | |
| 89 | + [ | |
| 90 | + 'taxonomy' => WINP_SNIPPETS_TAXONOMY, | |
| 91 | + 'field' => 'slug', | |
| 92 | + 'terms' => [ WINP_Plugin::app()->request->get( 'winp_filter_tag', '' ) ], | |
| 93 | + 'operator' => 'IN', | |
| 94 | + ], | |
| 95 | + ]; | |
| 96 | + $query->set( 'tax_query', $taxquery ); | |
| 97 | + } | |
| 98 | + | |
| 99 | + if ( WINP_SNIPPETS_POST_TYPE == $type && is_admin() && 'edit.php' == $pagenow && WINP_Plugin::app()->request->get( 'winp_filter_type', '' ) ) { | |
| 100 | + $meta_query = [ | |
| 101 | + [ | |
| 102 | + 'key' => 'wbcr_inp_snippet_type', | |
| 103 | + 'value' => WINP_Plugin::app()->request->get( 'winp_filter_type', '' ), | |
| 104 | + 'compare' => '=', | |
| 105 | + ] | |
| 106 | + ]; | |
| 107 | + $query->set( 'meta_query', $meta_query ); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + | |
| 111 | +} | |