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-permastructs.php
86 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Display the page where the slugs could be regenerated or replaced |
| 5 | */ |
| 6 | class Permalink_Manager_Permastructs extends Permalink_Manager_Class { |
| 7 | |
| 8 | public function __construct() { |
| 9 | add_filter( 'permalink_manager_sections', array($this, 'add_admin_section'), 2 ); |
| 10 | } |
| 11 | |
| 12 | public function add_admin_section($admin_sections) { |
| 13 | |
| 14 | $admin_sections['permastructs'] = array( |
| 15 | 'name' => __('Permastructures', 'permalink-manager'), |
| 16 | 'function' => array('class' => 'Permalink_Manager_Permastructs', 'method' => 'output') |
| 17 | ); |
| 18 | |
| 19 | return $admin_sections; |
| 20 | } |
| 21 | |
| 22 | public function get_fields() { |
| 23 | global $permalink_manager_permastructs; |
| 24 | |
| 25 | $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array('full'); |
| 26 | $woocommerce_icon = "<i class=\"woocommerce-icon woocommerce-cart\"></i>"; |
| 27 | |
| 28 | // 1. Get fields |
| 29 | $fields = array( |
| 30 | 'post_types' => array( |
| 31 | 'section_name' => __('Post types', 'permalink-manager'), |
| 32 | 'container' => 'row', |
| 33 | 'fields' => array() |
| 34 | ), |
| 35 | 'taxonomies' => array( |
| 36 | 'section_name' => __('Taxonomies', 'permalink-manager'), |
| 37 | 'container' => 'row', |
| 38 | 'append_content' => Permalink_Manager_Admin_Functions::pro_text(), |
| 39 | 'fields' => array() |
| 40 | ) |
| 41 | ); |
| 42 | |
| 43 | // 2. Woocommerce support |
| 44 | if(class_exists('WooCommerce')) { |
| 45 | $fields['woocommerce'] = array( |
| 46 | 'section_name' => "{$woocommerce_icon} " . __('WooCommerce', 'permalink-manager'), |
| 47 | 'container' => 'row', |
| 48 | 'append_content' => Permalink_Manager_Admin_Functions::pro_text(), |
| 49 | 'fields' => array() |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | // 3. Append fields for all post types |
| 54 | foreach($all_post_types as $post_type) { |
| 55 | if($post_type['name'] == 'shop_coupon') { continue; } |
| 56 | |
| 57 | $fields["post_types"]["fields"][$post_type['name']] = array( |
| 58 | 'label' => $post_type['label'], |
| 59 | 'container' => 'row', |
| 60 | 'input_class' => 'permastruct-field', |
| 61 | 'post_type' => $post_type, |
| 62 | 'type' => 'permastruct' |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | return apply_filters('permalink_manager_permastructs_fields', $fields); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get the array with settings and render the HTML output |
| 71 | */ |
| 72 | public function output() { |
| 73 | global $permalink_manager_permastructs; |
| 74 | |
| 75 | $sidebar = sprintf('<h3>%s</h3>', __('Instructions', 'permalink-manager')); |
| 76 | $sidebar .= sprintf(wpautop(__('The current permastructures settings will be applied <strong>only to the new posts & terms</strong>. To apply the <strong>new permastructures to existing posts and terms</strong>, please regenerate the custom permalinks <a href="%s">here</a>.', 'permalink-manager')), admin_url('tools.php?page=permalink-manager§ion=tools&subsection=regenerate_slugs')); |
| 77 | |
| 78 | $sidebar .= sprintf('<h4>%s</h4>', __('Permastructure tags', 'permalink-manager')); |
| 79 | $sidebar .= wpautop(sprintf(__('All allowed <a href="%s" target="_blank">permastructure tags</a> are listed below. Please note that some of them can be used only for particular post types or taxonomies.', 'permalink-manager'), "https://codex.wordpress.org/Using_Permalinks#Structure_Tags")); |
| 80 | $sidebar .= Permalink_Manager_Helper_Functions::get_all_structure_tags(); |
| 81 | |
| 82 | return Permalink_Manager_Admin_Functions::get_the_form(self::get_fields(), '', array('text' => __( 'Save permastructures', 'permalink-manager' ), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'permalink_manager_permastructs')); |
| 83 | } |
| 84 | |
| 85 | } |
| 86 |