permalink-manager-debug.php
3 years ago
permalink-manager-permastructs.php
3 years ago
permalink-manager-settings.php
3 years ago
permalink-manager-tools.php
3 years ago
permalink-manager-uri-editor-post.php
3 years ago
permalink-manager-uri-editor.php
3 years ago
permalink-manager-settings.php
249 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Display the settings page |
| 5 | */ |
| 6 | class Permalink_Manager_Settings { |
| 7 | |
| 8 | public function __construct() { |
| 9 | add_filter( 'permalink_manager_sections', array( $this, 'add_admin_section' ), 3 ); |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Add a new section to the Permalink Manager UI |
| 14 | * |
| 15 | * @param array $admin_sections |
| 16 | * |
| 17 | * @return array |
| 18 | */ |
| 19 | public function add_admin_section( $admin_sections ) { |
| 20 | $admin_sections['settings'] = array( |
| 21 | 'name' => __( 'Settings', 'permalink-manager' ), |
| 22 | 'function' => array( 'class' => 'Permalink_Manager_Settings', 'method' => 'output' ) |
| 23 | ); |
| 24 | |
| 25 | return $admin_sections; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Get the array with settings and render the HTML output |
| 30 | * |
| 31 | * @return string |
| 32 | */ |
| 33 | public function output() { |
| 34 | // Get all registered post types & taxonomies |
| 35 | $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array( null, null, true ); |
| 36 | $all_taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array( false, false, true ); |
| 37 | $content_types = ( defined( 'PERMALINK_MANAGER_PRO' ) ) ? array( 'post_types' => $all_post_types, 'taxonomies' => $all_taxonomies ) : array( 'post_types' => $all_post_types ); |
| 38 | |
| 39 | $sections_and_fields = apply_filters( 'permalink_manager_settings_fields', array( |
| 40 | 'general' => array( |
| 41 | 'section_name' => __( 'General settings', 'permalink-manager' ), |
| 42 | 'container' => 'row', |
| 43 | 'name' => 'general', |
| 44 | 'fields' => array( |
| 45 | 'auto_update_uris' => array( |
| 46 | 'type' => 'select', |
| 47 | 'label' => __( 'URI update mode', 'permalink-manager' ), |
| 48 | 'input_class' => '', |
| 49 | 'choices' => array( 0 => __( 'Don\'t auto-update permalinks (default mode)', 'permalink-manager' ), 1 => __( 'Auto-update permalinks', 'permalink-manager' ), 2 => __( 'Don\'t save/generate custom permalinks for new items', 'permalink-manager' ) ), |
| 50 | 'description' => sprintf( '<strong>%s</strong><br />%s<br />%s', __( 'After a post/term is updated, Permalink Manager can automatically update its custom permalink to follow the default format set in Permastructure settings.', 'permalink-manager' ), __( 'Choose the last option if you wish to use the native permalinks rather than generate custom permalinks whenever a new post or term is added.', 'permalink-manager' ), __( 'You may override the global settings in the URI Editor by selecting a different setting for each post or term individually.', 'permalink-manager' ) ) |
| 51 | ), |
| 52 | 'force_custom_slugs' => array( |
| 53 | 'type' => 'select', |
| 54 | 'label' => __( 'Slugs mode', 'permalink-manager' ), |
| 55 | 'input_class' => 'settings-select', |
| 56 | 'choices' => array( 0 => __( 'Use native slugs', 'permalink-manager' ), 1 => __( 'Use actual titles as slugs', 'permalink-manager' ), 2 => __( 'Inherit parents\' slugs', 'permalink-manager' ) ), |
| 57 | 'description' => sprintf( '%s<br />%s<br />%s', __( '<strong>Permalink Manager can use either native slugs or actual titles for custom permalinks.</strong>', 'permalink-manager' ), __( 'The native slug is generated from the initial title after the post or term is published.', 'permalink-manager' ), __( 'Use this field if you would like Permalink Manager to use the actual titles instead of native slugs.', 'permalink-manager' ) ) |
| 58 | ), |
| 59 | 'trailing_slashes' => array( |
| 60 | 'type' => 'select', |
| 61 | 'label' => __( 'Trailing slashes', 'permalink-manager' ), |
| 62 | 'input_class' => 'settings-select', |
| 63 | 'choices' => array( 0 => __( 'Use default settings', 'permalink-manager' ), 1 => __( 'Add trailing slashes', 'permalink-manager' ), 2 => __( 'Remove trailing slashes', 'permalink-manager' ) ), |
| 64 | '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' ) ) |
| 65 | ), |
| 66 | 'partial_disable' => array( |
| 67 | 'type' => 'checkbox', |
| 68 | 'label' => __( 'Exclude content types', 'permalink-manager' ), |
| 69 | 'choices' => $content_types, |
| 70 | 'description' => __( 'Permalink Manager will ignore and not filter the custom permalinks of all selected above post types & taxonomies.', 'permalink-manager' ) |
| 71 | ), |
| 72 | 'ignore_drafts' => array( |
| 73 | 'type' => 'select', |
| 74 | 'label' => __( 'Exclude drafts & pending posts', 'permalink-manager' ), |
| 75 | 'choices' => array( 0 => __( 'Do not exclude', 'permalink-manager' ), 1 => __( 'Exclude drafts', 'permalink-manager' ), 2 => __( 'Exclude drafts & pending posts', 'permalink-manager' ) ), |
| 76 | 'description' => __( 'If enabled, custom permalinks for posts marked as "draft" or "pending" will not be created.', 'permalink-manager' ) |
| 77 | ) |
| 78 | ) |
| 79 | ), |
| 80 | 'redirect' => array( |
| 81 | 'section_name' => __( 'Redirect settings', 'permalink-manager' ), |
| 82 | 'container' => 'row', |
| 83 | 'name' => 'general', |
| 84 | 'fields' => array( |
| 85 | 'canonical_redirect' => array( |
| 86 | 'type' => 'single_checkbox', |
| 87 | 'label' => __( 'Canonical redirect', 'permalink-manager' ), |
| 88 | 'input_class' => '', |
| 89 | 'description' => sprintf( '%s<br />%s', __( '<strong>Canonical redirect allows WordPress to "correct" the requested URL and redirect visitor to the canonical permalink.</strong>', 'permalink-manager' ), __( 'This feature will be also used to redirect (old) original permalinks to (new) custom permalinks set with Permalink Manager.', 'permalink-manager' ) ) |
| 90 | ), |
| 91 | /*'endpoint_redirect' => array( |
| 92 | 'type' => 'single_checkbox', |
| 93 | 'label' => __('Redirect with endpoints', 'permalink-manager'), |
| 94 | 'input_class' => '', |
| 95 | 'description' => sprintf('%s', |
| 96 | __('<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') |
| 97 | ) |
| 98 | ),*/ 'old_slug_redirect' => array( |
| 99 | 'type' => 'single_checkbox', |
| 100 | 'label' => __( 'Old slug redirect', 'permalink-manager' ), |
| 101 | 'input_class' => '', |
| 102 | 'description' => sprintf( '%s<br />%s', __( '<strong>Old slug redirect is used by WordPress to provide a fallback for old version of slugs after they are changed.</strong>', 'permalink-manager' ), __( 'If enabled, the visitors trying to access the URL with the old slug will be redirected to the canonical permalink.', 'permalink-manager' ) ) |
| 103 | ), |
| 104 | 'extra_redirects' => array( |
| 105 | 'type' => 'single_checkbox', |
| 106 | 'label' => __( 'Extra redirects (aliases)', 'permalink-manager' ), |
| 107 | 'input_class' => '', |
| 108 | 'pro' => true, |
| 109 | 'disabled' => true, |
| 110 | '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' ) ) |
| 111 | ), |
| 112 | 'setup_redirects' => array( |
| 113 | 'type' => 'single_checkbox', |
| 114 | 'label' => __( 'Save old custom permalinks as extra redirects', 'permalink-manager' ), |
| 115 | 'input_class' => '', |
| 116 | 'pro' => true, |
| 117 | 'disabled' => true, |
| 118 | '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' ) ) |
| 119 | ), |
| 120 | 'trailing_slashes_redirect' => array( |
| 121 | 'type' => 'single_checkbox', |
| 122 | 'label' => __( 'Trailing slashes redirect', 'permalink-manager' ), |
| 123 | 'input_class' => '', |
| 124 | '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' ) ) |
| 125 | ), |
| 126 | 'copy_query_redirect' => array( |
| 127 | 'type' => 'single_checkbox', |
| 128 | 'label' => __( 'Redirect with query parameters', 'permalink-manager' ), |
| 129 | 'input_class' => '', |
| 130 | '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' ) ) |
| 131 | ), |
| 132 | 'sslwww_redirect' => array( |
| 133 | 'type' => 'single_checkbox', |
| 134 | 'label' => __( 'Force HTTPS/WWW', 'permalink-manager' ), |
| 135 | 'input_class' => '', |
| 136 | 'description' => sprintf( '%s<br />%s', __( '<strong>You can use Permalink Manager to force SSL or "www" prefix in WordPress permalinks.</strong>', 'permalink-manager' ), __( 'Please disable it if you encounter any redirect loop issues.', 'permalink-manager' ) ) |
| 137 | ), |
| 138 | 'redirect' => array( |
| 139 | 'type' => 'select', |
| 140 | 'label' => __( 'Redirect mode', 'permalink-manager' ), |
| 141 | 'input_class' => 'settings-select', |
| 142 | 'choices' => array( 0 => __( 'Disable (Permalink Manager redirect functions)', 'permalink-manager' ), "301" => __( '301 redirect', 'permalink-manager' ), "302" => __( '302 redirect', 'permalink-manager' ) ), |
| 143 | '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' ) ) |
| 144 | ) |
| 145 | ) |
| 146 | ), |
| 147 | 'third_parties' => array( |
| 148 | 'section_name' => __( 'Third party plugins', 'permalink-manager' ), |
| 149 | 'container' => 'row', |
| 150 | 'name' => 'general', |
| 151 | 'fields' => array( |
| 152 | 'fix_language_mismatch' => array( |
| 153 | 'type' => 'select', |
| 154 | 'label' => __( 'WPML/Polylang fix language mismatch', 'permalink-manager' ), |
| 155 | 'input_class' => '', |
| 156 | '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' ) ), |
| 157 | 'class_exists' => array( 'SitePress', 'Polylang' ), |
| 158 | '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' ) |
| 159 | ), |
| 160 | 'wpml_support' => array( |
| 161 | 'type' => 'single_checkbox', |
| 162 | 'label' => __( 'WPML compatibility functions', 'permalink-manager' ), |
| 163 | 'input_class' => '', |
| 164 | 'class_exists' => array( 'SitePress' ), |
| 165 | 'description' => __( 'Please disable this feature if the language code in the custom permalinks is incorrect.', 'permalink-manager' ) |
| 166 | ), |
| 167 | 'pmxi_support' => array( |
| 168 | 'type' => 'single_checkbox', |
| 169 | 'label' => __( 'WP All Import/Export support', 'permalink-manager' ), |
| 170 | 'input_class' => '', |
| 171 | 'class_exists' => array( 'PMXI_Plugin', 'PMXE_Plugin' ), |
| 172 | 'description' => __( 'If disabled, the custom permalinks <strong>will not be saved</strong> for the posts imported with WP All Import plugin.', 'permalink-manager' ) |
| 173 | ), |
| 174 | 'um_support' => array( |
| 175 | 'type' => 'single_checkbox', |
| 176 | 'label' => __( 'Ultimate Member support', 'permalink-manager' ), |
| 177 | 'input_class' => '', |
| 178 | 'class_exists' => 'UM', |
| 179 | 'description' => __( 'If enabled, Permalink Manager will detect the additional Ultimate Member pages (eg. "account" sections).', 'permalink-manager' ) |
| 180 | ), |
| 181 | 'yoast_breadcrumbs' => array( |
| 182 | 'type' => 'single_checkbox', |
| 183 | 'label' => __( 'Breadcrumbs support', 'permalink-manager' ), |
| 184 | 'input_class' => '', |
| 185 | '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' ) |
| 186 | ), |
| 187 | 'primary_category' => array( |
| 188 | 'type' => 'single_checkbox', |
| 189 | 'label' => __( '"Primary category" support', 'permalink-manager' ), |
| 190 | 'input_class' => '', |
| 191 | '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' ) |
| 192 | ), |
| 193 | ) |
| 194 | ), |
| 195 | 'advanced' => array( |
| 196 | 'section_name' => __( 'Advanced settings', 'permalink-manager' ), |
| 197 | 'container' => 'row', |
| 198 | 'name' => 'general', |
| 199 | 'fields' => array( |
| 200 | 'show_native_slug_field' => array( |
| 201 | 'type' => 'single_checkbox', |
| 202 | 'label' => __( 'Show "Native slug" field in URI Editor', 'permalink-manager' ) |
| 203 | ), |
| 204 | 'partial_disable_strict' => array( |
| 205 | 'type' => 'single_checkbox', |
| 206 | 'label' => __( '"Exclude content types" strict mode', 'permalink-manager' ), |
| 207 | '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>General settings -> Exclude content types</em>" options.', 'permalink-manager' ) |
| 208 | ), |
| 209 | 'pagination_redirect' => array( |
| 210 | 'type' => 'single_checkbox', |
| 211 | 'label' => __( 'Force 404 on non-existing pagination pages', 'permalink-manager' ), |
| 212 | 'description' => __( 'If enabled, the non-existing pagination pages (for single posts) will return 404 ("Not Found") error.<br /><strong>Please disable it, if you encounter any problems with pagination pages or use custom pagination system.</strong>', 'permalink-manager' ) |
| 213 | ), |
| 214 | 'disable_slug_sanitization' => array( |
| 215 | 'type' => 'select', |
| 216 | 'label' => __( 'Strip special characters', 'permalink-manager' ), |
| 217 | 'input_class' => 'settings-select', |
| 218 | 'choices' => array( 0 => __( 'Yes, use native settings', 'permalink-manager' ), 1 => __( 'No, keep special characters (.,|_+) in the slugs', 'permalink-manager' ) ), |
| 219 | 'description' => __( 'If enabled only alphanumeric characters, underscores and dashes will be allowed for post/term slugs.', 'permalink-manager' ) |
| 220 | ), |
| 221 | 'keep_accents' => array( |
| 222 | 'type' => 'select', |
| 223 | 'label' => __( 'Convert accented letters', 'permalink-manager' ), |
| 224 | 'input_class' => 'settings-select', |
| 225 | 'choices' => array( 0 => __( 'Yes, use native settings', 'permalink-manager' ), 1 => __( 'No, keep accented letters in the slugs', 'permalink-manager' ) ), |
| 226 | 'description' => __( 'If enabled, all the accented letters will be replaced with their non-accented equivalent (eg. � |
| 227 | => A, Æ => AE, Ø => O, Ć => C).', 'permalink-manager' ) |
| 228 | ), |
| 229 | 'edit_uris_cap' => array( |
| 230 | 'type' => 'select', |
| 231 | 'label' => __( 'URI Editor role capability', 'permalink-manager' ), |
| 232 | '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' ) ), |
| 233 | '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' ) |
| 234 | ), |
| 235 | 'auto_fix_duplicates' => array( |
| 236 | 'type' => 'select', |
| 237 | 'label' => __( 'Automatically fix broken URIs', 'permalink-manager' ), |
| 238 | 'input_class' => 'settings-select', |
| 239 | 'choices' => array( 0 => __( 'No', 'permalink-manager' ), 1 => __( 'Fix URIs individually (during page load)', 'permalink-manager' ), 2 => __( 'Bulk fix all URIs (once a day, in the background)', 'permalink-manager' ) ), |
| 240 | 'description' => sprintf( '%s', __( 'Enable this option if you would like to automatically remove redundant permalinks & duplicated redirects.', 'permalink-manager' ) ) |
| 241 | ) |
| 242 | ) |
| 243 | ) |
| 244 | ) ); |
| 245 | |
| 246 | return Permalink_Manager_Admin_Functions::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' ) ); |
| 247 | } |
| 248 | } |
| 249 |