PluginProbe ʕ •ᴥ•ʔ
Admin Help Docs / 2.0.0.1
Admin Help Docs v2.0.0.1
2.0.1.1 trunk 1.4.3.2 2.0.0 2.0.0.1 2.0.0.2 2.0.1
admin-help-docs / inc / taxonomy-folders.php
admin-help-docs / inc Last commit date
css 3 months ago docs 3 months ago img 3 months ago js 3 months ago tabs 3 months ago api.php 3 months ago cleanup.php 3 months ago colors.php 3 months ago deprecated.php 3 months ago header.php 3 months ago helpers.php 3 months ago index.php 3 months ago menu.php 3 months ago plugins-page.php 3 months ago post-type-help-doc-imports.php 3 months ago post-type-help-docs.php 3 months ago shortcodes.php 3 months ago taxonomy-folders.php 3 months ago
taxonomy-folders.php
162 lines
1 <?php
2 /**
3 * Help Docs folders taxonomy (Folders Tab)
4 */
5
6 namespace PluginRx\AdminHelpDocs;
7
8 if ( ! defined( 'ABSPATH' ) ) exit;
9
10 class Folders {
11
12 /**
13 * Taxonomy slug
14 *
15 * @var string
16 */
17 public static $taxonomy = 'help-docs-folder';
18
19
20 /**
21 * The single instance of the class
22 *
23 * @var self|null
24 */
25 private static ?Folders $instance = null;
26
27
28 /**
29 * Get the singleton instance
30 *
31 * @return self
32 */
33 public static function instance() : self {
34 return self::$instance ??= new self();
35 } // End instance()
36
37
38 /**
39 * Folders constructor.
40 *
41 * Private to enforce singleton pattern.
42 */
43 private function __construct() {
44
45 // Register the taxonomy
46 add_action( 'init', [ $this, 'register_taxonomy' ] );
47
48 // Add the header to the top of the admin list page
49 add_action( 'load-edit-tags.php', [ $this, 'add_header' ] );
50
51 // Move the search box to the subheader
52 add_action( 'helpdocs_subheader_right', [ $this, 'render_search_box' ] );
53
54 // Remove the description column
55 add_filter( 'manage_edit-' . self::$taxonomy . '_columns', [ $this, 'remove_description_column' ] );
56
57 } // End __construct()
58
59
60 /**
61 * Register taxonomy
62 */
63 public function register_taxonomy() {
64 // Create the labels
65 $labels = [
66 'name' => _x( 'Folder', 'Taxonomy General Name', 'admin-help-docs' ),
67 'singular_name' => _x( 'Folder', 'Taxonomy Singular Name', 'admin-help-docs' ),
68 'search_items' => __( 'Search Folders', 'admin-help-docs' ),
69 'all_items' => __( 'Add to Folder', 'admin-help-docs' ),
70 'parent_item' => __( 'Parent Folder', 'admin-help-docs' ),
71 'parent_item_colon' => __( 'Parent Folder: ', 'admin-help-docs' ),
72 'edit_item' => __( 'Edit Folder', 'admin-help-docs' ),
73 'update_item' => __( 'Update Folder', 'admin-help-docs' ),
74 'add_new_item' => __( 'Add New Folder', 'admin-help-docs' ),
75 'new_item_name' => __( 'New Folder Name', 'admin-help-docs' ),
76 'menu_name' => __( 'Folders', 'admin-help-docs' ),
77 ];
78
79 // Register it as a new taxonomy
80 register_taxonomy( self::$taxonomy, HelpDocs::$post_type, [
81 'hierarchical' => false,
82 'labels' => $labels,
83 'show_ui' => true,
84 'show_in_rest' => false,
85 'show_admin_column' => true,
86 'show_in_quick_edit' => true,
87 'query_var' => true,
88 'public' => false,
89 'rewrite' => [ 'slug' => self::$taxonomy, 'with_front' => false ],
90 ] );
91 } // End register_taxonomy()
92
93
94 /**
95 * Add the header to the top of the admin list page
96 *
97 * @return void
98 */
99 public function add_header() {
100 $screen = get_current_screen();
101 if ( 'edit-' . self::$taxonomy === $screen->id ) {
102 add_action( 'in_admin_header', function() {
103 include Bootstrap::path( 'inc/header.php' );
104 } );
105 }
106 } // End add_header()
107
108
109 /**
110 * Add a search box to the subheader on the folders page
111 *
112 * @param string $current_tab The current admin tab
113 * @return void
114 */
115 public function render_search_box( string $current_tab ) {
116 if ( $current_tab !== 'folders' ) {
117 return;
118 }
119
120 $screen = get_current_screen();
121 if ( $screen->id !== 'edit-' . self::$taxonomy || $screen->base !== 'edit-tags' ) {
122 return;
123 }
124
125 $search_value = sanitize_text_field( wp_unslash( $_GET[ 's' ] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
126 ?>
127 <form method="get" class="helpdocs-tax-search">
128 <?php foreach ( $_GET as $key => $value ) : // phpcs:ignore WordPress.Security.NonceVerification.Recommended
129 if ( in_array( $key, [ 's', 'action', 'paged' ], true ) ) continue;
130 ?>
131 <input type="hidden" name="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $value ); ?>" />
132 <?php endforeach; ?>
133
134 <input type="search"
135 name="s"
136 value="<?php echo esc_attr( $search_value ); ?>"
137 placeholder="<?php echo esc_attr__( 'Search Folders', 'admin-help-docs' ); ?>"
138 class="helpdocs-search-input" />
139
140 <input type="submit"
141 class="helpdocs-button"
142 value="<?php echo esc_attr__( 'Search', 'admin-help-docs' ); ?>" />
143 </form>
144 <?php
145 } // End render_search_box()
146
147
148 /**
149 * Remove the description column from the folders list table
150 *
151 * @param array $columns The existing columns
152 * @return array The modified columns
153 */
154 public function remove_description_column( $columns ) {
155 unset( $columns[ 'description' ] );
156 return $columns;
157 } // End remove_description_column()
158
159 }
160
161
162 Folders::instance();