PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.4.0
Permalink Manager Lite v2.4.0
2.6.0 2.5.5 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-permastructs.php
permalink-manager / includes / views Last commit date
permalink-manager-debug.php 3 years ago permalink-manager-permastructs.php 3 years ago permalink-manager-settings.php 3 years ago permalink-manager-tools.php 3 years ago permalink-manager-uri-editor-post.php 3 years ago permalink-manager-uri-editor.php 3 years ago
permalink-manager-permastructs.php
143 lines
1 <?php
2
3 /**
4 * Display the page where the slugs could be regenerated or replaced
5 */
6 class Permalink_Manager_Permastructs {
7
8 public function __construct() {
9 add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 2 );
10 }
11
12 /**
13 * Add a new section to the Permalink Manager UI
14 *
15 * @param array $admin_sections
16 *
17 * @return array
18 */
19 public function add_admin_section( $admin_sections ) {
20 $admin_sections['permastructs'] = array(
21 'name' => __( 'Permastructures', 'permalink-manager' ),
22 'function' => array( 'class' => 'Permalink_Manager_Permastructs', 'method' => 'output' )
23 );
24
25 return $admin_sections;
26 }
27
28 /**
29 * Return an array of fields that will be used to adjust the permastructure settings
30 *
31 * @return array
32 */
33 public function get_fields() {
34 $post_types = Permalink_Manager_Helper_Functions::get_post_types_array( 'full' );
35 $taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array( 'full' );
36
37 // Display additional information in Permalink Manager Lite
38 if ( ! Permalink_Manager_Admin_Functions::is_pro_active() ) {
39 $pro_text = sprintf( __( 'To edit taxonomy permalinks, <a href="%s" target="_blank">Permalink Manager Pro</a> is required.', 'permalink-manager' ), PERMALINK_MANAGER_WEBSITE );
40 $pro_text = sprintf( '<div class="alert info">%s</div>', $pro_text );
41 }
42
43 // 1. Get fields
44 $fields = array(
45 'post_types' => array(
46 'section_name' => __( 'Post types', 'permalink-manager' ),
47 'container' => 'row',
48 'fields' => array()
49 ),
50 'taxonomies' => array(
51 'section_name' => __( 'Taxonomies', 'permalink-manager' ),
52 'container' => 'row',
53 'append_content' => ( ! empty( $pro_text ) ) ? $pro_text : '',
54 'fields' => array()
55 )
56 );
57
58 // 2. Add a separate section for WooCommerce content types
59 if ( class_exists( 'WooCommerce' ) ) {
60 $fields['woocommerce'] = array(
61 'section_name' => "<i class=\"woocommerce-icon woocommerce-cart\"></i> " . __( 'WooCommerce', 'permalink-manager' ),
62 'container' => 'row',
63 'append_content' => ( ! empty( $pro_text ) ) ? $pro_text : '',
64 'fields' => array()
65 );
66 }
67
68 // 3A. Add permastructure fields for post types
69 foreach ( $post_types as $post_type ) {
70 if ( $post_type['name'] == 'shop_coupon' ) {
71 continue;
72 }
73
74 $fields["post_types"]["fields"][ $post_type['name'] ] = array(
75 'label' => $post_type['label'],
76 'container' => 'row',
77 'input_class' => 'permastruct-field',
78 'post_type' => $post_type,
79 'type' => 'permastruct'
80 );
81 }
82
83 // 3B. Add permastructure fields for taxonomies
84 foreach ( $taxonomies as $taxonomy ) {
85 $taxonomy_name = $taxonomy['name'];
86
87 // Check if taxonomy exists
88 if ( ! taxonomy_exists( $taxonomy_name ) ) {
89 continue;
90 }
91
92 $fields["taxonomies"]["fields"][ $taxonomy_name ] = array(
93 'label' => $taxonomy['label'],
94 'container' => 'row',
95 'input_class' => 'permastruct-field',
96 'taxonomy' => $taxonomy,
97 'type' => 'permastruct'
98 );
99 }
100
101 // 4. Separate WooCommerce CPT & custom taxonomies
102 if ( class_exists( 'WooCommerce' ) ) {
103 $woocommerce_fields = array( 'product' => 'post_types', 'product_tag' => 'taxonomies', 'product_cat' => 'taxonomies' );
104 $woocommerce_attributes = wc_get_attribute_taxonomies();
105
106 foreach ( $woocommerce_attributes as $woocommerce_attribute ) {
107 $woocommerce_fields["pa_{$woocommerce_attribute->attribute_name}"] = 'taxonomies';
108 }
109
110 foreach ( $woocommerce_fields as $field => $field_type ) {
111 if ( empty( $fields[ $field_type ]["fields"][ $field ] ) ) {
112 continue;
113 }
114
115 $fields["woocommerce"]["fields"][ $field ] = $fields[ $field_type ]["fields"][ $field ];
116 $fields["woocommerce"]["fields"][ $field ]["name"] = "{$field_type}[{$field}]";
117 unset( $fields[ $field_type ]["fields"][ $field ] );
118 }
119 }
120
121 return apply_filters( 'permalink_manager_permastructs_fields', $fields );
122 }
123
124 /**
125 * Get the array with settings and render the HTML output
126 */
127 public function output() {
128 $sidebar = sprintf( '<h3>%s</h3>', __( 'Instructions', 'permalink-manager' ) );
129 $sidebar .= "<div class=\"notice notice-warning\"><p>";
130 $sidebar .= __( 'The current permastructures settings will be automatically applied <strong>only to the new posts & terms</strong>.' );
131 $sidebar .= '<br />';
132 $sidebar .= sprintf( __( 'To apply the <strong>new format to existing posts and terms</strong>, please use "<a href="%s">Regenerate/reset</a>" tool after you update the permastructure settings below.', 'permalink-manager' ), admin_url( 'tools.php?page=permalink-manager&section=tools&subsection=regenerate_slugs' ) );
133 $sidebar .= "</p></div>";
134
135 $sidebar .= sprintf( '<h4>%s</h4>', __( 'Permastructure tags', 'permalink-manager' ) );
136 $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" ) );
137 $sidebar .= Permalink_Manager_Helper_Functions::get_all_structure_tags();
138
139 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' ) );
140 }
141
142 }
143