| 1 |
<?php |
| 2 |
/** |
| 3 |
* Fetch our TAXOPRESS Autoterms option. |
| 4 |
* |
| 5 |
* @return mixed |
| 6 |
*/ |
| 7 |
function taxopress_get_autoterm_data() |
| 8 |
{ |
| 9 |
return array_filter((array)apply_filters('taxopress_get_autoterm_data', get_option('taxopress_autoterms', []), |
| 10 |
get_current_blog_id())); |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Fetch our TAXOPRESS Autoterms content option. |
| 15 |
* |
| 16 |
* @return mixed |
| 17 |
*/ |
| 18 |
function taxopress_get_autoterms_content_data() |
| 19 |
{ |
| 20 |
return array_filter((array)apply_filters('taxopress_get_autoterm_content_data', get_option('taxopress_autoterms_content', []), |
| 21 |
get_current_blog_id())); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Fetch our TAXOPRESS Autoterms schedule option. |
| 26 |
* |
| 27 |
* @return mixed |
| 28 |
*/ |
| 29 |
function taxopress_get_autoterms_schedule_data() |
| 30 |
{ |
| 31 |
return array_filter((array)apply_filters('taxopress_get_autoterm_schedule_data', get_option('taxopress_autoterms_schedule', []), |
| 32 |
get_current_blog_id())); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Get the selected autoterm from the $_POST global. |
| 37 |
* |
| 38 |
* @return bool|string False on no result, sanitized autoterm if set. |
| 39 |
* @internal |
| 40 |
* |
| 41 |
*/ |
| 42 |
function taxopress_get_current_autoterm() |
| 43 |
{ |
| 44 |
|
| 45 |
$autoterms = false; |
| 46 |
|
| 47 |
if (!empty($_GET) && isset($_GET['taxopress_autoterms'])) { |
| 48 |
$autoterms = sanitize_text_field($_GET['taxopress_autoterms']); |
| 49 |
} else { |
| 50 |
$autoterms = taxopress_get_autoterm_data(); |
| 51 |
if (!empty($autoterms)) { |
| 52 |
// Will return the first array key. |
| 53 |
$autoterms = key($autoterms); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Filters the current autoterm to edit. |
| 59 |
* |
| 60 |
* @param string $autoterms autoterm slug. |
| 61 |
*/ |
| 62 |
return apply_filters('taxopress_current_autoterm', $autoterms); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Get auto terms for current post |
| 67 |
* |
| 68 |
* |
| 69 |
* @return mixed |
| 70 |
*/ |
| 71 |
function taxopress_post_type_autoterms() |
| 72 |
{ |
| 73 |
global $pagenow; |
| 74 |
|
| 75 |
$allowed_pages = ['post-new.php', 'post.php', 'page.php', 'page-new.php']; |
| 76 |
if (!in_array($pagenow, $allowed_pages)) { |
| 77 |
return false; |
| 78 |
} |
| 79 |
|
| 80 |
$autoterms = taxopress_get_autoterm_data(); |
| 81 |
|
| 82 |
if (count($autoterms) > 0) { |
| 83 |
foreach ($autoterms as $autoterm) { |
| 84 |
|
| 85 |
$post_types = (isset($autoterm['post_types']) && is_array($autoterm['post_types']) && count($autoterm['post_types']) > 0) ? $autoterm['post_types'] : false; |
| 86 |
|
| 87 |
if (!$post_types) { |
| 88 |
continue; |
| 89 |
} |
| 90 |
|
| 91 |
if (in_array(get_post_type(), $post_types)) { |
| 92 |
return $autoterm; |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
return false; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Handle the save and deletion of autoterm data. |
| 102 |
*/ |
| 103 |
function taxopress_process_autoterm() |
| 104 |
{ |
| 105 |
|
| 106 |
if (wp_doing_ajax()) { |
| 107 |
return; |
| 108 |
} |
| 109 |
|
| 110 |
if (!is_admin()) { |
| 111 |
return; |
| 112 |
} |
| 113 |
|
| 114 |
if(!current_user_can('simple_tags')){ |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
if (empty($_GET)) { |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
if (!isset($_GET['page'])) { |
| 123 |
return; |
| 124 |
} |
| 125 |
if (!in_array($_GET['page'], ['st_autoterms', 'st_autoterms_schedule'])) { |
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
if (isset($_GET['new_autoterm'])) { |
| 130 |
if ((int)$_GET['new_autoterm'] === 1) { |
| 131 |
add_action('admin_notices', "taxopress_autoterms_update_success_admin_notice"); |
| 132 |
add_filter('removable_query_args', 'taxopress_saved_autoterm_filter_removable_query_args'); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
if (isset($_GET['deleted_autoterm'])) { |
| 137 |
if ((int)$_GET['deleted_autoterm'] === 1) { |
| 138 |
add_action('admin_notices', "taxopress_autoterms_delete_success_admin_notice"); |
| 139 |
add_filter('removable_query_args', 'taxopress_deleted_autoterm_filter_removable_query_args'); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
if (!empty($_POST) && isset($_POST['autoterm_submit'])) { |
| 145 |
$result = ''; |
| 146 |
if (isset($_POST['autoterm_submit'])) { |
| 147 |
check_admin_referer('taxopress_addedit_autoterm_nonce_action', |
| 148 |
'taxopress_addedit_autoterm_nonce_field'); |
| 149 |
$result = taxopress_update_autoterm($_POST); |
| 150 |
} |
| 151 |
|
| 152 |
if ($result) { |
| 153 |
wp_safe_redirect( |
| 154 |
add_query_arg( |
| 155 |
[ |
| 156 |
'page' => 'st_autoterms', |
| 157 |
'add' => 'new_item', |
| 158 |
'action' => 'edit', |
| 159 |
'taxopress_autoterms' => $result, |
| 160 |
'new_autoterm' => 1, |
| 161 |
], |
| 162 |
taxopress_admin_url('admin.php') |
| 163 |
) |
| 164 |
); |
| 165 |
|
| 166 |
exit(); |
| 167 |
} |
| 168 |
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-delete-autoterm') { |
| 169 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 170 |
if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) { |
| 171 |
taxopress_action_delete_autoterm(sanitize_text_field($_REQUEST['taxopress_autoterms'])); |
| 172 |
add_action('admin_notices', "taxopress_autoterms_delete_autoterm_admin_notice"); |
| 173 |
} |
| 174 |
add_filter('removable_query_args', 'taxopress_delete_autoterm_filter_removable_query_args'); |
| 175 |
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-delete-autoterm-log') { |
| 176 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 177 |
if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) { |
| 178 |
wp_delete_post((int)$_REQUEST['taxopress_autoterms_log'], true); |
| 179 |
add_action('admin_notices', "taxopress_autoterms_delete_autoterm_log_admin_notice"); |
| 180 |
} |
| 181 |
add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args'); |
| 182 |
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-delete-autoterm-logs') { |
| 183 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 184 |
if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) { |
| 185 |
global $wpdb; |
| 186 |
$result = $wpdb->query( |
| 187 |
$wpdb->prepare(" |
| 188 |
DELETE posts, pt, pm |
| 189 |
FROM {$wpdb->prefix}posts posts |
| 190 |
LEFT JOIN {$wpdb->prefix}term_relationships pt ON pt.object_id = posts.ID |
| 191 |
LEFT JOIN {$wpdb->prefix}postmeta pm ON pm.post_id = posts.ID |
| 192 |
WHERE posts.post_type = %s |
| 193 |
", |
| 194 |
'taxopress_logs' |
| 195 |
) |
| 196 |
); |
| 197 |
add_action('admin_notices', "taxopress_autoterms_delete_autoterm_logs_admin_notice"); |
| 198 |
} |
| 199 |
add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args'); |
| 200 |
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-enable-autoterm-logs') { |
| 201 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 202 |
if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) { |
| 203 |
delete_option('taxopress_autoterms_logs_disabled'); |
| 204 |
add_action('admin_notices', "taxopress_autoterms_enable_log_admin_notice"); |
| 205 |
} |
| 206 |
add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args'); |
| 207 |
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-disable-autoterm-logs') { |
| 208 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 209 |
if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) { |
| 210 |
update_option('taxopress_autoterms_logs_disabled', 1); |
| 211 |
add_action('admin_notices', "taxopress_autoterms_disable_log_admin_notice"); |
| 212 |
} |
| 213 |
add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args'); |
| 214 |
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-update-autoterm-limit') { |
| 215 |
$nonce = sanitize_text_field($_REQUEST['_wpnonce']); |
| 216 |
if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) { |
| 217 |
$limit = (int)$_REQUEST['limit']; |
| 218 |
if($limit > 0){ |
| 219 |
update_option('taxopress_auto_terms_logs_limit', $limit); |
| 220 |
add_action('admin_notices', "taxopress_autoterms_limit_updated_admin_notice"); |
| 221 |
}else{ |
| 222 |
add_action('admin_notices', "taxopress_autoterms_limit_invalid_admin_notice"); |
| 223 |
} |
| 224 |
} |
| 225 |
add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args'); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
add_action('admin_init', 'taxopress_process_autoterm', 8); |
| 230 |
|
| 231 |
|
| 232 |
/** |
| 233 |
* Create default autoterm. |
| 234 |
*/ |
| 235 |
function taxopress_create_default_autoterm() |
| 236 |
{ |
| 237 |
|
| 238 |
if (wp_doing_ajax()) { |
| 239 |
return; |
| 240 |
} |
| 241 |
|
| 242 |
if (!is_admin()) { |
| 243 |
return; |
| 244 |
} |
| 245 |
|
| 246 |
if(!current_user_can('simple_tags')){ |
| 247 |
return; |
| 248 |
} |
| 249 |
|
| 250 |
if ((int)get_option('taxopress_default_autoterms') > 0) { |
| 251 |
return; |
| 252 |
} |
| 253 |
|
| 254 |
if (count(taxopress_get_autoterm_data()) > 0) { |
| 255 |
return; |
| 256 |
} |
| 257 |
|
| 258 |
//create default or export previous |
| 259 |
$create_default = true; |
| 260 |
|
| 261 |
$options = get_option( STAGS_OPTIONS_NAME_AUTO ); |
| 262 |
if(is_array($options) && count($options) > 0 ){ |
| 263 |
foreach($options as $options_post_type => $options_taxdata){ |
| 264 |
if(is_array($options_taxdata) && count($options_taxdata) > 0){ |
| 265 |
$create_default = false; |
| 266 |
foreach($options_taxdata as $options_taxonomy => $options_taxonomy_data){ |
| 267 |
$taxonomy = get_taxonomy($options_taxonomy); |
| 268 |
$default = []; |
| 269 |
$default['taxopress_autoterm']['autoterm_from'] = 'posts'; |
| 270 |
$default['taxopress_autoterm']['title'] = ''. (is_object($taxonomy) ? $taxonomy->labels->name : $options_taxonomy ) .' '. ucwords($options_post_type) .' Auto term'; |
| 271 |
$default['taxopress_autoterm']['taxonomy'] = $options_taxonomy; |
| 272 |
$default['post_types'] = []; |
| 273 |
$default['post_status'] = ['publish']; |
| 274 |
$default['taxopress_autoterm']['autoterm_useall'] = isset($options_taxonomy_data['at_all']) ? $options_taxonomy_data['at_all'] : 0; |
| 275 |
$default['taxopress_autoterm']['autoterm_useonly'] = isset($options_taxonomy_data['at_all_no']) ? $options_taxonomy_data['at_all_no'] : 0; |
| 276 |
$default['taxopress_autoterm']['autoterm_target'] = isset($options_taxonomy_data['at_empty']) ? $options_taxonomy_data['at_empty'] : 0; |
| 277 |
$default['taxopress_autoterm']['autoterm_word'] = isset($options_taxonomy_data['only_full_word']) ? $options_taxonomy_data['only_full_word'] : 0; |
| 278 |
$default['taxopress_autoterm']['autoterm_hash'] = isset($options_taxonomy_data['allow_hashtag_format']) ? $options_taxonomy_data['allow_hashtag_format'] : 0; |
| 279 |
$default['specific_terms'] = isset($options_taxonomy_data['auto_list']) ? (array) maybe_unserialize($options_taxonomy_data['auto_list']) : []; |
| 280 |
$default['taxopress_autoterm']['terms_limit'] = '5'; |
| 281 |
$default['taxopress_autoterm']['synonyms_term'] = 1; |
| 282 |
|
| 283 |
$result = taxopress_update_autoterm($default); |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
if($create_default){ |
| 290 |
$default = []; |
| 291 |
$default['taxopress_autoterm']['title'] = esc_html__('Auto term', 'simple-tags'); |
| 292 |
$default['taxopress_autoterm']['taxonomy'] = 'post_tag'; |
| 293 |
$default['post_types'] = []; |
| 294 |
$default['post_status'] = ['publish']; |
| 295 |
$default['taxopress_autoterm']['autoterm_from'] = 'posts'; |
| 296 |
$default['taxopress_autoterm']['autoterm_use_taxonomy'] = '1'; |
| 297 |
$default['taxopress_autoterm']['autoterm_useall'] = '1'; |
| 298 |
$default['taxopress_autoterm']['autoterm_useonly'] = '0'; |
| 299 |
$default['taxopress_autoterm']['autoterm_target'] = '0'; |
| 300 |
$default['taxopress_autoterm']['autoterm_word'] = '0'; |
| 301 |
$default['taxopress_autoterm']['autoterm_hash'] = '0'; |
| 302 |
$default['taxopress_autoterm']['terms_limit'] = '5'; |
| 303 |
$default['taxopress_autoterm']['synonyms_term'] = 1; |
| 304 |
$default['taxopress_autoterm']['autoterm_for_post'] = '1'; |
| 305 |
$default['taxopress_autoterm']['autoterm_for_schedule'] = '1'; |
| 306 |
$default['taxopress_autoterm']['autoterm_for_existing_content'] = '1'; |
| 307 |
$default['taxopress_autoterm']['autoterm_for_metaboxes'] = '1'; |
| 308 |
$default['taxopress_autoterm']['schedule_terms_limit'] = '5'; |
| 309 |
$default['taxopress_autoterm']['schedule_autoterm_target'] = '0'; |
| 310 |
$default['taxopress_autoterm']['schedule_autoterm_word'] = '0'; |
| 311 |
$default['taxopress_autoterm']['schedule_autoterm_hash'] = '0'; |
| 312 |
$default['taxopress_autoterm']['existing_content_terms_limit'] = '5'; |
| 313 |
$default['specific_terms'] = []; |
| 314 |
$default['find_in_customs_entries'] = []; |
| 315 |
$default['find_in_custom_fields_custom_items'] = []; |
| 316 |
$default['find_in_taxonomies_custom_items'] = []; |
| 317 |
$result = taxopress_update_autoterm($default); |
| 318 |
} |
| 319 |
update_option('taxopress_default_autoterms', $result); |
| 320 |
} |
| 321 |
|
| 322 |
add_action('admin_init', 'taxopress_create_default_autoterm', 8); |
| 323 |
|
| 324 |
|
| 325 |
/** |
| 326 |
* Add to or update our TAXOPRESS option with new data. |
| 327 |
* |
| 328 |
* |
| 329 |
* @param array $data Array of autoterm data to update. Optional. |
| 330 |
* @return bool|string False on failure, string on success. |
| 331 |
* @internal |
| 332 |
* |
| 333 |
*/ |
| 334 |
function taxopress_update_autoterm($data = []) |
| 335 |
{ |
| 336 |
$sanitized_data = []; |
| 337 |
foreach ($data as $key => $value) { |
| 338 |
if (!is_array($value)) { |
| 339 |
$sanitized_data[$key] = taxopress_sanitize_text_field($value); |
| 340 |
} else { |
| 341 |
$new_value = []; |
| 342 |
foreach ($data[$key] as $option_key => $option_value) { |
| 343 |
if ($option_key === 'terms_regex_code') { |
| 344 |
$regex_pattern = sanitize_text_field($option_value); |
| 345 |
if ( !empty($regex_pattern) && preg_match( $regex_pattern, '' ) !== false ) { |
| 346 |
$new_value[$option_key] = $regex_pattern; |
| 347 |
} else { |
| 348 |
$new_value[$option_key] = '';//invalid expression |
| 349 |
} |
| 350 |
} elseif ($option_key === 'post_types' || $option_key === 'post_status') { |
| 351 |
$new_value[$option_key] = taxopress_sanitize_post_type_status($option_value); |
| 352 |
} else { |
| 353 |
$new_value[$option_key] = taxopress_sanitize_text_field($option_value); |
| 354 |
} |
| 355 |
} |
| 356 |
$sanitized_data[$key] = $new_value; |
| 357 |
} |
| 358 |
} |
| 359 |
$data = $sanitized_data; |
| 360 |
|
| 361 |
$autoterms = taxopress_get_autoterm_data(); |
| 362 |
|
| 363 |
$title = $data['taxopress_autoterm']['title']; |
| 364 |
$title = str_replace('"', '', htmlspecialchars_decode($title)); |
| 365 |
$title = htmlspecialchars($title, ENT_QUOTES); |
| 366 |
$title = trim($title); |
| 367 |
$data['taxopress_autoterm']['title'] = stripslashes_deep($title); |
| 368 |
|
| 369 |
|
| 370 |
//update other post post |
| 371 |
$data['taxopress_autoterm']['specific_terms'] = isset($data['specific_terms']) ? $data['specific_terms'] : []; |
| 372 |
$data['taxopress_autoterm']['post_types'] = isset($data['post_types']) ? $data['post_types'] : []; |
| 373 |
$data['taxopress_autoterm']['post_status'] = isset($data['post_status']) ? $data['post_status'] : []; |
| 374 |
|
| 375 |
$data['taxopress_autoterm']['html_exclusion'] = isset($data['html_exclusion']) ? $data['html_exclusion'] : []; |
| 376 |
$data['taxopress_autoterm']['html_exclusion_customs'] = isset($data['html_exclusion_customs']) ? $data['html_exclusion_customs'] : []; |
| 377 |
$data['taxopress_autoterm']['html_exclusion_customs_entry'] = isset($data['html_exclusion_customs_entry']) ? array_unique($data['html_exclusion_customs_entry']) : []; |
| 378 |
|
| 379 |
$data['taxopress_autoterm']['find_in_customs_entries'] = isset($data['find_in_customs_entries']) ? $data['find_in_customs_entries'] : []; |
| 380 |
$data['taxopress_autoterm']['find_in_custom_fields_custom_items'] = isset($data['find_in_custom_fields_custom_items']) ? $data['find_in_custom_fields_custom_items'] : []; |
| 381 |
$data['taxopress_autoterm']['find_in_taxonomies_custom_items'] = isset($data['find_in_taxonomies_custom_items']) ? $data['find_in_taxonomies_custom_items'] : []; |
| 382 |
|
| 383 |
|
| 384 |
//update our custom checkbox value if not checked |
| 385 |
if (!isset($data['taxopress_autoterm']['autoterm_useall'])) { |
| 386 |
$data['taxopress_autoterm']['autoterm_useall'] = 0; |
| 387 |
} |
| 388 |
if (!isset($data['taxopress_autoterm']['autoterm_useonly'])) { |
| 389 |
$data['taxopress_autoterm']['autoterm_useonly'] = 0; |
| 390 |
} |
| 391 |
if (!isset($data['taxopress_autoterm']['autoterm_target'])) { |
| 392 |
$data['taxopress_autoterm']['autoterm_target'] = 0; |
| 393 |
} |
| 394 |
if (!isset($data['taxopress_autoterm']['autoterm_word'])) { |
| 395 |
$data['taxopress_autoterm']['autoterm_word'] = 0; |
| 396 |
} |
| 397 |
if (!isset($data['taxopress_autoterm']['autoterm_hash'])) { |
| 398 |
$data['taxopress_autoterm']['autoterm_hash'] = 0; |
| 399 |
} |
| 400 |
if (!isset($data['taxopress_autoterm']['synonyms_term'])) { |
| 401 |
$data['taxopress_autoterm']['synonyms_term'] = 0; |
| 402 |
} |
| 403 |
if (!isset($data['taxopress_autoterm']['autoterm_for_post'])) { |
| 404 |
$data['taxopress_autoterm']['autoterm_for_post'] = 0; |
| 405 |
} |
| 406 |
if (!isset($data['taxopress_autoterm']['autoterm_for_schedule'])) { |
| 407 |
$data['taxopress_autoterm']['autoterm_for_schedule'] = 0; |
| 408 |
} |
| 409 |
if (!isset($data['taxopress_autoterm']['autoterm_for_existing_content'])) { |
| 410 |
$data['taxopress_autoterm']['autoterm_for_existing_content'] = 0; |
| 411 |
} |
| 412 |
if (!isset($data['taxopress_autoterm']['autoterm_for_metaboxes'])) { |
| 413 |
$data['taxopress_autoterm']['autoterm_for_metaboxes'] = 0; |
| 414 |
} |
| 415 |
if (!isset($data['taxopress_autoterm']['schedule_autoterm_target'])) { |
| 416 |
$data['taxopress_autoterm']['schedule_autoterm_target'] = 0; |
| 417 |
} |
| 418 |
if (!isset($data['taxopress_autoterm']['schedule_autoterm_word'])) { |
| 419 |
$data['taxopress_autoterm']['schedule_autoterm_word'] = 0; |
| 420 |
} |
| 421 |
if (!isset($data['taxopress_autoterm']['schedule_autoterm_hash'])) { |
| 422 |
$data['taxopress_autoterm']['schedule_autoterm_hash'] = 0; |
| 423 |
} |
| 424 |
|
| 425 |
if (isset($data['edited_autoterm'])) { |
| 426 |
$autoterm_id = $data['edited_autoterm']; |
| 427 |
$autoterms[$autoterm_id] = $data['taxopress_autoterm']; |
| 428 |
$success = update_option('taxopress_autoterms', $autoterms); |
| 429 |
//return 'update_success'; |
| 430 |
} else { |
| 431 |
$autoterm_id = (int)get_option('taxopress_autoterm_ids_increament') + 1; |
| 432 |
$data['taxopress_autoterm']['ID'] = $autoterm_id; |
| 433 |
$autoterms[$autoterm_id] = $data['taxopress_autoterm']; |
| 434 |
$success = update_option('taxopress_autoterms', $autoterms); |
| 435 |
$update_id = update_option('taxopress_autoterm_ids_increament', $autoterm_id); |
| 436 |
//return 'add_success'; |
| 437 |
} |
| 438 |
|
| 439 |
return $autoterm_id; |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* Successful update callback. |
| 444 |
*/ |
| 445 |
function taxopress_autoterms_update_success_admin_notice() |
| 446 |
{ |
| 447 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 448 |
echo taxopress_admin_notices_helper(esc_html__('Settings updated successfully.', 'simple-tags')); |
| 449 |
} |
| 450 |
|
| 451 |
/** |
| 452 |
* Successful deleted callback. |
| 453 |
*/ |
| 454 |
function taxopress_autoterms_delete_success_admin_notice() |
| 455 |
{ |
| 456 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 457 |
echo taxopress_admin_notices_helper(esc_html__('Auto Terms successfully deleted.', 'simple-tags'), false); |
| 458 |
} |
| 459 |
|
| 460 |
function taxopress_autoterms_enable_log_admin_notice() |
| 461 |
{ |
| 462 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 463 |
echo taxopress_admin_notices_helper(esc_html__('Auto Terms logs enabled successfully.', 'simple-tags')); |
| 464 |
} |
| 465 |
|
| 466 |
function taxopress_autoterms_disable_log_admin_notice() |
| 467 |
{ |
| 468 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 469 |
echo taxopress_admin_notices_helper(esc_html__('Auto Terms logs disabled successfully.', 'simple-tags')); |
| 470 |
} |
| 471 |
|
| 472 |
function taxopress_autoterms_delete_autoterm_admin_notice() |
| 473 |
{ |
| 474 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 475 |
echo taxopress_admin_notices_helper(esc_html__('Auto Terms deleted successfully.', 'simple-tags')); |
| 476 |
} |
| 477 |
|
| 478 |
function taxopress_autoterms_delete_autoterm_log_admin_notice() |
| 479 |
{ |
| 480 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 481 |
echo taxopress_admin_notices_helper(esc_html__('Auto Terms log deleted successfully.', 'simple-tags')); |
| 482 |
} |
| 483 |
|
| 484 |
function taxopress_autoterms_delete_autoterm_logs_admin_notice() |
| 485 |
{ |
| 486 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 487 |
echo taxopress_admin_notices_helper(esc_html__('Auto Terms logs deleted successfully.', 'simple-tags')); |
| 488 |
} |
| 489 |
|
| 490 |
function taxopress_autoterms_limit_updated_admin_notice() |
| 491 |
{ |
| 492 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 493 |
echo taxopress_admin_notices_helper(esc_html__('Auto Terms limit updated successfully.', 'simple-tags')); |
| 494 |
} |
| 495 |
|
| 496 |
function taxopress_autoterms_limit_invalid_admin_notice() |
| 497 |
{ |
| 498 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 499 |
echo taxopress_admin_notices_helper(esc_html__('Auto Terms limit must be greater than 0.', 'simple-tags'), false); |
| 500 |
} |
| 501 |
|
| 502 |
/** |
| 503 |
* Filters the list of query arguments which get removed from admin area URLs in WordPress. |
| 504 |
* |
| 505 |
* @link https://core.trac.wordpress.org/ticket/23367 |
| 506 |
* |
| 507 |
* @param string[] $args Array of removable query arguments. |
| 508 |
* @return string[] Updated array of removable query arguments. |
| 509 |
*/ |
| 510 |
function taxopress_saved_autoterm_filter_removable_query_args(array $args) |
| 511 |
{ |
| 512 |
return array_merge($args, [ |
| 513 |
'new_autoterm', |
| 514 |
]); |
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Filters the list of query arguments which get removed from admin area URLs in WordPress. |
| 519 |
* |
| 520 |
* @link https://core.trac.wordpress.org/ticket/23367 |
| 521 |
* |
| 522 |
* @param string[] $args Array of removable query arguments. |
| 523 |
* @return string[] Updated array of removable query arguments. |
| 524 |
*/ |
| 525 |
function taxopress_deleted_autoterm_filter_removable_query_args(array $args) |
| 526 |
{ |
| 527 |
return array_merge($args, [ |
| 528 |
'deleted_autoterm', |
| 529 |
]); |
| 530 |
} |
| 531 |
|
| 532 |
/** |
| 533 |
* Filters the list of query arguments which get removed from admin area URLs in WordPress. |
| 534 |
* |
| 535 |
* @link https://core.trac.wordpress.org/ticket/23367 |
| 536 |
* |
| 537 |
* @param string[] $args Array of removable query arguments. |
| 538 |
* @return string[] Updated array of removable query arguments. |
| 539 |
*/ |
| 540 |
function taxopress_delete_autoterm_filter_removable_query_args(array $args) |
| 541 |
{ |
| 542 |
return array_merge($args, [ |
| 543 |
'action', |
| 544 |
'taxopress_autoterms', |
| 545 |
'_wpnonce', |
| 546 |
]); |
| 547 |
} |
| 548 |
|
| 549 |
/** |
| 550 |
* Filters the list of query arguments which get removed from admin area URLs in WordPress. |
| 551 |
* |
| 552 |
* @link https://core.trac.wordpress.org/ticket/23367 |
| 553 |
* |
| 554 |
* @param string[] $args Array of removable query arguments. |
| 555 |
* @return string[] Updated array of removable query arguments. |
| 556 |
*/ |
| 557 |
function taxopress_delete_autoterm_log_filter_removable_query_args(array $args) |
| 558 |
{ |
| 559 |
return array_merge($args, [ |
| 560 |
'action', |
| 561 |
'taxopress_autoterms_log', |
| 562 |
'_wpnonce', |
| 563 |
]); |
| 564 |
} |
| 565 |
|
| 566 |
/** |
| 567 |
* Delete our custom autoterm from the array of autoterms. |
| 568 |
* @return bool|string False on failure, string on success. |
| 569 |
*/ |
| 570 |
function taxopress_action_delete_autoterm($autoterm_id) |
| 571 |
{ |
| 572 |
$autoterms = taxopress_get_autoterm_data(); |
| 573 |
|
| 574 |
if (array_key_exists($autoterm_id, $autoterms)) { |
| 575 |
unset($autoterms[$autoterm_id]); |
| 576 |
$success = update_option('taxopress_autoterms', $autoterms); |
| 577 |
} |
| 578 |
|
| 579 |
if (isset($success)) { |
| 580 |
add_action('admin_notices', "taxopress_taxdeleted_admin_notice"); |
| 581 |
wp_safe_redirect( |
| 582 |
add_query_arg( |
| 583 |
[ |
| 584 |
'page' => 'st_autoterms', |
| 585 |
'deleted_autoterm' => 1, |
| 586 |
], |
| 587 |
taxopress_admin_url('admin.php') |
| 588 |
) |
| 589 |
); |
| 590 |
exit(); |
| 591 |
} |
| 592 |
} |
| 593 |
|
| 594 |
/** |
| 595 |
* Get auto terms logs data |
| 596 |
* |
| 597 |
*/ |
| 598 |
function taxopress_autoterms_logs_data($per_page = 20, $current_page = 1, $orderby = 'ID', $order = 'desc', $schedule_query = false) |
| 599 |
{ |
| 600 |
|
| 601 |
$meta_query[] = array('relation' => 'AND'); |
| 602 |
$meta_query[] = array( |
| 603 |
'key' => '_taxopress_log_component', |
| 604 |
'value' => 'st_autoterms', |
| 605 |
); |
| 606 |
|
| 607 |
/** |
| 608 |
* Custom filter handler |
| 609 |
*/ |
| 610 |
$custom_filters = [ |
| 611 |
'log_source_filter' => '_taxopress_log_action', |
| 612 |
'log_filter_post_type' => '_taxopress_log_post_type', |
| 613 |
'log_filter_taxonomy' => '_taxopress_log_taxonomy', |
| 614 |
'log_filter_status_message' => '_taxopress_log_status_message', |
| 615 |
'log_filter_settings' => '_taxopress_log_option_id' |
| 616 |
]; |
| 617 |
foreach ($custom_filters as $filter => $option) { |
| 618 |
if (!empty($_REQUEST[$filter])) { |
| 619 |
$meta_query[] = array( |
| 620 |
'key' => sanitize_key($option), |
| 621 |
'value' => sanitize_text_field($_REQUEST[$filter]), |
| 622 |
); |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
if ($schedule_query) { |
| 627 |
$meta_query[] = array( |
| 628 |
'key' => '_taxopress_log_action', |
| 629 |
'value' => ['daily_cron_schedule', 'hourly_cron_schedule', 'weekly_cron_schedule'], |
| 630 |
'compare' => 'IN' |
| 631 |
); |
| 632 |
} |
| 633 |
|
| 634 |
$logs_arg = array( |
| 635 |
'post_type' => 'taxopress_logs', |
| 636 |
'post_status' => 'publish', |
| 637 |
'paged' => $current_page, |
| 638 |
'posts_per_page' => $per_page, |
| 639 |
'meta_query' => $meta_query, |
| 640 |
'orderby' => $orderby, |
| 641 |
'order' => $order, |
| 642 |
); |
| 643 |
|
| 644 |
/** |
| 645 |
* Handle search |
| 646 |
*/ |
| 647 |
if ((!empty($_REQUEST['s'])) && $search = sanitize_text_field($_REQUEST['s'])) { |
| 648 |
$logs_arg['s'] = $search; |
| 649 |
} |
| 650 |
|
| 651 |
$logs = new WP_Query($logs_arg); |
| 652 |
|
| 653 |
return ['posts'=> $logs->posts, 'counts'=> $logs->found_posts]; |
| 654 |
} |