__( '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( '

%s', __( 'A MySQL backup is highly recommended before using "Native slugs" 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( "

%s

", __( "List of duplicated permalinks", "permalink-manager" ) ); $html .= wpautop( sprintf( "%s", $button_url, __( 'Fix custom permalinks & redirects', 'permalink-manager' ) ) ); if ( ! empty( $all_duplicates ) ) { foreach ( $all_duplicates as $uri => $duplicates ) { $html .= ""; } } else { $html .= sprintf( "

%s

", __( '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. 1-8, 10, 25.', 'permalink-manager' ), //'pro' => true, 'input_class' => 'widefat' ) ), 'find_and_replace' ); $sidebar = '

' . __( 'Important notices', 'permalink-manager' ) . '

'; $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. 1-8, 10, 25.', 'permalink-manager' ), //'pro' => true, 'input_class' => 'widefat' ) ), 'regenerate' ); $sidebar = '

' . __( 'Important notices', 'permalink-manager' ) . '

'; $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; } }