permalink-manager
Last commit date
includes
8 years ago
languages
8 years ago
out
8 years ago
LICENSE.txt
8 years ago
README.txt
8 years ago
permalink-manager.php
8 years ago
permalink-manager.php
245 lines
| 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.0.5.1 |
| 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 | */ |
| 15 | |
| 16 | // If this file is called directly or plugin is already defined, abort. |
| 17 | if (!defined('WPINC')) { |
| 18 | die; |
| 19 | } |
| 20 | |
| 21 | // Define the directories used to load plugin files. |
| 22 | define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'Permalink Manager' ); |
| 23 | define( 'PERMALINK_MANAGER_PLUGIN_SLUG', 'permalink-manager' ); |
| 24 | define( 'PERMALINK_MANAGER_VERSION', '2.0.5.1' ); |
| 25 | define( 'PERMALINK_MANAGER_FILE', __FILE__ ); |
| 26 | define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) ); |
| 27 | define( 'PERMALINK_MANAGER_BASENAME', plugin_basename(__FILE__) ); |
| 28 | define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) ); |
| 29 | define( 'PERMALINK_MANAGER_WEBSITE', 'http://permalinkmanager.pro?utm_source=plugin' ); |
| 30 | define( 'PERMALINK_MANAGER_DONATE', 'https://www.paypal.me/Bismit' ); |
| 31 | |
| 32 | class Permalink_Manager_Class { |
| 33 | |
| 34 | public $permalink_manager, $permalink_manager_options_page, $permalink_manager_options; |
| 35 | public $sections, $functions, $permalink_manager_before_sections_html, $permalink_manager_after_sections_html; |
| 36 | |
| 37 | /** |
| 38 | * Get options from DB, load subclasses & hooks |
| 39 | */ |
| 40 | public function __construct() { |
| 41 | $this->include_subclassess(); |
| 42 | $this->register_init_hooks(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Include back-end classess and set their instances |
| 47 | */ |
| 48 | function include_subclassess() { |
| 49 | // WP_List_Table needed for post types & taxnomies editors |
| 50 | if( ! class_exists( 'WP_List_Table' ) ) { |
| 51 | require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
| 52 | } |
| 53 | |
| 54 | $classes = array( |
| 55 | 'core' => array( |
| 56 | 'helper-functions' => 'Permalink_Manager_Helper_Functions', |
| 57 | 'uri-functions-post' => 'Permalink_Manager_URI_Functions_Post', |
| 58 | 'uri-functions-tax' => 'Permalink_Manager_URI_Functions_Tax', |
| 59 | 'admin-functions' => 'Permalink_Manager_Admin_Functions', |
| 60 | 'actions' => 'Permalink_Manager_Actions', |
| 61 | 'third-parties' => 'Permalink_Manager_Third_Parties', |
| 62 | 'core-functions' => 'Permalink_Manager_Core_Functions', |
| 63 | 'pro-functions' => 'Permalink_Manager_Pro_Functions' |
| 64 | ), |
| 65 | 'views' => array( |
| 66 | 'uri-editor' => 'Permalink_Manager_Uri_Editor', |
| 67 | 'tools' => 'Permalink_Manager_Tools', |
| 68 | 'permastructs' => 'Permalink_Manager_Permastructs', |
| 69 | 'settings' => 'Permalink_Manager_Settings', |
| 70 | 'debug' => 'Permalink_Manager_Debug', |
| 71 | 'pro-addons' => 'Permalink_Manager_Pro_Addons', |
| 72 | 'upgrade' => 'Permalink_Manager_Upgrade', |
| 73 | 'uri-editor-tax' => false, |
| 74 | 'uri-editor-post' => false |
| 75 | ) |
| 76 | ); |
| 77 | |
| 78 | // Load classes and set-up their instances |
| 79 | foreach($classes as $class_type => $classes_array) { |
| 80 | foreach($classes_array as $class => $class_name) { |
| 81 | $filename = PERMALINK_MANAGER_DIR . "/includes/{$class_type}/permalink-manager-{$class}.php"; |
| 82 | |
| 83 | if(file_exists($filename)) { |
| 84 | require_once $filename; |
| 85 | if($class_name) { $this->functions[$class] = new $class_name(); } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Register general hooks |
| 93 | */ |
| 94 | public function register_init_hooks() { |
| 95 | // Localize plugin |
| 96 | add_action( 'plugins_loaded', array($this, 'localize_me'), 1 ); |
| 97 | |
| 98 | // Load globals & options |
| 99 | add_action( 'plugins_loaded', array($this, 'get_options_and_globals'), 9 ); |
| 100 | |
| 101 | // Legacy support |
| 102 | add_action( 'init', array($this, 'legacy_support'), 2 ); |
| 103 | |
| 104 | // Default settings & alerts |
| 105 | add_filter( 'permalink-manager-options', array($this, 'default_settings'), 1 ); |
| 106 | add_filter( 'permalink-manager-alerts', array($this, 'default_alerts'), 1 ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Localize this plugin |
| 111 | */ |
| 112 | function localize_me() { |
| 113 | load_plugin_textdomain( 'permalink-manager', false, PERMALINK_MANAGER_DIR ); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Get options values & set global |
| 118 | */ |
| 119 | public function get_options_and_globals() { |
| 120 | // 1. Globals with data stored in DB |
| 121 | global $permalink_manager_options, $permalink_manager_uris, $permalink_manager_permastructs, $permalink_manager_redirects; |
| 122 | |
| 123 | $this->permalink_manager_options = $permalink_manager_options = apply_filters('permalink-manager-options', get_option('permalink-manager', array())); |
| 124 | $this->permalink_manager_uris = $permalink_manager_uris = apply_filters('permalink-manager-uris', get_option('permalink-manager-uris', array())); |
| 125 | $this->permalink_manager_permastructs = $permalink_manager_permastructs = apply_filters('permalink-manager-permastructs', get_option('permalink-manager-permastructs', array())); |
| 126 | $this->permalink_manager_redirects = $permalink_manager_redirects = apply_filters('permalink-manager-redirects', get_option('permalink-manager-redirects', array())); |
| 127 | |
| 128 | // 2. Globals used to display additional content (eg. alerts) |
| 129 | global $permalink_manager_alerts, $permalink_manager_before_sections_html, $permalink_manager_after_sections_html; |
| 130 | |
| 131 | $this->permalink_manager_alerts = $permalink_manager_alerts = apply_filters('permalink-manager-alerts', get_option('permalink-manager-alerts', array())); |
| 132 | $this->permalink_manager_before_sections_html = $permalink_manager_before_sections_html = apply_filters('permalink-manager-before-sections', ''); |
| 133 | $this->permalink_manager_after_sections_html = $permalink_manager_after_sections_html = apply_filters('permalink-manager-after-sections', ''); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Set the initial/default settings (including "Screen Options") |
| 138 | */ |
| 139 | public function default_settings($settings) { |
| 140 | $all_taxonomies = Permalink_Manager_Helper_Functions::get_taxonomies_array(); |
| 141 | $all_post_types = Permalink_Manager_Helper_Functions::get_post_types_array(); |
| 142 | |
| 143 | $default_settings = apply_filters('permalink-manager-default-options', array( |
| 144 | 'screen-options' => array( |
| 145 | 'per_page' => 20, |
| 146 | 'post_statuses' => array('publish'), |
| 147 | 'group' => false, |
| 148 | ), |
| 149 | 'general' => array( |
| 150 | 'force_custom_slugs' => 0, |
| 151 | 'auto_update_uris' => 0, |
| 152 | 'case_insensitive_permalinks' => 0, |
| 153 | 'yoast_primary_term' => 1, |
| 154 | 'redirect' => '301', |
| 155 | 'yoast_attachment_redirect' => 1, |
| 156 | 'canonical_redirect' => 1, |
| 157 | 'trailing_slashes' => 0, |
| 158 | 'setup_redirects' => 1, |
| 159 | 'auto_remove_duplicates' => 0, |
| 160 | 'partial_disable' => array(), |
| 161 | 'deep_detect' => 1 |
| 162 | ), |
| 163 | 'licence' => array() |
| 164 | )); |
| 165 | |
| 166 | // Apply the default settings (if empty values) in all settings sections |
| 167 | foreach($default_settings as $group_name => $fields) { |
| 168 | foreach($fields as $field_name => $field) { |
| 169 | if(!isset($settings[$group_name][$field_name])) { |
| 170 | $settings[$group_name][$field_name] = $field; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | return $settings; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Set the initial/default admin notices |
| 180 | */ |
| 181 | public function default_alerts($alerts) { |
| 182 | $default_alerts = apply_filters('permalink-manager-default-alerts', array( |
| 183 | 'november' => array( |
| 184 | 'txt' => sprintf( |
| 185 | __("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 20% using \"NOVEMBER\" coupon code!</strong> Valid until 31.11!", "permalink-manager"), |
| 186 | PERMALINK_MANAGER_WEBSITE |
| 187 | ), |
| 188 | 'type' => 'notice-info', |
| 189 | 'show' => 'pro_hide', |
| 190 | 'plugin_only' => true, |
| 191 | 'until' => '2017-11-31' |
| 192 | ) |
| 193 | )); |
| 194 | |
| 195 | // Apply the default settings (if empty values) in all settings sections |
| 196 | return $alerts + $default_alerts; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Temporary hook |
| 201 | */ |
| 202 | function legacy_support() { |
| 203 | global $permalink_manager_permastructs, $permalink_manager_options; |
| 204 | |
| 205 | if(isset($permalink_manager_options['base-editor'])) { |
| 206 | $new_options['post_types'] = $permalink_manager_options['base-editor']; |
| 207 | update_option('permalink-manager-permastructs', $new_options); |
| 208 | } |
| 209 | else if(empty($permalink_manager_permastructs['post_types']) && count($permalink_manager_permastructs) > 0) { |
| 210 | $new_options['post_types'] = $permalink_manager_permastructs; |
| 211 | update_option('permalink-manager-permastructs', $new_options); |
| 212 | } |
| 213 | |
| 214 | // Adjust options structure |
| 215 | if(!empty($permalink_manager_options['miscellaneous'])) { |
| 216 | // Get the options direclty from database |
| 217 | $permalink_manager_unfiltered_options = get_option('permalink-manager', array('general' => array(), 'miscellaneous' => array(), 'licence')); |
| 218 | |
| 219 | // Combine general & general |
| 220 | $permalink_manager_unfiltered_options['general'] = array_merge($permalink_manager_unfiltered_options['general'], $permalink_manager_unfiltered_options['miscellaneous']); |
| 221 | |
| 222 | // Move licence key to different section |
| 223 | $permalink_manager_unfiltered_options['licence']['licence_key'] = (!empty($permalink_manager_unfiltered_options['miscellaneous']['license_key'])) ? $permalink_manager_unfiltered_options['miscellaneous']['license_key'] : ""; |
| 224 | |
| 225 | // Remove redundant keys |
| 226 | unset($permalink_manager_unfiltered_options['general']['license_key']); |
| 227 | unset($permalink_manager_unfiltered_options['miscellaneous']); |
| 228 | unset($permalink_manager_unfiltered_options['permalink_manager_options']); |
| 229 | unset($permalink_manager_unfiltered_options['_wp_http_referer']); |
| 230 | |
| 231 | // Save the settings in database |
| 232 | update_option('permalink-manager', $permalink_manager_unfiltered_options); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Begins execution of the plugin. |
| 240 | */ |
| 241 | function run_permalink_manager() { |
| 242 | $Permalink_Manager_Class = new Permalink_Manager_Class(); |
| 243 | } |
| 244 | run_permalink_manager(); |
| 245 |