$term_id ] );
}
/**
* Test if current URL is not a DEV environnement
*
* Copy from monsterinsights_is_dev_url(), thanks !
*
* @param string $url
*
* @return bool
*/
private static function is_dev_url( $url = '' ) {
$is_local_url = false;
// Trim it up
$url = strtolower( trim( $url ) );
// Need to get the host...so let's add the scheme so we can use parse_url
if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) {
$url = 'http://' . $url;
}
$url_parts = wp_parse_url( $url );
$host = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false;
if ( ! empty( $url ) && ! empty( $host ) ) {
if ( false !== ip2long( $host ) ) {
if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
$is_local_url = true;
}
} elseif ( 'localhost' === $host ) {
$is_local_url = true;
}
$tlds_to_check = array( '.local', ':8888', ':8080', ':8081', '.invalid', '.example', '.test' );
foreach ( $tlds_to_check as $tld ) {
if ( false !== strpos( $host, $tld ) ) {
$is_local_url = true;
break;
}
}
if ( substr_count( $host, '.' ) > 1 ) {
$subdomains_to_check = array( 'dev.', '*.staging.', 'beta.', 'test.' );
foreach ( $subdomains_to_check as $subdomain ) {
$subdomain = str_replace( '.', '(.)', $subdomain );
$subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain );
if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) {
$is_local_url = true;
break;
}
}
}
}
return $is_local_url;
}
/**
* Init taxonomy class variable, load this action after all actions on init !
* Make a public static function for call it from children class...
*
* @return void
* @author WebFactory Ltd
*/
public static function register_taxonomy() {
add_action( 'init', array( __CLASS__, 'init' ), 99999999 );
}
/**
* Put in var class the current taxonomy choose by the user
*
* @return void
* @author WebFactory Ltd
*/
public static function init() {
self::$taxo_name = esc_html__( 'Post tags', 'simple-tags' );
self::$post_type_name = esc_html__( 'Posts', 'simple-tags' );
// Custom CPT ?
if ( isset( $_GET['cpt'] ) && ! empty( $_GET['cpt'] ) && post_type_exists( sanitize_text_field($_GET['cpt']) ) ) {
$cpt = get_post_type_object( sanitize_text_field($_GET['cpt']) );
self::$post_type = $cpt->name;
self::$post_type_name = $cpt->labels->name;
}
// Get compatible taxo for current post type
$compatible_taxonomies = get_object_taxonomies( self::$post_type );
// Custom taxo ?
if ( isset( $_GET['taxo'] ) && ! empty( $_GET['taxo'] ) && taxonomy_exists( sanitize_text_field($_GET['taxo']) ) ) {
$taxo = get_taxonomy( sanitize_text_field($_GET['taxo']) );
// Taxo is compatible ?
if ( in_array( $taxo->name, $compatible_taxonomies ) ) {
self::$taxonomy = $taxo->name;
self::$taxo_name = $taxo->labels->name;
} else {
unset( $taxo );
}
}
// Default taxo from CPT...
if ( ! isset( $taxo ) && is_array( $compatible_taxonomies ) && ! empty( $compatible_taxonomies ) ) {
// Take post_tag before category
if ( in_array( 'post_tag', $compatible_taxonomies, true ) ) {
$taxo = get_taxonomy( 'post_tag' );
} else {
$taxo = get_taxonomy( current( $compatible_taxonomies ) );
}
self::$taxonomy = $taxo->name;
self::$taxo_name = $taxo->labels->name;
// TODO: Redirect for help user that see the URL...
} elseif ( ! isset( $taxo ) ) {
wp_die( esc_html__( 'This custom post type not have taxonomies.', 'simple-tags' ) );
}
// Free memory
unset( $cpt, $taxo );
}
/**
* Build HTML form for allow user to change taxonomy for the current page.
*
* @param string $page_value
*
* @return void
* @author Olatechpro
*/
public static function boxSelectorTaxonomy( $page_value = '' ) {
echo '
' . PHP_EOL;
echo '
' . PHP_EOL;
echo '' . PHP_EOL;
echo '
' . PHP_EOL;
echo '
' . PHP_EOL;
}
/**
* Init somes JS and CSS need for TaxoPress.
*
* @return void
* @author WebFactory Ltd
*/
public static function admin_enqueue_scripts() {
global $pagenow;
do_action('taxopress_admin_class_before_assets_register');
//color picker style
wp_enqueue_style( 'wp-color-picker' );
// Helper TaxoPress
wp_register_script( 'st-helper-add-tags', STAGS_URL . '/assets/js/helper-add-tags.js', array( 'jquery' ), STAGS_VERSION );
wp_register_script( 'st-helper-options', STAGS_URL . '/assets/js/helper-options.js', array( 'jquery', 'wp-color-picker' ), STAGS_VERSION );
// Register CSS
wp_register_style( 'st-admin', STAGS_URL . '/assets/css/admin.css', array(), STAGS_VERSION, 'all' );
//Register and enqueue admin js
wp_register_script( 'st-admin-js', STAGS_URL . '/assets/js/admin.js', array( 'jquery' ), STAGS_VERSION );
wp_enqueue_script( 'st-admin-js' );
//localize script
wp_localize_script( 'st-admin-js', 'st_admin_localize', [
'ajaxurl' => admin_url('admin-ajax.php'),
'select_valid'=> esc_html__( 'Please select a valid', 'simple-tags' ),
'check_nonce' => wp_create_nonce('st-admin-js'),
]);
//Register remodal assets
wp_register_script( 'st-remodal-js', STAGS_URL . '/assets/js/remodal.min.js', array( 'jquery' ), STAGS_VERSION );
wp_register_style( 'st-remodal-css', STAGS_URL . '/assets/css/remodal.css', array(), STAGS_VERSION, 'all' );
wp_register_style( 'st-remodal-default-theme-css', STAGS_URL . '/assets/css/remodal-default-theme.css', array(), STAGS_VERSION, 'all' );
// Register location
$wp_post_pages = array( 'post.php', 'post-new.php' );
$wp_page_pages = array( 'page.php', 'page-new.php' );
$taxopress_pages = taxopress_admin_pages();
// Common Helper for Post, Page and Plugin Page
if (
in_array( $pagenow, $wp_post_pages ) ||
( in_array( $pagenow, $wp_page_pages ) && is_page_have_tags() ) ||
( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages ) )
) {
wp_enqueue_script( 'st-remodal-js' );
wp_enqueue_style( 'st-remodal-css' );
wp_enqueue_style( 'st-remodal-default-theme-css' );
wp_enqueue_style( 'st-admin' );
do_action('taxopress_admin_class_after_styles_enqueue');
}
// add jQuery tabs for options page. Use jQuery UI Tabs from WP
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array('st_options','st_terms_display') ) ) {
wp_enqueue_script( 'jquery-ui-tabs' );
wp_enqueue_script( 'st-helper-options' );
}
do_action('taxopress_admin_class_after_assets_enqueue');
}
/**
* Register log post type.
*
* @return void
* @author olatechpro
*/
public static function taxopress_log_post_type() {
// set up labels
$labels = array(
'name' => __('TaxoPress Logs', 'simple-tags'),
'singular_name' => __('TaxoPress Logs', 'simple-tags'),
'search_items' => __('Search TaxoPress Logs', 'simple-tags'),
'all_items' => __('TaxoPress Logs', 'simple-tags'),
'edit_item' => __('Edit TaxoPress Logs', 'simple-tags'),
'update_item' => __('Update TaxoPress Logs', 'simple-tags'),
'add_new_item' => __('Add New TaxoPress Logs', 'simple-tags'),
'new_item_name' => __('New TaxoPress Logs', 'simple-tags'),
'menu_name' => __('TaxoPress Logs', 'simple-tags')
);
register_post_type('taxopress_logs', array(
'labels' => $labels,
'public' => false,
'show_ui' => false,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'taxopress_logs'),
'query_var' => false,
'show_in_nav_menus' => false,
'menu_icon' => 'dashicons-editor-justify',
'supports' => array(
'title',
'editor',
'author',
),
));
}
/**
* Add settings page on WordPress admin menu
*
* @return void
* @author WebFactory Ltd
*/
public static function admin_menu() {
self::$admin_url = admin_url( 'admin.php?page=' . self::MENU_SLUG );
add_menu_page(
__( 'TaxoPress: Options', 'simple-tags' ),
__( 'TaxoPress', 'simple-tags' ),
'admin_simple_tags',
self::MENU_SLUG,
array(
__CLASS__,
'page_options',
),
'dashicons-tag',
69
);
add_submenu_page(
self::MENU_SLUG,
__( 'TaxoPress: Options', 'simple-tags' ),
__( 'Settings', 'simple-tags' ),
'admin_simple_tags',
self::MENU_SLUG,
array(
__CLASS__,
'page_options',
)
);
}
/**
* Build HTML for page options, manage also save/reset settings
*
* @return void
* @author WebFactory Ltd
*/
public static function page_options() {
// Get options
$options = SimpleTags_Plugin::get_option();
if(current_user_can('admin_simple_tags')){
// Update or reset options
if ( isset( $_POST['updateoptions'] ) ) {
check_admin_referer( 'updateresetoptions-simpletags' );
foreach ( (array) $options as $key => $value ) {
$newval = ( isset( $_POST[ $key ] ) ) ? stripslashes( sanitize_text_field($_POST[ $key ]) ) : '0';
if ( $newval != $value ) {
$options[ $key ] = $newval;
}
}
SimpleTags_Plugin::set_option( $options );
do_action( 'simpletags_settings_save_general_end' );
add_settings_error( __CLASS__, __CLASS__, esc_html__( 'Options saved', 'simple-tags' ), 'updated' );
} elseif ( isset( $_POST['reset_options'] ) ) {
check_admin_referer( 'updateresetoptions-simpletags' );
SimpleTags_Plugin::set_default_option();
add_settings_error( __CLASS__, __CLASS__, esc_html__( 'TaxoPress options resetted to default options!', 'simple-tags' ), 'updated' );
}
}
settings_errors( __CLASS__ );
include STAGS_DIR . '/views/admin/page-settings.php';
}
/**
* Get terms for a post, format terms for input and autocomplete usage
*
* @param string $taxonomy
* @param integer $post_id
*
* @return string
* @author WebFactory Ltd
*/
public static function getTermsToEdit( $taxonomy = 'post_tag', $post_id = 0 ) {
$post_id = (int) $post_id;
if ( ! $post_id ) {
return '';
}
$terms = wp_get_post_terms( $post_id, $taxonomy, array( 'fields' => 'names' ) );
if ( empty( $terms ) || is_wp_error( $terms ) ) {
return '';
}
$terms = array_unique( $terms ); // Remove duplicate
$terms = join( ', ', $terms );
$terms = esc_attr( $terms );
$terms = apply_filters( 'tags_to_edit', $terms );
return $terms;
}
/**
* Default content for meta box of TaxoPress
*
* @return string
* @author WebFactory Ltd
*/
public static function getDefaultContentBox() {
if ( (int) wp_count_terms( 'post_tag', array( 'hide_empty' => false ) ) == 0 ) { // TODO: Custom taxonomy
return esc_html__( 'This feature requires at least 1 tag to work. Begin by adding tags!', 'simple-tags' );
} else {
return esc_html__( 'This feature works only with activated JavaScript. Activate it in your Web browser so you can!', 'simple-tags' );
}
}
/**
* A short public static function for display the same copyright on all admin pages
*
* @return void
* @author WebFactory Ltd
*/
public static function printAdminFooter() {
/* ?>
$options ) {
$colspan = count( $options ) > 1 ? 'colspan="2"' : '';
$desc_html_tag = 'div';
if($section === 'legacy'){
$table_sub_tab = '
Tag Cloud |
Tags for Current Post |
Related Posts |
Auto link
' . PHP_EOL;
}else{
$table_sub_tab = '';
}
$output .= '' . PHP_EOL;
$output .= $table_sub_tab;
$output .= '
' . PHP_EOL;
$output .= '
' . PHP_EOL;
}
return $output;
}
/**
* Get nice title for tabs title option
*
* @param string $id
*
* @return string
*/
public static function getNiceTitleOptions( $id = '' ) {
switch ( $id ) {
case 'administration':
return esc_html__( 'Administration', 'simple-tags' );
case 'auto-links':
return esc_html__( 'Auto link', 'simple-tags' );
case 'features':
return esc_html__( 'Features', 'simple-tags' );
case 'embeddedtags':
return esc_html__( 'Embedded Tags', 'simple-tags' );
case 'tagspost':
return esc_html__( 'Tags for Current Post', 'simple-tags' );
case 'relatedposts':
return esc_html__( 'Related Posts', 'simple-tags' );
case 'legacy':
return esc_html__( 'Legacy', 'simple-tags' );
}
return '';
}
/**
* This method allow to check if the DB is up to date, and if a upgrade is need for options
* TODO, useful or delete ?
*
* @return void
* @author WebFactory Ltd
*/
public static function upgrade() {
// Get current version number
$current_version = get_option( STAGS_OPTIONS_NAME . '-version' );
// Upgrade needed ?
if ( $current_version == false || version_compare( $current_version, STAGS_VERSION, '<' ) ) {
$current_options = get_option( STAGS_OPTIONS_NAME );
$default_options = (array) include( STAGS_DIR . '/inc/helper.options.default.php' );
// Add new options
foreach ( $default_options as $key => $default_value ) {
if ( ! isset( $current_options[ $key ] ) ) {
$current_options[ $key ] = $default_value;
}
}
// Remove old options
foreach ( $current_options as $key => $current_value ) {
if ( ! isset( $default_options[ $key ] ) ) {
unset( $current_options[ $key ] );
}
}
update_option( STAGS_OPTIONS_NAME . '-version', STAGS_VERSION );
update_option( STAGS_OPTIONS_NAME, $current_options );
}
}
/**
* Make a simple SQL query with some args for get terms for ajax display
*
* @param string $taxonomy
* @param string $search
* @param string $order_by
* @param string $order
*
* @return array
* @author WebFactory Ltd
*/
public static function getTermsForAjax( $taxonomy = 'post_tag', $search = '', $order_by = 'name', $order = 'ASC', $limit = '' ) {
global $wpdb;
if ( ! empty( $search ) ) {
return $wpdb->get_results( $wpdb->prepare( "
SELECT DISTINCT t.name, t.term_id
FROM {$wpdb->terms} AS t
INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = %s
AND t.name LIKE %s
ORDER BY $order_by $order $limit
", $taxonomy, '%' . $wpdb->esc_like($search) . '%' ) );
} else {
return $wpdb->get_results( $wpdb->prepare( "
SELECT DISTINCT t.name, t.term_id
FROM {$wpdb->terms} AS t
INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
WHERE tt.taxonomy = %s
ORDER BY $order_by $order $limit
", $taxonomy ) );
}
}
}