initial
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Display the page where the slugs could be regenerated or replaced
|
||||
*/
|
||||
class Permalink_Manager_Debug {
|
||||
|
||||
public function __construct() {
|
||||
add_filter( 'permalink_manager_sections', array( $this, 'add_debug_section' ), 4 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new section to the Permalink Manager UI
|
||||
*
|
||||
* @param array $admin_sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_debug_section( $admin_sections ) {
|
||||
$admin_sections['debug'] = array(
|
||||
'name' => __( 'Debug', 'permalink-manager' ),
|
||||
'function' => array( 'class' => 'Permalink_Manager_Debug', 'method' => 'output' )
|
||||
);
|
||||
|
||||
return $admin_sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a URL pointing to the "Debug" tab in Permalink Manager UI
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_remove_settings_url( $field = '' ) {
|
||||
return add_query_arg( array(
|
||||
'section' => 'debug',
|
||||
'remove-permalink-manager-settings' => $field,
|
||||
'permalink-manager-nonce' => wp_create_nonce( 'permalink-manager' )
|
||||
), Permalink_Manager_Admin_Functions::get_admin_url() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define and display HTML output of a new section with the "Debug" data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function output() {
|
||||
global $permalink_manager_options, $permalink_manager_permastructs, $permalink_manager_redirects, $permalink_manager_external_redirects;
|
||||
|
||||
// Get the permalinks array & count permalinks and calculate the size of array
|
||||
$custom_permalinks = Permalink_Manager_URI_Functions::get_all_uris();
|
||||
list ( $custom_permalinks_size, $custom_permalinks_count ) = Permalink_Manager_URI_Functions::get_all_uris( true );
|
||||
|
||||
if ( $custom_permalinks_count >= 1 ) {
|
||||
$custom_permalinks_size = ( is_numeric( ( $custom_permalinks_size ) ) ) ? round( $custom_permalinks_size / 1024, 2 ) . __( 'kb', 'permalink-manager' ) : '-';
|
||||
/* translators: 1: Custom permalinks count, 2: Custom permalinks array size */
|
||||
$custom_permalinks_stats = sprintf( __( 'Custom permalinks count: <strong>%1$s</strong> | Custom permalinks array size in DB: <strong>%2$s</strong>', 'permalink-manager' ), esc_html( $custom_permalinks_count ), esc_html( $custom_permalinks_size ) );
|
||||
} else {
|
||||
$custom_permalinks_stats = __( 'The custom permalinks array has not been stored in the database yet.', 'permalink-manager' );
|
||||
}
|
||||
|
||||
$sections_and_fields = apply_filters( 'permalink_manager_debug_fields', array(
|
||||
'debug-data' => array(
|
||||
'section_name' => __( 'Debug data', 'permalink-manager' ),
|
||||
'fields' => array(
|
||||
'uris' => array(
|
||||
'type' => 'textarea',
|
||||
'description' => sprintf( '%s<br />%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', __( 'List of the URIs generated by this plugin.', 'permalink-manager' ), $custom_permalinks_stats, $this->get_remove_settings_url( 'uris' ), __( 'Remove all custom permalinks', 'permalink-manager' ) ),
|
||||
'label' => __( 'Array with custom permalinks', 'permalink-manager' ),
|
||||
'input_class' => 'short-textarea widefat',
|
||||
'value' => ( $custom_permalinks ) ? print_r( $custom_permalinks, true ) : ''
|
||||
),
|
||||
'custom-redirects' => array(
|
||||
'type' => 'textarea',
|
||||
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', __( 'List of custom redirects set-up by this plugin.', 'permalink-manager' ), $this->get_remove_settings_url( 'redirects' ), __( 'Remove all custom redirects', 'permalink-manager' ) ),
|
||||
'label' => __( 'Array with redirects', 'permalink-manager' ),
|
||||
'input_class' => 'short-textarea widefat',
|
||||
'value' => ( $permalink_manager_redirects ) ? print_r( $permalink_manager_redirects, true ) : ''
|
||||
),
|
||||
'external-redirects' => array(
|
||||
'type' => 'textarea',
|
||||
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', __( 'List of external redirects set-up by this plugin.', 'permalink-manager' ), $this->get_remove_settings_url( 'external-redirects' ), __( 'Remove all external redirects', 'permalink-manager' ) ),
|
||||
'label' => __( 'Array with external redirects', 'permalink-manager' ),
|
||||
'input_class' => 'short-textarea widefat',
|
||||
'value' => ( $permalink_manager_external_redirects ) ? print_r( array_filter( $permalink_manager_external_redirects ), true ) : ''
|
||||
),
|
||||
'permastructs' => array(
|
||||
'type' => 'textarea',
|
||||
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', __( 'List of permastructures set-up by this plugin.', 'permalink-manager' ), $this->get_remove_settings_url( 'permastructs' ), __( 'Remove all permastructures settings', 'permalink-manager' ) ),
|
||||
'label' => __( 'Array with permastructures', 'permalink-manager' ),
|
||||
'input_class' => 'short-textarea widefat',
|
||||
'value' => ( $permalink_manager_permastructs ) ? print_r( $permalink_manager_permastructs, true ) : ''
|
||||
),
|
||||
'settings' => array(
|
||||
'type' => 'textarea',
|
||||
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', __( 'List of plugin settings.', 'permalink-manager' ), $this->get_remove_settings_url( 'settings' ), __( 'Remove all plugin settings', 'permalink-manager' ) ),
|
||||
'label' => __( 'Array with settings used in this plugin.', 'permalink-manager' ),
|
||||
'input_class' => 'short-textarea widefat',
|
||||
'value' => print_r( $permalink_manager_options, true )
|
||||
)
|
||||
)
|
||||
)
|
||||
) );
|
||||
|
||||
// Now get the HTML output
|
||||
$output = '';
|
||||
foreach ( $sections_and_fields as $section_id => $section ) {
|
||||
$output .= ( isset( $section['section_name'] ) ) ? "<h3>{$section['section_name']}</h3>" : "";
|
||||
$output .= ( isset( $section['description'] ) ) ? "<p class=\"description\">{$section['description']}</p>" : "";
|
||||
$output .= "<table class=\"form-table fixed-table\">";
|
||||
|
||||
// Loop through all fields assigned to this section
|
||||
foreach ( $section['fields'] as $field_id => $field ) {
|
||||
$field_name = "{$section_id}[$field_id]";
|
||||
$field['container'] = 'row';
|
||||
|
||||
$output .= Permalink_Manager_UI_Elements::generate_option_field( $field_name, $field );
|
||||
}
|
||||
|
||||
// End the section
|
||||
$output .= "</table>";
|
||||
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
+300
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the page where the slugs could be regenerated or replaced
|
||||
*/
|
||||
class Permalink_Manager_Permastructs {
|
||||
|
||||
public function __construct() {
|
||||
add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new section to the Permalink Manager UI
|
||||
*
|
||||
* @param array $admin_sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_admin_section( $admin_sections ) {
|
||||
$admin_sections['permastructs'] = array(
|
||||
'name' => __( '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, <a href="%s" target="_blank">Permalink Manager Pro</a> is required.', 'permalink-manager' ), PERMALINK_MANAGER_PROMO );
|
||||
$pro_text = sprintf( '<div class="alert info">%s</div>', $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' => "<i class=\"woocommerce-icon woocommerce-cart\"></i> " . __( '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( "<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 ) );
|
||||
|
||||
$buttons = sprintf( "<p class=\"permastruct-buttons\">
|
||||
<span><a href=\"#\" class=\"button button-small button-secondary extra-settings\"><span class=\"dashicons dashicons-admin-settings\"></span> %s</a></span>
|
||||
<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>
|
||||
</p>", __( "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( "<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" ) );
|
||||
|
||||
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( "<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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
$default_permastruct_row = sprintf( "<p class=\"default-permastruct-row columns-container\">
|
||||
<span class=\"column-2_4\"><strong>%s:</strong> %s</span>
|
||||
<span class=\"column-2_4\"><a href=\"#\" class=\"restore-default\"><span class=\"dashicons dashicons-image-rotate\"></span> %s</a></span>
|
||||
</p>", __( "Default permastructure", "permalink-manager" ), esc_html( $default_permastruct ), __( "Restore default permastructure", "permalink-manager" ) );
|
||||
|
||||
$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" ) ) ) );
|
||||
|
||||
// Combine all HTML chunks
|
||||
$html = sprintf( "<div class=\"permastruct-container\">%s%s</div>", $permastruct_field, $buttons );
|
||||
$html .= sprintf( "<div class=\"permastruct-settings\">%s%s%s</div>", $language_fields, $default_permastruct_row, $permastructure_settings );
|
||||
$html .= sprintf( '<div id="%s" style="display:none;">%s</div>', $tags_container_id, $available_tags );
|
||||
|
||||
$label_tag = sprintf( "<th><label for=\"%s\">%s</label></th>", $field_name, $content_type_label );
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the array with settings and render the HTML output
|
||||
*/
|
||||
public function output() {
|
||||
$sidebar = "<div class=\"notice notice-warning inline\"><p>";
|
||||
$sidebar .= __( 'The current permastructures settings will be automatically applied <strong>only to the new posts & terms</strong>.', 'permalink-manager' );
|
||||
$sidebar .= '<br />';
|
||||
/* translators: %s: Regenerate/reset admin URL */
|
||||
$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§ion=tools&subsection=regenerate_slugs' ) );
|
||||
$sidebar .= "</div>";
|
||||
|
||||
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( '<h3>%s</h3>', $tags_group['heading'] );
|
||||
|
||||
if ( ! empty( $tags_group['pro'] ) ) {
|
||||
$pro_text = Permalink_Manager_UI_Elements::pro_text( true );
|
||||
$html .= ( ! empty( $pro_text ) ) ? sprintf( '<span class="notice notice-error inline">%s</span>', $pro_text ) : '';
|
||||
}
|
||||
|
||||
$html .= '<div class="permastruct-tag-container">';
|
||||
$html .= sprintf( '<div><p class="description">%s</p></div>', $tags_group['description'] );
|
||||
|
||||
$html .= '<div><div class="permastruct-tag-buttons">';
|
||||
foreach ( $tags_group['tags'] as $tag ) {
|
||||
$html .= ( ! empty( $tag ) ) ? sprintf( '<button type="button" class="button button-small button-secondary" data-original-text="%1$s">%1$s</button>', $tag ) : '';
|
||||
}
|
||||
$html .= '</div></div>';
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
return sprintf( "<div class=\"structure-tags-list\">%s</div>", $html );
|
||||
}
|
||||
|
||||
}
|
||||
+300
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Display the page where the slugs could be regenerated or replaced
|
||||
*/
|
||||
class Permalink_Manager_Pro_Addons {
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'init' ), 9 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hooks used to change the Permalink Manager UI
|
||||
*/
|
||||
public function init() {
|
||||
add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 5 );
|
||||
|
||||
// Stop Words
|
||||
add_action( 'admin_init', array( $this, 'save_stop_words' ), 9 );
|
||||
|
||||
add_filter( 'permalink_manager_tools_fields', array( $this, 'filter_tools_fields' ), 9, 2 );
|
||||
add_filter( 'permalink_manager_settings_fields', array( $this, 'filter_settings_fields' ), 9 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the fields disabled in free version
|
||||
*
|
||||
* @param array $fields
|
||||
* @param string $subsection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filter_tools_fields( $fields, $subsection ) {
|
||||
unset( $fields['content_type']['disabled'] );
|
||||
unset( $fields['content_type']['pro'] );
|
||||
unset( $fields['taxonomies']['pro'] );
|
||||
unset( $fields['ids']['disabled'] );
|
||||
unset( $fields['ids']['pro'] );
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add support for taxonomies in Bulk URI Editor & allow import from "Custom Permalinks" plugin
|
||||
*
|
||||
* @param array $admin_sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_admin_section( $admin_sections ) {
|
||||
// Add "Stop words" subsection for "Tools"
|
||||
$admin_sections['tools']['subsections']['stop_words']['function'] = array( 'class' => 'Permalink_Manager_Pro_Addons', 'method' => 'stop_words_output' );
|
||||
|
||||
// Display Permalinks for all selected taxonomies
|
||||
if ( ! empty( $admin_sections['uri_editor']['subsections'] ) ) {
|
||||
foreach ( $admin_sections['uri_editor']['subsections'] as &$subsection ) {
|
||||
if ( isset( $subsection['pro'] ) ) {
|
||||
$subsection['function'] = array( 'class' => 'Permalink_Manager_Tax_Uri_Editor_Table', 'method' => 'display_admin_section' );
|
||||
unset( $subsection['html'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add "Support" section
|
||||
$admin_sections['support'] = array(
|
||||
'name' => __( 'Support', 'permalink-manager' ),
|
||||
'function' => array( 'class' => 'Permalink_Manager_Pro_Addons', 'method' => 'support_output' )
|
||||
);
|
||||
|
||||
// Import support
|
||||
$admin_sections['tools']['subsections']['import']['function'] = array( 'class' => 'Permalink_Manager_Pro_Addons', 'method' => 'import_output' );
|
||||
|
||||
return $admin_sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the fields displayed in the "Settings" tab
|
||||
*
|
||||
* @param array $fields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filter_settings_fields( $fields ) {
|
||||
// Network license key (multisite)
|
||||
$license_key = Permalink_Manager_Pro_License::get_license_key();
|
||||
$expiration_info = Permalink_Manager_Pro_License::get_expiration_date();
|
||||
|
||||
// 1. license key
|
||||
$fields['licence'] = array(
|
||||
'section_name' => __( 'License', 'permalink-manager' ),
|
||||
'container' => 'row',
|
||||
'fields' => array(
|
||||
'licence_key' => array(
|
||||
'type' => 'text',
|
||||
'value' => $license_key,
|
||||
'label' => __( 'License key', 'permalink-manager' ),
|
||||
'after_description' => sprintf( '<p class="field-description description licence-info">%1$s</p><p class="field-description description"><a href="#" id="pm_get_exp_date" class="mute">%2$s</a> | <a href="%3$s" target="_blank" class="mute">%4$s</a></p>', $expiration_info, __( 'Reload the expiration date', 'permalink-manager' ), Permalink_Manager_Pro_License::get_license_info_link( $license_key ), __( 'Get license information', 'permalink-manager' ) )
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if ( defined( 'PMP_LICENCE_KEY' ) || defined( 'PMP_LICENSE_KEY' ) ) {
|
||||
$fields['licence']['fields']['licence_key']['disabled'] = true;
|
||||
$fields['licence']['fields']['licence_key']['type'] = 'password';
|
||||
}
|
||||
|
||||
// 2. Unblock some fields
|
||||
unset( $fields['redirect']['fields']['setup_redirects']['pro'] );
|
||||
unset( $fields['redirect']['fields']['setup_redirects']['disabled'] );
|
||||
unset( $fields['redirect']['fields']['extra_redirects']['pro'] );
|
||||
unset( $fields['redirect']['fields']['extra_redirects']['disabled'] );
|
||||
unset( $fields['exclusion']['fields']['exclude_term_ids']['pro'] );
|
||||
unset( $fields['exclusion']['fields']['exclude_term_ids']['disabled'] );
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Stop words" subsection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function stop_words_output() {
|
||||
global $permalink_manager_options;
|
||||
|
||||
// Fix the escaped quotes
|
||||
$words_list = ( ! empty( $permalink_manager_options['stop-words']['stop-words-list'] ) ) ? stripslashes( $permalink_manager_options['stop-words']['stop-words-list'] ) : "";
|
||||
|
||||
// Get stop-words languages
|
||||
$languages = array_merge( array( '' => __( '-- Use predefined words list --', 'permalink-manager' ) ), Permalink_Manager_Pro_Functions::load_stop_words_languages() );
|
||||
|
||||
$buttons = "<table class=\"stop-words-buttons\"><tr>";
|
||||
$buttons .= sprintf( "<td><a href=\"#\" class=\"clear_all_words button button-small\">%s</a></td>", __( "Remove all words", "permalink-manager" ) );
|
||||
$buttons .= sprintf( "<td>%s<td>", Permalink_Manager_UI_Elements::generate_option_field( "load_stop_words", array( "type" => "select", "input_class" => "widefat small-select load_stop_words", "choices" => $languages ) ) );
|
||||
$buttons .= sprintf( "<td>%s</td>", get_submit_button( __( 'Add the words from the list', 'permalink-manager' ), 'button-small button-primary', 'load_stop_words_button', false ) );
|
||||
$buttons .= "</tr></table>";
|
||||
|
||||
$fields = apply_filters( 'permalink_manager_tools_fields', array(
|
||||
'stop-words' => array(
|
||||
'container' => 'row',
|
||||
'fields' => array(
|
||||
'stop-words-enable' => array(
|
||||
'label' => __( 'Enable "stop words"', 'permalink-manager' ),
|
||||
'type' => 'single_checkbox',
|
||||
'container' => 'row',
|
||||
'input_class' => 'enable_stop_words'
|
||||
),
|
||||
'stop-words-list' => array(
|
||||
'label' => __( '"Stop words" list', 'permalink-manager' ),
|
||||
'type' => 'textarea',
|
||||
'container' => 'row',
|
||||
'value' => $words_list,
|
||||
'description' => __( 'Type comma to separate the words.', 'permalink-manager' ),
|
||||
'input_class' => 'widefat stop_words',
|
||||
'after_description' => $buttons
|
||||
)
|
||||
)
|
||||
)
|
||||
), 'stop_words' );
|
||||
|
||||
$sidebar = '<h3>' . __( 'Instructions', 'permalink-manager' ) . '</h3>';
|
||||
$sidebar .= wpautop( __( 'If enabled, all selected "stop words" will be automatically removed from default URIs.', 'permalink-manager' ) );
|
||||
$sidebar .= wpautop( __( 'Each of the words can be removed and any new words can be added to the list. You can also use a predefined list (available in 21 languages).', 'permalink-manager' ) );
|
||||
|
||||
return Permalink_Manager_UI_Elements::get_the_form( $fields, '', array( 'text' => __( 'Save', 'permalink-manager' ), 'class' => 'primary margin-top' ), $sidebar, array( 'action' => 'permalink-manager', 'name' => 'save_stop_words' ), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the user-defined stop words list
|
||||
*/
|
||||
public function save_stop_words() {
|
||||
if ( isset( $_POST['stop-words'] ) && wp_verify_nonce( $_POST['save_stop_words'], 'permalink-manager' ) ) {
|
||||
Permalink_Manager_Actions::save_settings( 'stop-words', $_POST['stop-words'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display "Import" subsection (Custom Permalinks)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function import_output() {
|
||||
// Count custom permalinks URIs
|
||||
$count_custom_permalinks = count( Permalink_Manager_Third_Parties::custom_permalinks_uris() );
|
||||
|
||||
$fields = apply_filters( 'permalink_manager_tools_fields', array(
|
||||
'disable_custom_permalinks' => array(
|
||||
'label' => __( 'Custom Permalinks', 'permalink-manager' ),
|
||||
'checkbox_label' => __( 'Deactivate after import', 'permalink-manager' ),
|
||||
'type' => 'single_checkbox',
|
||||
'container' => 'row',
|
||||
'description' => __( 'If selected, "Custom Permalinks" plugin will be deactivated after its custom URIs are imported.', 'permalink-manager' ),
|
||||
'input_class' => ''
|
||||
)
|
||||
), 'custom_permalinks_import' );
|
||||
|
||||
$sidebar = '<h3>' . __( 'Instructions', 'permalink-manager' ) . '</h3>';
|
||||
$sidebar .= wpautop( __( 'Please note that "Custom Permalinks" (if activated) may break the behavior of this plugin.', 'permalink-manager' ) );
|
||||
$sidebar .= wpautop( __( 'Therefore, it is recommended to disable "Custom Permalink" and import old permalinks before using Permalink Manager Pro.', 'permalink-manager' ) );
|
||||
|
||||
// Show some additional info data
|
||||
if ( $count_custom_permalinks > 0 ) {
|
||||
$button = array(
|
||||
/* translators: %s: Custom permalinks to import (count) */
|
||||
'text' => sprintf( __( 'Import %d URIs', 'permalink-manager' ), $count_custom_permalinks ),
|
||||
'class' => 'primary margin-top'
|
||||
);
|
||||
} else {
|
||||
$button = array(
|
||||
'text' => __( 'No custom URIs to import', 'permalink-manager' ),
|
||||
'class' => 'secondary margin-top',
|
||||
'attributes' => array( 'disabled' => 'disabled' )
|
||||
);
|
||||
}
|
||||
|
||||
return Permalink_Manager_UI_Elements::get_the_form( $fields, 'columns-3', $button, $sidebar, array( 'action' => 'permalink-manager', 'name' => 'import' ), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Support" section
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function support_output() {
|
||||
$output = sprintf( "<h3>%s</h3>", __( "Technical support", "permalink-manager" ) );
|
||||
/* translators: %s: Support section heading */
|
||||
$output .= wpautop( sprintf( __( 'To find the answers on frequently asked questions and information about how to deal with the most common issues please go to the <strong>Knowledge Base</strong> using <a target="_blank" href="%s">this link</a>.', 'permalink-manager' ), 'https://permalinkmanager.pro/docs/' ) );
|
||||
$output .= wpautop( __( 'If you still did not find the answer to your question, please send us your question or a detailed description of your problem/issue to <a href="mailto:support@permalinkmanager.pro">support@permalinkmanager.pro</a>.', 'permalink-manager' ) );
|
||||
$output .= wpautop( __( 'To reduce the response time, please attach your license key and if possible also: URL address of your website and screenshots explaining the issue.', 'permalink-manager' ) );
|
||||
|
||||
/* translators: %s: Support section heading */
|
||||
$output .= sprintf( "<h3>%s</h3>", __( "Suggestions/feedback", "permalink-manager" ) );
|
||||
$output .= wpautop( __( 'If you would like to suggest a new functionality or leave us feedback, we are open to all new ideas and would be grateful for all your comments!', 'permalink-manager' ) );
|
||||
$output .= wpautop( __( ' Please send your remarks to <a href="mailto:contact@permalinkmanager.pro">contact@permalinkmanager.pro</a>.', 'permalink-manager' ) );
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the HTML output of "Custom Redirects" panel in URI Editor
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function display_redirect_form( $element_id ) {
|
||||
global $permalink_manager_redirects, $permalink_manager_options, $permalink_manager_external_redirects;
|
||||
|
||||
// Do not trigger if "Extra redirects" option is turned off
|
||||
if ( empty( $permalink_manager_options['general']['redirect'] ) || empty( $permalink_manager_options['general']['extra_redirects'] ) ) {
|
||||
return __( 'Turn on "<strong>Extra redirects (aliases)</strong>" in Permalink Manager settings to enable this feature.', 'permalink-manager' );
|
||||
}
|
||||
|
||||
// 1. Extra redirects
|
||||
$html = "<div class=\"single-section\">";
|
||||
|
||||
$html .= sprintf( "<p><label for=\"auto_auri\" class=\"strong\">%s %s</label></p>", __( "Extra redirects (aliases)", "permalink-manager" ), Permalink_Manager_UI_Elements::help_tooltip( __( "All URIs specified below will redirect the visitors to the custom URI defined above in \"Current URI\" field.", "permalink-manager" ) ) );
|
||||
|
||||
$html .= "<table>";
|
||||
// 1A. Sample row
|
||||
$html .= sprintf( "<tr class=\"sample-row\"><td>%s</td><td>%s</td></tr>", Permalink_Manager_UI_Elements::generate_option_field( "permalink-manager-redirects", array( "input_class" => "widefat", "value" => "", 'extra_atts' => "data-index=\"\"", "placeholder" => __( 'sample/custom-uri', 'permalink-manager' ) ) ), "<a href=\"#\" class=\"remove-redirect\"><span class=\"dashicons dashicons-no\"></span></a>" );
|
||||
|
||||
// 1B. Rows with redirects
|
||||
if ( ! empty( $permalink_manager_redirects[ $element_id ] ) && is_array( $permalink_manager_redirects[ $element_id ] ) ) {
|
||||
foreach ( $permalink_manager_redirects[ $element_id ] as $index => $redirect ) {
|
||||
$html .= sprintf( "<tr><td>%s</td><td>%s</td></tr>", Permalink_Manager_UI_Elements::generate_option_field( "permalink-manager-redirects[{$index}]", array( "input_class" => "widefat", "value" => $redirect, 'extra_atts' => "data-index=\"{$index}\"" ) ), "<a href=\"#\" class=\"remove-redirect\"><span class=\"dashicons dashicons-no\"></span></a>" );
|
||||
}
|
||||
}
|
||||
$html .= "</table>";
|
||||
|
||||
// 1C. Add new redirect button
|
||||
$html .= sprintf( "<button type=\"button\" class=\"button button-small hide-if-no-js\" id=\"permalink-manager-new-redirect\">%s</button>", __( "Add new redirect", "permalink-manager" ) );
|
||||
|
||||
// 1D. Description
|
||||
$html .= "<div class=\"redirects-panel-description\">";
|
||||
/* translators: %s: Homepage URL */
|
||||
$html .= sprintf( wpautop( __( "<strong>Please use URIs only!</strong><br />For instance, to set-up a redirect for <code>%s/old-uri</code> please use <code>old-uri</code>.", "permalink-manager" ) ), home_url() );
|
||||
$html .= "</div>";
|
||||
|
||||
$html .= "</div>";
|
||||
|
||||
// 2. Extra redirects
|
||||
$html .= "<div class=\"single-section\">";
|
||||
|
||||
$html .= sprintf( "<p><label for=\"auto_auri\" class=\"strong\">%s %s</label></p>", __( "Redirect this page to external URL", "permalink-manager" ), Permalink_Manager_UI_Elements::help_tooltip( __( "If not empty, the visitors trying to access this page will be redirected to the URL specified below.", "permalink-manager" ) ) );
|
||||
|
||||
$external_redirect_url = ( ! empty( $permalink_manager_external_redirects[ $element_id ] ) ) ? esc_url( $permalink_manager_external_redirects[ $element_id ] ) : "";
|
||||
$html .= Permalink_Manager_UI_Elements::generate_option_field( "permalink-manager-external-redirect", array( "input_class" => "widefat", "value" => urldecode( $external_redirect_url ), "placeholder" => __( "http://another-website.com/final-target-url", "permalink-manager" ) ) );
|
||||
|
||||
// 2B. Description
|
||||
$html .= "<div class=\"redirects-panel-description\">";
|
||||
$html .= wpautop( __( "<strong>Please use full URLs!</strong><br />For instance, <code>http://another-website.com/final-target-url</code>.", "permalink-manager" ) );
|
||||
$html .= "</div>";
|
||||
|
||||
$html .= "</div>";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
+298
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Display the settings page
|
||||
*/
|
||||
class Permalink_Manager_Settings {
|
||||
|
||||
public function __construct() {
|
||||
add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new section to the Permalink Manager UI
|
||||
*
|
||||
* @param array $admin_sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_admin_section( $admin_sections ) {
|
||||
$admin_sections['settings'] = array(
|
||||
'name' => __( 'Settings', 'permalink-manager' ),
|
||||
'function' => array( 'class' => 'Permalink_Manager_Settings', 'method' => 'output' )
|
||||
);
|
||||
|
||||
return $admin_sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array with settings and render the HTML output
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function output() {
|
||||
// Get all registered post types & taxonomies
|
||||
$all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array( null, null, true );
|
||||
$all_taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array( false, false, true );
|
||||
$content_types = ( defined( 'PERMALINK_MANAGER_PRO' ) ) ? array( 'post_types' => $all_post_types, 'taxonomies' => $all_taxonomies ) : array( 'post_types' => $all_post_types );
|
||||
|
||||
$sections_and_fields = apply_filters( 'permalink_manager_settings_fields', array(
|
||||
'general' => array(
|
||||
'section_name' => __( 'General settings', 'permalink-manager' ),
|
||||
'container' => 'row',
|
||||
'name' => 'general',
|
||||
'fields' => array(
|
||||
'auto_update_uris' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Permalink update', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'choices' => array( 0 => __( 'Don\'t auto-update custom permalinks (default mode)', 'permalink-manager' ), 1 => __( 'Auto-update custom permalinks', 'permalink-manager' ), 2 => __( 'Disable custom permalinks for new posts/terms', 'permalink-manager' ) ),
|
||||
'description' => sprintf( '<strong>%s</strong><br />%s<br />%s', __( 'Custom permalinks in Permalink Manager will not be updated automatically to avoid overwriting individual modifications. If necessary, you can opt to change them every time a post/term is saved to match the Permastructure settings default format.', 'permalink-manager' ), __( 'If you select the third option, Permalink Manager will not generate new custom permalinks for newly added items. This lets you choose which pages will have custom permalinks and which will continue to use the original WordPress permalinks.', 'permalink-manager' ), __( 'The Permalink Manager editor allows you to select a different mode and override this global settings for specific posts and terms.', 'permalink-manager' ) )
|
||||
),
|
||||
'force_custom_slugs' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Slugs mode', 'permalink-manager' ),
|
||||
'input_class' => 'settings-select',
|
||||
'choices' => array( 0 => __( 'Use WordPress slugs (default mode)', 'permalink-manager' ), 1 => __( 'Use actual titles instead of WordPress slugs', 'permalink-manager' ), 2 => __( 'Inherit parents\' slugs', 'permalink-manager' ) ),
|
||||
'description' => sprintf( '<strong>%s</strong><br />%s<br />%s', __( 'Permalink Manager can generate custom permalinks using either WordPress slugs or actual titles.', 'permalink-manager' ), __( 'A slug is a permalink component that identifies a certain page. For example, "<em>shop</em>" and "<em>sample-product</em>" are two slugs in the permalink "<em>shop/sample-product</em>".', 'permalink-manager' ), __( 'WordPress slugs are generated automatically from the first title and remain the same even if the title is changed.', 'permalink-manager' ) )
|
||||
),
|
||||
'trailing_slashes' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Trailing slashes', 'permalink-manager' ),
|
||||
'input_class' => 'settings-select',
|
||||
'choices' => array( 0 => __( 'Use default settings', 'permalink-manager' ), 1 => __( 'Add trailing slashes', 'permalink-manager' ), 2 => __( 'Remove trailing slashes', 'permalink-manager' ) ),
|
||||
'description' => sprintf( '<strong>%s</strong><br />%s<br />%s', __( 'This option can be used to alter the native settings and control if trailing slash should be added or removed from the end of posts & terms permalinks.', 'permalink-manager' ), __( 'You can use this feature to either add or remove the slashes from end of WordPress permalinks.', 'permalink-manager' ), __( 'Please go to "<em>Redirect settings -> Trailing slashes redirect</em>" to force the trailing slashes mode with redirect.', 'permalink-manager' ) )
|
||||
)
|
||||
)
|
||||
),
|
||||
'redirect' => array(
|
||||
'section_name' => __( 'Redirect settings', 'permalink-manager' ),
|
||||
'container' => 'row',
|
||||
'name' => 'general',
|
||||
'fields' => array(
|
||||
'canonical_redirect' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Canonical redirect', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'description' => sprintf( '<strong>%s</strong><br />%s', __( 'Canonical redirect allows WordPress to "correct" the requested URL and redirect visitor to the canonical permalink.', 'permalink-manager' ), __( 'Permalink Manager uses canonical redirect to avoid "duplicate content" SEO issues by redirecting different permalinks that lead to the same content to a custom permalink set in the plugin.', 'permalink-manager' ) )
|
||||
),
|
||||
/*'endpoint_redirect' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __('Redirect with endpoints', 'permalink-manager'),
|
||||
'input_class' => '',
|
||||
'description' => sprintf('%s',
|
||||
__('<strong>Please enable this option if you would like to copy the endpoint from source URL to the target URL during the canonical redirect.</strong>', 'permalink-manager')
|
||||
)
|
||||
),*/ 'old_slug_redirect' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Old slug redirect', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'description' => sprintf( '<strong>%s</strong><br />%s', __( 'Old slug redirect is used by WordPress to provide a fallback for old version of slugs after they are changed.', 'permalink-manager' ), __( 'If enabled, the visitors trying to access the URL with the old slug will be redirected to the canonical permalink.', 'permalink-manager' ) )
|
||||
),
|
||||
'extra_redirects' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Extra redirects (aliases)', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'pro' => true,
|
||||
'disabled' => true,
|
||||
'description' => sprintf( '%s<br /><strong>%s</strong>', __( 'Please enable this option if you would like to manage additional custom redirects (aliases) in URI Editor for individual posts & terms.', 'permalink-manager' ), __( 'You can disable this feature if you use another plugin to control the redirects, eg. Yoast SEO Premium or Redirection.', 'permalink-manager' ) )
|
||||
),
|
||||
'setup_redirects' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Save old custom permalinks as extra redirects', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'pro' => true,
|
||||
'disabled' => true,
|
||||
'description' => sprintf( '%s<br /><strong>%s</strong>', __( 'If enabled, Permalink Manager will save the "extra redirect" for earlier version of custom permalink after you change it (eg. with URI Editor or Regenerate/reset tool).', 'permalink-manager' ), __( 'Please note that the new redirects will be saved only if "Extra redirects (aliases)" option is turned on above.', 'permalink-manager' ) )
|
||||
),
|
||||
'trailing_slashes_redirect' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Trailing slashes redirect', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'description' => sprintf( '%s<br /><strong>%s</strong>', __( 'Permalink Manager can force the trailing slashes settings in the custom permalinks with redirect.', 'permalink-manager' ), __( 'Please go to "<em>General settings -> Trailing slashes</em>" to choose if trailing slashes should be added or removed from WordPress permalinks.', 'permalink-manager' ) )
|
||||
),
|
||||
'copy_query_redirect' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Redirect with query parameters', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'description' => sprintf( '%s<br />%s', __( 'If enabled, the query parameters will be copied to the target URL when the redirect is triggered.', 'permalink-manager' ), __( 'Example: <em>https://example.com/product/old-product-url/<strong>?discount-code=blackfriday</strong></em> => <em>https://example.com/new-product-url/<strong>?discount-code=blackfriday</strong></em>', 'permalink-manager' ) )
|
||||
),
|
||||
'sslwww_redirect' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Force HTTPS/WWW', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'description' => sprintf( '<strong>%s</strong><br />%s', __( 'You can use Permalink Manager to force SSL or "www" prefix in WordPress permalinks.', 'permalink-manager' ), __( 'Please disable it if you encounter any redirect loop issues.', 'permalink-manager' ) )
|
||||
),
|
||||
'redirect' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Redirect mode', 'permalink-manager' ),
|
||||
'input_class' => 'settings-select',
|
||||
'choices' => array( 0 => __( 'Disable (Permalink Manager redirect functions)', 'permalink-manager' ), "301" => __( '301 redirect', 'permalink-manager' ), "302" => __( '302 redirect', 'permalink-manager' ) ),
|
||||
'description' => sprintf( '%s<br /><strong>%s</strong>', __( 'Permalink Manager includes a set of hooks that allow to extend the redirect functions used natively by WordPress to avoid 404 errors.', 'permalink-manager' ), __( 'You can disable this feature if you do not want Permalink Manager to trigger any additional redirect functions at all.', 'permalink-manager' ) )
|
||||
)
|
||||
)
|
||||
),
|
||||
'exclusion' => array(
|
||||
'section_name' => __( 'Exclusion settings', 'permalink-manager' ),
|
||||
'container' => 'row',
|
||||
'name' => 'general',
|
||||
'fields' => array(
|
||||
'partial_disable' => array(
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Exclude content types', 'permalink-manager' ),
|
||||
'choices' => $content_types,
|
||||
'description' => __( 'Permalink Manager will ignore and not filter the custom permalinks of all selected above post types & taxonomies.', 'permalink-manager' )
|
||||
),
|
||||
'partial_disable_strict' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( '"Exclude content types" strict mode', 'permalink-manager' ),
|
||||
'description' => __( 'If this option is enabled, any custom post types and taxonomies with the "<strong>query_var</strong>" and "<strong>rewrite</strong>" attributes set to "<em>false</em>" will be excluded from the plugin and hence will not be shown in the "<em>Exclude content types</em>" options.', 'permalink-manager' )
|
||||
),
|
||||
'exclude_post_ids' => array(
|
||||
'type' => 'text',
|
||||
'label' => __( 'Exclude posts/pages by ID', 'permalink-manager' ),
|
||||
'input_class' => 'widefat',
|
||||
'description' => sprintf( '%s<br />%s', __( 'Specify the IDs of posts/pages for which you want to preserve the original WordPress URLs instead of applying custom permalinks.', 'permalink-manager' ), __( 'Enter single IDs (e.g., "<em>4, 8, 15, 16</em>"), ID ranges (e.g., "<em>23-42</em>"), or a combination of both.', 'permalink-manager' ) )
|
||||
),
|
||||
'exclude_term_ids' => array(
|
||||
'type' => 'text',
|
||||
'label' => __( 'Exclude terms by ID', 'permalink-manager' ),
|
||||
'input_class' => 'widefat',
|
||||
'pro' => true,
|
||||
'disabled' => true,
|
||||
'description' => sprintf( '%s<br />%s', __( 'Specify the IDs of categories/terms for which you want to preserve the original WordPress URLs instead of applying custom permalinks.', 'permalink-manager' ), __( 'Enter single IDs (e.g., "<em>4, 8, 15, 16</em>"), ID ranges (e.g., "<em>23-42</em>"), or a combination of both.', 'permalink-manager' ) )
|
||||
),
|
||||
/*'exclude_query_vars' => array(
|
||||
'type' => 'text',
|
||||
'label' => __( 'Non-redirectable query variables', 'permalink-manager' ),
|
||||
'placeholder' => 'e.g. um_user, um_tab',
|
||||
'input_class' => 'widefat',
|
||||
'description' => __( 'Use this field to exclude specific query variables from triggering a redirect when Permalink Manager detects permalinks. To prevent the redirect on dynamic sections (e.g. profile tabs), you can enter the variable used by the third-party plugin (e.g. <em>um_user</em> for Ultimate Member plugin).', 'permalink-manager' )
|
||||
),*/ 'ignore_drafts' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Exclude drafts & pending posts', 'permalink-manager' ),
|
||||
'choices' => array( 0 => __( 'Do not exclude', 'permalink-manager' ), 1 => __( 'Exclude drafts', 'permalink-manager' ), 2 => __( 'Exclude drafts & pending posts', 'permalink-manager' ) ),
|
||||
'description' => __( 'If enabled, custom permalinks for posts marked as "draft" or "pending" will not be created.', 'permalink-manager' )
|
||||
)
|
||||
)
|
||||
),
|
||||
'third_parties' => array(
|
||||
'section_name' => __( 'Third party plugins', 'permalink-manager' ),
|
||||
'container' => 'row',
|
||||
'name' => 'general',
|
||||
'fields' => array(
|
||||
'fix_language_mismatch' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'WPML/Polylang fix language mismatch', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'choices' => array( 0 => __( 'Disable', 'permalink-manager' ), 1 => __( 'Load the language variant of the requested page', 'permalink-manager' ), 2 => __( 'Redirect to the language variant of the requested page', 'permalink-manager' ) ),
|
||||
'class_exists' => array( 'SitePress', 'Polylang' ),
|
||||
'description' => __( 'The plugin may load the relevant translation or trigger the canonical redirect when a custom permalink is detected, but the URL language code does not match the detected item\'s language code. ', 'permalink-manager' )
|
||||
),
|
||||
'wpml_support' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'WPML compatibility functions', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'class_exists' => array( 'SitePress' ),
|
||||
'description' => __( 'Please disable this feature if the language code in the custom permalinks is incorrect.', 'permalink-manager' )
|
||||
),
|
||||
'wpml_translate_mode' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Edit permalinks in WPML\'s Translation Editor', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'class_exists' => array( 'SitePress' ),
|
||||
'description' => __( 'If enabled, you will be able to <strong>manually edit custom permalinks</strong> directly while translating the content in WPML.', 'permalink-manager' )
|
||||
),
|
||||
'pmxi_support' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'WP All Import/Export support', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'class_exists' => array( 'PMXI_Plugin', 'PMXE_Plugin' ),
|
||||
'description' => __( 'If disabled, the custom permalinks <strong>will not be saved</strong> for the posts imported with WP All Import plugin.', 'permalink-manager' )
|
||||
),
|
||||
'um_support' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Ultimate Member support', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'class_exists' => 'UM',
|
||||
'description' => __( 'If enabled, Permalink Manager will detect the additional Ultimate Member pages (eg. "account" sections).', 'permalink-manager' )
|
||||
),
|
||||
'rankmath_redirect' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'RankMath\'s "Redirections" fix redirect conflict', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'description' => sprintf( '%s<br />%s', __( 'If enabled, the Permalink Manager plugin <strong>will stop a redirect set with the RankMath SEO plugin\'s "Source URLs"</strong> if this URL is already being used as a custom permalink by any post or term.', 'permalink-manager' ), __( 'This prevents redirect loops when both plugins manage redirects on the same URL.', 'permalink-manager' ) )
|
||||
),
|
||||
'yoast_breadcrumbs' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Breadcrumbs support', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'description' => __( 'If enabled, the HTML breadcrumbs will be filtered by Permalink Manager to mimic the current URL structure.<br />Works with: <strong>WooCommerce, Yoast SEO, Slim Seo, RankMath and SEOPress</strong> breadcrumbs.', 'permalink-manager' )
|
||||
),
|
||||
'primary_category' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( '"Primary category" support', 'permalink-manager' ),
|
||||
'input_class' => '',
|
||||
'description' => __( 'If enabled, Permalink Manager will use the "primary category" for the default post permalinks.<br />Works with: <strong>Yoast SEO, The SEO Framework, RankMath and SEOPress</strong>.', 'permalink-manager' )
|
||||
),
|
||||
)
|
||||
),
|
||||
'advanced' => array(
|
||||
'section_name' => __( 'Advanced settings', 'permalink-manager' ),
|
||||
'container' => 'row',
|
||||
'name' => 'general',
|
||||
'fields' => array(
|
||||
'show_native_slug_field' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Show "Native slug" field in URI Editor', 'permalink-manager' )
|
||||
),
|
||||
'pagination_redirect' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Handling non-existent pagination pages', 'permalink-manager' ),
|
||||
'choices' => array( 0 => __( 'Stop canonical redirect without forcing "404" status code', 'permalink-manager' ), 1 => __( 'Stop canonical redirect and force "404" status code', 'permalink-manager' ), 2 => __( 'Allow canonical redirect without forcing "404" status code', 'permalink-manager' ) ),
|
||||
'description' => __( 'Decide if you would like the plugin to force a "404" error or allow canonical redirect for pagination pages that do not exist.<br /><strong>If you experience any issues with pagination pages, please select the first option.</strong>', 'permalink-manager' )
|
||||
),
|
||||
'disable_slug_sanitization' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Strip special characters', 'permalink-manager' ),
|
||||
'input_class' => 'settings-select',
|
||||
'choices' => array( 0 => __( 'Yes, use native settings', 'permalink-manager' ), 1 => __( 'No, keep special characters (.,|_+) in the slugs', 'permalink-manager' ) ),
|
||||
'description' => __( 'If enabled only alphanumeric characters, underscores and dashes will be allowed for post/term slugs.', 'permalink-manager' )
|
||||
),
|
||||
'keep_accents' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'Convert accented letters', 'permalink-manager' ),
|
||||
'input_class' => 'settings-select',
|
||||
'choices' => array( 0 => __( 'Yes, use native settings', 'permalink-manager' ), 1 => __( 'No, keep accented letters in the slugs', 'permalink-manager' ) ),
|
||||
'description' => __( 'If enabled, all the accented letters will be replaced with their non-accented equivalent (eg. Å => A, Æ => AE, Ø => O, Ć => C).', 'permalink-manager' )
|
||||
),
|
||||
'edit_uris_cap' => array(
|
||||
'type' => 'select',
|
||||
'label' => __( 'URI Editor role capability', 'permalink-manager' ),
|
||||
'choices' => array( 'edit_theme_options' => __( 'Administrator (edit_theme_options)', 'permalink-manager' ), 'publish_pages' => __( 'Editor (publish_pages)', 'permalink-manager' ), 'publish_posts' => __( 'Author (publish_posts)', 'permalink-manager' ), 'edit_posts' => __( 'Contributor (edit_posts)', 'permalink-manager' ) ),
|
||||
/* translators: %s: WordPress.org docs reference */ 'description' => sprintf( __( 'Only the users who have selected capability will be able to access URI Editor.<br />The list of capabilities <a href="%s" target="_blank">can be found here</a>.', 'permalink-manager' ), 'https://wordpress.org/support/article/roles-and-capabilities/#capability-vs-role-table' )
|
||||
),
|
||||
'force_unique_uris' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Force unique custom permalinks', 'permalink-manager' ),
|
||||
'description' => __( 'Enable this option if you want the plugin to automatically append a numeric suffix (e.g. -2, -3) to duplicated permalinks.', 'permalink-manager' )
|
||||
),
|
||||
'auto_fix_duplicates' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Automatically fix broken URIs', 'permalink-manager' ),
|
||||
'description' => sprintf( '%s', __( 'Enable this option if you would like to automatically remove redundant permalinks & duplicated redirects during page load.', 'permalink-manager' ) )
|
||||
),
|
||||
'debug_mode' => array(
|
||||
'type' => 'single_checkbox',
|
||||
'label' => __( 'Debug mode', 'permalink-manager' ),
|
||||
'description' => __( 'Debug mode allows access to extra debug info by adding <em>?debug_url</em> to the URL for plugin troubleshooting.', 'permalink-manager' )
|
||||
)
|
||||
)
|
||||
)
|
||||
) );
|
||||
|
||||
return Permalink_Manager_UI_Elements::get_the_form( $sections_and_fields, 'tabs', array( 'text' => __( 'Save settings', 'permalink-manager' ), 'class' => 'primary margin-top' ), '', array( 'action' => 'permalink-manager', 'name' => 'permalink_manager_options' ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Display the page where the slugs could be regenerated or replaced
|
||||
*/
|
||||
class Permalink_Manager_Tools {
|
||||
|
||||
public function __construct() {
|
||||
add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 1 );
|
||||
add_action( 'plugins_loaded', array( $this, 'init' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register hooks
|
||||
*/
|
||||
public function init() {
|
||||
add_filter( 'permalink_manager_tools_fields', array( $this, 'add_preview_mode_toggle' ), 50, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new section to the Permalink Manager UI
|
||||
*
|
||||
* @param array $admin_sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_admin_section( $admin_sections ) {
|
||||
$admin_sections['tools'] = array(
|
||||
'name' => __( 'Tools', 'permalink-manager' ),
|
||||
'subsections' => array(
|
||||
'duplicates' => array(
|
||||
'name' => __( 'Permalink Duplicates', 'permalink-manager' ),
|
||||
'function' => array( 'class' => 'Permalink_Manager_Tools', 'method' => 'duplicates_output' )
|
||||
),
|
||||
'find_and_replace' => array(
|
||||
'name' => __( 'Find & Replace', 'permalink-manager' ),
|
||||
'function' => array( 'class' => 'Permalink_Manager_Tools', 'method' => 'find_and_replace_output' )
|
||||
),
|
||||
'regenerate_slugs' => array(
|
||||
'name' => __( 'Regenerate/Reset', 'permalink-manager' ),
|
||||
'function' => array( 'class' => 'Permalink_Manager_Tools', 'method' => 'regenerate_slugs_output' )
|
||||
),
|
||||
'stop_words' => array(
|
||||
'name' => __( 'Stop Words', 'permalink-manager' ),
|
||||
'function' => array( 'class' => 'Permalink_Manager_UI_Elements', 'method' => 'pro_text' )
|
||||
),
|
||||
'import' => array(
|
||||
'name' => __( 'Custom Permalinks', 'permalink-manager' ),
|
||||
'function' => array( 'class' => 'Permalink_Manager_UI_Elements', 'method' => 'pro_text' )
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $admin_sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a warning message before the user changes the permalinks mode to "Native slugs"
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_instructions() {
|
||||
return sprintf( '<p><strong>%s</strong>', __( 'A MySQL backup is highly recommended before using "<em>Native slugs</em>" mode!', 'permalink-manager' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a list of all duplicated URIs and redirects
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function duplicates_output() {
|
||||
// Get the duplicates & another variables
|
||||
$all_duplicates = Permalink_Manager_Admin_Functions::get_all_duplicates();
|
||||
|
||||
$button_url = add_query_arg( array(
|
||||
'section' => 'tools',
|
||||
'subsection' => 'duplicates',
|
||||
'clear-permalink-manager-uris' => 1,
|
||||
'permalink-manager-nonce' => wp_create_nonce( 'permalink-manager' )
|
||||
), Permalink_Manager_Admin_Functions::get_admin_url() );
|
||||
|
||||
$html = sprintf( "<h3>%s</h3>", __( "List of duplicated permalinks", "permalink-manager" ) );
|
||||
$html .= wpautop( sprintf( "<a class=\"button button-primary\" href=\"%s\">%s</a>", $button_url, __( 'Fix custom permalinks & redirects', 'permalink-manager' ) ) );
|
||||
|
||||
if ( ! empty( $all_duplicates ) ) {
|
||||
foreach ( $all_duplicates as $uri => $duplicates ) {
|
||||
$html .= "<div class=\"permalink-manager postbox permalink-manager-duplicate-box\">";
|
||||
$html .= sprintf( '<h4 class="heading"><a href="%1$s" target="_blank">%1$s <span class="dashicons dashicons-external"></span></a></h4>', Permalink_Manager_Core_Functions::control_trailing_slashes( home_url( $uri ) ) );
|
||||
$html .= "<table>";
|
||||
|
||||
foreach ( $duplicates as $item_id ) {
|
||||
$html .= "<tr>";
|
||||
|
||||
// Detect duplicate type
|
||||
preg_match( "/(redirect-([\d]+)_)?(?:(tax-)?([\d]*))/", $item_id, $parts );
|
||||
|
||||
$is_extra_redirect = ( ! empty( $parts[1] ) ) ? true : false;
|
||||
$duplicate_type = ( $is_extra_redirect ) ? __( 'Extra Redirect', 'permalink-manager' ) : __( 'Custom permalink', 'permalink-manager' );
|
||||
$detected_id = $parts[4];
|
||||
// $detected_index = $parts[2];
|
||||
$detected_term = ( ! empty( $parts[3] ) ) ? true : false;
|
||||
$remove_link = ( $is_extra_redirect ) ? sprintf( " <a href=\"%s\"><span class=\"dashicons dashicons-trash\"></span> %s</a>", admin_url( "tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-redirect={$item_id}" ), __( 'Remove Redirect', 'permalink-manager' ) ) : "";
|
||||
|
||||
// Get term
|
||||
if ( $detected_term && ! empty( $detected_id ) ) {
|
||||
$term = get_term( $detected_id );
|
||||
if ( ! empty( $term->name ) ) {
|
||||
$title = $term->name;
|
||||
$edit_label = "<span class=\"dashicons dashicons-edit\"></span>" . __( "Edit term", "permalink-manager" );
|
||||
$edit_link = get_edit_tag_link( $term->term_id, $term->taxonomy );
|
||||
} else {
|
||||
$title = __( "(Removed term)", "permalink-manager" );
|
||||
$edit_label = "<span class=\"dashicons dashicons-trash\"></span>" . __( "Remove broken URI", "permalink-manager" );
|
||||
$edit_link = admin_url( "tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-uri=tax-{$detected_id}" );
|
||||
}
|
||||
} // Get post
|
||||
else if ( ! empty( $detected_id ) ) {
|
||||
$post = get_post( $detected_id );
|
||||
if ( ! empty( $post->post_title ) && post_type_exists( $post->post_type ) ) {
|
||||
$title = $post->post_title;
|
||||
$edit_label = "<span class=\"dashicons dashicons-edit\"></span>" . __( "Edit post", "permalink-manager" );
|
||||
$edit_link = get_edit_post_link( $post->ID );
|
||||
} else {
|
||||
$title = __( "(Removed post)", "permalink-manager" );
|
||||
$edit_label = "<span class=\"dashicons dashicons-trash\"></span>" . __( "Remove broken URI", "permalink-manager" );
|
||||
$edit_link = admin_url( "tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-uri={$detected_id}" );
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$html .= sprintf( '<td><a href="%1$s">%2$s</a>%3$s</td><td>%4$s</td><td class="actions"><a href="%1$s">%5$s</a>%6$s</td>', $edit_link, $title, " <small>#{$detected_id}</small>", $duplicate_type, $edit_label, $remove_link );
|
||||
$html .= "</tr>";
|
||||
}
|
||||
$html .= "</table>";
|
||||
$html .= "</div>";
|
||||
}
|
||||
} else {
|
||||
$html .= sprintf( "<p class=\"alert notice-success notice\">%s</p>", __( 'Congratulations! No duplicated URIs or Redirects found!', 'permalink-manager' ) );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a form for "Tools -> Find & replace" tool
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function find_and_replace_output() {
|
||||
// Get all registered post types array & statuses
|
||||
$all_post_statuses_array = Permalink_Manager_Helper_Functions::get_post_statuses();
|
||||
$all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array();
|
||||
$all_taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array();
|
||||
|
||||
$fields = apply_filters( 'permalink_manager_tools_fields', array(
|
||||
'old_string' => array(
|
||||
'label' => __( 'Find ...', 'permalink-manager' ),
|
||||
'type' => 'text',
|
||||
'container' => 'row',
|
||||
'input_class' => 'widefat'
|
||||
),
|
||||
'new_string' => array(
|
||||
'label' => __( 'Replace with ...', 'permalink-manager' ),
|
||||
'type' => 'text',
|
||||
'container' => 'row',
|
||||
'input_class' => 'widefat'
|
||||
),
|
||||
'mode' => array(
|
||||
'label' => __( 'Mode', 'permalink-manager' ),
|
||||
'type' => 'select',
|
||||
'container' => 'row',
|
||||
'choices' => array(
|
||||
'custom_uris' => __( 'Custom permalinks', 'permalink-manager' ),
|
||||
'slugs' => __( 'Native slugs', 'permalink-manager' )
|
||||
),
|
||||
),
|
||||
'content_type' => array(
|
||||
'label' => __( 'Select content type', 'permalink-manager' ),
|
||||
'type' => 'select',
|
||||
'disabled' => true,
|
||||
'pro' => true,
|
||||
'container' => 'row',
|
||||
'default' => 'post_types',
|
||||
'choices' => array(
|
||||
'post_types' => __( 'Post types', 'permalink-manager' ),
|
||||
'taxonomies' => __( 'Taxonomies', 'permalink-manager' )
|
||||
),
|
||||
),
|
||||
'post_types' => array(
|
||||
'label' => __( 'Select post types', 'permalink-manager' ),
|
||||
'type' => 'checkbox',
|
||||
'container' => 'row',
|
||||
'default' => array( 'post', 'page' ),
|
||||
'choices' => $all_post_types,
|
||||
'select_all' => '',
|
||||
'unselect_all' => '',
|
||||
),
|
||||
'taxonomies' => array(
|
||||
'label' => __( 'Select taxonomies', 'permalink-manager' ),
|
||||
'type' => 'checkbox',
|
||||
'container' => 'row',
|
||||
'container_class' => 'hidden',
|
||||
'default' => array( 'category', 'post_tag' ),
|
||||
'choices' => $all_taxonomies,
|
||||
'pro' => true,
|
||||
'select_all' => '',
|
||||
'unselect_all' => '',
|
||||
),
|
||||
'post_statuses' => array(
|
||||
'label' => __( 'Select post statuses', 'permalink-manager' ),
|
||||
'type' => 'checkbox',
|
||||
'container' => 'row',
|
||||
'default' => array( 'publish' ),
|
||||
'choices' => $all_post_statuses_array,
|
||||
'select_all' => '',
|
||||
'unselect_all' => '',
|
||||
),
|
||||
'ids' => array(
|
||||
'label' => __( 'Select IDs', 'permalink-manager' ),
|
||||
'type' => 'text',
|
||||
'container' => 'row',
|
||||
//'disabled' => true,
|
||||
'description' => __( 'To narrow the above filters you can type the post IDs (or ranges) here. E.g. <strong>1-8, 10, 25</strong>.', 'permalink-manager' ),
|
||||
//'pro' => true,
|
||||
'input_class' => 'widefat'
|
||||
)
|
||||
), 'find_and_replace' );
|
||||
|
||||
$sidebar = '<h3>' . __( 'Important notices', 'permalink-manager' ) . '</h3>';
|
||||
$sidebar .= self::display_instructions();
|
||||
|
||||
return Permalink_Manager_UI_Elements::get_the_form( $fields, 'columns-3', array( 'text' => __( 'Find and replace', 'permalink-manager' ), 'class' => 'primary margin-top' ), $sidebar, array( 'action' => 'permalink-manager', 'name' => 'find_and_replace' ), true, 'form-ajax' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a form for "Tools -> Regenerate/reset" tool
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function regenerate_slugs_output() {
|
||||
// Get all registered post types array & statuses
|
||||
$all_post_statuses_array = Permalink_Manager_Helper_Functions::get_post_statuses();
|
||||
$all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array();
|
||||
$all_taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array();
|
||||
|
||||
$fields = apply_filters( 'permalink_manager_tools_fields', array(
|
||||
'mode' => array(
|
||||
'label' => __( 'Mode', 'permalink-manager' ),
|
||||
'type' => 'select',
|
||||
'container' => 'row',
|
||||
'choices' => array(
|
||||
'custom_uris' => __( 'Regenerate custom permalinks', 'permalink-manager' ),
|
||||
'slugs' => __( 'Regenerate native slugs', 'permalink-manager' ),
|
||||
'native' => __( 'Use original URLs as custom permalinks', 'permalink-manager' )
|
||||
),
|
||||
),
|
||||
'content_type' => array(
|
||||
'label' => __( 'Select content type', 'permalink-manager' ),
|
||||
'type' => 'select',
|
||||
'disabled' => true,
|
||||
'pro' => true,
|
||||
'container' => 'row',
|
||||
'default' => 'post_types',
|
||||
'choices' => array(
|
||||
'post_types' => __( 'Post types', 'permalink-manager' ),
|
||||
'taxonomies' => __( 'Taxonomies', 'permalink-manager' )
|
||||
),
|
||||
),
|
||||
'post_types' => array(
|
||||
'label' => __( 'Select post types', 'permalink-manager' ),
|
||||
'type' => 'checkbox',
|
||||
'container' => 'row',
|
||||
'default' => array( 'post', 'page' ),
|
||||
'choices' => $all_post_types,
|
||||
'select_all' => '',
|
||||
'unselect_all' => '',
|
||||
),
|
||||
'taxonomies' => array(
|
||||
'label' => __( 'Select taxonomies', 'permalink-manager' ),
|
||||
'type' => 'checkbox',
|
||||
'container' => 'row',
|
||||
'container_class' => 'hidden',
|
||||
'default' => array( 'category', 'post_tag' ),
|
||||
'choices' => $all_taxonomies,
|
||||
'pro' => true,
|
||||
'select_all' => '',
|
||||
'unselect_all' => '',
|
||||
),
|
||||
'post_statuses' => array(
|
||||
'label' => __( 'Select post statuses', 'permalink-manager' ),
|
||||
'type' => 'checkbox',
|
||||
'container' => 'row',
|
||||
'default' => array( 'publish' ),
|
||||
'choices' => $all_post_statuses_array,
|
||||
'select_all' => '',
|
||||
'unselect_all' => '',
|
||||
),
|
||||
'ids' => array(
|
||||
'label' => __( 'Select IDs', 'permalink-manager' ),
|
||||
'type' => 'text',
|
||||
'container' => 'row',
|
||||
//'disabled' => true,
|
||||
'description' => __( 'To narrow the above filters you can type the post IDs (or ranges) here. E.g. <strong>1-8, 10, 25</strong>.', 'permalink-manager' ),
|
||||
//'pro' => true,
|
||||
'input_class' => 'widefat'
|
||||
)
|
||||
), 'regenerate' );
|
||||
|
||||
$sidebar = '<h3>' . __( 'Important notices', 'permalink-manager' ) . '</h3>';
|
||||
$sidebar .= self::display_instructions();
|
||||
|
||||
return Permalink_Manager_UI_Elements::get_the_form( $fields, 'columns-3', array( 'text' => __( 'Regenerate', 'permalink-manager' ), 'class' => 'primary margin-top' ), $sidebar, array( 'action' => 'permalink-manager', 'name' => 'regenerate' ), true, 'form-ajax' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Preview mode" toggle to the end of options list in "Regenerate/rest" and "Find & replace"
|
||||
*
|
||||
* @param $fields
|
||||
* @param $tool_name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_preview_mode_toggle( $fields, $tool_name ) {
|
||||
if ( is_array( $fields ) && in_array( $tool_name, array( 'regenerate', 'find_and_replace' ) ) ) {
|
||||
$fields['preview_mode'] = array(
|
||||
'label' => __( 'Preview mode', 'permalink-manager' ),
|
||||
'type' => 'single_checkbox',
|
||||
'container' => 'row',
|
||||
'description' => __( 'Enable this option if you want to review the changes in "read mode" before saving them in the database.', 'permalink-manager' )
|
||||
);
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
+849
@@ -0,0 +1,849 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional UI functions related to WordPress Admin Dashboard UI
|
||||
*/
|
||||
class Permalink_Manager_UI_Elements {
|
||||
|
||||
public function __construct() {
|
||||
add_filter( 'default_hidden_columns', array( $this, 'quick_edit_hide_column' ), 99 );
|
||||
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_column_form' ), 999, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the option field
|
||||
*
|
||||
* @param $input_name
|
||||
* @param $args
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function generate_option_field( $input_name, $args ) {
|
||||
global $permalink_manager_options;
|
||||
|
||||
// Reset $fields variables
|
||||
$fields = '';
|
||||
|
||||
// Allow to filter the $args
|
||||
$args = apply_filters( 'permalink_manager_field_args', $args, $input_name );
|
||||
|
||||
$field_type = ( isset( $args['type'] ) ) ? $args['type'] : 'text';
|
||||
$default = ( isset( $args['default'] ) ) ? $args['default'] : '';
|
||||
$label = ( isset( $args['label'] ) ) ? $args['label'] : '';
|
||||
$rows = ( isset( $args['rows'] ) ) ? "rows=\"{$args['rows']}\"" : "rows=\"5\"";
|
||||
$description = ( isset( $args['before_description'] ) ) ? $args['before_description'] : "";
|
||||
$description .= ( isset( $args['description'] ) ) ? "<p class=\"field-description description\">{$args['description']}</p>" : "";
|
||||
$description .= ( isset( $args['after_description'] ) ) ? $args['after_description'] : "";
|
||||
$description .= ( isset( $args['pro'] ) ) ? sprintf( "<p class=\"field-description description alert info\">%s</p>", ( self::pro_text( true ) ) ) : "";
|
||||
$append_content = ( isset( $args['append_content'] ) ) ? "{$args['append_content']}" : "";
|
||||
|
||||
// Input attributes
|
||||
$input_atts = ( ! empty( $args['input_class'] ) ) ? "class='{$args['input_class']}'" : '';
|
||||
$input_atts .= ( ! empty( $args['readonly'] ) ) ? " readonly='readonly'" : '';
|
||||
$input_atts .= ( ! empty( $args['disabled'] ) ) ? " disabled='disabled'" : '';
|
||||
$input_atts .= ( ! empty( $args['placeholder'] ) ) ? " placeholder='{$args['placeholder']}'" : '';
|
||||
$input_atts .= ( ! empty( $args['extra_atts'] ) ) ? " {$args['extra_atts']}" : '';
|
||||
|
||||
// Display the field if the related class exists
|
||||
if ( ! empty( $args['class_exists'] ) ) {
|
||||
$related_classes = (array) $args['class_exists'];
|
||||
$related_classes_exist = 0;
|
||||
|
||||
foreach ( $related_classes as $related_class ) {
|
||||
if ( class_exists( $related_class ) ) {
|
||||
$related_classes_exist = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Do not display if the related class it not found
|
||||
if ( empty( $related_classes_exist ) ) {
|
||||
$field_type = $args['container_class'] = 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
// Check the container classes
|
||||
$container_class = ( isset( $args['container_class'] ) ) ? " class=\"{$args['container_class']} field-container\"" : " class=\"field-container\"";
|
||||
|
||||
// Get the field value (if it is not set in $args)
|
||||
if ( ! empty( $args['value'] ) ) {
|
||||
$value = $args['value'];
|
||||
} else {
|
||||
// Extract the section and field name from $input_name
|
||||
preg_match( '/([^\[]+)(?:\[([^\[]+)\])(?:\[([^\[]+)\])?/', $input_name, $field_section_and_name );
|
||||
|
||||
if ( $field_section_and_name ) {
|
||||
$section_name = $field_section_and_name[1];
|
||||
$field_name = $field_section_and_name[2];
|
||||
|
||||
if ( ! empty( $field_section_and_name[3] ) ) {
|
||||
$subsection_name = $field_section_and_name[3];
|
||||
$value = ( isset( $permalink_manager_options[ $section_name ][ $field_name ][ $subsection_name ] ) ) ? $permalink_manager_options[ $section_name ][ $field_name ][ $subsection_name ] : $default;
|
||||
} else {
|
||||
$value = ( isset( $permalink_manager_options[ $section_name ][ $field_name ] ) ) ? $permalink_manager_options[ $section_name ][ $field_name ] : $default;
|
||||
}
|
||||
} else {
|
||||
$value = ( isset( $permalink_manager_options[ $input_name ] ) ) ? $permalink_manager_options[ $input_name ] : $default;
|
||||
}
|
||||
}
|
||||
|
||||
switch ( $field_type ) {
|
||||
case 'checkbox' :
|
||||
$fields .= '<div class="checkboxes">';
|
||||
foreach ( $args['choices'] as $choice_value => $choice ) {
|
||||
$input_template = "<label for='%s[]'><input type='checkbox' %s value='%s' name='%s[]' %s /> %s</label>";
|
||||
|
||||
if ( empty( $choice['label'] ) && is_array( $choice ) ) {
|
||||
if ( in_array( $choice_value, array( 'post_types', 'taxonomies' ) ) ) {
|
||||
$group_labels = array( 'post_types' => __( 'Post types', 'permalink-manager' ), 'taxonomies' => __( 'Taxonomies', 'permalink-manager' ) );
|
||||
$fields .= sprintf( '<p>%s</p>', $group_labels[ $choice_value ] );
|
||||
}
|
||||
|
||||
foreach ( $choice as $sub_choice_value => $sub_choice ) {
|
||||
$label = ( ! empty( $sub_choice['label'] ) ) ? $sub_choice['label'] : $sub_choice;
|
||||
$atts = ( ! empty( $value[ $choice_value ] ) && in_array( $sub_choice_value, $value[ $choice_value ] ) ) ? "checked='checked'" : "";
|
||||
$atts .= ( ! empty( $sub_choice['atts'] ) ) ? " {$sub_choice['atts']}" : "";
|
||||
|
||||
$fields .= sprintf( $input_template, $input_name, $input_atts, $sub_choice_value, "{$input_name}[{$choice_value}]", $atts, $label );
|
||||
}
|
||||
} else {
|
||||
$label = ( ! empty( $choice['label'] ) ) ? $choice['label'] : $choice;
|
||||
$atts = ( is_array( $value ) && in_array( $choice_value, $value ) ) ? "checked='checked'" : "";
|
||||
$atts .= ( ! empty( $choice['atts'] ) ) ? " {$choice['atts']}" : "";
|
||||
|
||||
$fields .= sprintf( $input_template, $input_name, $input_atts, $choice_value, $input_name, $atts, $label );
|
||||
}
|
||||
}
|
||||
$fields .= '</div>';
|
||||
|
||||
// Add helper checkboxes for bulk actions
|
||||
if ( isset( $args['select_all'] ) || isset( $args['unselect_all'] ) ) {
|
||||
$select_all_label = ( ! empty( $args['select_all'] ) ) ? $args['select_all'] : __( 'Select all', 'permalink-manager' );
|
||||
$unselect_all_label = ( ! empty( $args['unselect_all'] ) ) ? $args['unselect_all'] : __( 'Unselect all', 'permalink-manager' );
|
||||
|
||||
$fields .= "<p class=\"checkbox_actions extra-links\">";
|
||||
$fields .= ( isset( $args['select_all'] ) ) ? "<a href=\"#\" class=\"select_all\">{$select_all_label}</a> " : "";
|
||||
$fields .= ( isset( $args['unselect_all'] ) ) ? "<a href=\"#\" class=\"unselect_all\">{$unselect_all_label}</a>" : "";
|
||||
$fields .= "</p>";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'single_checkbox' :
|
||||
$fields .= '<div class="single_checkbox">';
|
||||
if ( is_array( $value ) ) {
|
||||
$input_key = preg_replace( '/(.*)(?:\[([^\[]+)\])$/', '$2', $input_name );
|
||||
$checked = ( ! empty( $value[ $input_key ] ) ) ? "checked='checked'" : "";
|
||||
} else {
|
||||
$checked = ( $value == 1 ) ? "checked='checked'" : "";
|
||||
}
|
||||
$checkbox_label = ( isset( $args['checkbox_label'] ) ) ? $args['checkbox_label'] : '';
|
||||
|
||||
$fields .= "<input type='hidden' {$input_atts} value='0' name='{$input_name}' />";
|
||||
$fields .= "<label for='{$input_name}'><input type='checkbox' {$input_atts} value='1' name='{$input_name}' {$checked} /> {$checkbox_label}</label>";
|
||||
$fields .= '</div>';
|
||||
break;
|
||||
|
||||
case 'radio' :
|
||||
$fields .= '<div class="radios">';
|
||||
foreach ( $args['choices'] as $choice_value => $choice ) {
|
||||
$label = ( is_array( $choice ) ) ? $choice['label'] : $choice;
|
||||
$atts = ( $choice_value == $value ) ? "checked='checked'" : "";
|
||||
$atts .= ( ! empty( $choice['atts'] ) ) ? " {$choice['atts']}" : "";
|
||||
|
||||
$fields .= "<label for='{$input_name}[]'><input type='radio' {$input_atts} value='{$choice_value}' name='{$input_name}[]' {$atts} /> {$label}</label>";
|
||||
}
|
||||
$fields .= '</div>';
|
||||
break;
|
||||
|
||||
case 'select' :
|
||||
$fields .= '<span class="select">';
|
||||
$fields .= "<select name='{$input_name}' {$input_atts}>";
|
||||
foreach ( $args['choices'] as $choice_value => $choice ) {
|
||||
$label = ( is_array( $choice ) ) ? $choice['label'] : $choice;
|
||||
$atts = ( $choice_value == $value ) ? "selected='selected'" : "";
|
||||
$atts .= ( ! empty( $choice['atts'] ) ) ? " {$choice['atts']}" : "";
|
||||
|
||||
if ( $choice == '---' ) {
|
||||
$fields .= "<option disabled=\"disabled\">------------------</option>";
|
||||
} else {
|
||||
$fields .= "<option value='{$choice_value}' {$atts}>{$label}</option>";
|
||||
}
|
||||
}
|
||||
$fields .= '</select>';
|
||||
$fields .= '</span>';
|
||||
break;
|
||||
|
||||
case 'textarea' :
|
||||
$fields .= sprintf( "<textarea %s name='%s' %s>%s</textarea>", $input_atts, $input_name, $rows, esc_textarea( $value ) );
|
||||
break;
|
||||
|
||||
case 'pre' :
|
||||
$fields .= sprintf( "<pre %s>%s</pre>", $input_atts, esc_textarea( $value ) );
|
||||
break;
|
||||
|
||||
case 'info' :
|
||||
$fields .= sprintf( "<div %s>%s</div>", $input_atts, $value );
|
||||
break;
|
||||
|
||||
case 'clearfix' :
|
||||
return "<div class=\"clearfix\"></div>";
|
||||
|
||||
default :
|
||||
$input_type = ( in_array( $field_type, array( 'text', 'password', 'number', 'hidden' ) ) ) ? $field_type : 'text';
|
||||
$fields .= sprintf( "<%s type='%s' %s value='%s' name='%s' />", 'input', $input_type, $input_atts, esc_attr( $value ), $input_name );
|
||||
}
|
||||
|
||||
// Get the final HTML output
|
||||
if ( isset( $args['container'] ) && $args['container'] == 'tools' ) {
|
||||
$html = "<div{$container_class}>";
|
||||
$html .= "<h4>{$label}</h4>";
|
||||
$html .= "<div class='{$input_name}-container'>{$fields}</div>";
|
||||
$html .= $description;
|
||||
$html .= $append_content;
|
||||
$html .= "</div>";
|
||||
} else if ( isset( $args['container'] ) && $args['container'] == 'row' ) {
|
||||
$html = sprintf( "<tr id=\"%s\" data-field=\"%s\" %s>", esc_attr( preg_replace( '/(?:.*\[)(.*)(?:\].*)/', '$1', $input_name ) ), $input_name, $container_class );
|
||||
$html .= sprintf( "<th><label for=\"%s\">%s</label></th>", $input_name, $args['label'] );
|
||||
$html .= sprintf( "<td><fieldset>%s%s</fieldset></td>", $fields, $description );
|
||||
$html .= "</tr>";
|
||||
$html .= ( $append_content ) ? "<tr class=\"appended-row\"><td colspan=\"2\">{$append_content}</td></tr>" : "";
|
||||
} else if ( isset( $args['container'] ) && $args['container'] == 'screen-options' ) {
|
||||
$html = "<fieldset data-field=\"{$input_name}\" {$container_class}><legend>{$args['label']}</legend>";
|
||||
$html .= "<div class=\"field-content\">{$fields}{$description}</div>";
|
||||
$html .= ( $append_content ) ? "<div class=\"appended-row\">{$append_content}</div>" : "";
|
||||
$html .= "</fieldset>";
|
||||
} else {
|
||||
$html = $fields . $append_content;
|
||||
}
|
||||
|
||||
return apply_filters( 'permalink_manager_field_output', $html );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display hidden field to indicate posts or taxonomies admin sections
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function section_type_field( $type = 'post' ) {
|
||||
return self::generate_option_field( 'content_type', array( 'value' => $type, 'type' => 'hidden' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the HTML output of form for provided fields array
|
||||
*
|
||||
* @param array $fields
|
||||
* @param string $container
|
||||
* @param array $button
|
||||
* @param string $sidebar
|
||||
* @param array $nonce
|
||||
* @param bool $wrap
|
||||
* @param string $form_class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function get_the_form( $fields = array(), $container = '', $button = array(), $sidebar = '', $nonce = array(), $wrap = false, $form_class = '' ) {
|
||||
// 1. Check if the content will be displayed in columns and button details
|
||||
switch ( $container ) {
|
||||
case 'columns-3' :
|
||||
$wrapper_class = 'columns-container';
|
||||
$form_column_class = 'column column-2_3';
|
||||
$sidebar_class = 'column column-1_3';
|
||||
break;
|
||||
|
||||
case 'tabs' :
|
||||
$wrapper_class = 'form settings-tabs';
|
||||
$sidebar_class = $form_column_class = '';
|
||||
break;
|
||||
|
||||
// there will be more cases in the future ...
|
||||
default :
|
||||
$sidebar_class = 'sidebar';
|
||||
$wrapper_class = $form_column_class = '';
|
||||
}
|
||||
|
||||
// 2. Process the array with button and nonce field settings
|
||||
$button_text = ( ! empty( $button['text'] ) ) ? $button['text'] : '';
|
||||
$button_class = ( ! empty( $button['class'] ) ) ? $button['class'] : '';
|
||||
$button_attributes = ( ! empty( $button['attributes'] ) ) ? $button['attributes'] : '';
|
||||
$nonce_action = ( ! empty( $nonce['action'] ) ) ? $nonce['action'] : '';
|
||||
$nonce_name = ( ! empty( $nonce['name'] ) ) ? $nonce['name'] : '';
|
||||
$form_classes = ( ! empty( $form_class ) ) ? $form_class : '';
|
||||
|
||||
// 3. Now get the HTML output (start section row container)
|
||||
$html = ( $wrapper_class ) ? "<div class=\"{$wrapper_class}\">" : '';
|
||||
|
||||
// 4. Display settings tabs
|
||||
if ( $container == 'tabs' ) {
|
||||
// Get active section
|
||||
$active_tab = ( ! empty( $_POST['pm_active_tab'] ) ) ? sanitize_key( $_POST['pm_active_tab'] ) : key( array_slice( $fields, 0, 1, true ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
|
||||
$html .= "<ul class=\"subsubsub\">";
|
||||
foreach ( $fields as $tab_name => $tab ) {
|
||||
$active_class = ( $active_tab === $tab_name ) ? 'current' : '';
|
||||
$html .= sprintf( "<li><a href=\"#%s\" class=\"%s\" data-tab=\"%s\">%s</a></li>", $tab_name, $active_class, $tab_name, $tab['section_name'] );
|
||||
}
|
||||
$html .= "</ul>";
|
||||
}
|
||||
|
||||
// 5. Display some notes
|
||||
if ( $sidebar_class && $sidebar ) {
|
||||
$html .= sprintf( "<div class=\"%s\">", $sidebar_class );
|
||||
$html .= "<div class=\"section-notes\">";
|
||||
$html .= $sidebar;
|
||||
$html .= "</div>";
|
||||
$html .= "</div>";
|
||||
}
|
||||
|
||||
// 6. Start fields' section
|
||||
$html .= ( $form_column_class ) ? sprintf( "<div class=\"%s\">", $form_column_class ) : "";
|
||||
$html .= sprintf( "<form method=\"POST\" class=\"%s\">", $form_classes );
|
||||
$html .= ( $wrap ) ? "<table class=\"form-table\">" : "";
|
||||
|
||||
// 7. Loop through all fields assigned to this section
|
||||
foreach ( $fields as $field_name => $field ) {
|
||||
$tab_name = ( isset( $field['fields'] ) ) ? $field_name : '';
|
||||
$field_name = ( ! empty( $field['name'] ) ) ? $field['name'] : $field_name;
|
||||
|
||||
// A. Display table row
|
||||
if ( isset( $field['container'] ) && $field['container'] == 'row' ) {
|
||||
$row_output = "";
|
||||
|
||||
// Loop through all fields assigned to this section
|
||||
if ( isset( $field['fields'] ) ) {
|
||||
foreach ( $field['fields'] as $section_field_id => $section_field ) {
|
||||
if ( is_string( $section_field ) ) {
|
||||
$row_output .= $section_field;
|
||||
} else {
|
||||
$section_field_name = ( ! empty( $section_field['name'] ) ) ? $section_field['name'] : "{$field_name}[$section_field_id]";
|
||||
$section_field['container'] = 'row';
|
||||
|
||||
$row_output .= self::generate_option_field( $section_field_name, $section_field );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$row_output .= self::generate_option_field( $field_name, $field );
|
||||
}
|
||||
|
||||
if ( isset( $field['section_name'] ) ) {
|
||||
if ( $container == 'tabs' ) {
|
||||
$is_active_tab = ( ! empty( $active_tab ) && $active_tab == $tab_name ) ? 'class="active-tab"' : '';
|
||||
|
||||
$html .= sprintf( "<div id=\"pm_%s\" data-tab=\"%s\" %s>", $tab_name, $tab_name, $is_active_tab );
|
||||
}
|
||||
|
||||
$html .= "<h3>{$field['section_name']}</h3>";
|
||||
$html .= ( isset( $field['append_content'] ) ) ? $field['append_content'] : "";
|
||||
$html .= ( isset( $field['description'] ) ) ? sprintf( "<p class=\"description\">%s</p>", $field['description'] ) : "";
|
||||
$html .= sprintf( "<table class=\"form-table\" data-field=\"%s\">%s</table>", $field_name, $row_output );
|
||||
$html .= ( $container == 'tabs' ) ? "</div>" : "";
|
||||
} else {
|
||||
$html .= $row_output;
|
||||
}
|
||||
} // B. Display single field
|
||||
else {
|
||||
$html .= self::generate_option_field( $field_name, $field );
|
||||
}
|
||||
}
|
||||
|
||||
$html .= ( $wrap ) ? "</table>" : "";
|
||||
|
||||
// 8. Add a hidden field with section name for settings page
|
||||
if ( $container == 'tabs' && ! empty( $active_tab ) ) {
|
||||
$html .= self::generate_option_field( 'pm_active_tab', array( 'value' => $active_tab, 'type' => 'hidden', 'readonly' => true ) );
|
||||
}
|
||||
|
||||
// 9. End the fields' section + add button & nonce fields
|
||||
if ( $nonce_action && $nonce_name ) {
|
||||
$html .= wp_nonce_field( $nonce_action, $nonce_name, true, false );
|
||||
$html .= self::generate_option_field( 'pm_session_id', array( 'value' => uniqid(), 'type' => 'hidden' ) );
|
||||
}
|
||||
$html .= ( $button_text ) ? get_submit_button( $button_text, $button_class, '', false, $button_attributes ) : "";
|
||||
$html .= '</form>';
|
||||
$html .= ( $form_column_class ) ? "</div>" : "";
|
||||
|
||||
// 10. End the section row container
|
||||
$html .= ( $wrapper_class ) ? "</div>" : "";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin sections' HTML code
|
||||
*
|
||||
* @param array $sections
|
||||
* @param string $active_section
|
||||
* @param string $active_subsection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static public function get_plugin_sections_html( $sections, $active_section = '', $active_subsection = '' ) {
|
||||
global $permalink_manager_after_sections_html;
|
||||
|
||||
$html = "<div id=\"permalink-manager\" class=\"wrap\">";
|
||||
$html .= sprintf( '<h2 id="plugin-name-heading">%1$s <a href="%2$s" class="author-link" target="_blank">%3$s</a></h2>', PERMALINK_MANAGER_PLUGIN_NAME, esc_attr( PERMALINK_MANAGER_PROMO ), PERMALINK_MANAGER_VERSION );
|
||||
|
||||
// Display the tab navigation
|
||||
$html .= "<div id=\"permalink-manager-tab-nav\" class=\"nav-tab-wrapper\">";
|
||||
foreach ( $sections as $section_name => $section_properties ) {
|
||||
$active_class = ( $active_section === $section_name ) ? 'nav-tab-active nav-tab' : 'nav-tab';
|
||||
$section_url = Permalink_Manager_Admin_Functions::get_admin_url( "§ion={$section_name}" );
|
||||
|
||||
$html .= sprintf( "<a href=\"%s\" class=\"%s section_%s\">%s</a>", $section_url, $active_class, $section_name, $section_properties['name'] );
|
||||
}
|
||||
|
||||
// Upgrade to Pro version
|
||||
$html .= ( ! Permalink_Manager_Admin_Functions::is_pro_active() ) ? sprintf( "<a href=\"%s\" target=\"_blank\" class=\"nav-tab section_upgrade\"><i class=\"dashicons dashicons-external\"></i> %s</a>", PERMALINK_MANAGER_PROMO, __( 'Upgrade to PRO', 'permalink-manager' ) ) : '';
|
||||
$html .= "</div>";
|
||||
|
||||
// Now display the active section
|
||||
$html .= "<div id=\"permalink-manager-sections\">";
|
||||
$active_section_array = ( isset( $sections[ $active_section ] ) ) ? $sections[ $active_section ] : "";
|
||||
|
||||
// Display additional navigation for subsections
|
||||
if ( isset( $sections[ $active_section ]['subsections'] ) ) {
|
||||
$html .= "<ul class=\"subsubsub\">";
|
||||
foreach ( $sections[ $active_section ]['subsections'] as $subsection_name => $subsection ) {
|
||||
$active_class = ( $active_subsection === $subsection_name ) ? 'current' : '';
|
||||
$subsection_url = Permalink_Manager_Admin_Functions::get_admin_url( "§ion={$active_section}&subsection={$subsection_name}" );
|
||||
|
||||
$html .= "<li><a href=\"{$subsection_url}\" class=\"{$active_class}\">{$subsection['name']}</a></li>";
|
||||
}
|
||||
$html .= "</ul>";
|
||||
}
|
||||
|
||||
// A. Execute the function assigned to the subsection
|
||||
if ( isset( $active_section_array['subsections'][ $active_subsection ]['function'] ) ) {
|
||||
$class_name = $active_section_array['subsections'][ $active_subsection ]['function']['class'];
|
||||
$section_object = new $class_name();
|
||||
|
||||
$section_content = call_user_func( array( $section_object, $active_section_array['subsections'][ $active_subsection ]['function']['method'] ) );
|
||||
} // B. Execute the function assigned to the section
|
||||
else if ( isset( $active_section_array['function'] ) ) {
|
||||
$class_name = $active_section_array['function']['class'];
|
||||
$section_object = new $class_name();
|
||||
|
||||
$section_content = call_user_func( array( $section_object, $active_section_array['function']['method'] ) );
|
||||
} // C. Display the raw HTMl output of subsection
|
||||
else if ( isset( $active_section_array['subsections'][ $active_subsection ]['html'] ) ) {
|
||||
$section_content = $active_section_array['subsections'][ $active_subsection ]['html'];
|
||||
} // D. Try to display the raw HTMl output of section
|
||||
else {
|
||||
$section_content = ( isset( $active_section_array['html'] ) ) ? $active_section_array['html'] : "";
|
||||
}
|
||||
|
||||
$html .= "<div class=\"single-section\" data-section=\"{$active_section}\" id=\"{$active_section}\">{$section_content}</div>";
|
||||
$html .= "</div>";
|
||||
|
||||
// Display alerts and another content if needed and close .wrap container
|
||||
$html .= $permalink_manager_after_sections_html;
|
||||
$html .= "</div>";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the array or HTML table with updated slugs after one of the actions is triggered
|
||||
*
|
||||
* @param array $updated_array
|
||||
* @param bool $return_array
|
||||
* @param bool $display_full_table
|
||||
* @param bool $preview_mode
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
static function display_updated_slugs( $updated_array, $return_array = false, $display_full_table = true, $preview_mode = false ) {
|
||||
global $permalink_manager_before_sections_html, $adjust_id_url_filter_off;
|
||||
|
||||
$updated_slugs_count = 0;
|
||||
$html = $main_content = $alert = "";
|
||||
|
||||
// Disable "Adjust IDs for multilingual functionality" in WPML to make sure that the correct URLs are displayed in the results table
|
||||
$adjust_id_url_filter_off = true; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
||||
|
||||
if ( is_array( $updated_array ) ) {
|
||||
// Check if slugs should be displayed
|
||||
$first_slug = reset( $updated_array );
|
||||
$show_slugs = ( ! empty( $_POST['mode'] ) && $_POST['mode'] == 'slugs' ) ? true : false; // phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
|
||||
$header_footer = '<tr>';
|
||||
$header_footer .= sprintf( '<th class="column-primary">%s</th>', __( 'Title', 'permalink-manager' ) );
|
||||
if ( $show_slugs ) {
|
||||
$header_footer .= ( isset( $first_slug['old_slug'] ) ) ? sprintf( '<th>%s</th>', __( 'Old Slug', 'permalink-manager' ) ) : '';
|
||||
$header_footer .= ( isset( $first_slug['new_slug'] ) ) ? sprintf( '<th>%s</th>', __( 'New Slug', 'permalink-manager' ) ) : '';
|
||||
} else {
|
||||
$header_footer .= sprintf( '<th>%s</th>', __( 'Old URI', 'permalink-manager' ) );
|
||||
$header_footer .= sprintf( '<th>%s</th>', __( 'New URI', 'permalink-manager' ) );
|
||||
}
|
||||
$header_footer .= '</tr>';
|
||||
|
||||
$screen_reader_button = sprintf( '<button type="button" class="toggle-row"><span class="screen-reader-text">%s</span></button>', __( 'Show more details', 'permalink-manager' ) );
|
||||
|
||||
foreach ( $updated_array as $row ) {
|
||||
// Odd/even class
|
||||
$updated_slugs_count ++;
|
||||
$alternate_class = ( $updated_slugs_count % 2 == 1 ) ? ' class="alternate"' : '';
|
||||
|
||||
// Taxonomy
|
||||
if ( ! empty( $row['tax'] ) ) {
|
||||
$term_link = get_term_link( intval( $row['ID'] ), $row['tax'] );
|
||||
$permalink = ( is_wp_error( $term_link ) ) ? "-" : $term_link;
|
||||
} else {
|
||||
$permalink = get_permalink( $row['ID'] );
|
||||
}
|
||||
|
||||
// Decode permalink
|
||||
$permalink = rawurldecode( rawurldecode( $permalink ) );
|
||||
|
||||
$main_content .= sprintf( '<tr data-id="%s" %s>', $row['ID'], $alternate_class );
|
||||
$main_content .= sprintf( '<td class="row-title column-primary" data-colname="%s">%s<a target="_blank" href="%s"><span class="small">%s</span></a> %s</td>', __( 'Title', 'permalink-manager' ), sanitize_text_field( $row['item_title'] ), $permalink, $permalink, $screen_reader_button );
|
||||
|
||||
if ( $show_slugs ) {
|
||||
$main_content .= ( isset( $row['old_slug'] ) ) ? sprintf( '<td data-colname="%s">%s</td>', __( 'Old Slug', 'permalink-manager' ), rawurldecode( $row['old_slug'] ) ) : "";
|
||||
$main_content .= ( isset( $row['new_slug'] ) ) ? sprintf( '<td data-colname="%s">%s</td>', __( 'New Slug', 'permalink-manager' ), rawurldecode( $row['new_slug'] ) ) : "";
|
||||
} else {
|
||||
$main_content .= sprintf( '<td data-colname="%s">%s</td>', __( 'Old URI', 'permalink-manager' ), rawurldecode( $row['old_uri'] ) );
|
||||
$main_content .= sprintf( '<td data-colname="%s">%s</td>', __( 'New URI', 'permalink-manager' ), rawurldecode( $row['new_uri'] ) );
|
||||
}
|
||||
$main_content .= '</tr>';
|
||||
}
|
||||
|
||||
// Merge header, footer and content
|
||||
if ( $display_full_table ) {
|
||||
$html = sprintf( '<h3 id="updated-list">%s</h3>', __( 'List of updated items', 'permalink-manager' ) );
|
||||
$html .= '<table class="widefat wp-list-table updated-slugs-table">';
|
||||
$html .= sprintf( '<thead>%s</thead><tbody>%s</tbody><tfoot>%s</tfoot>', $header_footer, $main_content, $header_footer );
|
||||
} else {
|
||||
$html = $main_content;
|
||||
}
|
||||
|
||||
$html .= '</table>';
|
||||
}
|
||||
|
||||
// 3. Display the alert
|
||||
if ( isset( $updated_slugs_count ) ) {
|
||||
if ( $updated_slugs_count > 0 && ! $preview_mode ) {
|
||||
// translators: %d is the number of items where custom permalinks were updated
|
||||
$alert_content = sprintf( _n( '<strong class="updated_count">%d</strong> item was updated!', '<strong class="updated_count">%d</strong> items were updated!', $updated_slugs_count, 'permalink-manager' ), $updated_slugs_count ) . ' ';
|
||||
// translators: %s is the anchor link to the updated items' table
|
||||
$alert_content .= sprintf( __( '<a %s>Click here</a> to go to the list of processed items', 'permalink-manager' ), "href=\"#updated-list\"" );
|
||||
|
||||
$alert = self::get_alert_message( $alert_content, 'updated updated_slugs' );
|
||||
} else {
|
||||
$alert_content = ( $preview_mode ) ? sprintf( '[%s] ', __( 'Preview mode', 'permalink-manager' ) ) : '';
|
||||
$alert_content .= __( '<strong>No items</strong> were processed!', 'permalink-manager' );
|
||||
|
||||
$alert = self::get_alert_message( $alert_content, 'error updated_slugs' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $return_array ) {
|
||||
return array(
|
||||
'html' => $html,
|
||||
'alert' => $alert
|
||||
);
|
||||
} else {
|
||||
$permalink_manager_before_sections_html .= $alert;
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML output of URI Editor
|
||||
*
|
||||
* @param WP_Post|WP_Term $element
|
||||
* @param bool $gutenberg
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function display_uri_box( $element, $gutenberg = false ) {
|
||||
global $permalink_manager_options;
|
||||
|
||||
// Check the user capabilities
|
||||
if ( Permalink_Manager_Admin_Functions::current_user_can_edit_uris() === false ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( ! empty( $element->ID ) ) {
|
||||
$id = $element_id = $element->ID;
|
||||
$native_slug = $element->post_name;
|
||||
|
||||
$auto_update_val = get_post_meta( $id, "auto_update_uri", true );
|
||||
|
||||
$is_draft = ( ! empty( $element->post_status ) && ( in_array( $element->post_status, array( 'draft', 'auto-draft' ) ) ) ) ? true : false;
|
||||
$is_draft_excluded = Permalink_Manager_Helper_Functions::is_draft_excluded( $element );
|
||||
$is_front_page = Permalink_Manager_Helper_Functions::is_front_page( $id );
|
||||
|
||||
// Allow users force the URI Editor to appear for drafts and auto-drafts
|
||||
if ( $is_draft_excluded && $is_draft ) {
|
||||
$is_draft_excluded = apply_filters( 'permalink_manager_auto_draft_hide_editor', $is_draft_excluded, $element, $gutenberg );
|
||||
}
|
||||
|
||||
// Get URIs
|
||||
$uri = Permalink_Manager_URI_Functions_Post::get_post_uri( $id, true, $is_draft );
|
||||
$default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $id );
|
||||
$native_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $id, true );
|
||||
} else if ( class_exists( 'Permalink_Manager_URI_Functions_Tax' ) ) {
|
||||
$id = $element->term_id;
|
||||
$element_id = "tax-{$id}";
|
||||
$native_slug = $element->slug;
|
||||
|
||||
$auto_update_val = get_term_meta( $id, "auto_update_uri", true );
|
||||
|
||||
// Get URIs
|
||||
$uri = Permalink_Manager_URI_Functions_Tax::get_term_uri( $element->term_id, true );
|
||||
$default_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri( $element->term_id );
|
||||
$native_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri( $element->term_id, true );
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
// If the draft is excluded do not display the contents of URI Editor
|
||||
if ( ! empty( $is_draft_excluded ) ) {
|
||||
if ( ! empty( $element->post_status ) && $element->post_status == 'auto-draft' ) {
|
||||
$alert = __( 'Save your post to activate the permalink editor and make changes to the custom permalink.', 'permalink-manager' );
|
||||
} else {
|
||||
/* translators: Link to settings page */
|
||||
$alert = sprintf( __( 'The custom permalink cannot be edited due to the <a href="%s" target="_blank">Permalink Manager settings</a> ("<strong>Exclude drafts & pending posts</strong>") and the post status not allowing it.', 'permalink-manager' ), Permalink_Manager_Admin_Functions::get_admin_url( '§ion=settings#exclusion' ) );
|
||||
}
|
||||
|
||||
$html = ( ! $gutenberg ) ? "<div class=\"permalink-manager-edit-uri-box\">" : "<div class=\"permalink-manager-gutenberg permalink-manager-edit-uri-box\">";
|
||||
$html .= sprintf( '<p class="uri_locked">%s</p>', $alert );
|
||||
$html .= "</div>";
|
||||
} 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( "<span><button type=\"button\" class=\"button button-small hide-if-no-js\" id=\"permalink-manager-toggle\">%s</button></span>", __( "Permalink Manager", "permalink-manager" ) );
|
||||
|
||||
$html .= "<div id=\"permalink-manager\" class=\"postbox permalink-manager-edit-uri-box\" style=\"display: none;\">";
|
||||
|
||||
// 2. The heading
|
||||
$html .= "<a class=\"close-button\"><span class=\"screen-reader-text\">" . __( "Close: ", "permalink-manager" ) . __( "Permalink Manager", "permalink-manager" ) . "</span><span class=\"close-icon\" aria-hidden=\"false\"></span></a>";
|
||||
$html .= sprintf( "<h2><span>%s</span></h2>", __( "Permalink Manager", "permalink-manager" ) );
|
||||
|
||||
// 3. The fields container [start]
|
||||
$html .= "<div class=\"inside\">";
|
||||
} else {
|
||||
$html = "<div class=\"permalink-manager-gutenberg permalink-manager-edit-uri-box\">";
|
||||
}
|
||||
|
||||
// 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( '<p class="uri_locked hidden">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'The URL above is displayed in read-only mode. To enable editing, change the "<strong>Permalink update</strong>" setting to <em>Don\'t auto-update "Custom permalink"</em>.', 'permalink-manager' ) );
|
||||
}
|
||||
|
||||
$html .= sprintf( "<div class=\"custom_uri_container\"><p><label for=\"custom_uri\" class=\"strong\">%s</label></p><span>%s</span><span class=\"duplicated_uri_alert\"></span></div>", __( "Custom permalink", "permalink-manager" ), $custom_uri_field );
|
||||
|
||||
// 5. Auto-update URI
|
||||
if ( empty( $is_front_page ) ) {
|
||||
if ( ! empty( $auto_update_choices ) ) {
|
||||
$html .= sprintf( "<div><p><label for=\"auto_auri\" class=\"strong\">%s %s</label></p><span>%s</span></div>", __( "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( "<div class=\"native_slug_container\"><p><label for=\"native_slug\" class=\"strong\">%s %s</label></p><span>%s</span></div>", __( "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 .= "<div class=\"default-permalink-row columns-container\">";
|
||||
$html .= sprintf( "<span class=\"column-3_4\"><strong>%s:</strong> %s</span>", __( "Default custom permalink", "permalink-manager" ), esc_html( $default_uri ) );
|
||||
$html .= sprintf( "<span class=\"column-1_4\"><a href=\"#\" class=\"restore-default\"><span class=\"dashicons dashicons-image-rotate\"></span> %s</a></span>", __( "Use \"Default custom permalink\"", "permalink-manager" ) );
|
||||
// $html .= sprintf( "<span class=\"column-1_4\"><a href=\"#\" class=\"restore-default\" target=\"_blank\"><span class=\"dashicons dashicons-external\"></span> %s</a></span>", __( "Go to \"Permastructures\"", "permalink-manager" ) );
|
||||
$html .= "</div>";
|
||||
|
||||
// 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( "<div class=\"default-permalink-row columns-container\"><span><strong>%s</strong> <a href=\"%s\">%s</a></span></div>", $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}" );
|
||||
|
||||
if ( defined( 'PERMALINK_MANAGER_PRO' ) && class_exists( 'Permalink_Manager_Pro_License' ) ) {
|
||||
$html .= Permalink_Manager_Pro_License::license_info_uri_editor();
|
||||
}
|
||||
|
||||
// 10. Extra save button for Gutenberg
|
||||
if ( $gutenberg ) {
|
||||
$html .= sprintf( "<div class=\"default-permalink-row save-row columns-container hidden\"><div><a href=\"#\" class=\"button button-primary\" id=\"permalink-manager-save-button\">%s</a></div></div>", __( "Save permalink", "permalink-manager" ) );
|
||||
} else {
|
||||
$html .= "</div>";
|
||||
}
|
||||
|
||||
$html .= "</div>";
|
||||
}
|
||||
|
||||
// 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 = "<div class=\"permalink-manager redirects-row redirects-panel columns-container\">";
|
||||
$html .= sprintf( "<div><a class=\"button\" href=\"#\" id=\"toggle-redirect-panel\">%s</a></div>", __( "Manage redirects", "permalink-manager" ) );
|
||||
|
||||
$html .= "<div id=\"redirect-panel-inside\">";
|
||||
if ( class_exists( 'Permalink_Manager_Pro_Addons' ) ) {
|
||||
$html .= Permalink_Manager_Pro_Addons::display_redirect_form( $element_id );
|
||||
} else {
|
||||
$html .= self::pro_text( true );
|
||||
}
|
||||
$html .= "</div>";
|
||||
$html .= "</div>";
|
||||
|
||||
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 .= '<fieldset class="inline-edit-permalink">';
|
||||
$html .= sprintf( "<legend class=\"inline-edit-legend\">%s</legend>", __( "Permalink Manager", "permalink-manager" ) );
|
||||
|
||||
$html .= '<div class="inline-edit-col">';
|
||||
$html .= sprintf( "<label class=\"inline-edit-group\"><span class=\"title\">%s</span><span class=\"input-text-wrap\">%s</span></label>", __( "Custom permalink", "permalink-manager" ), Permalink_Manager_UI_Elements::generate_option_field( "custom_uri", array( "input_class" => "custom_uri", "value" => '' ) ) );
|
||||
$html .= "</div>";
|
||||
|
||||
$html .= "</fieldset>";
|
||||
|
||||
// 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( "<div class=\"{$alert_type} permalink-manager-notice notice {$class}\"{$alert_id}> %s</div>", wpautop( $alert_content ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML output of help tooltip
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function help_tooltip( $text = '' ) {
|
||||
return " <a href=\"#\" title=\"{$text}\" class=\"help_tooltip\"><span class=\"dashicons dashicons-editor-help\"></span></a>";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 <a href="%s" target="_blank">Permalink Manager Pro</a>.', 'permalink-manager' ), PERMALINK_MANAGER_PROMO );
|
||||
}
|
||||
|
||||
return ( $text_only ) ? $text : sprintf( "<div class=\"alert info\"> %s</div>", wpautop( $text, 'alert' ) );
|
||||
}
|
||||
}
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use WP_List_Table to display the "Bulk URI Editor" for post items
|
||||
*/
|
||||
class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
|
||||
|
||||
public $displayed_post_types, $displayed_post_statuses;
|
||||
|
||||
public function __construct() {
|
||||
global $permalink_manager_options, $active_subsection;
|
||||
|
||||
parent::__construct( array(
|
||||
'singular' => 'slug',
|
||||
'plural' => 'slugs'
|
||||
) );
|
||||
|
||||
$this->displayed_post_statuses = ( isset( $permalink_manager_options['screen-options']['post_statuses'] ) ) ? Permalink_Manager_Helper_Functions::prepare_array_for_sql_in( $permalink_manager_options['screen-options']['post_statuses'] ) : "'no-post-status'";
|
||||
$this->displayed_post_types = ( $active_subsection == 'all' ) ? Permalink_Manager_Helper_Functions::prepare_array_for_sql_in( $permalink_manager_options['screen-options']['post_types'] ) : "'{$active_subsection}'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML output with the whole WP_List_Table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_admin_section() {
|
||||
$output = "<form id=\"permalinks-post-types-table\" class=\"slugs-table\" method=\"post\">";
|
||||
$output .= wp_nonce_field( 'permalink-manager', 'uri_editor_nonce' );
|
||||
$output .= Permalink_Manager_UI_Elements::generate_option_field( 'pm_session_id', array( 'value' => uniqid(), 'type' => 'hidden' ) );
|
||||
|
||||
// Bypass
|
||||
ob_start();
|
||||
|
||||
$this->prepare_items();
|
||||
$this->display();
|
||||
$output .= ob_get_contents();
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
$output .= "</form>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of classes to be used in the HTML table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_table_classes() {
|
||||
return array( 'widefat', 'striped', $this->_args['plural'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add columns to the table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
return apply_filters( 'permalink_manager_uri_editor_columns', array(
|
||||
'item_title' => __( 'Post title', 'permalink-manager' ),
|
||||
'item_uri' => __( 'Custom permalink', 'permalink-manager' )
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define sortable columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_sortable_columns() {
|
||||
return array(
|
||||
'item_title' => array( 'post_title', false )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data inside the columns
|
||||
*
|
||||
* @param array $item
|
||||
* @param string $column_name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function column_default( $item, $column_name ) {
|
||||
global $permalink_manager_options;
|
||||
|
||||
if ( Permalink_Manager_Helper_Functions::is_front_page( $item['ID'] ) ) {
|
||||
$uri = '';
|
||||
$permalink = Permalink_Manager_Permastructure_Functions::get_permalink_base( $item['ID'] );
|
||||
$is_front_page = true;
|
||||
} else {
|
||||
$is_draft = ( $item["post_status"] == 'draft' ) ? true : false;
|
||||
$uri = Permalink_Manager_URI_Functions_Post::get_post_uri( $item['ID'], true, $is_draft );
|
||||
$uri = ( ! empty( $permalink_manager_options['general']['decode_uris'] ) ) ? urldecode( $uri ) : $uri;
|
||||
$permalink = get_permalink( $item['ID'] );
|
||||
$is_front_page = false;
|
||||
}
|
||||
|
||||
$field_args_base = array( 'type' => 'text', 'value' => $uri, 'without_label' => true, 'input_class' => 'custom_uri', 'extra_atts' => "data-element-id=\"{$item['ID']}\"" );
|
||||
$post_title = sanitize_text_field( $item['post_title'] );
|
||||
|
||||
$post_statuses_array = Permalink_Manager_Helper_Functions::get_post_statuses();
|
||||
$post_statuses_array['inherit'] = __( 'Inherit (Attachment)', 'permalink-manager' );
|
||||
|
||||
$output = apply_filters( 'permalink_manager_uri_editor_column_content', '', $column_name, get_post( $item['ID'] ) );
|
||||
if ( ! empty( $output ) ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
switch ( $column_name ) {
|
||||
case 'item_uri':
|
||||
// Get auto-update settings
|
||||
$auto_update_val = get_post_meta( $item['ID'], "auto_update_uri", true );
|
||||
$auto_update_uri = ( ! empty( $auto_update_val ) ) ? $auto_update_val : $permalink_manager_options["general"]["auto_update_uris"];
|
||||
|
||||
if ( $is_front_page ) {
|
||||
$field_args_base['disabled'] = true;
|
||||
$field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor is disabled because a custom permalink cannot be set for a front page.', 'permalink-manager' ) );
|
||||
} else if ( Permalink_Manager_Helper_Functions::is_draft_excluded( (int) $item['ID'] ) ) {
|
||||
$field_args_base['disabled'] = true;
|
||||
$field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor disabled due to "Exclude drafts & pending posts" setting and the post status.', 'permalink-manager' ) );
|
||||
} else if ( $auto_update_uri == 1 ) {
|
||||
$field_args_base['readonly'] = true;
|
||||
$field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'The above permalink will be automatically updated and is locked for editing.', 'permalink-manager' ) );
|
||||
} else if ( $auto_update_uri == 2 ) {
|
||||
$field_args_base['disabled'] = true;
|
||||
$field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor disabled due to "Permalink update" setting.', 'permalink-manager' ) );
|
||||
}
|
||||
|
||||
$output = '<div class="custom_uri_container">';
|
||||
$output .= Permalink_Manager_UI_Elements::generate_option_field( "uri[{$item['ID']}]", $field_args_base );
|
||||
$output .= "<span class=\"duplicated_uri_alert\"></span>";
|
||||
$output .= sprintf( "<a class=\"small post_permalink\" href=\"%s\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> %s</a>", $permalink, urldecode( $permalink ) );
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
|
||||
case 'item_title':
|
||||
$output = esc_html( $post_title );
|
||||
$output .= '<div class="extra-info small">';
|
||||
$output .= sprintf( "<span><strong>%s:</strong> %s</span>", __( "Slug", "permalink-manager" ), urldecode( $item['post_name'] ) );
|
||||
$output .= sprintf( " | <span><strong>%s:</strong> {$post_statuses_array[$item["post_status"]]}</span>", __( "Post status", "permalink-manager" ) );
|
||||
$output .= apply_filters( 'permalink_manager_uri_editor_extra_info', '', $column_name, get_post( $item['ID'] ) );
|
||||
$output .= '</div>';
|
||||
|
||||
$output .= '<div class="row-actions">';
|
||||
$output .= sprintf( '<span class="edit"><a href="%1$s" title="%2$s">%2$s</a> | </span>', esc_url( get_edit_post_link( $item['ID'] ) ), __( 'Edit', 'permalink-manager' ) );
|
||||
$output .= sprintf( '<span class="view"><a target="_blank" href="%1$s" title="%2$s %3$s" rel="permalink">%2$s</a> | </span>', esc_attr( $permalink ), __( 'View', 'permalink-manager' ), esc_html( $post_title ) );
|
||||
$output .= sprintf( '<span class="id">#%s</span>', esc_html( $item['ID'] ) );
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
|
||||
default:
|
||||
return $item[ $column_name ];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The button that allows to save updated slugs
|
||||
*/
|
||||
function extra_tablenav( $which ) {
|
||||
global $wpdb, $active_section, $active_subsection;
|
||||
|
||||
if ( $which == "top" ) {
|
||||
$button_text = __( 'Save all the permalinks below', 'permalink-manager' );
|
||||
$button_name = 'update_all_slugs[top]';
|
||||
} else {
|
||||
$button_text = __( 'Save all the permalinks above', 'permalink-manager' );
|
||||
$button_name = 'update_all_slugs[bottom]';
|
||||
}
|
||||
|
||||
$html = "<div class=\"alignleft actions\">";
|
||||
$html .= get_submit_button( $button_text, 'primary alignleft', $button_name, false, array( 'id' => 'doaction', 'value' => 'update_all_slugs' ) );
|
||||
$html .= "</div>";
|
||||
|
||||
if ( $which == "top" ) {
|
||||
// Filter by date
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$months = $wpdb->get_results( "SELECT DISTINCT month(post_date) AS m, year(post_date) AS y FROM {$wpdb->posts} WHERE post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types) ORDER BY post_date DESC", ARRAY_A );
|
||||
|
||||
if ( $months ) {
|
||||
$choices = array( __( 'All dates', 'permalink-manager' ) );
|
||||
|
||||
foreach ( $months as $month ) {
|
||||
$month_raw = sprintf( "%s-%s", $month['y'], $month['m'] );
|
||||
$choices[ $month_raw ] = date_i18n( "F Y", strtotime( $month_raw ) );
|
||||
}
|
||||
|
||||
$select_field = Permalink_Manager_UI_Elements::generate_option_field( 'month', array(
|
||||
'type' => 'select',
|
||||
'choices' => $choices,
|
||||
'value' => ( isset( $_REQUEST['month'] ) ) ? sanitize_key( $_REQUEST['month'] ) : ''
|
||||
) );
|
||||
|
||||
$html .= sprintf( '<div id="months-filter" class="alignleft actions">%s</div>', $select_field );
|
||||
}
|
||||
|
||||
$extra_fields = apply_filters( 'permalink_manager_uri_editor_extra_fields', '', 'posts' );
|
||||
|
||||
if ( $months || $extra_fields ) {
|
||||
$html .= $extra_fields;
|
||||
|
||||
$html .= '<div class="alignleft">';
|
||||
$html .= get_submit_button( __( "Filter", "permalink-manager" ), 'button', false, false, array( 'id' => 'filter-button', 'name' => 'filter-button' ) );
|
||||
$html .= "</div>";
|
||||
}
|
||||
|
||||
$html .= '<div class="alignright">';
|
||||
$html .= $this->search_box( __( 'Search', 'permalink-manager' ), 'search-input' );
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the search input field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function search_box( $text = '', $input_id = '' ) {
|
||||
$search_query = ( ! empty( $_REQUEST['s'] ) ) ? esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) ) : "";
|
||||
|
||||
$output = "<p class=\"search-box\">";
|
||||
$output .= "<label class=\"screen-reader-text\" for=\"{$input_id}\">{$text}:</label>";
|
||||
$output .= Permalink_Manager_UI_Elements::generate_option_field( 's', array( 'value' => $search_query, 'type' => 'search' ) );
|
||||
$output .= get_submit_button( $text, 'button', false, false, array( 'id' => 'search-submit', 'name' => 'search-submit' ) );
|
||||
$output .= "</p>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the items for the table to process
|
||||
*/
|
||||
public function prepare_items() {
|
||||
global $wpdb;
|
||||
|
||||
$columns = $this->get_columns();
|
||||
$hidden = $this->get_hidden_columns();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
$current_page = $this->get_pagenum();
|
||||
|
||||
// SQL query parameters
|
||||
$order = ( isset( $_REQUEST['order'] ) && in_array( $_REQUEST['order'], array( 'asc', 'desc' ) ) ) ? sanitize_sql_orderby( wp_unslash( $_REQUEST['order'] ) ) : 'desc';
|
||||
$orderby = ( isset( $_REQUEST['orderby'] ) ) ? sanitize_sql_orderby( wp_unslash( $_REQUEST['orderby'] ) ) : 'ID';
|
||||
$search_query = ( ! empty( $_REQUEST['s'] ) ) ? esc_sql( sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) ) : "";
|
||||
|
||||
// Extra filters
|
||||
$extra_filters = $attachment_support = '';
|
||||
if ( ! empty( $_GET['month'] ) ) {
|
||||
$month = gmdate( "n", strtotime( sanitize_key( $_GET['month'] ) ) );
|
||||
$year = gmdate( "Y", strtotime( sanitize_key( $_GET['month'] ) ) );
|
||||
|
||||
$extra_filters .= "AND month(post_date) = {$month} AND year(post_date) = {$year}";
|
||||
}
|
||||
|
||||
// Support for attachments
|
||||
if ( strpos( $this->displayed_post_types, 'attachment' ) !== false ) {
|
||||
$attachment_support = " OR (post_type = 'attachment')";
|
||||
}
|
||||
|
||||
// Grab posts from database
|
||||
$sql_parts['start'] = "SELECT * FROM {$wpdb->posts} AS p ";
|
||||
if ( $search_query ) {
|
||||
$sql_parts['where'] = "WHERE (LOWER(post_title) LIKE LOWER('%{$search_query}%') ";
|
||||
|
||||
// Search in array with custom URIs
|
||||
$found = Permalink_Manager_URI_Functions::find_uri( $search_query, false, 'posts' );
|
||||
if ( $found ) {
|
||||
$sql_parts['where'] .= sprintf( "OR ID IN (%s)", implode( ',', $found ) );
|
||||
}
|
||||
$sql_parts['where'] .= " ) AND ((post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types)) {$attachment_support}) {$extra_filters} ";
|
||||
} else {
|
||||
$sql_parts['where'] = "WHERE ((post_status IN ($this->displayed_post_statuses) AND post_type IN ($this->displayed_post_types)) {$attachment_support}) {$extra_filters} ";
|
||||
}
|
||||
|
||||
// Do not display excluded posts in Bulk URI Editor
|
||||
$excluded_posts = Permalink_Manager_Helper_Functions::get_excluded_post_ids();
|
||||
if ( ! empty( $excluded_posts ) && is_array( $excluded_posts ) ) {
|
||||
$sql_parts['where'] .= sprintf( "AND ID NOT IN (%s) ", Permalink_Manager_Helper_Functions::prepare_array_for_sql_in( $excluded_posts ) );
|
||||
}
|
||||
|
||||
$sql_parts['end'] = "ORDER BY {$orderby} {$order}";
|
||||
|
||||
list( $all_items, $total_items, $per_page ) = Permalink_Manager_URI_Editor::prepare_sql_query( $sql_parts, $current_page, false );
|
||||
|
||||
$this->set_pagination_args( array(
|
||||
'total_items' => $total_items,
|
||||
'per_page' => $per_page
|
||||
) );
|
||||
|
||||
$this->_column_headers = array( $columns, $hidden, $sortable );
|
||||
$this->items = $all_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define hidden columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_hidden_columns() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the data
|
||||
*
|
||||
* @param mixed $a
|
||||
* @param mixed $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function sort_data( $a, $b ) {
|
||||
// Set defaults
|
||||
$orderby = ( ! empty( $_GET['orderby'] ) ) ? sanitize_sql_orderby( wp_unslash( $_GET['orderby'] ) ) : 'post_title';
|
||||
$order = ( ! empty( $_GET['order'] ) ) ? sanitize_sql_orderby( wp_unslash( $_GET['order'] ) ) : 'asc';
|
||||
$result = strnatcasecmp( $a[ $orderby ], $b[ $orderby ] );
|
||||
|
||||
return ( $order === 'asc' ) ? $result : - $result;
|
||||
}
|
||||
|
||||
}
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use WP_List_Table to display the "Bulk URI Editor" for post items
|
||||
*/
|
||||
class Permalink_Manager_Tax_Uri_Editor_Table extends WP_List_Table {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct( array(
|
||||
'singular' => 'slug',
|
||||
'plural' => 'slugs'
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML output with the whole WP_List_Table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function display_admin_section() {
|
||||
$output = "<form id=\"permalinks-post-types-table\" class=\"slugs-table\" method=\"post\">";
|
||||
$output .= wp_nonce_field( 'permalink-manager', 'uri_editor_nonce' );
|
||||
$output .= Permalink_Manager_UI_Elements::generate_option_field( 'pm_session_id', array( 'value' => uniqid(), 'type' => 'hidden' ) );
|
||||
$output .= Permalink_Manager_UI_Elements::section_type_field( 'taxonomies' );
|
||||
|
||||
// Bypass
|
||||
ob_start();
|
||||
|
||||
$this->prepare_items();
|
||||
$this->display();
|
||||
$output .= ob_get_contents();
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
$output .= "</form>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of classes to be used in the HTML table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_table_classes() {
|
||||
return array( 'widefat', 'striped', $this->_args['plural'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add columns to the table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_columns() {
|
||||
return apply_filters( 'permalink_manager_uri_editor_columns', array(
|
||||
//'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
|
||||
'item_title' => __( 'Term title', 'permalink-manager' ),
|
||||
'item_uri' => __( 'Custom permalink', 'permalink-manager' ),
|
||||
'count' => __( 'Count', 'permalink-manager' ),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sortable columns
|
||||
*/
|
||||
public function get_sortable_columns() {
|
||||
return array(
|
||||
'item_title' => array( 'name', false )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data inside the columns
|
||||
*/
|
||||
public function column_default( $item, $column_name ) {
|
||||
global $permalink_manager_options;
|
||||
|
||||
$uri = Permalink_Manager_URI_Functions_Tax::get_term_uri( $item['term_id'], true );
|
||||
$uri = ( ! empty( $permalink_manager_options['general']['decode_uris'] ) ) ? urldecode( $uri ) : $uri;
|
||||
|
||||
$field_args_base = array( 'type' => 'text', 'value' => $uri, 'without_label' => true, 'input_class' => 'custom_uri', 'extra_atts' => "data-element-id=\"tax-{$item['term_id']}\"" );
|
||||
$term = get_term( $item['term_id'] );
|
||||
$permalink = get_term_link( intval( $item['term_id'] ), $item['taxonomy'] );
|
||||
$term_title = sanitize_text_field( $item['name'] );
|
||||
|
||||
$all_terms_link = admin_url( "edit.php?{$term->taxonomy}={$term->slug}" );
|
||||
|
||||
$output = apply_filters( 'permalink_manager_uri_editor_column_content', '', $column_name, $term );
|
||||
if ( ! empty( $output ) ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
switch ( $column_name ) {
|
||||
|
||||
case 'item_title':
|
||||
$output = esc_html( $term_title );
|
||||
$output .= '<div class="extra-info small">';
|
||||
$output .= sprintf( "<span><strong>%s:</strong> %s</span>", __( "Slug", "permalink-manager" ), urldecode( $item['slug'] ) );
|
||||
$output .= apply_filters( 'permalink_manager_uri_editor_extra_info', '', $column_name, $term );
|
||||
$output .= '</div>';
|
||||
|
||||
$output .= '<div class="row-actions">';
|
||||
$output .= sprintf( '<span class="edit"><a href="%1$s" title="%2$s">%2$s</a> | </span>', esc_url( get_edit_tag_link( $item['term_id'], $item['taxonomy'] ) ), __( 'Edit', 'permalink-manager' ) );
|
||||
$output .= sprintf( '<span class="view"><a target="_blank" href="%1$s" title="%2$s %3$s" rel="permalink">%2$s</a> | </span>', esc_attr( $permalink ), __( 'View', 'permalink-manager' ), esc_html( $term_title ) );
|
||||
$output .= sprintf( '<span class="id">#%s</span>', esc_html( $item['term_id'] ) );
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
|
||||
case 'item_uri':
|
||||
// Get auto-update settings
|
||||
$auto_update_val = get_term_meta( $item['term_id'], "auto_update_uri", true );
|
||||
$auto_update_uri = ( ! empty( $auto_update_val ) ) ? $auto_update_val : $permalink_manager_options["general"]["auto_update_uris"];
|
||||
|
||||
if ( $auto_update_uri == 1 ) {
|
||||
$field_args_base['readonly'] = true;
|
||||
$field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'The above permalink will be automatically updated and is locked for editing.', 'permalink-manager' ) );
|
||||
} else if ( $auto_update_uri == 2 ) {
|
||||
$field_args_base['disabled'] = true;
|
||||
$field_args_base['append_content'] = sprintf( '<p class="small uri_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', __( 'URI Editor disabled due to "Permalink update" setting.', 'permalink-manager' ) );
|
||||
}
|
||||
|
||||
$output .= '<div class="custom_uri_container">';
|
||||
$output .= Permalink_Manager_UI_Elements::generate_option_field( "uri[tax-{$item['term_id']}]", $field_args_base );
|
||||
$output .= "<span class=\"duplicated_uri_alert\"></span>";
|
||||
$output .= sprintf( "<a class=\"small post_permalink\" href=\"%s\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> %s</a>", $permalink, urldecode( $permalink ) );
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
|
||||
case 'count':
|
||||
return "<a href=\"{$all_terms_link}\">{$term->count}</a>";
|
||||
|
||||
default:
|
||||
return $item[ $column_name ];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The button that allows to save updated slugs
|
||||
*/
|
||||
function extra_tablenav( $which ) {
|
||||
if ( $which == "top" ) {
|
||||
$button_text = __( 'Save all the permalinks below', 'permalink-manager' );
|
||||
$button_name = 'update_all_slugs[top]';
|
||||
} else {
|
||||
$button_text = __( 'Save all the permalinks above', 'permalink-manager' );
|
||||
$button_name = 'update_all_slugs[bottom]';
|
||||
}
|
||||
|
||||
$html = '<div class="alignleft actions">';
|
||||
$html .= get_submit_button( $button_text, 'primary alignleft', $button_name, false, array( 'id' => 'doaction', 'value' => 'update_all_slugs' ) );
|
||||
$html .= '</div>';
|
||||
|
||||
if ( $which == 'top' ) {
|
||||
$extra_fields = apply_filters( 'permalink_manager_uri_editor_extra_fields', '', 'taxonomies' );
|
||||
|
||||
if ( $extra_fields ) {
|
||||
$html .= $extra_fields;
|
||||
|
||||
$html .= '<div class="alignleft">';
|
||||
$html .= get_submit_button( __( "Filter", "permalink-manager" ), 'button', false, false, array( 'id' => 'filter-button', 'name' => 'filter-button' ) );
|
||||
$html .= "</div>";
|
||||
}
|
||||
|
||||
$html .= '<div class="alignright">';
|
||||
$html .= $this->search_box( __( 'Search', 'permalink-manager' ), 'search-input' );
|
||||
$html .= '</div>';
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search box
|
||||
*/
|
||||
public function search_box( $text = '', $input_id = '' ) {
|
||||
$search_query = ( ! empty( $_REQUEST['s'] ) ) ? esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) ) : "";
|
||||
|
||||
$output = "<p class=\"search-box\">";
|
||||
$output .= "<label class=\"screen-reader-text\" for=\"{$input_id}\">{$text}:</label>";
|
||||
$output .= Permalink_Manager_UI_Elements::generate_option_field( 's', array( 'value' => $search_query, 'type' => 'search' ) );
|
||||
$output .= get_submit_button( $text, 'button', false, false, array( 'id' => 'search-submit', 'name' => 'search-submit' ) );
|
||||
$output .= "</p>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the items for the table to process
|
||||
*/
|
||||
public function prepare_items() {
|
||||
global $wpdb, $current_admin_tax;
|
||||
|
||||
$columns = $this->get_columns();
|
||||
$hidden = $this->get_hidden_columns();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
$current_page = $this->get_pagenum();
|
||||
|
||||
// Get query variables
|
||||
$taxonomies = sprintf( "'%s'", $current_admin_tax );
|
||||
$search_query = ( ! empty( $_REQUEST['s'] ) ) ? esc_sql( sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) ) : "";
|
||||
|
||||
// SQL query parameters
|
||||
$order = ( isset( $_REQUEST['order'] ) && in_array( $_REQUEST['order'], array( 'asc', 'desc' ) ) ) ? sanitize_sql_orderby( wp_unslash( $_REQUEST['order'] ) ) : 'desc';
|
||||
$orderby = ( isset( $_REQUEST['orderby'] ) ) ? sanitize_sql_orderby( wp_unslash( $_REQUEST['orderby'] ) ) : 't.term_id';
|
||||
|
||||
// Grab terms from database
|
||||
$sql_parts['start'] = "SELECT t.*, tt.taxonomy FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON (tt.term_id = t.term_id) ";
|
||||
if ( $search_query ) {
|
||||
$sql_parts['where'] = "WHERE (LOWER(t.name) LIKE LOWER('%{$search_query}%') ";
|
||||
|
||||
// Search in array with custom URIs
|
||||
$found = Permalink_Manager_URI_Functions::find_uri( $search_query, false, 'taxonomies' );
|
||||
if ( $found ) {
|
||||
$sql_parts['where'] .= sprintf( "OR t.term_id IN (%s) ", implode( ',', $found ) );
|
||||
}
|
||||
$sql_parts['where'] .= ") AND tt.taxonomy IN ({$taxonomies}) ";
|
||||
} else {
|
||||
$sql_parts['where'] = "WHERE tt.taxonomy IN ({$taxonomies}) ";
|
||||
}
|
||||
|
||||
// Do not display excluded terms in Bulk URI Editor
|
||||
$excluded_terms = Permalink_Manager_Helper_Functions::get_excluded_term_ids();
|
||||
if ( ! empty( $excluded_terms ) ) {
|
||||
$sql_parts['where'] .= sprintf( "AND t.term_id NOT IN (%s) ", Permalink_Manager_Helper_Functions::prepare_array_for_sql_in( $excluded_terms ) );
|
||||
}
|
||||
|
||||
$sql_parts['end'] = "ORDER BY {$orderby} {$order}";
|
||||
|
||||
list( $all_items, $total_items, $per_page ) = Permalink_Manager_URI_Editor::prepare_sql_query( $sql_parts, $current_page, true );
|
||||
|
||||
$this->set_pagination_args( array(
|
||||
'total_items' => $total_items,
|
||||
'per_page' => $per_page
|
||||
) );
|
||||
|
||||
$this->_column_headers = array( $columns, $hidden, $sortable );
|
||||
$this->items = $all_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define hidden columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_hidden_columns() {
|
||||
return array( 'post_date_gmt' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the data
|
||||
*
|
||||
* @param mixed $a
|
||||
* @param mixed $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function sort_data( $a, $b ) {
|
||||
// Set defaults
|
||||
$orderby = ( ! empty( $_GET['orderby'] ) ) ? sanitize_sql_orderby( wp_unslash( $_GET['orderby'] ) ) : 'name';
|
||||
$order = ( ! empty( $_GET['order'] ) ) ? sanitize_sql_orderby( wp_unslash( $_GET['order'] ) ) : 'asc';
|
||||
$result = strnatcasecmp( $a[ $orderby ], $b[ $orderby ] );
|
||||
|
||||
return ( $order === 'asc' ) ? $result : - $result;
|
||||
}
|
||||
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
/**
|
||||
* Display Bulk URI Editor
|
||||
*/
|
||||
class Permalink_Manager_URI_Editor {
|
||||
public $this_section = 'uri_editor';
|
||||
|
||||
public function __construct() {
|
||||
add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 0 );
|
||||
add_filter( 'screen_settings', array( $this, 'screen_options' ), 99, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new section to the Permalink Manager UI
|
||||
*
|
||||
* @param array $admin_sections
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_admin_section( $admin_sections ) {
|
||||
$admin_sections[ $this->this_section ] = array(
|
||||
'name' => __( 'URI Editor', 'permalink-manager' )
|
||||
);
|
||||
|
||||
// Display separate section for each post type
|
||||
$post_types = Permalink_Manager_Helper_Functions::get_post_types_array( 'full' );
|
||||
foreach ( $post_types as $post_type_name => $post_type ) {
|
||||
// Check if post type exists
|
||||
if ( ! post_type_exists( $post_type_name ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$icon = ( class_exists( 'WooCommerce' ) && $post_type_name == 'product' ) ? "<i class=\"woocommerce-icon woocommerce-cart\"></i>" : "";
|
||||
|
||||
$admin_sections[ $this->this_section ]['subsections'][ $post_type_name ] = array(
|
||||
'name' => "{$icon} {$post_type['label']}",
|
||||
'function' => array( 'class' => 'Permalink_Manager_URI_Editor_Post', 'method' => 'display_admin_section' )
|
||||
);
|
||||
}
|
||||
|
||||
// Permalink Manager Pro: Display separate section for each taxonomy
|
||||
$taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array( 'full' );
|
||||
foreach ( $taxonomies as $taxonomy_name => $taxonomy ) {
|
||||
// Check if taxonomy exists
|
||||
if ( ! taxonomy_exists( $taxonomy_name ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the icon
|
||||
$icon = ( class_exists( 'WooCommerce' ) && in_array( $taxonomy_name, array( 'product_tag', 'product_cat' ) ) ) ? "<i class=\"woocommerce-icon woocommerce-cart\"></i>" : "<i class=\"dashicons dashicons-tag\"></i>";
|
||||
|
||||
$admin_sections[ $this->this_section ]['subsections']["tax_{$taxonomy_name}"] = array(
|
||||
'name' => "{$icon} {$taxonomy['label']}",
|
||||
'html' => Permalink_Manager_UI_Elements::pro_text(),
|
||||
'pro' => true
|
||||
);
|
||||
}
|
||||
|
||||
// A little dirty hack to move wooCommerce product & taxonomies to the end of array
|
||||
if ( class_exists( 'WooCommerce' ) ) {
|
||||
foreach ( array( 'product', 'tax_product_tag', 'tax_product_cat' ) as $section_name ) {
|
||||
if ( empty( $admin_sections[ $this->this_section ]['subsections'][ $section_name ] ) ) {
|
||||
continue;
|
||||
}
|
||||
$section = $admin_sections[ $this->this_section ]['subsections'][ $section_name ];
|
||||
unset( $admin_sections[ $this->this_section ]['subsections'][ $section_name ] );
|
||||
$admin_sections[ $this->this_section ]['subsections'][ $section_name ] = $section;
|
||||
}
|
||||
}
|
||||
|
||||
return $admin_sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display "Screen options"
|
||||
*
|
||||
* @param string $html
|
||||
* @param string $screen
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function screen_options( $html, $screen ) {
|
||||
global $active_section;
|
||||
|
||||
// Display the screen options only in "Permalink Editor"
|
||||
if ( $active_section != $this->this_section ) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
$button = get_submit_button( __( 'Apply', 'permalink-manager' ), 'primary', 'screen-options-apply', false );
|
||||
$html = "<fieldset class=\"permalink-manager-screen-options\">";
|
||||
|
||||
$screen_options = array(
|
||||
'per_page' => array(
|
||||
'type' => 'number',
|
||||
'label' => __( 'Per page', 'permalink-manager' ),
|
||||
'input_class' => 'settings-select'
|
||||
),
|
||||
'post_statuses' => array(
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Post statuses', 'permalink-manager' ),
|
||||
'choices' => Permalink_Manager_Helper_Functions::get_post_statuses(),
|
||||
'select_all' => '',
|
||||
'unselect_all' => '',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $screen_options as $field_name => $field_args ) {
|
||||
$field_args['container'] = 'screen-options';
|
||||
$html .= Permalink_Manager_UI_Elements::generate_option_field( "screen-options[{$field_name}]", $field_args );
|
||||
}
|
||||
|
||||
$html .= sprintf( "</fieldset>%s", $button );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger SQL query to get all items
|
||||
*
|
||||
* @param $sql_parts
|
||||
* @param $current_page
|
||||
* @param $is_taxonomy
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function prepare_sql_query( $sql_parts, $current_page, $is_taxonomy = false ) {
|
||||
global $permalink_manager_options, $wpdb;
|
||||
|
||||
$per_page = is_numeric( $permalink_manager_options['screen-options']['per_page'] ) ? $permalink_manager_options['screen-options']['per_page'] : 10;
|
||||
$offset = ( $current_page - 1 ) * $per_page;
|
||||
|
||||
// Prepare the count SQL query
|
||||
$count_query_parts = $sql_parts;
|
||||
$count_query_parts['start'] = preg_replace( '/(SELECT.*FROM)/', 'SELECT COUNT(*) FROM', $count_query_parts['start'] );
|
||||
$count_query = apply_filters( 'permalink_manager_filter_uri_editor_query', implode( "", $count_query_parts ), $count_query_parts, $is_taxonomy );
|
||||
$total_items_raw = $wpdb->get_var( $count_query );
|
||||
|
||||
// Pagination support
|
||||
$sql_query = implode( "", $sql_parts );
|
||||
$sql_query .= sprintf( " LIMIT %d, %d", $offset, $per_page );
|
||||
|
||||
// Get items
|
||||
$sql_query = apply_filters( 'permalink_manager_filter_uri_editor_query', $sql_query, $sql_parts, $is_taxonomy );
|
||||
$all_items_raw = $wpdb->get_results( $sql_query, ARRAY_A );
|
||||
|
||||
$total_items = ( is_numeric( $total_items_raw ) ) ? (int) $total_items_raw : 0;
|
||||
$all_items = ( ! empty( $all_items_raw ) ) ? $all_items_raw : array();
|
||||
|
||||
return array( $all_items, $total_items, $per_page );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user