PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.6.0
Permalink Manager Lite v2.6.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-permastructures.php
permalink-manager / includes / views Last commit date
permalink-manager-debug.php 2 weeks ago permalink-manager-permastructures.php 2 weeks ago permalink-manager-settings.php 2 weeks ago permalink-manager-tools.php 2 weeks ago permalink-manager-ui-elements.php 2 weeks ago permalink-manager-uri-editor-post.php 2 weeks ago permalink-manager-uri-editor.php 2 weeks ago
permalink-manager-permastructures.php
300 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Display the page where the slugs could be regenerated or replaced
9 */
10 class Permalink_Manager_Permastructs {
11
12 public function __construct() {
13 add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 2 );
14 }
15
16 /**
17 * Add a new section to the Permalink Manager UI
18 *
19 * @param array $admin_sections
20 *
21 * @return array
22 */
23 public function add_admin_section( $admin_sections ) {
24 $admin_sections['permastructs'] = array(
25 'name' => __( 'Permastructures', 'permalink-manager' ),
26 'function' => array( 'class' => 'Permalink_Manager_Permastructs', 'method' => 'output' )
27 );
28
29 return $admin_sections;
30 }
31
32 /**
33 * Return an array of fields that will be used to adjust the permastructure settings
34 *
35 * @return array
36 */
37 public function get_fields() {
38 $post_types = Permalink_Manager_Helper_Functions::get_post_types_array( 'full' );
39 $taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array( 'full' );
40
41 // Display additional information in Permalink Manager Lite
42 if ( ! Permalink_Manager_Admin_Functions::is_pro_active() ) {
43 $website_url = Permalink_Manager_Admin_Functions::get_plugin_website_url( 'features' );
44
45 /* translators: %s: Permalink Manager Pro website */
46 $pro_text = sprintf( __( 'To edit taxonomy permalinks, <a href="%s" target="_blank">Permalink Manager Pro</a> is required.', 'permalink-manager' ), $website_url );
47 $pro_text = sprintf( '<div class="alert info">%s</div>', $pro_text );
48 }
49
50 // 1. Get fields
51 $fields = array(
52 'post_types' => array(
53 'section_name' => __( 'Post types', 'permalink-manager' ),
54 'container' => 'row',
55 'fields' => array()
56 ),
57 'taxonomies' => array(
58 'section_name' => __( 'Taxonomies', 'permalink-manager' ),
59 'container' => 'row',
60 'fields' => array(),
61 'append_content' => ( ! empty( $pro_text ) ) ? $pro_text : ''
62 )
63 );
64
65 // 2. Add a separate section for WooCommerce content types
66 if ( class_exists( 'WooCommerce' ) ) {
67 $fields['woocommerce'] = array(
68 'section_name' => "<i class=\"woocommerce-icon woocommerce-cart\"></i> " . __( 'WooCommerce', 'permalink-manager' ),
69 'container' => 'row',
70 'fields' => array(),
71 'append_content' => ( ! empty( $pro_text ) ) ? $pro_text : ''
72 );
73 }
74
75 // 3A. Add permastructure fields for post types
76 foreach ( $post_types as $post_type ) {
77 if ( $post_type['name'] == 'shop_coupon' ) {
78 continue;
79 }
80
81 $fields["post_types"]["fields"][ $post_type['name'] ] = self::get_single_permastructure_field( $post_type, false, false );
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 ] = self::get_single_permastructure_field( $taxonomy, true, isset( $pro_text ) );
94 }
95
96 return apply_filters( 'permalink_manager_permastructs_fields', $fields );
97 }
98
99 /**
100 * Get the row of the permastructure field for single content type
101 *
102 * @param $content_type
103 * @param bool $is_tax
104 * @param bool $pro_alert
105 *
106 * @return string
107 */
108 function get_single_permastructure_field( $content_type, $is_tax = false, $pro_alert = false ) {
109 if ( empty( $content_type['name'] ) ) {
110 return '';
111 }
112
113 $content_group = ( $is_tax ) ? "taxonomies" : "post_types";
114 $content_type_name = $content_type['name'];
115 $content_type_label = $content_type['label'];
116
117 $siteurl = Permalink_Manager_Permastructure_Functions::get_permalink_base();
118 $tags_container_id = sprintf( 'permastruct-tags-%s-%s', $content_group, $content_type_name );
119 $available_tags = self::get_all_structure_tags( $content_type_name, $is_tax );
120
121 // Get permastructures
122 $default_permastruct = trim( Permalink_Manager_Permastructure_Functions::get_default_permastruct( $content_type_name ), "/" );
123 $current_permastruct = Permalink_Manager_Permastructure_Functions::get_permastructure( $content_type_name, $is_tax );
124
125 // Append extra attributes
126 $field_atts = array(
127 'value' => $current_permastruct,
128 'input_class' => 'permastruct-field',
129 'disabled' => $pro_alert,
130 'placeholder' => $default_permastruct,
131 'extra_atts' => " data-default=\"{$default_permastruct}\""
132 );
133
134 $field_name = sprintf( '%s[%s]', $content_group, $content_type_name );
135 $permastruct_field = sprintf( "<div class=\"permastruct-field-container\"><span><code>%s/</code></span><span>%s</span></div>", $siteurl, Permalink_Manager_UI_Elements::generate_option_field( $field_name, $field_atts ) );
136
137 $buttons = sprintf( "<p class=\"permastruct-buttons\">
138 <span><a href=\"#\" class=\"button button-small button-secondary extra-settings\"><span class=\"dashicons dashicons-admin-settings\"></span> %s</a></span>
139 <span><a href=\"/?TB_inline&width=800&height=600&inlineId=%s\" class=\"button button-small button-secondary show-tags thickbox\"><span class=\"dashicons dashicons-tag\"></span> %s</a></span>
140 </p>", __( "Extra settings", "permalink-manager" ), $tags_container_id, __( "Available tags", "permalink-manager" ) );
141
142 $language_fields = '';
143 $languages = Permalink_Manager_Language_Plugins::get_all_languages( true );
144 if ( $languages ) {
145 $language_fields = sprintf( "<h4>%s</h4><p class=\"permastruct-instruction\">%s</p>", __( "Permastructure translations", "permalink-manager" ), __( "If you would like to translate the permastructures and set-up different permalink structure per language, please fill in the fields below. Otherwise the permastructure set for default language (see field above) will be applied.", "permalink-manager" ) );
146
147 foreach ( $languages as $lang => $name ) {
148 $current_lang_permastruct = Permalink_Manager_Permastructure_Functions::get_permastructure( $content_type_name, $is_tax, $lang );
149
150 $lang_field_atts = array_merge( $field_atts, array( 'value' => $current_lang_permastruct, 'extra_atts' => 'data-default=""', 'placeholder' => $current_permastruct ) );
151 $lang_field_name = str_replace( "]", "_{$lang}]", $field_name );
152
153 $language_fields .= sprintf( "<label>%s</label><div class=\"permastruct-field-container\"><span><code>%s/</code></span><span>%s</span></div>", $name, Permalink_Manager_Language_Plugins::prepend_lang_prefix( $siteurl, '', $lang ), Permalink_Manager_UI_Elements::generate_option_field( $lang_field_name, $lang_field_atts ) );
154 }
155 }
156
157 $default_permastruct_row = sprintf( "<p class=\"default-permastruct-row columns-container\">
158 <span class=\"column-2_4\"><strong>%s:</strong> %s</span>
159 <span class=\"column-2_4\"><a href=\"#\" class=\"restore-default\"><span class=\"dashicons dashicons-image-rotate\"></span> %s</a></span>
160 </p>", __( "Default permastructure", "permalink-manager" ), esc_html( $default_permastruct ), __( "Restore default permastructure", "permalink-manager" ) );
161
162 $permastructure_settings = sprintf( "<h4>%s</h4><div class=\"settings-container\">%s</div>", __( "Permastructure settings", "permalink-manager" ), Permalink_Manager_UI_Elements::generate_option_field( "permastructure-settings[do_not_append_slug][$content_group][{$content_type_name}]", array( 'type' => 'single_checkbox', 'default' => 1, 'checkbox_label' => __( "Do not automatically append the slug", "permalink-manager" ) ) ) );
163
164 // Combine all HTML chunks
165 $html = sprintf( "<div class=\"permastruct-container\">%s%s</div>", $permastruct_field, $buttons );
166 $html .= sprintf( "<div class=\"permastruct-settings\">%s%s%s</div>", $language_fields, $default_permastruct_row, $permastructure_settings );
167 $html .= sprintf( '<div id="%s" style="display:none;">%s</div>', $tags_container_id, $available_tags );
168
169 $label_tag = sprintf( "<th><label for=\"%s\">%s</label></th>", $field_name, $content_type_label );
170
171 return sprintf( "<tr id=\"%s_%s\" data-field=\"%s\" class=\"%s\">%s<td><fieldset>%s</fieldset></td></tr>", esc_attr( $content_group ), esc_attr( $content_type_name ), esc_attr( $field_name ), 'field-container permastruct-row', $label_tag, $html );
172 }
173
174
175 /**
176 * Get the array with settings and render the HTML output
177 */
178 public function output() {
179 $sidebar = "<div class=\"notice notice-warning inline\"><p>";
180 $sidebar .= __( 'The current permastructures settings will be automatically applied <strong>only to the new posts & terms</strong>.', 'permalink-manager' );
181 $sidebar .= '<br />';
182 /* translators: %s: Regenerate/reset admin URL */
183 $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' ) );
184 $sidebar .= "</div>";
185
186 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' ) );
187 }
188
189 /**
190 * Get a list of all structure tags
191 *
192 * @param string $content_type
193 * @param bool $is_taxonomy
194 *
195 * @return string
196 */
197 static function get_all_structure_tags( $content_type = '', $is_taxonomy = false ) {
198 if ( empty( $content_type ) ) {
199 return '';
200 }
201
202 $html = '';
203
204 $tags_groups = array(
205 'slug' => array(
206 'heading' => __( 'Native slug & title', 'permalink-manager' ),
207 'description' => __( 'The native slug is generated from the initial title and will not update automatically if the title is changed later. You can use the %native_title% tag to replace native slugs with actual titles, even if another content item has the same title.', 'permalink-manager' )
208 ),
209 'meta' => array(
210 'heading' => __( 'Meta data', 'permalink-manager' ),
211 'description' => __( 'Using meta tags, you may add post-specific information like item IDs or author names to permalinks. This might be beneficial to news, events, and time-sensitive content where you can use date-based tags.', 'permalink-manager' )
212 ),
213 'taxonomies' => array(
214 'heading' => __( 'Taxonomies', 'permalink-manager' ),
215 'description' => __( 'Custom permalinks can include taxonomy-based slugs such as categories, tags, and custom taxonomy terms. If a post belongs to multiple terms, the lowest-level one is used unless a specific term is selected as primary.', 'permalink-manager' )
216 ),
217 'custom_fields' => array(
218 'heading' => __( 'Custom fields', 'permalink-manager' ),
219 'description' => __( 'Permalinks can be modified with custom fields to dynamically include extra data. For example, you can append product SKUs to WooCommerce URLs or include geolocation details in your custom post types\' permalinks.', 'permalink-manager' ),
220 'pro' => true
221 )
222 );
223
224 if ( ! $is_taxonomy ) {
225 $post_type_tag = Permalink_Manager_Permastructure_Functions::get_post_tag( $content_type );
226 $post_type_taxonomies = get_object_taxonomies( $content_type, 'objects' );
227
228 $tags_groups['slug']['tags'] = array(
229 $post_type_tag,
230 ( $content_type !== 'post' ) ? '%postname%' : '',
231 '%native_title%'
232 );
233
234 $tags_groups['meta']['tags'] = array(
235 '%post_id%',
236 '%author%',
237 '%year%',
238 '%monthnum%',
239 '%monthname%',
240 '%day%',
241 '%hour%',
242 '%minute%',
243 '%second%',
244 '%post_type%'
245 );
246
247 if ( ! empty( $post_type_taxonomies ) ) {
248 $tags_groups['taxonomies']['tags'] = array();
249
250 foreach ( $post_type_taxonomies as $post_type_taxonomy ) {
251 $tags_groups['taxonomies']['tags'][] = sprintf( '%%%s%%', $post_type_taxonomy->name );
252 }
253 }
254 } else {
255 $taxonomy_tag = sprintf( '%%%s%%', $content_type );
256
257 $tags_groups['slug']['tags'] = array(
258 $taxonomy_tag,
259 '%term_name%',
260 '%native_title%'
261 );
262
263 $tags_groups['meta']['tags'] = array(
264 '%term_id%',
265 '%taxonomy%'
266 );
267 }
268
269 $tags_groups['custom_fields']['tags'] = array(
270 '%__custom_field_name%'
271 );
272
273 foreach ( $tags_groups as $tags_group ) {
274 if ( empty( $tags_group['tags'] ) ) {
275 continue;
276 }
277
278 $html .= sprintf( '<h3>%s</h3>', $tags_group['heading'] );
279
280 if ( ! empty( $tags_group['pro'] ) ) {
281 $pro_text = Permalink_Manager_UI_Elements::pro_text( true );
282 $html .= ( ! empty( $pro_text ) ) ? sprintf( '<span class="notice notice-error inline">%s</span>', $pro_text ) : '';
283 }
284
285 $html .= '<div class="permastruct-tag-container">';
286 $html .= sprintf( '<div><p class="description">%s</p></div>', $tags_group['description'] );
287
288 $html .= '<div><div class="permastruct-tag-buttons">';
289 foreach ( $tags_group['tags'] as $tag ) {
290 $html .= ( ! empty( $tag ) ) ? sprintf( '<button type="button" class="button button-small button-secondary" data-original-text="%1$s">%1$s</button>', $tag ) : '';
291 }
292 $html .= '</div></div>';
293 $html .= '</div>';
294 }
295
296 return sprintf( "<div class=\"structure-tags-list\">%s</div>", $html );
297 }
298
299 }
300