| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Permalink Manager Lite |
| 5 |
* Plugin URI: https://permalinkmanager.pro?utm_source=plugin |
| 6 |
* Description: Advanced plugin that allows to set-up custom permalinks (bulk editors included), slugs and permastructures (WooCommerce compatible). |
| 7 |
* Version: 2.2.20.3 |
| 8 |
* Author: Maciej Bis |
| 9 |
* Author URI: http://maciejbis.net/ |
| 10 |
* License: GPL-2.0+ |
| 11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 12 |
* Text Domain: permalink-manager |
| 13 |
* Domain Path: /languages |
| 14 |
* WC requires at least: 3.0.0 |
| 15 |
* WC tested up to: 7.1.0 |
| 16 |
*/ |
| 17 |
|
| 18 |
// If this file is called directly or plugin is already defined, abort. |
| 19 |
if (!defined('WPINC')) { |
| 20 |
die; |
| 21 |
} |
| 22 |
|
| 23 |
if(!class_exists('Permalink_Manager_Class')) { |
| 24 |
|
| 25 |
// Define the directories used to load plugin files. |
| 26 |
define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'Permalink Manager' ); |
| 27 |
define( 'PERMALINK_MANAGER_PLUGIN_SLUG', 'permalink-manager' ); |
| 28 |
define( 'PERMALINK_MANAGER_VERSION', '2.2.20.3' ); |
| 29 |
define( 'PERMALINK_MANAGER_FILE', __FILE__ ); |
| 30 |
define( 'PERMALINK_MANAGER_DIR', untrailingslashit(dirname(__FILE__)) ); |
| 31 |
define( 'PERMALINK_MANAGER_BASENAME', plugin_basename(__FILE__)); |
| 32 |
define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url('', __FILE__) ) ); |
| 33 |
define( 'PERMALINK_MANAGER_WEBSITE', 'http://permalinkmanager.pro?utm_source=plugin' ); |
| 34 |
define( 'PERMALINK_MANAGER_DONATE', 'https://www.paypal.me/Bismit' ); |
| 35 |
|
| 36 |
class Permalink_Manager_Class { |
| 37 |
|
| 38 |
public $permalink_manager_options_page, $permalink_manager_options; |
| 39 |
public $sections, $functions, $permalink_manager_before_sections_html, $permalink_manager_after_sections_html; |
| 40 |
|
| 41 |
/** |
| 42 |
* Get options from DB, load subclasses & hooks |
| 43 |
*/ |
| 44 |
public function __construct() { |
| 45 |
$this->include_subclassess(); |
| 46 |
$this->register_init_hooks(); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Include back-end classess and set their instances |
| 51 |
*/ |
| 52 |
function include_subclassess() { |
| 53 |
// WP_List_Table needed for post types & taxnomies editors |
| 54 |
if( ! class_exists( 'WP_List_Table' ) ) { |
| 55 |
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
| 56 |
} |
| 57 |
|
| 58 |
$classes = array( |
| 59 |
'core' => array( |
| 60 |
'helper-functions' => 'Permalink_Manager_Helper_Functions', |
| 61 |
'uri-functions' => 'Permalink_Manager_URI_Functions', |
| 62 |
'uri-functions-post' => 'Permalink_Manager_URI_Functions_Post', |
| 63 |
'uri-functions-tax' => 'Permalink_Manager_URI_Functions_Tax', |
| 64 |
'admin-functions' => 'Permalink_Manager_Admin_Functions', |
| 65 |
'actions' => 'Permalink_Manager_Actions', |
| 66 |
'third-parties' => 'Permalink_Manager_Third_Parties', |
| 67 |
'language-plugins' => 'Permalink_Manager_Language_Plugins', |
| 68 |
'core-functions' => 'Permalink_Manager_Core_Functions', |
| 69 |
'gutenberg' => 'Permalink_Manager_Gutenberg', |
| 70 |
'debug' => 'Permalink_Manager_Debug_Functions', |
| 71 |
'pro-functions' => 'Permalink_Manager_Pro_Functions' |
| 72 |
), |
| 73 |
'views' => array( |
| 74 |
'uri-editor' => 'Permalink_Manager_Uri_Editor', |
| 75 |
'tools' => 'Permalink_Manager_Tools', |
| 76 |
'permastructs' => 'Permalink_Manager_Permastructs', |
| 77 |
'settings' => 'Permalink_Manager_Settings', |
| 78 |
'debug' => 'Permalink_Manager_Debug', |
| 79 |
'pro-addons' => 'Permalink_Manager_Pro_Addons', |
| 80 |
'help' => 'Permalink_Manager_Help', |
| 81 |
'uri-editor-tax' => false, |
| 82 |
'uri-editor-post' => false |
| 83 |
) |
| 84 |
); |
| 85 |
|
| 86 |
// Load classes and set-up their instances |
| 87 |
foreach($classes as $class_type => $classes_array) { |
| 88 |
foreach($classes_array as $class => $class_name) { |
| 89 |
$filename = PERMALINK_MANAGER_DIR . "/includes/{$class_type}/permalink-manager-{$class}.php"; |
| 90 |
|
| 91 |
if(file_exists($filename)) { |
| 92 |
require_once $filename; |
| 93 |
if($class_name) { $this->functions[$class] = new $class_name(); } |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Register general hooks |
| 101 |
*/ |
| 102 |
public function register_init_hooks() { |
| 103 |
// Localize plugin |
| 104 |
add_action( 'init', array($this, 'localize_me'), 1 ); |
| 105 |
|
| 106 |
// Support deprecated hooks |
| 107 |
add_action( 'plugins_loaded', array($this, 'deprecated_hooks'), 9 ); |
| 108 |
|
| 109 |
// Deactivate free version if Permalink Manager Pro is activated |
| 110 |
add_action( 'plugins_loaded', array($this, 'is_pro_activated'), 9 ); |
| 111 |
|
| 112 |
// Load globals & options |
| 113 |
add_action( 'plugins_loaded', array($this, 'get_options_and_globals'), 9 ); |
| 114 |
|
| 115 |
// Legacy support |
| 116 |
add_action( 'init', array($this, 'legacy_support'), 2 ); |
| 117 |
|
| 118 |
// Default settings & alerts |
| 119 |
add_filter( 'permalink_manager_options', array($this, 'default_settings'), 1 ); |
| 120 |
add_filter( 'permalink_manager_alerts', array($this, 'default_alerts'), 1 ); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Localize this plugin |
| 125 |
*/ |
| 126 |
function localize_me() { |
| 127 |
load_plugin_textdomain( 'permalink-manager', false, basename(dirname(__FILE__)) . "/languages" ); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Get options values & set global |
| 132 |
*/ |
| 133 |
public function get_options_and_globals() { |
| 134 |
// 1. Globals with data stored in DB |
| 135 |
global $permalink_manager_options, $permalink_manager_uris, $permalink_manager_permastructs, $permalink_manager_redirects, $permalink_manager_external_redirects; |
| 136 |
|
| 137 |
$this->permalink_manager_options = $permalink_manager_options = (array) apply_filters('permalink_manager_options', get_option('permalink-manager', array())); |
| 138 |
$this->permalink_manager_uris = $permalink_manager_uris = (array) apply_filters('permalink_manager_uris', get_option('permalink-manager-uris', array())); |
| 139 |
$this->permalink_manager_permastructs = $permalink_manager_permastructs = (array) apply_filters('permalink_manager_permastructs', get_option('permalink-manager-permastructs', array())); |
| 140 |
$this->permalink_manager_redirects = $permalink_manager_redirects = (array) apply_filters('permalink_manager_redirects', get_option('permalink-manager-redirects', array())); |
| 141 |
$this->permalink_manager_external_redirects = $permalink_manager_external_redirects = (array) apply_filters('permalink_manager_external_redirects', get_option('permalink-manager-external-redirects', array())); |
| 142 |
|
| 143 |
// 2. Globals used to display additional content (eg. alerts) |
| 144 |
global $permalink_manager_alerts, $permalink_manager_before_sections_html, $permalink_manager_after_sections_html; |
| 145 |
|
| 146 |
$this->permalink_manager_alerts = $permalink_manager_alerts = apply_filters('permalink_manager_alerts', array()); |
| 147 |
$this->permalink_manager_before_sections_html = $permalink_manager_before_sections_html = apply_filters('permalink_manager_before_sections', ''); |
| 148 |
$this->permalink_manager_after_sections_html = $permalink_manager_after_sections_html = apply_filters('permalink_manager_after_sections', ''); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Set the initial/default settings (including "Screen Options") |
| 153 |
*/ |
| 154 |
public function default_settings($settings) { |
| 155 |
$default_settings = apply_filters('permalink_manager_default_options', array( |
| 156 |
'screen-options' => array( |
| 157 |
'per_page' => 20, |
| 158 |
'post_statuses' => array('publish'), |
| 159 |
'group' => false, |
| 160 |
), |
| 161 |
'general' => array( |
| 162 |
'auto_update_uris' => 0, |
| 163 |
'show_native_slug_field' => 0, |
| 164 |
'pagination_redirect' => 0, |
| 165 |
'sslwww_redirect' => 0, |
| 166 |
'canonical_redirect' => 1, |
| 167 |
'old_slug_redirect' => 0, |
| 168 |
'setup_redirects' => 0, |
| 169 |
'redirect' => '301', |
| 170 |
'extra_redirects' => 1, |
| 171 |
'copy_query_redirect' => 1, |
| 172 |
'trailing_slashes' => 0, |
| 173 |
'trailing_slash_redirect' => 0, |
| 174 |
'auto_fix_duplicates' => 0, |
| 175 |
'fix_language_mismatch' => 1, |
| 176 |
'wpml_support' => 1, |
| 177 |
'pmxi_support' => 1, |
| 178 |
'um_support' => 1, |
| 179 |
'yoast_breadcrumbs' => 0, |
| 180 |
'primary_category' => 1, |
| 181 |
'force_custom_slugs' => 0, |
| 182 |
'disable_slug_sanitization' => 0, |
| 183 |
'keep_accents' => 0, |
| 184 |
'partial_disable' => array( |
| 185 |
'post_types' => array('attachment', 'tribe_events', 'e-landing-page') |
| 186 |
), |
| 187 |
'partial_disable_strict' => 1, |
| 188 |
'ignore_drafts' => 1, |
| 189 |
'edit_uris_cap' => 'publish_posts', |
| 190 |
), |
| 191 |
'licence' => array() |
| 192 |
)); |
| 193 |
|
| 194 |
// Check if settings array is empty |
| 195 |
$settings_empty = empty($settings); |
| 196 |
|
| 197 |
// Apply the default settings (if empty values) in all settings sections |
| 198 |
foreach($default_settings as $group_name => $fields) { |
| 199 |
foreach($fields as $field_name => $field) { |
| 200 |
if($settings_empty || (!isset($settings[$group_name][$field_name]) && strpos($field_name, 'partial_disable') === false)) { |
| 201 |
$settings[$group_name][$field_name] = $field; |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
return $settings; |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* Set the initial/default admin notices |
| 211 |
*/ |
| 212 |
public function default_alerts($alerts) { |
| 213 |
$default_alerts = apply_filters('permalink_manager_default_alerts', array( |
| 214 |
'jan21' => array( |
| 215 |
'txt' => sprintf( |
| 216 |
__("Get access to extra features: full taxonomy and WooCommerce support, possibility to use custom fields inside the permalinks and more!<br /><strong>Buy Permalink Manager Pro <a href=\"%s\" target=\"_blank\">here</a> and save %s using \"%s\" coupon code!</strong> Valid until %s!", "permalink-manager"), |
| 217 |
PERMALINK_MANAGER_WEBSITE . "&utm_campaign=discount_code", |
| 218 |
'20%', |
| 219 |
'NEWYEAR21', |
| 220 |
'09.01' |
| 221 |
), |
| 222 |
'type' => 'notice-info', |
| 223 |
'show' => 'pro_hide', |
| 224 |
'plugin_only' => true, |
| 225 |
'until' => '2021-01-09' |
| 226 |
) |
| 227 |
)); |
| 228 |
|
| 229 |
// Apply the default settings (if empty values) in all settings sections |
| 230 |
return (array) $alerts + (array) $default_alerts; |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Temporary hook |
| 235 |
*/ |
| 236 |
function legacy_support() { |
| 237 |
global $permalink_manager_permastructs, $permalink_manager_options; |
| 238 |
|
| 239 |
if(isset($permalink_manager_options['base-editor'])) { |
| 240 |
$new_options['post_types'] = $permalink_manager_options['base-editor']; |
| 241 |
update_option('permalink-manager-permastructs', $new_options); |
| 242 |
} |
| 243 |
else if(empty($permalink_manager_permastructs['post_types']) && empty($permalink_manager_permastructs['taxonomies']) && count($permalink_manager_permastructs) > 0) { |
| 244 |
$new_options['post_types'] = $permalink_manager_permastructs; |
| 245 |
update_option('permalink-manager-permastructs', $new_options); |
| 246 |
} |
| 247 |
|
| 248 |
// Adjust options structure |
| 249 |
if(!empty($permalink_manager_options['miscellaneous'])) { |
| 250 |
// Combine general & miscellaneous options |
| 251 |
$permalink_manager_unfiltered_options['general'] = array_merge($permalink_manager_unfiltered_options['general'], $permalink_manager_unfiltered_options['miscellaneous']); |
| 252 |
|
| 253 |
// Move licence key to different section |
| 254 |
$permalink_manager_unfiltered_options['licence']['licence_key'] = (!empty($permalink_manager_unfiltered_options['miscellaneous']['license_key'])) ? $permalink_manager_unfiltered_options['miscellaneous']['license_key'] : ""; |
| 255 |
} |
| 256 |
|
| 257 |
// Separate "Trailing slashes" & "Trailing slashes redirect" setting fields |
| 258 |
if(!empty($permalink_manager_options['general']['trailing_slashes']) && $permalink_manager_options['general']['trailing_slashes'] >= 10) { |
| 259 |
$permalink_manager_unfiltered_options = (!empty($permalink_manager_unfiltered_options)) ? $permalink_manager_unfiltered_options : $permalink_manager_options; |
| 260 |
|
| 261 |
$permalink_manager_unfiltered_options['general']['trailing_slashes_redirect'] = 1; |
| 262 |
$permalink_manager_unfiltered_options['general']['trailing_slashes'] = ($permalink_manager_options['general']['trailing_slashes'] == 10) ? 1 : 2; |
| 263 |
} |
| 264 |
|
| 265 |
// Adjust WP All Import suport mode |
| 266 |
if(isset($permalink_manager_options['general']['pmxi_import_support'])) { |
| 267 |
$permalink_manager_unfiltered_options = (!empty($permalink_manager_unfiltered_options)) ? $permalink_manager_unfiltered_options : $permalink_manager_options; |
| 268 |
|
| 269 |
$permalink_manager_unfiltered_options['general']['pmxi_support'] = (empty($permalink_manager_options['general']['pmxi_import_support'])) ? 1 : 0; |
| 270 |
unset($permalink_manager_unfiltered_options['general']['pmxi_import_support']); |
| 271 |
} |
| 272 |
|
| 273 |
// Save the settings in database |
| 274 |
if(!empty($permalink_manager_unfiltered_options)) { |
| 275 |
update_option('permalink-manager', $permalink_manager_unfiltered_options); |
| 276 |
} |
| 277 |
|
| 278 |
// Remove obsolete 'permalink-manager-alerts' from wp_options table |
| 279 |
if(get_option('permalink-manager-alerts')) { |
| 280 |
delete_option('permalink-manager-alerts'); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
/** |
| 285 |
* Support deprecated hooks |
| 286 |
*/ |
| 287 |
function deprecated_hooks_list($filters = true) { |
| 288 |
$deprecated_filters = array( |
| 289 |
'permalink_manager_default_options' => 'permalink-manager-default-options', |
| 290 |
'permalink_manager_options' => 'permalink-manager-options', |
| 291 |
'permalink_manager_uris' => 'permalink-manager-uris', |
| 292 |
'permalink_manager_alerts' => 'permalink-manager-alerts', |
| 293 |
'permalink_manager_redirects' => 'permalink-manager-redirects', |
| 294 |
'permalink_manager_external_redirects' => 'permalink-manager-external-redirects', |
| 295 |
'permalink_manager_permastructs' => 'permalink-manager-permastructs', |
| 296 |
|
| 297 |
'permalink_manager_alerts' => 'permalink-manager-alerts', |
| 298 |
'permalink_manager_before_sections' => 'permalink-manager-before-sections', |
| 299 |
'permalink_manager_sections' => 'permalink-manager-sections', |
| 300 |
'permalink_manager_after_sections' => 'permalink-manager-after-sections', |
| 301 |
|
| 302 |
'permalink_manager_field_args' => 'permalink-manager-field-args', |
| 303 |
'permalink_manager_field_output' => 'permalink-manager-field-output', |
| 304 |
|
| 305 |
'permalink_manager_deep_uri_detect' => 'permalink-manager-deep-uri-detect', |
| 306 |
'permalink_manager_detect_uri' => 'permalink-manager-detect-uri', |
| 307 |
'permalink_manager_detected_element_id' => 'permalink-manager-detected-initial-id', |
| 308 |
'permalink_manager_detected_term_id' => 'permalink-manager-detected-term-id', |
| 309 |
'permalink_manager_detected_post_id' => 'permalink-manager-detected-post-id', |
| 310 |
|
| 311 |
'permalink_manager_primary_term' => 'permalink-manager-primary-term', |
| 312 |
'permalink_manager_disabled_post_types' => 'permalink-manager-disabled-post-types', |
| 313 |
'permalink_manager_disabled_taxonomies' => 'permalink-manager-disabled-taxonomies', |
| 314 |
'permalink_manager_endpoints' => 'permalink-manager-endpoints', |
| 315 |
'permalink_manager_filter_permalink_base' => 'permalink_manager-filter-permalink-base', |
| 316 |
'permalink_manager_force_lowercase_uris' => 'permalink-manager-force-lowercase-uris', |
| 317 |
|
| 318 |
'permalink_manager_uri_editor_extra_info' => 'permalink-manager-uri-editor-extra-info', |
| 319 |
'permalink_manager_debug_fields' => 'permalink-manager-debug-fields', |
| 320 |
'permalink_manager_permastructs_fields' => 'permalink-manager-permastructs-fields', |
| 321 |
'permalink_manager_settings_fields' => 'permalink-manager-settings-fields', |
| 322 |
'permalink_manager_tools_fields' => 'permalink-manager-tools-fields', |
| 323 |
|
| 324 |
'permalink_manager_uri_editor_columns' => 'permalink-manager-uri-editor-columns', |
| 325 |
'permalink_manager_uri_editor_column_content' => 'permalink-manager-uri-editor-column-content', |
| 326 |
|
| 327 |
'permalink_manager_redirect_shop_archive' => 'permalink-manager-redirect-shop-archive' |
| 328 |
); |
| 329 |
|
| 330 |
return ($filters) ? $deprecated_filters : array(); |
| 331 |
} |
| 332 |
|
| 333 |
function deprecated_hooks() { |
| 334 |
$deprecated_filters = (array) $this->deprecated_hooks_list(true); |
| 335 |
foreach($deprecated_filters as $new => $old) { |
| 336 |
add_filter($new, array($this, 'deprecated_hooks_mapping'), -1000, 8); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
function deprecated_hooks_mapping($data) { |
| 341 |
$deprecated_filters = $this->deprecated_hooks_list(true); |
| 342 |
$filter = current_filter(); |
| 343 |
|
| 344 |
if(isset($deprecated_filters[$filter])) { |
| 345 |
if(has_filter($deprecated_filters[$filter])) { |
| 346 |
$args = func_get_args(); |
| 347 |
$data = apply_filters_ref_array($deprecated_filters[$filter], $args); |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
return $data; |
| 352 |
} |
| 353 |
|
| 354 |
/** |
| 355 |
* Deactivate Permalink Manager Lite if Permalink Manager Pro is enabled |
| 356 |
*/ |
| 357 |
function is_pro_activated() { |
| 358 |
if(function_exists('is_plugin_active') && is_plugin_active('permalink-manager/permalink-manager.php') && is_plugin_active('permalink-manager-pro/permalink-manager.php')) { |
| 359 |
deactivate_plugins('permalink-manager/permalink-manager.php'); |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
/** |
| 366 |
* Begins execution of the plugin. |
| 367 |
*/ |
| 368 |
function run_permalink_manager() { |
| 369 |
global $permalink_manager; |
| 370 |
|
| 371 |
// Do not run when Elementor is opened |
| 372 |
if((!empty($_REQUEST['action']) && strpos($_REQUEST['action'], 'elementor') !== false) || isset($_REQUEST['elementor-preview'])) { return; } |
| 373 |
|
| 374 |
$permalink_manager = new Permalink_Manager_Class(); |
| 375 |
} |
| 376 |
|
| 377 |
run_permalink_manager(); |
| 378 |
} |
| 379 |
|