";
} else {
// Auto-update settings
$auto_update_def_val = $permalink_manager_options["general"]["auto_update_uris"];
if ( $auto_update_def_val == 1 ) {
$auto_update_def_label = __( "Auto-update \"Custom permalink\"", "permalink-manager" );
} else if ( $auto_update_def_val == 2 ) {
$auto_update_def_label = __( "Don't save/generate custom permalinks", "permalink-manager" );
} else {
$auto_update_def_label = __( "Don't auto-update \"Custom permalink\"", "permalink-manager" );
}
$auto_update_choices = array(
/* translators: The global value of the "Auto-update" mode setting */
0 => array( "label" => sprintf( __( "Use global settings [%s]", "permalink-manager" ), $auto_update_def_label ), "atts" => "data-readonly=\"{$auto_update_def_val}\"" ),
10 => '---',
- 1 => array( "label" => __( "Don't auto-update \"Custom permalink\"", "permalink-manager" ), "atts" => "data-readonly=\"0\"" ),
- 2 => array( "label" => __( "Don't auto-update \"Custom permalink\" and exclude from the \"Regenerate/reset\" tool", "permalink-manager" ), "atts" => "data-readonly=\"0\"" ),
1 => array( "label" => __( "Auto-update \"Custom permalink\"", "permalink-manager" ), "atts" => "data-readonly=\"1\"" ),
11 => '---',
2 => array( "label" => __( "Disable custom permalink (disallow further changes)", "permalink-manager" ), "atts" => "data-readonly=\"2\"" ),
);
// Decode default URI
$default_uri = rawurldecode( $default_uri );
// Start HTML output
// 1. Button
if ( ! $gutenberg ) {
$html = sprintf( "
";
// 2. The heading
$html .= "
" . __( "Close: ", "permalink-manager" ) . __( "Permalink Manager", "permalink-manager" ) . "";
$html .= sprintf( "
%s
", __( "Permalink Manager", "permalink-manager" ) );
// 3. The fields container [start]
$html .= "
";
} else {
$html = "
";
}
// 4. Custom URI
if ( ! empty( $is_front_page ) ) {
$custom_uri_field = self::generate_option_field( "custom_uri", array( "type" => "hidden", "extra_atts" => "data-default=\"{$default_uri}\" data-element-id=\"{$element_id}\"", "input_class" => "widefat custom_uri", "value" => rawurldecode( $uri ) ) );
$custom_uri_field .= __( "The custom URI cannot be edited on frontpage.", "permalink-manager" );
} else {
$custom_uri_field = self::generate_option_field( "custom_uri", array( "extra_atts" => "data-default=\"{$default_uri}\" data-element-id=\"{$element_id}\"", "input_class" => "widefat custom_uri", "value" => rawurldecode( $uri ) ) );
$custom_uri_field .= sprintf( '
%s %s
', '
', __( 'The URL above is displayed in read-only mode. To enable editing, change the "
Permalink update" setting to
Don\'t auto-update "Custom permalink".', 'permalink-manager' ) );
}
$html .= sprintf( "
", __( "Custom permalink", "permalink-manager" ), $custom_uri_field );
// 5. Auto-update URI
if ( empty( $is_front_page ) ) {
if ( ! empty( $auto_update_choices ) ) {
$html .= sprintf( "
", __( "Permalink update", "permalink-manager" ), self::help_tooltip( __( "If 'auto-update mode' is turned on, the 'Custom permalink' field will be automatically changed to 'Default custom permalink' (displayed below) after the post is saved or updated.", "permalink-manager" ) ), self::generate_option_field( "auto_update_uri", array( "type" => "select", "input_class" => "widefat auto_update", "value" => $auto_update_val, "choices" => $auto_update_choices ) ) );
}
}
// 6. Native slug
if ( ! empty( $element->ID ) && ! empty( $permalink_manager_options["general"]["show_native_slug_field"] ) ) {
$native_slug_field = self::generate_option_field( "native_slug", array( "extra_atts" => "data-default=\"{$native_slug}\" data-element-id=\"{$element_id}\"", "input_class" => "widefat native_slug", "value" => rawurldecode( $native_slug ) ) );
$html .= sprintf( "
", __( "Native slug", "permalink-manager" ), self::help_tooltip( __( "The native slug is by default automatically used in native permalinks (when Permalink Manager is disabled).", "permalink-manager" ) ), $native_slug_field );
}
if ( empty( $is_front_page ) ) {
// 7. Default custom permalink
$html .= "
";
$html .= sprintf( "
%s: %s", __( "Default custom permalink", "permalink-manager" ), esc_html( $default_uri ) );
$html .= sprintf( "
%s", __( "Use \"Default custom permalink\"", "permalink-manager" ) );
// $html .= sprintf( "
%s", __( "Go to \"Permastructures\"", "permalink-manager" ) );
$html .= "
";
// 8. Native permalink info
if ( ! empty( $permalink_manager_options['general']['redirect'] ) && ! ( ! empty( $element->post_status ) && in_array( $element->post_status, array( 'auto-draft', 'trash', 'draft' ) ) ) ) {
$native_permalink = trim( Permalink_Manager_Permastructure_Functions::get_permalink_base( $element ), "/" ) . "/";
$native_permalink .= $native_uri;
$native_permalink_label = ( $native_uri === $uri ) ? __( "Original WordPress permalink:", "permalink-manager" ) : __( "Original WordPress permalink (redirected):", "permalink-manager" );
$html .= sprintf( "
", $native_permalink_label, $native_permalink, rawurldecode( $native_uri ) );
}
}
// 9. Custom redirects
$html .= ( $element->ID ) ? self::display_redirect_panel( $id ) : self::display_redirect_panel( "tax-{$id}" );
// 10. Extra save button for Gutenberg
if ( $gutenberg ) {
$html .= sprintf( "
", __( "Save permalink", "permalink-manager" ) );
} else {
$html .= "
";
}
$html .= "
";
}
// 11. Append nonce field, element ID & native slug
$html .= self::generate_option_field( "permalink-manager-edit-uri-element-slug", array( "type" => "hidden", "value" => $native_slug ) );
$html .= self::generate_option_field( "permalink-manager-edit-uri-element-id", array( "type" => "hidden", "value" => $element_id ) );
$html .= wp_nonce_field( 'permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false );
return $html;
}
/**
* Get the HTML output of the redirect panel
*
* @param string|int $element_id
*
* @return string
*/
public static function display_redirect_panel( $element_id ) {
// Heading
$html = "
";
$html .= sprintf( "
", __( "Manage redirects", "permalink-manager" ) );
$html .= "
";
if ( class_exists( 'Permalink_Manager_Pro_Addons' ) ) {
$html .= Permalink_Manager_Pro_Addons::display_redirect_form( $element_id );
} else {
$html .= self::pro_text( true );
}
$html .= "
";
$html .= "
";
return $html;
}
/**
* Hide "Custom URI" column
*
* @param array $hidden
*
* @return array
*/
function quick_edit_hide_column( $hidden ) {
$hidden[] = 'permalink-manager-col';
return $hidden;
}
/**
* Display the simplified URI Editor in "Quick Edit" mode
*
* @param string $column_name
* @param string $post_type
* @param string $taxonomy
*/
public static function quick_edit_column_form( $column_name, $post_type, $taxonomy = '' ) {
// Check the user capabilities
if ( Permalink_Manager_Admin_Functions::current_user_can_edit_uris() === false || $column_name !== 'permalink-manager-col' ) {
return;
}
$html = Permalink_Manager_UI_Elements::generate_option_field( 'permalink-manager-quick-edit', array( 'value' => true, 'type' => 'hidden' ) );
$html .= '
";
// Append nonce field & element ID
$html .= Permalink_Manager_UI_Elements::generate_option_field( "permalink-manager-edit-uri-element-id", array( "type" => "hidden", "input_class" => "permalink-manager-edit-uri-element-id", "value" => "" ) );
$html .= wp_nonce_field( 'permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $html;
}
/**
* Get the HTML output of error/info message
*
* @param string $alert_content
* @param string $alert_type
* @param bool $dismissible
* @param bool $id
*
* @return string
*/
public static function get_alert_message( $alert_content = "", $alert_type = "", $dismissible = true, $id = false ) {
// Ignore empty messages (just in case)
if ( empty( $alert_content ) || empty( $alert_type ) ) {
return "";
}
$class = ( $dismissible ) ? "is-dismissible" : "";
$alert_id = ( $id ) ? " data-alert_id=\"{$id}\"" : "";
return sprintf( "
%s
", wpautop( $alert_content ) );
}
/**
* Get the HTML output of help tooltip
*
* @param string $text
*
* @return string
*/
static function help_tooltip( $text = '' ) {
return "
";
}
/**
* Display the license expiration date (in Pro version) or information about the premium functionality
*
* @param string $text_only
*
* @return string
*/
static function pro_text( $text_only = false ) {
if ( class_exists( 'Permalink_Manager_Pro_License' ) ) {
$text = Permalink_Manager_Pro_License::get_expiration_date( false, true );
} else {
/* translators: Permalink Manager Pro website */
$text = sprintf( __( 'This functionality is available only in
Permalink Manager Pro.', 'permalink-manager' ), PERMALINK_MANAGER_PROMO );
}
return ( $text_only ) ? $text : sprintf( "
%s
", wpautop( $text, 'alert' ) );
}
}PK =\n
vN4 N4 + views/permalink-manager-permastructures.phpnu [ __( 'Permastructures', 'permalink-manager' ),
'function' => array( 'class' => 'Permalink_Manager_Permastructs', 'method' => 'output' )
);
return $admin_sections;
}
/**
* Return an array of fields that will be used to adjust the permastructure settings
*
* @return array
*/
public function get_fields() {
$post_types = Permalink_Manager_Helper_Functions::get_post_types_array( 'full' );
$taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array( 'full' );
// Display additional information in Permalink Manager Lite
if ( ! Permalink_Manager_Admin_Functions::is_pro_active() ) {
/* translators: %s: Permalink Manager Pro website */
$pro_text = sprintf( __( 'To edit taxonomy permalinks,
Permalink Manager Pro is required.', 'permalink-manager' ), PERMALINK_MANAGER_PROMO );
$pro_text = sprintf( '
%s
', $pro_text );
}
// 1. Get fields
$fields = array(
'post_types' => array(
'section_name' => __( 'Post types', 'permalink-manager' ),
'container' => 'row',
'fields' => array()
),
'taxonomies' => array(
'section_name' => __( 'Taxonomies', 'permalink-manager' ),
'container' => 'row',
'fields' => array(),
'append_content' => ( ! empty( $pro_text ) ) ? $pro_text : ''
)
);
// 2. Add a separate section for WooCommerce content types
if ( class_exists( 'WooCommerce' ) ) {
$fields['woocommerce'] = array(
'section_name' => "
" . __( 'WooCommerce', 'permalink-manager' ),
'container' => 'row',
'fields' => array(),
'append_content' => ( ! empty( $pro_text ) ) ? $pro_text : ''
);
}
// 3A. Add permastructure fields for post types
foreach ( $post_types as $post_type ) {
if ( $post_type['name'] == 'shop_coupon' ) {
continue;
}
$fields["post_types"]["fields"][ $post_type['name'] ] = self::get_single_permastructure_field( $post_type, false, false );
}
// 3B. Add permastructure fields for taxonomies
foreach ( $taxonomies as $taxonomy ) {
$taxonomy_name = $taxonomy['name'];
// Check if taxonomy exists
if ( ! taxonomy_exists( $taxonomy_name ) ) {
continue;
}
$fields["taxonomies"]["fields"][ $taxonomy_name ] = self::get_single_permastructure_field( $taxonomy, true, isset( $pro_text ) );
}
return apply_filters( 'permalink_manager_permastructs_fields', $fields );
}
/**
* Get the row of the permastructure field for single content type
*
* @param $content_type
* @param bool $is_tax
* @param bool $pro_alert
*
* @return string
*/
function get_single_permastructure_field( $content_type, $is_tax = false, $pro_alert = false ) {
global $permalink_manager_permastructs;
if ( empty( $content_type['name'] ) ) {
return '';
}
$content_group = ( $is_tax ) ? "taxonomies" : "post_types";
$content_type_name = $content_type['name'];
$content_type_label = $content_type['label'];
$siteurl = Permalink_Manager_Permastructure_Functions::get_permalink_base();
$tags_container_id = sprintf( 'permastruct-tags-%s-%s', $content_group, $content_type_name );
$available_tags = self::get_all_structure_tags( $content_type_name, $is_tax );
// Get permastructures
$permastructures = ( ! empty( $permalink_manager_permastructs[ $content_group ] ) ) ? $permalink_manager_permastructs[ $content_group ] : array();
$default_permastruct = trim( Permalink_Manager_Permastructure_Functions::get_default_permastruct( $content_type_name ), "/" );
$current_permastruct = isset( $permastructures[ $content_type_name ] ) ? $permastructures[ $content_type_name ] : $default_permastruct;
// Append extra attributes
$field_atts = array(
'value' => $current_permastruct,
'input_class' => 'permastruct-field',
'disabled' => $pro_alert,
'placeholder' => $default_permastruct,
'extra_atts' => " data-default=\"{$default_permastruct}\""
);
$field_name = sprintf( '%s[%s]', $content_group, $content_type_name );
$permastruct_field = sprintf( "
%s/%s
", $siteurl, Permalink_Manager_UI_Elements::generate_option_field( $field_name, $field_atts ) );
$buttons = sprintf( "
%s
%s
", __( "Extra settings", "permalink-manager" ), $tags_container_id, __( "Available tags", "permalink-manager" ) );
$language_fields = '';
$languages = Permalink_Manager_Language_Plugins::get_all_languages( true );
if ( $languages ) {
$language_fields = sprintf( "
%s
%s
", __( "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" ) );
foreach ( $languages as $lang => $name ) {
$current_lang_permastruct = isset( $permastructures["{$content_type_name}_{$lang}"] ) ? $permastructures["{$content_type_name}_{$lang}"] : '';
$lang_field_atts = array_merge( $field_atts, array( 'value' => $current_lang_permastruct, 'extra_atts' => 'data-default=""', 'placeholder' => $current_permastruct ) );
$lang_field_name = str_replace( "]", "_{$lang}]", $field_name );
$language_fields .= sprintf( "
%s/%s
", $name, Permalink_Manager_Language_Plugins::prepend_lang_prefix( $siteurl, '', $lang ), Permalink_Manager_UI_Elements::generate_option_field( $lang_field_name, $lang_field_atts ) );
}
}
$default_permastruct_row = sprintf( "
%s: %s
%s
", __( "Default permastructure", "permalink-manager" ), esc_html( $default_permastruct ), __( "Restore default permastructure", "permalink-manager" ) );
$permastructure_settings = sprintf( "
%s
%s
", __( "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" ) ) ) );
// Combine all HTML chunks
$html = sprintf( "
%s%s
", $permastruct_field, $buttons );
$html .= sprintf( "
%s%s%s
", $language_fields, $default_permastruct_row, $permastructure_settings );
$html .= sprintf( '
%s
', $tags_container_id, $available_tags );
$label_tag = sprintf( "
| ", $field_name, $content_type_label );
return sprintf( "
%s |
", esc_attr( $content_group ), esc_attr( $content_type_name ), esc_attr( $field_name ), 'field-container permastruct-row', $label_tag, $html );
}
/**
* Get the array with settings and render the HTML output
*/
public function output() {
$sidebar = "
";
$sidebar .= __( 'The current permastructures settings will be automatically applied only to the new posts & terms.', 'permalink-manager' );
$sidebar .= '
';
/* translators: %s: Regenerate/reset admin URL */
$sidebar .= sprintf( __( 'To apply the new format to existing posts and terms, please use "Regenerate/reset" tool after you update the permastructure settings below.', 'permalink-manager' ), admin_url( 'tools.php?page=permalink-manager§ion=tools&subsection=regenerate_slugs' ) );
$sidebar .= "
";
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' ) );
}
/**
* Get a list of all structure tags
*
* @param string $content_type
* @param bool $is_taxonomy
*
* @return string
*/
static function get_all_structure_tags( $content_type = '', $is_taxonomy = false ) {
if ( empty( $content_type ) ) {
return '';
}
$html = '';
$tags_groups = array(
'slug' => array(
'heading' => __( 'Native slug & title', 'permalink-manager' ),
'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' )
),
'meta' => array(
'heading' => __( 'Meta data', 'permalink-manager' ),
'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' )
),
'taxonomies' => array(
'heading' => __( 'Taxonomies', 'permalink-manager' ),
'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' )
),
'custom_fields' => array(
'heading' => __( 'Custom fields', 'permalink-manager' ),
'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' ),
'pro' => true
)
);
if ( ! $is_taxonomy ) {
$post_type_tag = Permalink_Manager_Permastructure_Functions::get_post_tag( $content_type );
$post_type_taxonomies = get_taxonomies( array( 'object_type' => array( $content_type ) ), 'objects' );
$tags_groups['slug']['tags'] = array(
$post_type_tag,
( $content_type !== 'post' ) ? '%postname%' : '',
'%native_title%'
);
$tags_groups['meta']['tags'] = array(
'%post_id%',
'%author%',
'%year%',
'%monthnum%',
'%monthname%',
'%day%',
'%hour%',
'%minute%',
'%second%',
'%post_type%'
);
if ( ! empty( $post_type_taxonomies ) ) {
$tags_groups['taxonomies']['tags'] = array();
foreach ( $post_type_taxonomies as $post_type_taxonomy ) {
$tags_groups['taxonomies']['tags'][] = sprintf( '%%%s%%', $post_type_taxonomy->name );
}
}
} else {
$taxonomy_tag = sprintf( '%%%s%%', $content_type );
$tags_groups['slug']['tags'] = array(
$taxonomy_tag,
'%term_name%',
'%native_title%'
);
$tags_groups['meta']['tags'] = array(
'%term_id%',
'%taxonomy%'
);
}
$tags_groups['custom_fields']['tags'] = array(
'%__custom_field_name%'
);
foreach ( $tags_groups as $tags_group ) {
if ( empty( $tags_group['tags'] ) ) {
continue;
}
$html .= sprintf( '
%s
', $tags_group['heading'] );
if ( ! empty( $tags_group['pro'] ) ) {
$pro_text = Permalink_Manager_UI_Elements::pro_text( true );
$html .= ( ! empty( $pro_text ) ) ? sprintf( '
%s', $pro_text ) : '';
}
$html .= '
';
$html .= sprintf( '
', $tags_group['description'] );
$html .= '
';
foreach ( $tags_group['tags'] as $tag ) {
$html .= ( ! empty( $tag ) ) ? sprintf( '', $tag ) : '';
}
$html .= '
';
$html .= '
';
}
return sprintf( "
%s
", $html );
}
}
PK =\|j j &