| 1 |
<?php |
| 2 |
|
| 3 |
class SimpleTags_Admin { |
| 4 |
// CPT and Taxonomy support |
| 5 |
public static $post_type = 'post'; |
| 6 |
public static $post_type_name = ''; |
| 7 |
public static $taxonomy = ''; |
| 8 |
public static $taxo_name = ''; |
| 9 |
public static $admin_url = ''; |
| 10 |
|
| 11 |
const MENU_SLUG = 'st_options'; |
| 12 |
|
| 13 |
/** |
| 14 |
* Initialize Admin |
| 15 |
* |
| 16 |
* @return void |
| 17 |
* @author WebFactory Ltd |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
// DB Upgrade ? |
| 21 |
self::upgrade(); |
| 22 |
|
| 23 |
// Which taxo ? |
| 24 |
self::register_taxonomy(); |
| 25 |
|
| 26 |
// Admin menu |
| 27 |
add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) ); |
| 28 |
// Log cpt |
| 29 |
add_action( 'init', array( __CLASS__, 'taxopress_log_post_type' ) ); |
| 30 |
|
| 31 |
//Admin footer credit |
| 32 |
add_action( 'in_admin_footer', array( __CLASS__, 'taxopress_admin_footer') ); |
| 33 |
|
| 34 |
// Load JavaScript and CSS |
| 35 |
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_scripts' ) ); |
| 36 |
|
| 37 |
//ui class is used accross many pages. So, it should be here |
| 38 |
require STAGS_DIR . '/inc/class.admin.taxonomies.ui.php'; |
| 39 |
|
| 40 |
//tag clouds/ terms display |
| 41 |
$active_terms_display = isset($_POST['updateoptions']) && |
| 42 |
( |
| 43 |
!isset($_POST['active_terms_display']) || |
| 44 |
(isset($_POST['active_terms_display']) && (int)$_POST['active_terms_display'] === 0) |
| 45 |
) ? 0 : 1; |
| 46 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_terms_display' ) || (isset($_POST['active_terms_display']) && (int)$_POST['active_terms_display'] === 1)) && $active_terms_display === 1 ) { |
| 47 |
require_once STAGS_DIR . '/inc/tag-clouds-action.php'; |
| 48 |
require STAGS_DIR . '/inc/tag-clouds-table.php'; |
| 49 |
require STAGS_DIR . '/inc/tag-clouds.php'; |
| 50 |
SimpleTags_Tag_Clouds::get_instance(); |
| 51 |
} |
| 52 |
|
| 53 |
//post tags |
| 54 |
$active_post_tags = isset($_POST['updateoptions']) && |
| 55 |
( |
| 56 |
!isset($_POST['active_post_tags']) || |
| 57 |
(isset($_POST['active_post_tags']) && (int)$_POST['active_post_tags'] === 0) |
| 58 |
) ? 0 : 1; |
| 59 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_post_tags' ) || (isset($_POST['active_post_tags']) && (int)$_POST['active_post_tags'] === 1)) && $active_post_tags === 1 ) { |
| 60 |
require_once STAGS_DIR . '/inc/post-tags-action.php'; |
| 61 |
require STAGS_DIR . '/inc/post-tags-table.php'; |
| 62 |
require STAGS_DIR . '/inc/post-tags.php'; |
| 63 |
SimpleTags_Post_Tags::get_instance(); |
| 64 |
} |
| 65 |
|
| 66 |
//Related Posts |
| 67 |
$active_related_posts_new = isset($_POST['updateoptions']) && |
| 68 |
( |
| 69 |
!isset($_POST['active_related_posts_new']) || |
| 70 |
(isset($_POST['active_related_posts_new']) && (int)$_POST['active_related_posts_new'] === 0) |
| 71 |
) ? 0 : 1; |
| 72 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_related_posts_new' ) || (isset($_POST['active_related_posts_new']) && (int)$_POST['active_related_posts_new'] === 1)) && $active_related_posts_new === 1 ) { |
| 73 |
require_once STAGS_DIR . '/inc/related-posts-action.php'; |
| 74 |
require STAGS_DIR . '/inc/related-posts-table.php'; |
| 75 |
require STAGS_DIR . '/inc/related-posts.php'; |
| 76 |
SimpleTags_Related_Post::get_instance(); |
| 77 |
} |
| 78 |
|
| 79 |
//Auto Links |
| 80 |
$active_auto_links = isset($_POST['updateoptions']) && |
| 81 |
( |
| 82 |
!isset($_POST['active_auto_links']) || |
| 83 |
(isset($_POST['active_auto_links']) && (int)$_POST['active_auto_links'] === 0) |
| 84 |
) ? 0 : 1; |
| 85 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_auto_links' ) || (isset($_POST['active_auto_links']) && (int)$_POST['active_auto_links'] === 1)) && $active_auto_links === 1 ) { |
| 86 |
require STAGS_DIR . '/inc/autolinks-table.php'; |
| 87 |
require STAGS_DIR . '/inc/autolinks.php'; |
| 88 |
SimpleTags_Autolink::get_instance(); |
| 89 |
} |
| 90 |
|
| 91 |
//Auto Terms |
| 92 |
$active_auto_terms = isset($_POST['updateoptions']) && |
| 93 |
( |
| 94 |
!isset($_POST['active_auto_terms']) || |
| 95 |
(isset($_POST['active_auto_terms']) && (int)$_POST['active_auto_terms'] === 0) |
| 96 |
) ? 0 : 1; |
| 97 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_auto_terms' ) || (isset($_POST['active_auto_terms']) && (int)$_POST['active_auto_terms'] === 1)) && $active_auto_terms === 1 ) { |
| 98 |
require STAGS_DIR . '/inc/autoterms-table.php'; |
| 99 |
require STAGS_DIR . '/inc/autoterms-logs-table.php'; |
| 100 |
require STAGS_DIR . '/inc/autoterms.php'; |
| 101 |
SimpleTags_Autoterms::get_instance(); |
| 102 |
} |
| 103 |
|
| 104 |
//Suggest Terms |
| 105 |
$active_suggest_terms = isset($_POST['updateoptions']) && |
| 106 |
( |
| 107 |
!isset($_POST['active_suggest_terms']) || |
| 108 |
(isset($_POST['active_suggest_terms']) && (int)$_POST['active_suggest_terms'] === 0) |
| 109 |
) ? 0 : 1; |
| 110 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_suggest_terms' ) || (isset($_POST['active_suggest_terms']) && (int)$_POST['active_suggest_terms'] === 1)) && $active_suggest_terms === 1 ) { |
| 111 |
require STAGS_DIR . '/inc/suggestterms-table.php'; |
| 112 |
require STAGS_DIR . '/inc/suggestterms.php'; |
| 113 |
SimpleTags_SuggestTerms::get_instance(); |
| 114 |
} |
| 115 |
|
| 116 |
//suggest terms option |
| 117 |
$active_mass_edit = isset($_POST['updateoptions']) && |
| 118 |
( |
| 119 |
!isset($_POST['active_mass_edit']) || |
| 120 |
(isset($_POST['active_mass_edit']) && (int)$_POST['active_mass_edit'] === 0) |
| 121 |
) ? 0 : 1; |
| 122 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_mass_edit' ) || (isset($_POST['active_mass_edit']) && (int)$_POST['active_mass_edit'] === 1)) && $active_mass_edit === 1 ) { |
| 123 |
require STAGS_DIR . '/inc/class.admin.suggest.php'; |
| 124 |
new SimpleTags_Admin_Suggest(); |
| 125 |
} |
| 126 |
|
| 127 |
//click terms option |
| 128 |
require STAGS_DIR . '/inc/class.admin.clickterms.php'; |
| 129 |
new SimpleTags_Admin_ClickTags(); |
| 130 |
|
| 131 |
require STAGS_DIR . '/inc/class.admin.autocomplete.php'; |
| 132 |
new SimpleTags_Admin_Autocomplete(); |
| 133 |
|
| 134 |
$active_mass_edit = isset($_POST['updateoptions']) && |
| 135 |
( |
| 136 |
!isset($_POST['active_mass_edit']) || |
| 137 |
(isset($_POST['active_mass_edit']) && (int)$_POST['active_mass_edit'] === 0) |
| 138 |
) ? 0 : 1; |
| 139 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_mass_edit' ) || (isset($_POST['active_mass_edit']) && (int)$_POST['active_mass_edit'] === 1)) && $active_mass_edit === 1 ) { |
| 140 |
require STAGS_DIR . '/inc/class.admin.mass.php'; |
| 141 |
new SimpleTags_Admin_Mass(); |
| 142 |
} |
| 143 |
|
| 144 |
$active_manage = isset($_POST['updateoptions']) && |
| 145 |
( |
| 146 |
!isset($_POST['active_manage']) || |
| 147 |
(isset($_POST['active_manage']) && (int)$_POST['active_manage'] === 0) |
| 148 |
) ? 0 : 1; |
| 149 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_manage' ) || (isset($_POST['active_manage']) && (int)$_POST['active_manage'] === 1)) && $active_manage === 1 ) { |
| 150 |
require STAGS_DIR . '/inc/class-tag-table.php'; |
| 151 |
require STAGS_DIR . '/inc/class.admin.manage.php'; |
| 152 |
SimpleTags_Admin_Manage::get_instance(); |
| 153 |
} |
| 154 |
|
| 155 |
require STAGS_DIR . '/inc/class.admin.post.php'; |
| 156 |
new SimpleTags_Admin_Post_Settings(); |
| 157 |
|
| 158 |
//taxonomies |
| 159 |
$active_taxonomies = isset($_POST['updateoptions']) && |
| 160 |
( |
| 161 |
!isset($_POST['active_taxonomies']) || |
| 162 |
(isset($_POST['active_taxonomies']) && (int)$_POST['active_taxonomies'] === 0) |
| 163 |
) ? 0 : 1; |
| 164 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_taxonomies' ) || (isset($_POST['active_taxonomies']) && (int)$_POST['active_taxonomies'] === 1)) && $active_taxonomies === 1 ) { |
| 165 |
require_once STAGS_DIR . '/inc/taxonomies-action.php'; |
| 166 |
require STAGS_DIR . '/inc/class-taxonomies-table.php'; |
| 167 |
require STAGS_DIR . '/inc/taxonomies.php'; |
| 168 |
SimpleTags_Admin_Taxonomies::get_instance(); |
| 169 |
} |
| 170 |
|
| 171 |
do_action('taxopress_admin_class_after_includes'); |
| 172 |
|
| 173 |
// Ajax action, JS Helper and admin action |
| 174 |
add_action( 'wp_ajax_simpletags', array( __CLASS__, 'ajax_check' ) ); |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Ajax Dispatcher |
| 180 |
*/ |
| 181 |
public static function ajax_check() { |
| 182 |
if ( isset( $_GET['stags_action'] ) && 'maybe_create_tag' === $_GET['stags_action'] && isset( $_GET['tag'] ) ) { |
| 183 |
self::maybe_create_tag( wp_unslash( sanitize_text_field($_GET['tag']) ) ); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Maybe create a tag, and return the term_id |
| 189 |
* |
| 190 |
* @param string $tag_name |
| 191 |
*/ |
| 192 |
public static function maybe_create_tag( $tag_name = '' ) { |
| 193 |
$term_id = 0; |
| 194 |
//restore & in tag post |
| 195 |
$tag_name = sanitize_text_field(str_replace("simpletagand", "&", $tag_name)); |
| 196 |
$result_term = term_exists( $tag_name, 'post_tag', 0 ); |
| 197 |
if ( empty( $result_term ) ) { |
| 198 |
$result_term = wp_insert_term( |
| 199 |
$tag_name, |
| 200 |
'post_tag' |
| 201 |
); |
| 202 |
|
| 203 |
if ( ! is_wp_error( $result_term ) ) { |
| 204 |
$term_id = (int) $result_term['term_id']; |
| 205 |
} |
| 206 |
} else { |
| 207 |
$term_id = (int) $result_term['term_id']; |
| 208 |
} |
| 209 |
|
| 210 |
wp_send_json_success( [ 'term_id' => $term_id ] ); |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Test if current URL is not a DEV environnement |
| 215 |
* |
| 216 |
* Copy from monsterinsights_is_dev_url(), thanks ! |
| 217 |
* |
| 218 |
* @param string $url |
| 219 |
* |
| 220 |
* @return bool |
| 221 |
*/ |
| 222 |
private static function is_dev_url( $url = '' ) { |
| 223 |
$is_local_url = false; |
| 224 |
|
| 225 |
// Trim it up |
| 226 |
$url = strtolower( trim( $url ) ); |
| 227 |
// Need to get the host...so let's add the scheme so we can use parse_url |
| 228 |
if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) { |
| 229 |
$url = 'http://' . $url; |
| 230 |
} |
| 231 |
|
| 232 |
$url_parts = wp_parse_url( $url ); |
| 233 |
$host = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false; |
| 234 |
if ( ! empty( $url ) && ! empty( $host ) ) { |
| 235 |
if ( false !== ip2long( $host ) ) { |
| 236 |
if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) { |
| 237 |
$is_local_url = true; |
| 238 |
} |
| 239 |
} elseif ( 'localhost' === $host ) { |
| 240 |
$is_local_url = true; |
| 241 |
} |
| 242 |
|
| 243 |
$tlds_to_check = array( '.local', ':8888', ':8080', ':8081', '.invalid', '.example', '.test' ); |
| 244 |
foreach ( $tlds_to_check as $tld ) { |
| 245 |
if ( false !== strpos( $host, $tld ) ) { |
| 246 |
$is_local_url = true; |
| 247 |
break; |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
if ( substr_count( $host, '.' ) > 1 ) { |
| 252 |
$subdomains_to_check = array( 'dev.', '*.staging.', 'beta.', 'test.' ); |
| 253 |
foreach ( $subdomains_to_check as $subdomain ) { |
| 254 |
$subdomain = str_replace( '.', '(.)', $subdomain ); |
| 255 |
$subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain ); |
| 256 |
if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) { |
| 257 |
$is_local_url = true; |
| 258 |
break; |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
return $is_local_url; |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Init taxonomy class variable, load this action after all actions on init ! |
| 269 |
* Make a public static function for call it from children class... |
| 270 |
* |
| 271 |
* @return void |
| 272 |
* @author WebFactory Ltd |
| 273 |
*/ |
| 274 |
public static function register_taxonomy() { |
| 275 |
add_action( 'init', array( __CLASS__, 'init' ), 99999999 ); |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Put in var class the current taxonomy choose by the user |
| 280 |
* |
| 281 |
* @return void |
| 282 |
* @author WebFactory Ltd |
| 283 |
*/ |
| 284 |
public static function init() { |
| 285 |
self::$taxo_name = esc_html__( 'Post tags', 'simple-tags' ); |
| 286 |
self::$post_type_name = esc_html__( 'Posts', 'simple-tags' ); |
| 287 |
|
| 288 |
// Custom CPT ? |
| 289 |
if ( isset( $_GET['cpt'] ) && ! empty( $_GET['cpt'] ) && post_type_exists( sanitize_text_field($_GET['cpt']) ) ) { |
| 290 |
$cpt = get_post_type_object( sanitize_text_field($_GET['cpt']) ); |
| 291 |
self::$post_type = $cpt->name; |
| 292 |
self::$post_type_name = $cpt->labels->name; |
| 293 |
} |
| 294 |
|
| 295 |
// Get compatible taxo for current post type |
| 296 |
$compatible_taxonomies = get_object_taxonomies( self::$post_type ); |
| 297 |
|
| 298 |
// Custom taxo ? |
| 299 |
if ( isset( $_GET['taxo'] ) && ! empty( $_GET['taxo'] ) && taxonomy_exists( sanitize_text_field($_GET['taxo']) ) ) { |
| 300 |
$taxo = get_taxonomy( sanitize_text_field($_GET['taxo']) ); |
| 301 |
|
| 302 |
// Taxo is compatible ? |
| 303 |
if ( in_array( $taxo->name, $compatible_taxonomies ) ) { |
| 304 |
self::$taxonomy = $taxo->name; |
| 305 |
self::$taxo_name = $taxo->labels->name; |
| 306 |
} else { |
| 307 |
unset( $taxo ); |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
// Default taxo from CPT... |
| 312 |
if ( ! isset( $taxo ) && is_array( $compatible_taxonomies ) && ! empty( $compatible_taxonomies ) ) { |
| 313 |
// Take post_tag before category |
| 314 |
if ( in_array( 'post_tag', $compatible_taxonomies, true ) ) { |
| 315 |
$taxo = get_taxonomy( 'post_tag' ); |
| 316 |
} else { |
| 317 |
$taxo = get_taxonomy( current( $compatible_taxonomies ) ); |
| 318 |
} |
| 319 |
|
| 320 |
self::$taxonomy = $taxo->name; |
| 321 |
self::$taxo_name = $taxo->labels->name; |
| 322 |
|
| 323 |
// TODO: Redirect for help user that see the URL... |
| 324 |
} elseif ( ! isset( $taxo ) ) { |
| 325 |
wp_die( esc_html__( 'This custom post type not have taxonomies.', 'simple-tags' ) ); |
| 326 |
} |
| 327 |
|
| 328 |
// Free memory |
| 329 |
unset( $cpt, $taxo ); |
| 330 |
} |
| 331 |
|
| 332 |
/** |
| 333 |
* Build HTML form for allow user to change taxonomy for the current page. |
| 334 |
* |
| 335 |
* @param string $page_value |
| 336 |
* |
| 337 |
* @return void |
| 338 |
* @author Olatechpro |
| 339 |
*/ |
| 340 |
public static function boxSelectorTaxonomy( $page_value = '' ) { |
| 341 |
echo '<div class="box-selector-taxonomy">' . PHP_EOL; |
| 342 |
|
| 343 |
echo '<div class="change-taxo">' . PHP_EOL; |
| 344 |
echo '<form action="" method="get">' . PHP_EOL; |
| 345 |
if ( ! empty( $page_value ) ) { |
| 346 |
echo '<input type="hidden" name="page" value="' . esc_attr($page_value) . '" />' . PHP_EOL; |
| 347 |
} |
| 348 |
$taxonomies = []; |
| 349 |
echo '<select name="cpt" id="cpt-select" class="st-cpt-select">' . PHP_EOL; |
| 350 |
foreach ( get_post_types( array( 'show_ui' => true ), 'objects' ) as $post_type ) { |
| 351 |
$taxonomies_children = get_object_taxonomies( $post_type->name ); |
| 352 |
if ( empty( $taxonomies_children ) ) { |
| 353 |
continue; |
| 354 |
} |
| 355 |
$taxonomies[$post_type->name] = $taxonomies_children; |
| 356 |
echo '<option ' . selected( $post_type->name, self::$post_type, false ) . ' value="' . esc_attr( $post_type->name ) . '">' . esc_html( $post_type->labels->name ) . '</option>' . PHP_EOL; |
| 357 |
} |
| 358 |
echo '</select>' . PHP_EOL; |
| 359 |
|
| 360 |
echo '<select name="taxo" id="taxonomy-select" class="st-taxonomy-select">' . PHP_EOL; |
| 361 |
foreach ( $taxonomies as $parent_post => $taxonomy ) { |
| 362 |
if ( count($taxonomy) > 0){ |
| 363 |
foreach($taxonomy as $tax_name){ |
| 364 |
$taxonomy = get_taxonomy( $tax_name ); |
| 365 |
if ( false === (bool) $taxonomy->show_ui ) { |
| 366 |
continue; |
| 367 |
} |
| 368 |
|
| 369 |
if( self::$post_type == $parent_post){ |
| 370 |
$class = ""; |
| 371 |
}else{ |
| 372 |
$class="st-hide-content"; |
| 373 |
} |
| 374 |
|
| 375 |
echo '<option ' . selected( $tax_name, self::$taxonomy, false ) . ' value="' . esc_attr( $tax_name ) . '" data-post="'. esc_attr($parent_post) .'" class="'. esc_attr($class) .'">' . esc_html( $taxonomy->labels->name ) . '</option>' . PHP_EOL; |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
echo '</select>' . PHP_EOL; |
| 380 |
|
| 381 |
echo '<input type="submit" class="button" id="submit-change-taxo" value="' . esc_attr__( 'Change selection', 'simple-tags' ) . '" />' . PHP_EOL; |
| 382 |
echo '</form>' . PHP_EOL; |
| 383 |
echo '</div>' . PHP_EOL; |
| 384 |
echo '</div>' . PHP_EOL; |
| 385 |
|
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* Init somes JS and CSS need for TaxoPress. |
| 390 |
* |
| 391 |
* @return void |
| 392 |
* @author WebFactory Ltd |
| 393 |
*/ |
| 394 |
public static function admin_enqueue_scripts() { |
| 395 |
global $pagenow; |
| 396 |
|
| 397 |
|
| 398 |
do_action('taxopress_admin_class_before_assets_register'); |
| 399 |
|
| 400 |
//color picker style |
| 401 |
wp_enqueue_style( 'wp-color-picker' ); |
| 402 |
|
| 403 |
// Helper TaxoPress |
| 404 |
wp_register_script( 'st-helper-add-tags', STAGS_URL . '/assets/js/helper-add-tags.js', array( 'jquery' ), STAGS_VERSION ); |
| 405 |
wp_register_script( 'st-helper-options', STAGS_URL . '/assets/js/helper-options.js', array( 'jquery', 'wp-color-picker' ), STAGS_VERSION ); |
| 406 |
|
| 407 |
// Register CSS |
| 408 |
wp_register_style( 'st-admin', STAGS_URL . '/assets/css/admin.css', array(), STAGS_VERSION, 'all' ); |
| 409 |
|
| 410 |
//Register and enqueue admin js |
| 411 |
wp_register_script( 'st-admin-js', STAGS_URL . '/assets/js/admin.js', array( 'jquery' ), STAGS_VERSION ); |
| 412 |
wp_enqueue_script( 'st-admin-js' ); |
| 413 |
//localize script |
| 414 |
wp_localize_script( 'st-admin-js', 'st_admin_localize', [ |
| 415 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 416 |
'select_valid'=> esc_html__( 'Please select a valid', 'simple-tags' ), |
| 417 |
'check_nonce' => wp_create_nonce('st-admin-js'), |
| 418 |
]); |
| 419 |
|
| 420 |
|
| 421 |
//Register remodal assets |
| 422 |
wp_register_script( 'st-remodal-js', STAGS_URL . '/assets/js/remodal.min.js', array( 'jquery' ), STAGS_VERSION ); |
| 423 |
wp_register_style( 'st-remodal-css', STAGS_URL . '/assets/css/remodal.css', array(), STAGS_VERSION, 'all' ); |
| 424 |
wp_register_style( 'st-remodal-default-theme-css', STAGS_URL . '/assets/css/remodal-default-theme.css', array(), STAGS_VERSION, 'all' ); |
| 425 |
|
| 426 |
// Register location |
| 427 |
$wp_post_pages = array( 'post.php', 'post-new.php' ); |
| 428 |
$wp_page_pages = array( 'page.php', 'page-new.php' ); |
| 429 |
|
| 430 |
$taxopress_pages = taxopress_admin_pages(); |
| 431 |
|
| 432 |
// Common Helper for Post, Page and Plugin Page |
| 433 |
if ( |
| 434 |
in_array( $pagenow, $wp_post_pages ) || |
| 435 |
( in_array( $pagenow, $wp_page_pages ) && is_page_have_tags() ) || |
| 436 |
( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages ) ) |
| 437 |
) { |
| 438 |
wp_enqueue_script( 'st-remodal-js' ); |
| 439 |
wp_enqueue_style( 'st-remodal-css' ); |
| 440 |
wp_enqueue_style( 'st-remodal-default-theme-css' ); |
| 441 |
wp_enqueue_style( 'st-admin' ); |
| 442 |
|
| 443 |
do_action('taxopress_admin_class_after_styles_enqueue'); |
| 444 |
} |
| 445 |
|
| 446 |
// add jQuery tabs for options page. Use jQuery UI Tabs from WP |
| 447 |
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array('st_options','st_terms_display') ) ) { |
| 448 |
wp_enqueue_script( 'jquery-ui-tabs' ); |
| 449 |
wp_enqueue_script( 'st-helper-options' ); |
| 450 |
} |
| 451 |
|
| 452 |
do_action('taxopress_admin_class_after_assets_enqueue'); |
| 453 |
} |
| 454 |
|
| 455 |
/** |
| 456 |
* Register log post type. |
| 457 |
* |
| 458 |
* @return void |
| 459 |
* @author olatechpro |
| 460 |
*/ |
| 461 |
public static function taxopress_log_post_type() { |
| 462 |
|
| 463 |
// set up labels |
| 464 |
$labels = array( |
| 465 |
'name' => __('TaxoPress Logs', 'simple-tags'), |
| 466 |
'singular_name' => __('TaxoPress Logs', 'simple-tags'), |
| 467 |
'search_items' => __('Search TaxoPress Logs', 'simple-tags'), |
| 468 |
'all_items' => __('TaxoPress Logs', 'simple-tags'), |
| 469 |
'edit_item' => __('Edit TaxoPress Logs', 'simple-tags'), |
| 470 |
'update_item' => __('Update TaxoPress Logs', 'simple-tags'), |
| 471 |
'add_new_item' => __('Add New TaxoPress Logs', 'simple-tags'), |
| 472 |
'new_item_name' => __('New TaxoPress Logs', 'simple-tags'), |
| 473 |
'menu_name' => __('TaxoPress Logs', 'simple-tags') |
| 474 |
); |
| 475 |
|
| 476 |
register_post_type('taxopress_logs', array( |
| 477 |
'labels' => $labels, |
| 478 |
'public' => false, |
| 479 |
'show_ui' => false, |
| 480 |
'capability_type' => 'post', |
| 481 |
'hierarchical' => false, |
| 482 |
'rewrite' => array('slug' => 'taxopress_logs'), |
| 483 |
'query_var' => false, |
| 484 |
'show_in_nav_menus' => false, |
| 485 |
'menu_icon' => 'dashicons-editor-justify', |
| 486 |
'supports' => array( |
| 487 |
'title', |
| 488 |
'editor', |
| 489 |
'author', |
| 490 |
), |
| 491 |
)); |
| 492 |
} |
| 493 |
|
| 494 |
/** |
| 495 |
* Add settings page on WordPress admin menu |
| 496 |
* |
| 497 |
* @return void |
| 498 |
* @author WebFactory Ltd |
| 499 |
*/ |
| 500 |
public static function admin_menu() { |
| 501 |
self::$admin_url = admin_url( 'admin.php?page=' . self::MENU_SLUG ); |
| 502 |
|
| 503 |
add_menu_page( |
| 504 |
__( 'TaxoPress: Options', 'simple-tags' ), |
| 505 |
__( 'TaxoPress', 'simple-tags' ), |
| 506 |
'admin_simple_tags', |
| 507 |
self::MENU_SLUG, |
| 508 |
array( |
| 509 |
__CLASS__, |
| 510 |
'page_options', |
| 511 |
), |
| 512 |
'dashicons-tag', |
| 513 |
69.999 |
| 514 |
); |
| 515 |
add_submenu_page( |
| 516 |
self::MENU_SLUG, |
| 517 |
__( 'TaxoPress: Options', 'simple-tags' ), |
| 518 |
__( 'Settings', 'simple-tags' ), |
| 519 |
'admin_simple_tags', |
| 520 |
self::MENU_SLUG, |
| 521 |
array( |
| 522 |
__CLASS__, |
| 523 |
'page_options', |
| 524 |
) |
| 525 |
); |
| 526 |
} |
| 527 |
|
| 528 |
/** |
| 529 |
* Build HTML for page options, manage also save/reset settings |
| 530 |
* |
| 531 |
* @return void |
| 532 |
* @author WebFactory Ltd |
| 533 |
*/ |
| 534 |
public static function page_options() { |
| 535 |
// Get options |
| 536 |
$options = SimpleTags_Plugin::get_option(); |
| 537 |
|
| 538 |
if(current_user_can('admin_simple_tags')){ |
| 539 |
// Update or reset options |
| 540 |
if ( isset( $_POST['updateoptions'] ) ) { |
| 541 |
check_admin_referer( 'updateresetoptions-simpletags' ); |
| 542 |
|
| 543 |
foreach ( (array) $options as $key => $value ) { |
| 544 |
$newval = ( isset( $_POST[ $key ] ) ) ? stripslashes( sanitize_text_field($_POST[ $key ]) ) : '0'; |
| 545 |
if ( $newval != $value ) { |
| 546 |
$options[ $key ] = $newval; |
| 547 |
} |
| 548 |
} |
| 549 |
SimpleTags_Plugin::set_option( $options ); |
| 550 |
|
| 551 |
do_action( 'simpletags_settings_save_general_end' ); |
| 552 |
|
| 553 |
add_settings_error( __CLASS__, __CLASS__, esc_html__( 'Options saved', 'simple-tags' ), 'updated' ); |
| 554 |
} elseif ( isset( $_POST['reset_options'] ) ) { |
| 555 |
check_admin_referer( 'updateresetoptions-simpletags' ); |
| 556 |
|
| 557 |
SimpleTags_Plugin::set_default_option(); |
| 558 |
|
| 559 |
add_settings_error( __CLASS__, __CLASS__, esc_html__( 'TaxoPress options resetted to default options!', 'simple-tags' ), 'updated' ); |
| 560 |
} |
| 561 |
|
| 562 |
} |
| 563 |
|
| 564 |
settings_errors( __CLASS__ ); |
| 565 |
include STAGS_DIR . '/views/admin/page-settings.php'; |
| 566 |
} |
| 567 |
|
| 568 |
/** |
| 569 |
* Get terms for a post, format terms for input and autocomplete usage |
| 570 |
* |
| 571 |
* @param string $taxonomy |
| 572 |
* @param integer $post_id |
| 573 |
* |
| 574 |
* @return string |
| 575 |
* @author WebFactory Ltd |
| 576 |
*/ |
| 577 |
public static function getTermsToEdit( $taxonomy = 'post_tag', $post_id = 0 ) { |
| 578 |
$post_id = (int) $post_id; |
| 579 |
if ( ! $post_id ) { |
| 580 |
return ''; |
| 581 |
} |
| 582 |
|
| 583 |
$terms = wp_get_post_terms( $post_id, $taxonomy, array( 'fields' => 'names' ) ); |
| 584 |
if ( empty( $terms ) || is_wp_error( $terms ) ) { |
| 585 |
return ''; |
| 586 |
} |
| 587 |
|
| 588 |
$terms = array_unique( $terms ); // Remove duplicate |
| 589 |
$terms = join( ', ', $terms ); |
| 590 |
$terms = esc_attr( $terms ); |
| 591 |
$terms = apply_filters( 'tags_to_edit', $terms ); |
| 592 |
|
| 593 |
return $terms; |
| 594 |
} |
| 595 |
|
| 596 |
/** |
| 597 |
* Default content for meta box of TaxoPress |
| 598 |
* |
| 599 |
* @return string |
| 600 |
* @author WebFactory Ltd |
| 601 |
*/ |
| 602 |
public static function getDefaultContentBox() { |
| 603 |
if ( (int) wp_count_terms( 'post_tag', array( 'hide_empty' => false ) ) == 0 ) { // TODO: Custom taxonomy |
| 604 |
return esc_html__( 'This feature requires at least 1 tag to work. Begin by adding tags!', 'simple-tags' ); |
| 605 |
} else { |
| 606 |
return esc_html__( 'This feature works only with activated JavaScript. Activate it in your Web browser so you can!', 'simple-tags' ); |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
/** |
| 611 |
* A short public static function for display the same copyright on all admin pages |
| 612 |
* |
| 613 |
* @return void |
| 614 |
* @author WebFactory Ltd |
| 615 |
*/ |
| 616 |
public static function printAdminFooter() { |
| 617 |
/* ?> |
| 618 |
<p class="footer_st"><?php printf( __( 'Thanks for using TaxoPress | <a href="https://taxopress.com/">TaxoPress.com</a> | Version %s', 'simple-tags' ), STAGS_VERSION ); ?></p> |
| 619 |
<?php */ |
| 620 |
} |
| 621 |
|
| 622 |
/** |
| 623 |
* A short public static function for display the same copyright on all taxopress admin pages |
| 624 |
* |
| 625 |
* @return void |
| 626 |
* @author Olatechpro |
| 627 |
*/ |
| 628 |
public static function taxopress_admin_footer() { |
| 629 |
|
| 630 |
$taxopress_pages = taxopress_admin_pages(); |
| 631 |
|
| 632 |
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages )) { |
| 633 |
?> |
| 634 |
<p class="footer_st"> |
| 635 |
<?php |
| 636 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 637 |
printf( __( 'Thanks for using TaxoPress | %1sTaxoPress.com%2s | Version %3s', 'simple-tags' ), '<a href="https://taxopress.com/">', '</a>', esc_html(STAGS_VERSION) ); ?> |
| 638 |
</p> |
| 639 |
<?php |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
/** |
| 644 |
* Ouput formatted options |
| 645 |
* |
| 646 |
* @param array $option_data |
| 647 |
* |
| 648 |
* @return string |
| 649 |
* @author WebFactory Ltd |
| 650 |
*/ |
| 651 |
public static function print_options( $option_data ) { |
| 652 |
// Get options |
| 653 |
$option_actual = SimpleTags_Plugin::get_option(); |
| 654 |
|
| 655 |
// Generate output |
| 656 |
$output = ''; |
| 657 |
foreach ( $option_data as $section => $options ) { |
| 658 |
$colspan = count( $options ) > 1 ? 'colspan="2"' : ''; |
| 659 |
$desc_html_tag = 'div'; |
| 660 |
|
| 661 |
if($section === 'legacy'){ |
| 662 |
$table_sub_tab = '<div class="st-legacy-subtab"> |
| 663 |
<span class="active" data-content=".legacy-tag-cloud-content">Tag Cloud</span> | |
| 664 |
<span data-content=".legacy-post-tags-content">Tags for Current Post</span> | |
| 665 |
<span data-content=".legacy-related-posts-content">Related Posts</span> | |
| 666 |
<span data-content=".legacy-auto-link-content">Auto link</span> |
| 667 |
</div>' . PHP_EOL; |
| 668 |
}else{ |
| 669 |
$table_sub_tab = ''; |
| 670 |
} |
| 671 |
|
| 672 |
$output .= '<div class="group" id="' . sanitize_title( $section ) . '">' . PHP_EOL; |
| 673 |
$output .= $table_sub_tab; |
| 674 |
$output .= '<fieldset class="options">' . PHP_EOL; |
| 675 |
$output .= '<legend>' . self::getNiceTitleOptions( $section ) . '</legend>' . PHP_EOL; |
| 676 |
$output .= '<table class="form-table">' . PHP_EOL; |
| 677 |
foreach ( (array) $options as $option ) { |
| 678 |
|
| 679 |
$class = ''; |
| 680 |
if($section === 'legacy'){ |
| 681 |
$class = $option[5]; |
| 682 |
} |
| 683 |
|
| 684 |
// Helper |
| 685 |
if ( $option[2] == 'helper' ) { |
| 686 |
$output .= '<tr style="vertical-align: middle;" class="'.$class.'"><td class="helper" ' . $colspan . '>' . stripslashes( $option[4] ) . '</td></tr>' . PHP_EOL; |
| 687 |
continue; |
| 688 |
} |
| 689 |
|
| 690 |
// Fix notices |
| 691 |
if ( ! isset( $option_actual[ $option[0] ] ) ) { |
| 692 |
$option_actual[ $option[0] ] = ''; |
| 693 |
} |
| 694 |
|
| 695 |
$input_type = ''; |
| 696 |
switch ( $option[2] ) { |
| 697 |
case 'radio': |
| 698 |
$input_type = array(); |
| 699 |
foreach ( $option[3] as $value => $text ) { |
| 700 |
$input_type[] = '<label><input type="radio" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $value ) . '" ' . checked( $value, $option_actual[ $option[0] ], false ) . ' /> ' . $text . '</label>' . PHP_EOL; |
| 701 |
} |
| 702 |
$input_type = implode( '<br />', $input_type ); |
| 703 |
break; |
| 704 |
|
| 705 |
case 'checkbox': |
| 706 |
$desc_html_tag = 'span'; |
| 707 |
$input_type = '<input type="checkbox" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option[3] ) . '" ' . ( ( $option_actual[ $option[0] ] ) ? 'checked="checked"' : '' ) . ' />' . PHP_EOL; |
| 708 |
break; |
| 709 |
|
| 710 |
case 'dropdown': |
| 711 |
$selopts = explode( '/', $option[3] ); |
| 712 |
$seldata = ''; |
| 713 |
foreach ( (array) $selopts as $sel ) { |
| 714 |
$seldata .= '<option value="' . esc_attr( $sel ) . '" ' . ( ( isset( $option_actual[ $option[0] ] ) && $option_actual[ $option[0] ] == $sel ) ? 'selected="selected"' : '' ) . ' >' . ucfirst( $sel ) . '</option>' . PHP_EOL; |
| 715 |
} |
| 716 |
$input_type = '<select id="' . $option[0] . '" name="' . $option[0] . '">' . $seldata . '</select>' . PHP_EOL; |
| 717 |
break; |
| 718 |
|
| 719 |
case 'text-color': |
| 720 |
$input_type = '<input type="text" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="text-color ' . $option[3] . '" />' . PHP_EOL; |
| 721 |
break; |
| 722 |
|
| 723 |
case 'text': |
| 724 |
$input_type = '<input type="text" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="' . $option[3] . '" />' . PHP_EOL; |
| 725 |
break; |
| 726 |
|
| 727 |
case 'number': |
| 728 |
$input_type = '<input type="number" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="' . $option[3] . '" />' . PHP_EOL; |
| 729 |
break; |
| 730 |
} |
| 731 |
|
| 732 |
if( is_array($option[2]) ){ |
| 733 |
$input_type = '<input type="'.$option[2]["type"].'" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr( $option_actual[ $option[0] ] ) . '" class="' . $option[3] . '" '.$option[2]["attr"].' />' . PHP_EOL; |
| 734 |
} |
| 735 |
|
| 736 |
// Additional Information |
| 737 |
$extra = ''; |
| 738 |
if ( ! empty( $option[4] ) ) { |
| 739 |
$extra = '<' . $desc_html_tag . ' class="stpexplan">' . __( $option[4] ) . '</' . $desc_html_tag . '>' . PHP_EOL; |
| 740 |
} |
| 741 |
|
| 742 |
// Output |
| 743 |
$output .= '<tr style="vertical-align: top;" class="'.$class.'"><th scope="row"><label for="' . $option[0] . '">' . __( $option[1] ) . '</label></th><td>' . $input_type . ' ' . $extra . '</td></tr>' . PHP_EOL; |
| 744 |
} |
| 745 |
$output .= '</table>' . PHP_EOL; |
| 746 |
$output .= '</fieldset>' . PHP_EOL; |
| 747 |
$output .= '</div>' . PHP_EOL; |
| 748 |
} |
| 749 |
|
| 750 |
return $output; |
| 751 |
} |
| 752 |
|
| 753 |
/** |
| 754 |
* Get nice title for tabs title option |
| 755 |
* |
| 756 |
* @param string $id |
| 757 |
* |
| 758 |
* @return string |
| 759 |
*/ |
| 760 |
public static function getNiceTitleOptions( $id = '' ) { |
| 761 |
switch ( $id ) { |
| 762 |
case 'administration': |
| 763 |
return esc_html__( 'Administration', 'simple-tags' ); |
| 764 |
case 'auto-links': |
| 765 |
return esc_html__( 'Auto link', 'simple-tags' ); |
| 766 |
case 'features': |
| 767 |
return esc_html__( 'Features', 'simple-tags' ); |
| 768 |
case 'embeddedtags': |
| 769 |
return esc_html__( 'Embedded Tags', 'simple-tags' ); |
| 770 |
case 'tagspost': |
| 771 |
return esc_html__( 'Tags for Current Post', 'simple-tags' ); |
| 772 |
case 'relatedposts': |
| 773 |
return esc_html__( 'Related Posts', 'simple-tags' ); |
| 774 |
case 'legacy': |
| 775 |
return esc_html__( 'Legacy', 'simple-tags' ); |
| 776 |
} |
| 777 |
|
| 778 |
return ''; |
| 779 |
} |
| 780 |
|
| 781 |
/** |
| 782 |
* This method allow to check if the DB is up to date, and if a upgrade is need for options |
| 783 |
* TODO, useful or delete ? |
| 784 |
* |
| 785 |
* @return void |
| 786 |
* @author WebFactory Ltd |
| 787 |
*/ |
| 788 |
public static function upgrade() { |
| 789 |
// Get current version number |
| 790 |
$current_version = get_option( STAGS_OPTIONS_NAME . '-version' ); |
| 791 |
|
| 792 |
// Upgrade needed ? |
| 793 |
if ( $current_version == false || version_compare( $current_version, STAGS_VERSION, '<' ) ) { |
| 794 |
$current_options = get_option( STAGS_OPTIONS_NAME ); |
| 795 |
$default_options = (array) include( STAGS_DIR . '/inc/helper.options.default.php' ); |
| 796 |
|
| 797 |
// Add new options |
| 798 |
foreach ( $default_options as $key => $default_value ) { |
| 799 |
if ( ! isset( $current_options[ $key ] ) ) { |
| 800 |
$current_options[ $key ] = $default_value; |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
// Remove old options |
| 805 |
foreach ( $current_options as $key => $current_value ) { |
| 806 |
if ( ! isset( $default_options[ $key ] ) ) { |
| 807 |
unset( $current_options[ $key ] ); |
| 808 |
} |
| 809 |
} |
| 810 |
|
| 811 |
update_option( STAGS_OPTIONS_NAME . '-version', STAGS_VERSION ); |
| 812 |
update_option( STAGS_OPTIONS_NAME, $current_options ); |
| 813 |
} |
| 814 |
} |
| 815 |
|
| 816 |
/** |
| 817 |
* Make a simple SQL query with some args for get terms for ajax display |
| 818 |
* |
| 819 |
* @param string $taxonomy |
| 820 |
* @param string $search |
| 821 |
* @param string $order_by |
| 822 |
* @param string $order |
| 823 |
* |
| 824 |
* @return array |
| 825 |
* @author WebFactory Ltd |
| 826 |
*/ |
| 827 |
public static function getTermsForAjax( $taxonomy = 'post_tag', $search = '', $order_by = 'name', $order = 'ASC', $limit = '' ) { |
| 828 |
global $wpdb; |
| 829 |
|
| 830 |
if ( ! empty( $search ) ) { |
| 831 |
return $wpdb->get_results( $wpdb->prepare( " |
| 832 |
SELECT DISTINCT t.name, t.term_id |
| 833 |
FROM {$wpdb->terms} AS t |
| 834 |
INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id |
| 835 |
WHERE tt.taxonomy = %s |
| 836 |
AND t.name LIKE %s |
| 837 |
ORDER BY $order_by $order $limit |
| 838 |
", $taxonomy, '%' . $wpdb->esc_like($search) . '%' ) ); |
| 839 |
} else { |
| 840 |
return $wpdb->get_results( $wpdb->prepare( " |
| 841 |
SELECT DISTINCT t.name, t.term_id |
| 842 |
FROM {$wpdb->terms} AS t |
| 843 |
INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id |
| 844 |
WHERE tt.taxonomy = %s |
| 845 |
ORDER BY $order_by $order $limit |
| 846 |
", $taxonomy ) ); |
| 847 |
} |
| 848 |
} |
| 849 |
} |
| 850 |
|