PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.5.4
Permalink Manager Lite v2.5.4
2.5.4 2.5.3.4 2.2.18 2.2.19.2 2.2.19.3 2.2.19.3.1 2.2.2 2.2.20 2.2.20.1 2.2.20.3 2.2.4 2.2.5 2.2.6 2.2.7.2 2.2.7.3 2.2.7.5 2.2.7.6 2.2.8.4 2.2.8.5 2.2.8.6 2.2.8.7 2.2.8.9 2.2.9.1 2.2.9.2 2.2.9.2.1 2.2.9.3 2.2.9.4 2.2.9.6 2.2.9.7 2.2.9.9 2.3.0 2.3.1.1 2.4.0 2.4.1 2.4.1.2 2.4.1.3 2.4.1.4 2.4.1.5 2.4.1.6 2.4.2 2.4.2.1 2.4.3 2.4.3.1 2.4.3.2 2.4.3.3 2.4.3.4 2.4.4 2.4.4.1 2.4.4.2 2.4.4.3 2.5.0 2.5.1 2.5.1.1 2.5.1.2 2.5.1.3 2.5.1.4 2.5.2 2.5.2.1 2.5.2.2 2.5.2.3 2.5.2.4 2.5.3 2.5.3.1 2.5.3.2 2.5.3.3 trunk 0.2 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 0.4.4 0.4.6 0.4.7 0.4.8 0.4.9 0.5.3 0.5.4 1.0.0 1.0.1 1.0.4 1.1.0 1.1.1 1.1.2 1.11.6.3 2.0.0 2.0.3 2.0.4 2.0.4.3 2.0.5.1 2.0.5.2 2.0.5.3 2.0.5.3.1 2.0.5.4 2.0.5.4a 2.0.5.5 2.0.5.6 2.0.5.6.1 2.0.5.7 2.0.5.9a 2.0.6.2.1 2.0.6.2a 2.0.6.3 2.1.0 2.1.1 2.1.2.4 2.2.0 2.2.1.1 2.2.1.2 2.2.11 2.2.12 2.2.13.1 2.2.14 2.2.15.1 2.2.16 2.2.17
permalink-manager / includes / views / permalink-manager-uri-editor.php
permalink-manager / includes / views Last commit date
permalink-manager-debug.php 2 days ago permalink-manager-permastructures.php 2 days ago permalink-manager-settings.php 2 days ago permalink-manager-tools.php 2 days ago permalink-manager-ui-elements.php 2 days ago permalink-manager-uri-editor-post.php 2 days ago permalink-manager-uri-editor.php 2 days ago
permalink-manager-uri-editor.php
163 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Display Bulk URI Editor
9 */
10 class Permalink_Manager_URI_Editor {
11 public $this_section = 'uri_editor';
12
13 public function __construct() {
14 add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 0 );
15 add_filter( 'screen_settings', array( $this, 'screen_options' ), 99, 2 );
16 }
17
18 /**
19 * Add a new section to the Permalink Manager UI
20 *
21 * @param array $admin_sections
22 *
23 * @return array
24 */
25 public function add_admin_section( $admin_sections ) {
26 $admin_sections[ $this->this_section ] = array(
27 'name' => __( 'URI Editor', 'permalink-manager' )
28 );
29
30 // Display separate section for each post type
31 $post_types = Permalink_Manager_Helper_Functions::get_post_types_array( 'full' );
32 foreach ( $post_types as $post_type_name => $post_type ) {
33 // Check if post type exists
34 if ( ! post_type_exists( $post_type_name ) ) {
35 continue;
36 }
37
38 $icon = ( class_exists( 'WooCommerce' ) && $post_type_name == 'product' ) ? "<i class=\"woocommerce-icon woocommerce-cart\"></i>" : "";
39
40 $admin_sections[ $this->this_section ]['subsections'][ $post_type_name ] = array(
41 'name' => "{$icon} {$post_type['label']}",
42 'function' => array( 'class' => 'Permalink_Manager_URI_Editor_Post', 'method' => 'display_admin_section' )
43 );
44 }
45
46 // Permalink Manager Pro: Display separate section for each taxonomy
47 $taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array( 'full' );
48 foreach ( $taxonomies as $taxonomy_name => $taxonomy ) {
49 // Check if taxonomy exists
50 if ( ! taxonomy_exists( $taxonomy_name ) ) {
51 continue;
52 }
53
54 // Get the icon
55 $icon = ( class_exists( 'WooCommerce' ) && in_array( $taxonomy_name, array( 'product_tag', 'product_cat' ) ) ) ? "<i class=\"woocommerce-icon woocommerce-cart\"></i>" : "<i class=\"dashicons dashicons-tag\"></i>";
56
57 $admin_sections[ $this->this_section ]['subsections']["tax_{$taxonomy_name}"] = array(
58 'name' => "{$icon} {$taxonomy['label']}",
59 'html' => Permalink_Manager_UI_Elements::pro_text(),
60 'pro' => true
61 );
62 }
63
64 // A little dirty hack to move wooCommerce product & taxonomies to the end of array
65 if ( class_exists( 'WooCommerce' ) ) {
66 foreach ( array( 'product', 'tax_product_tag', 'tax_product_cat' ) as $section_name ) {
67 if ( empty( $admin_sections[ $this->this_section ]['subsections'][ $section_name ] ) ) {
68 continue;
69 }
70 $section = $admin_sections[ $this->this_section ]['subsections'][ $section_name ];
71 unset( $admin_sections[ $this->this_section ]['subsections'][ $section_name ] );
72 $admin_sections[ $this->this_section ]['subsections'][ $section_name ] = $section;
73 }
74 }
75
76 return $admin_sections;
77 }
78
79 /**
80 * Display "Screen options"
81 *
82 * @param string $html
83 * @param string $screen
84 *
85 * @return string
86 */
87 public function screen_options( $html, $screen ) {
88 global $permalink_manager_active_section;
89
90 // Display the screen options only in "Permalink Editor"
91 if ( $permalink_manager_active_section != $this->this_section ) {
92 return $html;
93 }
94
95 $button = get_submit_button( __( 'Apply', 'permalink-manager' ), 'primary', 'screen-options-apply', false );
96 $html = "<fieldset class=\"permalink-manager-screen-options\">";
97
98 $screen_options = array(
99 'per_page' => array(
100 'type' => 'number',
101 'label' => __( 'Per page', 'permalink-manager' ),
102 'input_class' => 'settings-select'
103 ),
104 'post_statuses' => array(
105 'type' => 'checkbox',
106 'label' => __( 'Post statuses', 'permalink-manager' ),
107 'choices' => Permalink_Manager_Helper_Functions::get_post_statuses(),
108 'select_all' => '',
109 'unselect_all' => '',
110 )
111 );
112
113 foreach ( $screen_options as $field_name => $field_args ) {
114 $field_args['container'] = 'screen-options';
115 $html .= Permalink_Manager_UI_Elements::generate_option_field( "screen-options[{$field_name}]", $field_args );
116 }
117
118 $html .= sprintf( "</fieldset>%s", $button );
119
120 return $html;
121 }
122
123 /**
124 * Trigger SQL query to get all items
125 *
126 * @param $sql_parts
127 * @param $current_page
128 * @param $is_taxonomy
129 *
130 * @return array
131 */
132 public static function prepare_sql_query( $sql_parts, $current_page, $is_taxonomy = false ) {
133 global $permalink_manager_options, $wpdb;
134
135 $per_page = is_numeric( $permalink_manager_options['screen-options']['per_page'] ) ? $permalink_manager_options['screen-options']['per_page'] : 10;
136 $offset = (int) ( ( $current_page - 1 ) * $per_page );
137
138 // Prepare the count SQL query
139 $count_query_parts = $sql_parts;
140 $count_query_parts['start'] = preg_replace( '/(SELECT.*FROM)/', 'SELECT COUNT(*) FROM', $count_query_parts['start'] );
141 $count_query = apply_filters( 'permalink_manager_filter_uri_editor_query', implode( "", $count_query_parts ), $count_query_parts, $is_taxonomy );
142
143 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Query built dynamically, sanitized upstream.
144 $total_items_raw = $wpdb->get_var( $count_query );
145
146 // Pagination support
147 $sql_query = implode( "", $sql_parts );
148 $sql_query .= sprintf( " LIMIT %d, %d", $offset, (int) $per_page );
149
150 // Get items
151 $sql_query = apply_filters( 'permalink_manager_filter_uri_editor_query', $sql_query, $sql_parts, $is_taxonomy );
152
153 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Query built dynamically, sanitized upstream.
154 $all_items_raw = $wpdb->get_results( $sql_query, ARRAY_A );
155
156 $total_items = ( is_numeric( $total_items_raw ) ) ? (int) $total_items_raw : 0;
157 $all_items = ( ! empty( $all_items_raw ) ) ? $all_items_raw : array();
158
159 return array( $all_items, $total_items, $per_page );
160 }
161
162 }
163