PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 1.0.4
Permalink Manager Lite v1.0.4
2.5.4 2.5.3.4 2.2.18 2.2.19.2 2.2.19.3 2.2.19.3.1 2.2.2 2.2.20 2.2.20.1 2.2.20.3 2.2.4 2.2.5 2.2.6 2.2.7.2 2.2.7.3 2.2.7.5 2.2.7.6 2.2.8.4 2.2.8.5 2.2.8.6 2.2.8.7 2.2.8.9 2.2.9.1 2.2.9.2 2.2.9.2.1 2.2.9.3 2.2.9.4 2.2.9.6 2.2.9.7 2.2.9.9 2.3.0 2.3.1.1 2.4.0 2.4.1 2.4.1.2 2.4.1.3 2.4.1.4 2.4.1.5 2.4.1.6 2.4.2 2.4.2.1 2.4.3 2.4.3.1 2.4.3.2 2.4.3.3 2.4.3.4 2.4.4 2.4.4.1 2.4.4.2 2.4.4.3 2.5.0 2.5.1 2.5.1.1 2.5.1.2 2.5.1.3 2.5.1.4 2.5.2 2.5.2.1 2.5.2.2 2.5.2.3 2.5.2.4 2.5.3 2.5.3.1 2.5.3.2 2.5.3.3 trunk 0.2 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 0.4.4 0.4.6 0.4.7 0.4.8 0.4.9 0.5.3 0.5.4 1.0.0 1.0.1 1.0.4 1.1.0 1.1.1 1.1.2 1.11.6.3 2.0.0 2.0.3 2.0.4 2.0.4.3 2.0.5.1 2.0.5.2 2.0.5.3 2.0.5.3.1 2.0.5.4 2.0.5.4a 2.0.5.5 2.0.5.6 2.0.5.6.1 2.0.5.7 2.0.5.9a 2.0.6.2.1 2.0.6.2a 2.0.6.3 2.1.0 2.1.1 2.1.2.4 2.2.0 2.2.1.1 2.2.1.2 2.2.11 2.2.12 2.2.13.1 2.2.14 2.2.15.1 2.2.16 2.2.17
permalink-manager / includes / core / permalink-manager-actions.php
permalink-manager / includes / core Last commit date
permalink-manager-actions.php 9 years ago permalink-manager-admin-functions.php 9 years ago permalink-manager-helper-functions.php 9 years ago permalink-manager-uri-functions-post.php 9 years ago
permalink-manager-actions.php
196 lines
1 <?php
2 /**
3 * Additional hooks for "Permalink Manager Pro"
4 */
5 class Permalink_Manager_Actions extends Permalink_Manager_Class {
6
7 public function __construct() {
8 add_action( 'admin_init', array($this, 'trigger_action'), 999 );
9 add_action( 'admin_init', array($this, 'clear_uris') );
10 }
11
12 /**
13 * Actions
14 */
15 public function trigger_action() {
16 global $permalink_manager_before_sections_html, $permalink_manager_after_sections_html;
17
18 // 1. Check if the form was submitted (make exception for clear sitemap cache function)
19 if(isset($_REQUEST['flush_sitemaps'])) {
20 $this->flush_sitemaps();
21 $permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message(__( 'Sitemap was updated!', 'permalink-manager' ), 'updated');
22
23 return;
24 } else if(empty($_POST)) { return; }
25
26 $actions_map = array(
27 'uri_editor' => array('function' => 'update_all_permalinks', 'display_uri_table' => true),
28 'regenerate' => array('function' => 'regenerate_all_permalinks', 'display_uri_table' => true),
29 'find_and_replace' => array('function' => 'find_and_replace', 'display_uri_table' => true),
30 'permalink_manager_options' => array('function' => 'save_settings'),
31 'permalink_manager_permastructs' => array('function' => 'save_permastructures'),
32 'flush_sitemaps' => array('function' => 'save_permastructures'),
33 );
34 // Clear URIs & reset settings & permastructs also should be added here.
35
36 // 2. Find the action
37 foreach($actions_map as $action => $map) {
38 if(isset($_POST[$action]) && wp_verify_nonce($_POST[$action], 'permalink-manager')) {
39 $output = call_user_func(array($this, $map['function']));
40
41 // Get list of updated URIs
42 if(!empty($map['display_uri_table'])) {
43 $updated_slugs_count = (isset($output['updated_count']) && $output['updated_count'] > 0) ? $output['updated_count'] : false;
44 $updated_slugs_array = ($updated_slugs_count) ? $output['updated'] : '';
45 }
46
47 // Trigger only one function
48 break;
49 }
50 }
51
52 // 3. Display the slugs table (and append the globals)
53 if(isset($updated_slugs_count)) {
54 if($updated_slugs_count > 0) {
55 $updated_title = __('List of updated items', 'bis');
56 $alert_content = sprintf( _n( '<strong>%d</strong> slug was updated!', '<strong>%d</strong> slugs were updated!', $updated_slugs_count, 'permalink-manager' ), $updated_slugs_count ) . ' ';
57 $alert_content .= sprintf( __( '<a %s>Click here</a> to go to the list of updated slugs', 'permalink-manager' ), "href=\"#TB_inline?width=100%&height=600&inlineId=updated-list\" title=\"{$updated_title}\" class=\"thickbox\"");
58
59 $permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message($alert_content, 'updated');
60 $permalink_manager_after_sections_html .= Permalink_Manager_Admin_Functions::display_updated_slugs($updated_slugs_array);
61 } else {
62 $permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message(__( '<strong>No slugs</strong> were updated!', 'permalink-manager' ), 'error');
63 }
64 }
65 }
66
67 /**
68 * Save settings
69 */
70 public static function save_settings() {
71 global $permalink_manager_options;
72
73 $post_fields = $_POST;
74 $new_options = array();
75
76 foreach($post_fields as $option_name => $option_value) {
77 $new_options[$option_name] = $option_value;
78 }
79
80 // Override the global with settings
81 $permalink_manager_options = $new_options = array_filter($new_options);
82
83 // Save the settings in database
84 update_option('permalink-manager', $new_options);
85 }
86
87 /**
88 * Save permastructures
89 */
90 public static function save_permastructures() {
91 global $permalink_manager_permastructs;
92
93 $post_fields = $_POST;
94 $new_options = array();
95
96 foreach($post_fields as $option_name => $option_value) {
97 $new_options[$option_name] = $option_value;
98 }
99
100 // Trim the trailing slashes & remove empty permastructures
101 $new_options = Permalink_Manager_Helper_Functions::multidimensional_array_map('untrailingslashit', $new_options);
102 foreach($new_options as $group_name => $group) {
103 if(is_array($group)) {
104 foreach($group as $element => $permastruct) {
105 // Trim slashes
106 $permastruct = trim($permastruct, "/");
107
108 // Do not store default permastructures
109 $default_permastruct = ($group_name == 'post_types') ? Permalink_Manager_Helper_Functions::get_default_permastruct($element, true) : "";
110 if($permastruct == $default_permastruct) { unset($group[$element]); }
111 }
112 // Do not store empty permastructures
113 $new_options[$group_name] = array_filter($group);
114 } else {
115 unset($new_options[$group_name]);
116 }
117 }
118
119 // Override the global with settings
120 $permalink_manager_permastructs = $new_options = array_filter($new_options);
121
122 // Save the settings in database
123 update_option('permalink-manager-permastructs', $new_options);
124 }
125
126 /**
127 * Remove URI from options array after post is moved to the trash
128 */
129 function clear_uris($post_id) {
130 global $permalink_manager_uris;
131
132 if(isset($_GET['clear-permalink-manager-uris']) && !empty($permalink_manager_uris)) {
133 foreach($permalink_manager_uris as $post_id => $uri) {
134 // Loop only through post URIs
135 if(is_numeric($post_id)) {
136 $post_status = get_post_status($post_id);
137 if(in_array($post_status, array('auto-draft', 'trash', ''))) {
138 unset($permalink_manager_uris[$post_id]);
139 }
140 }
141 }
142
143 update_option('permalink-manager-uris', $permalink_manager_uris);
144 }
145 }
146
147 /**
148 * "Find and replace" in "Tools"
149 */
150 function find_and_replace() {
151 // Check if posts or terms should be updated
152 if(!empty($_POST['section_type']) && $_POST['section_type'] == 'tax') {
153 return Permalink_Manager_URI_Functions_Tax::find_and_replace();
154 } else {
155 return Permalink_Manager_URI_Functions_Post::find_and_replace();
156 }
157 }
158
159 /**
160 * Regenerate all permalinks in "Tools"
161 */
162 function regenerate_all_permalinks() {
163 // Check if posts or terms should be updated
164 if(!empty($_POST['section_type']) && $_POST['section_type'] == 'tax') {
165 return Permalink_Manager_URI_Functions_Tax::regenerate_all_permalinks();
166 } else {
167 return Permalink_Manager_URI_Functions_Post::regenerate_all_permalinks();
168 }
169 }
170
171 /**
172 * Update all permalinks in "Permalink Editor"
173 */
174 function update_all_permalinks() {
175 // Check if posts or terms should be updated
176 if(!empty($_POST['section_type']) && $_POST['section_type'] == 'tax') {
177 return Permalink_Manager_URI_Functions_Tax::update_all_permalinks();
178 } else {
179 return Permalink_Manager_URI_Functions_Post::update_all_permalinks();
180 }
181 }
182
183 /**
184 * Clear sitemaps cache
185 */
186 function flush_sitemaps($types = array()) {
187 // Reset sitemap's cache
188 if(class_exists('WPSEO_Sitemaps_Cache')) {
189 $sitemaps = WPSEO_Sitemaps_Cache::clear($types);
190 }
191 }
192
193 }
194
195 ?>
196