__('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_Admin_Functions', 'method' => 'pro_text')
),
'import' => array(
'name' => __('Custom Permalinks', 'permalink-manager'),
'function' => array('class' => 'Permalink_Manager_Admin_Functions', 'method' => 'pro_text')
)
)
);
return $admin_sections;
}
public function display_instructions() {
return wpautop(__('A MySQL backup is highly recommended before using "Native slugs" mode!', 'permalink-manager'));
}
public function duplicates_output() {
global $permalink_manager_uris, $permalink_manager_redirects;
// Get the duplicates & another variables
$all_duplicates = Permalink_Manager_Helper_Functions::get_all_duplicates();
$home_url = trim(get_option('home'), "/");
$html = sprintf("
%s
", __("List of duplicated permalinks", "permalink-manager"));
$html .= wpautop(sprintf("%s", admin_url('tools.php?page=permalink-manager§ion=tools&subsection=duplicates&clear-permalink-manager-uris=1'), __('Fix custom permalinks & redirects', 'permalink-manager')));
if(!empty($all_duplicates)) {
foreach($all_duplicates as $uri => $duplicates) {
$html .= "";
$html .= "
";
$html .= "
";
foreach($duplicates as $item_id) {
$html .= "";
// 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 URI', 'permalink-manager');
$detected_id = $parts[4];
$detected_index = $parts[2];
$detected_term = (!empty($parts[3])) ? true : false;
$remove_link = ($is_extra_redirect) ? sprintf(" %s", admin_url("tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-redirect={$item_id}"), __("Remove Redirect")) : "";
// Get term
if($detected_term && !empty($detected_id)) {
$term = get_term($detected_id);
if(!empty($term->name)) {
$title = $term->name;
$edit_label = "" . __("Edit term", "permalink-manager");
$edit_link = get_edit_tag_link($term->term_id, $term->taxonomy);
} else {
$title = __("(Removed term)", "permalink-manager");
$edit_label = "" . __("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 = "" . __("Edit post", "permalink-manager");
$edit_link = get_edit_post_link($post->ID);
} else {
$title = __("(Removed post)", "permalink-manager");
$edit_label = "" . __("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(
'%2$s%3$s | %4$s | %5$s%6$s | ',
$edit_link,
$title,
" #{$detected_id}",
$duplicate_type,
$edit_label,
$remove_link
);
$html .= "
";
}
$html .= "
";
$html .= "
";
}
} else {
$html .= sprintf("%s
", __('Congratulations! No duplicated URIs or Redirects found!', 'permalink-manager'));
}
return $html;
}
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 URIs', '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. Eg. 1-8, 10, 25.', 'permalink-manager'),
//'pro' => true,
'input_class' => 'widefat'
)
), 'find_and_replace');
$sidebar = '' . __('Important notices', 'permalink-manager') . '
';
$sidebar .= self::display_instructions();
$output = Permalink_Manager_Admin_Functions::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');
return $output;
}
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. Eg. 1-8, 10, 25.', 'permalink-manager'),
//'pro' => true,
'input_class' => 'widefat'
)
), 'regenerate');
$sidebar = '' . __('Important notices', 'permalink-manager') . '
';
$sidebar .= self::display_instructions();
$output = Permalink_Manager_Admin_Functions::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');
return $output;
}
}