permalink-manager-debug.php
1 year ago
permalink-manager-permastructs.php
1 year ago
permalink-manager-settings.php
1 year ago
permalink-manager-tools.php
1 year ago
permalink-manager-ui-elements.php
1 year ago
permalink-manager-uri-editor-post.php
1 year ago
permalink-manager-uri-editor.php
1 year ago
permalink-manager-uri-editor.php
120 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Display Bulk URI Editor |
| 5 | */ |
| 6 | class Permalink_Manager_URI_Editor { |
| 7 | public $this_section = 'uri_editor'; |
| 8 | |
| 9 | public function __construct() { |
| 10 | add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 0 ); |
| 11 | add_filter( 'screen_settings', array( $this, 'screen_options' ), 99, 2 ); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Add a new section to the Permalink Manager UI |
| 16 | * |
| 17 | * @param array $admin_sections |
| 18 | * |
| 19 | * @return array |
| 20 | */ |
| 21 | public function add_admin_section( $admin_sections ) { |
| 22 | $admin_sections[ $this->this_section ] = array( |
| 23 | 'name' => __( 'URI Editor', 'permalink-manager' ) |
| 24 | ); |
| 25 | |
| 26 | // Display separate section for each post type |
| 27 | $post_types = Permalink_Manager_Helper_Functions::get_post_types_array( 'full' ); |
| 28 | foreach ( $post_types as $post_type_name => $post_type ) { |
| 29 | // Check if post type exists |
| 30 | if ( ! post_type_exists( $post_type_name ) ) { |
| 31 | continue; |
| 32 | } |
| 33 | |
| 34 | $icon = ( class_exists( 'WooCommerce' ) && $post_type_name == 'product' ) ? "<i class=\"woocommerce-icon woocommerce-cart\"></i>" : ""; |
| 35 | |
| 36 | $admin_sections[ $this->this_section ]['subsections'][ $post_type_name ] = array( |
| 37 | 'name' => "{$icon} {$post_type['label']}", |
| 38 | 'function' => array( 'class' => 'Permalink_Manager_URI_Editor_Post', 'method' => 'display_admin_section' ) |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | // Permalink Manager Pro: Display separate section for each taxonomy |
| 43 | $taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array( 'full' ); |
| 44 | foreach ( $taxonomies as $taxonomy_name => $taxonomy ) { |
| 45 | // Check if taxonomy exists |
| 46 | if ( ! taxonomy_exists( $taxonomy_name ) ) { |
| 47 | continue; |
| 48 | } |
| 49 | |
| 50 | // Get the icon |
| 51 | $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>"; |
| 52 | |
| 53 | $admin_sections[ $this->this_section ]['subsections']["tax_{$taxonomy_name}"] = array( |
| 54 | 'name' => "{$icon} {$taxonomy['label']}", |
| 55 | 'html' => Permalink_Manager_UI_Elements::pro_text(), |
| 56 | 'pro' => true |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | // A little dirty hack to move wooCommerce product & taxonomies to the end of array |
| 61 | if ( class_exists( 'WooCommerce' ) ) { |
| 62 | foreach ( array( 'product', 'tax_product_tag', 'tax_product_cat' ) as $section_name ) { |
| 63 | if ( empty( $admin_sections[ $this->this_section ]['subsections'][ $section_name ] ) ) { |
| 64 | continue; |
| 65 | } |
| 66 | $section = $admin_sections[ $this->this_section ]['subsections'][ $section_name ]; |
| 67 | unset( $admin_sections[ $this->this_section ]['subsections'][ $section_name ] ); |
| 68 | $admin_sections[ $this->this_section ]['subsections'][ $section_name ] = $section; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return $admin_sections; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Display "Screen options" |
| 77 | * |
| 78 | * @param string $html |
| 79 | * @param string $screen |
| 80 | * |
| 81 | * @return string |
| 82 | */ |
| 83 | public function screen_options( $html, $screen ) { |
| 84 | global $active_section; |
| 85 | |
| 86 | // Display the screen options only in "Permalink Editor" |
| 87 | if ( $active_section != $this->this_section ) { |
| 88 | return $html; |
| 89 | } |
| 90 | |
| 91 | $button = get_submit_button( __( 'Apply', 'permalink-manager' ), 'primary', 'screen-options-apply', false ); |
| 92 | $html = "<fieldset class=\"permalink-manager-screen-options\">"; |
| 93 | |
| 94 | $screen_options = array( |
| 95 | 'per_page' => array( |
| 96 | 'type' => 'number', |
| 97 | 'label' => __( 'Per page', 'permalink-manager' ), |
| 98 | 'input_class' => 'settings-select' |
| 99 | ), |
| 100 | 'post_statuses' => array( |
| 101 | 'type' => 'checkbox', |
| 102 | 'label' => __( 'Post statuses', 'permalink-manager' ), |
| 103 | 'choices' => get_post_statuses(), |
| 104 | 'select_all' => '', |
| 105 | 'unselect_all' => '', |
| 106 | ) |
| 107 | ); |
| 108 | |
| 109 | foreach ( $screen_options as $field_name => $field_args ) { |
| 110 | $field_args['container'] = 'screen-options'; |
| 111 | $html .= Permalink_Manager_UI_Elements::generate_option_field( "screen-options[{$field_name}]", $field_args ); |
| 112 | } |
| 113 | |
| 114 | $html .= sprintf( "</fieldset>%s", $button ); |
| 115 | |
| 116 | return $html; |
| 117 | } |
| 118 | |
| 119 | } |
| 120 |