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