PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.4.4.3
Permalink Manager Lite v2.4.4.3
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 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-permastructs.php
146 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() && ! class_exists( 'Permalink_Manager_URI_Functions_Tax' ) ) {
39 /* translators: %s: Permalink Manager Pro website */
40 $pro_text = sprintf( __( 'To edit taxonomy permalinks, <a href="%s" target="_blank">Permalink Manager Pro</a> is required.', 'permalink-manager' ), PERMALINK_MANAGER_WEBSITE );
41 $pro_text = sprintf( '<div class="alert info">%s</div>', $pro_text );
42 }
43
44 // 1. Get fields
45 $fields = array(
46 'post_types' => array(
47 'section_name' => __( 'Post types', 'permalink-manager' ),
48 'container' => 'row',
49 'fields' => array()
50 ),
51 'taxonomies' => array(
52 'section_name' => __( 'Taxonomies', 'permalink-manager' ),
53 'container' => 'row',
54 'append_content' => ( ! empty( $pro_text ) ) ? $pro_text : '',
55 'fields' => array()
56 )
57 );
58
59 // 2. Add a separate section for WooCommerce content types
60 if ( class_exists( 'WooCommerce' ) ) {
61 $fields['woocommerce'] = array(
62 'section_name' => "<i class=\"woocommerce-icon woocommerce-cart\"></i> " . __( 'WooCommerce', 'permalink-manager' ),
63 'container' => 'row',
64 'append_content' => ( ! empty( $pro_text ) ) ? $pro_text : '',
65 'fields' => array()
66 );
67 }
68
69 // 3A. Add permastructure fields for post types
70 foreach ( $post_types as $post_type ) {
71 if ( $post_type['name'] == 'shop_coupon' ) {
72 continue;
73 }
74
75 $fields["post_types"]["fields"][ $post_type['name'] ] = array(
76 'label' => $post_type['label'],
77 'container' => 'row',
78 'input_class' => 'permastruct-field',
79 'post_type' => $post_type,
80 'type' => 'permastruct'
81 );
82 }
83
84 // 3B. Add permastructure fields for taxonomies
85 foreach ( $taxonomies as $taxonomy ) {
86 $taxonomy_name = $taxonomy['name'];
87
88 // Check if taxonomy exists
89 if ( ! taxonomy_exists( $taxonomy_name ) ) {
90 continue;
91 }
92
93 $fields["taxonomies"]["fields"][ $taxonomy_name ] = array(
94 'label' => $taxonomy['label'],
95 'container' => 'row',
96 'input_class' => 'permastruct-field',
97 'taxonomy' => $taxonomy,
98 'type' => 'permastruct'
99 );
100 }
101
102 // 4. Separate WooCommerce CPT & custom taxonomies
103 if ( class_exists( 'WooCommerce' ) ) {
104 $woocommerce_fields = array( 'product' => 'post_types', 'product_tag' => 'taxonomies', 'product_cat' => 'taxonomies' );
105 $woocommerce_attributes = wc_get_attribute_taxonomies();
106
107 foreach ( $woocommerce_attributes as $woocommerce_attribute ) {
108 $woocommerce_fields["pa_{$woocommerce_attribute->attribute_name}"] = 'taxonomies';
109 }
110
111 foreach ( $woocommerce_fields as $field => $field_type ) {
112 if ( empty( $fields[ $field_type ]["fields"][ $field ] ) ) {
113 continue;
114 }
115
116 $fields["woocommerce"]["fields"][ $field ] = $fields[ $field_type ]["fields"][ $field ];
117 $fields["woocommerce"]["fields"][ $field ]["name"] = "{$field_type}[{$field}]";
118 unset( $fields[ $field_type ]["fields"][ $field ] );
119 }
120 }
121
122 return apply_filters( 'permalink_manager_permastructs_fields', $fields );
123 }
124
125 /**
126 * Get the array with settings and render the HTML output
127 */
128 public function output() {
129 $sidebar = sprintf( '<h3>%s</h3>', __( 'Instructions', 'permalink-manager' ) );
130 $sidebar .= "<div class=\"notice notice-warning\"><p>";
131 $sidebar .= __( 'The current permastructures settings will be automatically applied <strong>only to the new posts & terms</strong>.', 'permalink-manager' );
132 $sidebar .= '<br />';
133 /* translators: %s: Regenerate/reset admin URL */
134 $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' ) );
135 $sidebar .= "</p></div>";
136
137 $sidebar .= sprintf( '<h4>%s</h4>', __( 'Permastructure tags', 'permalink-manager' ) );
138 /* translators: %s: WordPress.org docs reference */
139 $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" ) );
140 $sidebar .= Permalink_Manager_Helper_Functions::get_all_structure_tags();
141
142 return Permalink_Manager_UI_Elements::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' ) );
143 }
144
145 }
146