permalink-manager-advanced.php
9 years ago
permalink-manager-permastructs.php
9 years ago
permalink-manager-settings.php
9 years ago
permalink-manager-tools.php
9 years ago
permalink-manager-uri-editor-post.php
9 years ago
permalink-manager-uri-editor.php
9 years ago
permalink-manager-tools.php
129 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Display the page where the slugs could be regenerated or replaced |
| 5 | */ |
| 6 | class Permalink_Manager_Tools extends Permalink_Manager_Class { |
| 7 | |
| 8 | public function __construct() { |
| 9 | add_filter( 'permalink-manager-sections', array($this, 'add_admin_section'), 1 ); |
| 10 | } |
| 11 | |
| 12 | public function add_admin_section($admin_sections) { |
| 13 | |
| 14 | $admin_sections['tools'] = array( |
| 15 | 'name' => __('Tools', 'permalink-manager'), |
| 16 | 'subsections' => array( |
| 17 | 'find_and_replace' => array( |
| 18 | 'name' => __('Find and replace', 'permalink-manager'), |
| 19 | 'function' => array('class' => 'Permalink_Manager_Tools', 'method' => 'find_and_replace_output') |
| 20 | ), |
| 21 | 'regenerate_slugs' => array( |
| 22 | 'name' => __('Regenerate/Reset', 'permalink-manager'), |
| 23 | 'function' => array('class' => 'Permalink_Manager_Tools', 'method' => 'regenerate_slugs_output') |
| 24 | ) |
| 25 | ) |
| 26 | ); |
| 27 | |
| 28 | return $admin_sections; |
| 29 | } |
| 30 | |
| 31 | public function display_instructions() { |
| 32 | return wpautop(__('<strong>A MySQL backup is highly recommended before using "<em>Custom & native slugs (post names)</em>" mode!</strong>.', 'permalink-manager')); |
| 33 | } |
| 34 | |
| 35 | public function find_and_replace_output() { |
| 36 | // Get all registered post types array & statuses |
| 37 | $all_post_statuses_array = get_post_statuses(); |
| 38 | $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array(); |
| 39 | |
| 40 | $fields = array( |
| 41 | 'old_string' => array( |
| 42 | 'label' => __( 'Find ...', 'permalink-manager' ), |
| 43 | 'type' => 'text', |
| 44 | 'container' => 'row', |
| 45 | 'container_class' => 'column column-1_2', |
| 46 | 'input_class' => 'widefat' |
| 47 | ), |
| 48 | 'new_string' => array( |
| 49 | 'label' => __( 'Replace with ...', 'permalink-manager' ), |
| 50 | 'type' => 'text', |
| 51 | 'container' => 'row', |
| 52 | 'container_class' => 'column column-1_2', |
| 53 | 'input_class' => 'widefat' |
| 54 | ), |
| 55 | 'mode' => array( |
| 56 | 'label' => __( 'Select mode', 'permalink-manager' ), |
| 57 | 'type' => 'select', |
| 58 | 'container' => 'row', |
| 59 | 'choices' => array('both' => '<strong>' . __('Full URIs', 'permalink-manager') . '</strong>', 'post_names' => '<strong>' . __('Custom & native slugs (post names)', 'permalink-manager') . '</strong>'), |
| 60 | 'default' => array('both'), |
| 61 | ), |
| 62 | 'post_types' => array( |
| 63 | 'label' => __( 'Filter by post types', 'permalink-manager' ), |
| 64 | 'type' => 'checkbox', |
| 65 | 'container' => 'row', |
| 66 | 'default' => array('post', 'page'), |
| 67 | 'choices' => $all_post_types, |
| 68 | 'select_all' => '', |
| 69 | 'unselect_all' => '', |
| 70 | ), |
| 71 | 'post_statuses' => array( |
| 72 | 'label' => __( 'Filter by post statuses', 'permalink-manager' ), |
| 73 | 'type' => 'checkbox', |
| 74 | 'container' => 'row', |
| 75 | 'default' => array('publish'), |
| 76 | 'choices' => $all_post_statuses_array, |
| 77 | 'select_all' => '', |
| 78 | 'unselect_all' => '', |
| 79 | ) |
| 80 | ); |
| 81 | |
| 82 | $sidebar = '<h3>' . __('Important notices', 'permalink-manager') . '</h3>'; |
| 83 | $sidebar .= self::display_instructions(); |
| 84 | |
| 85 | $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')); |
| 86 | |
| 87 | return $output; |
| 88 | } |
| 89 | |
| 90 | public function regenerate_slugs_output() { |
| 91 | // Get all registered post types array & statuses |
| 92 | $all_post_statuses_array = get_post_statuses(); |
| 93 | $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array(); |
| 94 | |
| 95 | $fields = array( |
| 96 | 'mode' => array( |
| 97 | 'label' => __( 'Select mode', 'permalink-manager' ), |
| 98 | 'type' => 'select', |
| 99 | 'container' => 'row', |
| 100 | 'choices' => array('both' => '<strong>' . __('Full URIs', 'permalink-manager') . '</strong>', 'post_names' => '<strong>' . __('Custom & native slugs (post names)', 'permalink-manager') . '</strong>'), |
| 101 | ), |
| 102 | 'post_types' => array( |
| 103 | 'label' => __( 'Filter by post types', 'permalink-manager' ), |
| 104 | 'type' => 'checkbox', |
| 105 | 'container' => 'row', |
| 106 | 'default' => array('post', 'page'), |
| 107 | 'choices' => $all_post_types, |
| 108 | 'select_all' => '', |
| 109 | 'unselect_all' => '', |
| 110 | ), |
| 111 | 'post_statuses' => array( |
| 112 | 'label' => __( 'Filter by post statuses', 'permalink-manager' ), |
| 113 | 'type' => 'checkbox', |
| 114 | 'container' => 'row', |
| 115 | 'default' => array('publish'), |
| 116 | 'choices' => $all_post_statuses_array, |
| 117 | 'select_all' => '', |
| 118 | 'unselect_all' => '', |
| 119 | ) |
| 120 | ); |
| 121 | |
| 122 | $sidebar = '<h3>' . __('Important notices', 'permalink-manager') . '</h3>'; |
| 123 | $sidebar .= self::display_instructions(); |
| 124 | $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')); |
| 125 | |
| 126 | return $output; |
| 127 | } |
| 128 | } |
| 129 |