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-settings.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Display the settings page |
| 5 | */ |
| 6 | class Permalink_Manager_Settings extends Permalink_Manager_Class { |
| 7 | |
| 8 | public function __construct() { |
| 9 | add_filter( 'permalink-manager-sections', array($this, 'add_admin_section'), 1 ); |
| 10 | add_filter( 'permalink-manager-options', array($this, 'default_settings'), 9 ); |
| 11 | } |
| 12 | |
| 13 | public function add_admin_section($admin_sections) { |
| 14 | $admin_sections['settings'] = array( |
| 15 | 'name' => __('Settings', 'permalink-manager'), |
| 16 | 'function' => array('class' => 'Permalink_Manager_Settings', 'method' => 'output') |
| 17 | ); |
| 18 | |
| 19 | return $admin_sections; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Set the initial/default settings |
| 24 | */ |
| 25 | public function default_settings($settings) { |
| 26 | $all_taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array(); |
| 27 | $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array(); |
| 28 | |
| 29 | $default_settings = apply_filters('permalink-manager-default-options', array( |
| 30 | 'screen-options' => array( |
| 31 | 'per_page' => 20, |
| 32 | 'post_statuses' => array('publish'), |
| 33 | 'post_types' => $all_post_types, |
| 34 | 'taxonomies' => $all_taxonomies |
| 35 | ), |
| 36 | 'miscellaneous' => array( |
| 37 | 'yoast_primary_term' => 1, |
| 38 | 'redirect' => "302", |
| 39 | 'canonical_redirect' => 1, |
| 40 | ) |
| 41 | )); |
| 42 | |
| 43 | // Apply the default settings (if empty values) in all settings sections |
| 44 | $final_settings = array(); |
| 45 | foreach($default_settings as $section => $fields) { |
| 46 | $final_settings[$section] = (isset($settings[$section])) ? array_replace($fields, $settings[$section]) : $fields; |
| 47 | } |
| 48 | |
| 49 | return $final_settings; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the array with settings and render the HTML output |
| 54 | */ |
| 55 | public function output() { |
| 56 | // Get all registered post types array & statuses |
| 57 | $all_post_statuses_array = get_post_statuses(); |
| 58 | $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array(); |
| 59 | |
| 60 | $sections_and_fields = apply_filters('permalink-manager-settings-fields', array( |
| 61 | 'screen-options' => array( |
| 62 | 'section_name' => __('Display settings', 'permalink-manager'), |
| 63 | 'description' => __('Adjust the data displayed in "Permalink Editor" section.', 'permalink-manager'), |
| 64 | 'container' => 'row', |
| 65 | 'fields' => array( |
| 66 | 'per_page' => array( |
| 67 | 'type' => 'number', |
| 68 | 'label' => __('Per page', 'permalink-manager'), |
| 69 | 'input_class' => 'settings-select' |
| 70 | ), |
| 71 | 'post_statuses' => array( |
| 72 | 'type' => 'checkbox', |
| 73 | 'label' => __('Post statuses', 'permalink-manager'), |
| 74 | 'choices' => $all_post_statuses_array, |
| 75 | 'select_all' => '', |
| 76 | 'unselect_all' => '', |
| 77 | ), |
| 78 | 'post_types' => array( |
| 79 | 'type' => 'checkbox', |
| 80 | 'label' => __('Post types', 'permalink-manager'), |
| 81 | 'choices' => $all_post_types, |
| 82 | 'select_all' => '', |
| 83 | 'unselect_all' => '', |
| 84 | ) |
| 85 | ) |
| 86 | ), |
| 87 | 'miscellaneous' => array( |
| 88 | 'section_name' => __('Miscellaneous & SEO functions', 'permalink-manager'), |
| 89 | 'container' => 'row', |
| 90 | 'fields' => array( |
| 91 | 'yoast_primary_term' => array( |
| 92 | 'type' => 'select', |
| 93 | 'label' => __('Primay term/category support', 'permalink-manager'), |
| 94 | 'input_class' => 'settings-select', |
| 95 | 'choices' => array(1 => __('Enable', 'permalink-manager'), 0 => __('Disable', 'permalink-manager')), |
| 96 | 'description' => __('Used to generate default permalinks in pages, posts & custom post types. Works only when "Yoast SEO" plugin is enabled.', 'permalink-manager') |
| 97 | ), |
| 98 | 'redirect' => array( |
| 99 | 'type' => 'select', |
| 100 | 'label' => __('Redirect', 'permalink-manager'), |
| 101 | 'input_class' => 'settings-select', |
| 102 | 'choices' => array(0 => __('Disable', 'permalink-manager'), "301" => __('Enable "301 redirect"', 'permalink-manager'), "302" => __('Enable "302 redirect"', 'permalink-manager')), |
| 103 | 'description' => __('If enabled - the visitors will be redirected from native permalinks to your custom permalinks. Please note that the redirects will work correctly only if native slug "post name" will not be changed.', 'permalink-manager') |
| 104 | ), |
| 105 | 'canonical_redirect' => array( |
| 106 | 'type' => 'select', |
| 107 | 'label' => __('Canonical redirect', 'permalink-manager'), |
| 108 | 'input_class' => 'settings-select', |
| 109 | 'choices' => array(0 => __('Disable', 'permalink-manager'), 1 => __('Enable', 'permalink-manager')), |
| 110 | 'description' => __('This function allows Wordpress to correct the URLs used by the visitors.', 'permalink-manager') |
| 111 | ), |
| 112 | 'debug_mode' => array( |
| 113 | 'type' => 'single_checkbox', |
| 114 | 'label' => __('Debug mode', 'permalink-manager') |
| 115 | ) |
| 116 | ) |
| 117 | ) |
| 118 | )); |
| 119 | |
| 120 | $output = Permalink_Manager_Admin_Functions::get_the_form($sections_and_fields, '', array('text' => __( 'Save settings', 'permalink-manager' ), 'class' => 'primary margin-top'), '', array('action' => 'permalink-manager', 'name' => 'permalink_manager_options')); |
| 121 | return $output; |
| 122 | } |
| 123 | } |
| 124 |