press_linked_terms, $taxopress_submenus);
}
// add settings as last item
if ($taxopress_settings) {
$taxopress_submenus = array_merge($taxopress_submenus, [$taxopress_settings]);
}
// upgrade to pro should be last item if exists
if ($taxopress_upgrade) {
$taxopress_submenus = array_merge($taxopress_submenus, [$taxopress_upgrade]);
}
//resort array
ksort($taxopress_submenus);
$submenu['st_options'] = $taxopress_submenus;
break;
}
}
}
function taxopress_add_at_menu_index($key_options, $new_menu, $existing_menus) {
foreach($key_options as $key_option) {
$index = array_search($key_option, array_column($existing_menus, 2));
if ($index !== false) {
$index++;//add it after
array_splice($existing_menus, $index, 0, [$new_menu]);
break;
}
}
// add as last if index is false;
if ($index === false) {
$existing_menus = array_merge($existing_menus, [$new_menu]);
}
return $existing_menus;
}
// Init TaxoPress
function init_simple_tags()
{
new SimpleTags_Client();
new SimpleTags_Client_TagCloud();
// Admin and XML-RPC
if (is_admin()) {
require STAGS_DIR . '/inc/class.admin.php';
new SimpleTags_Admin();
}
add_action('widgets_init', 'st_register_widget');
}
function taxopress_admin_pages()
{
$taxopress_pages = [
'st_dashboard',
'st_mass_terms',
'st_auto',
'st_options',
'st_manage',
'st_taxonomies',
'st_terms_display',
'st_post_tags',
'st_related_posts',
'st_autolinks',
'st_autoterms',
'st_terms',
'st_posts',
'st_taxopress_ai'
];
return apply_filters('taxopress_admin_pages', $taxopress_pages);
}
function is_taxopress_admin_page()
{
$taxopress_pages = taxopress_admin_pages();
$is_taxopress_page = false;
if (isset($_GET['page']) && in_array($_GET['page'], $taxopress_pages)) {
$is_taxopress_page = true;
}
return apply_filters('is_taxopress_admin_page', $is_taxopress_page);
}
function taxopress_starts_with($haystack, $needle)
{
$length = strlen($needle);
return substr($haystack, 0, $length) === $needle;
}
function taxopress_is_html($string)
{
return preg_match("/<[^<]+>/", $string, $m) != 0;
}
function taxopress_is_screen_main_page()
{
if (isset($_GET['action']) && $_GET['action'] === 'edit') {
return false;
}
if (isset($_GET['add']) && $_GET['add'] === 'new_item') {
return false;
}
if (isset($_GET['add']) && $_GET['add'] === 'taxonomy') {
return false;
}
return true;
}
function taxopress_format_class($class)
{
return esc_attr(ltrim($class, '.'));
}
function taxopress_add_class_to_format($xformat, $class)
{
$classes = $class;
$html = $xformat;
$patterns = array();
$replacements = array();
// matches where anchor has existing classes contained in single quotes
$patterns[0] = '/]*)class=\'([^\']*)\'([^>]*)>/';
$replacements[0] = '';
// matches where anchor has existing classes contained in double quotes
$patterns[1] = '/]*)class="([^"]*)"([^>]*)>/';
$replacements[1] = '';
// matches where anchor tag has no existing classes
$patterns[2] = '/]*class)([^>]*)>/';
$replacements[2] = '';
$html = preg_replace($patterns, $replacements, $html);
return $html;
}
function taxopress_change_to_strings($join)
{
if (is_array($join)) {
$join = join(", ", $join);
}
return $join;
}
function taxopress_change_to_array($array)
{
if (!is_array($array)) {
$array = preg_split("/\s*,\s*/", $array);
}
return $array;
}
function taxopress_html_character_and_entity($enity_code_as_key = false)
{
#Source https://dev.w3.org/html5/html-author/charref
$character_set = [
//'&' => '&',
'<' => '<',
'>' => '>',
' ' => ' ',
'!' => '!',
'"' => '"',
'#' => '#',
'$' => '$',
'%' => '%',
''' => ''',
'(' => '(',
')' => ')',
'* ' => '*',
'+' => '+',
',' => ',',
'.' => '.',
'/' => '/',
':' => ':',
';' => ';',
'=' => '=',
'?' => '?',
'@' => '@',
'[' => '[',
'\' => '\',
']' => ']',
'^' => '^',
'_' => '_',
'`' => '`',
'{' => '{',
'|' => '|',
'}' => '}',
'¡' => '¡',
'¢' => '¢',
'£' => '£',
'©' => '©',
'ª' => 'ª',
'«' => '«',
'®' => '®',
'°' => '°',
'±' => '±',
'²' => '²',
'³' => '³',
'´' => '´',
'¹' => '¹',
'º' => 'º',
'»' => '»',
'¼' => '¼',
'½' => '½',
'¾' => '¾',
'→' => '→',
'←' => '←',
'↑' => '↑',
'↓' => '↓',
'™' => '™',
'’' => '’',
'’' => '’',
'‘' => '‘',
'‚' => '‚',
'&' => 'taxopressamp',
];
if ($enity_code_as_key) {
$character_set = array_flip($character_set);
}
return $character_set;
}
/**
* Sanitize taxopress text field
*
* @param string $content
* @return string
*/
function taxopress_sanitize_text_field($content)
{
if (is_array($content)) {
return stripslashes_deep(array_map('taxopress_sanitize_text_field', $content));
}
$content = stripslashes_deep($content);
$content = wp_kses_post($content);
return $content;
}
/**
* Dashboard items
*
* @param mixed $current
*
* @return array
*/
function taxopress_dashboard_options()
{
$features = [];
$features['st_taxonomies'] = [
'label' => esc_html__('Taxonomies', 'simple-tags'),
'description' => esc_html__('This feature allows you to create new taxonomies and edit all the settings for each taxonomy.', 'simple-tags'),
'option_key' => 'active_taxonomies',
];
$features['st_terms'] = [
'label' => esc_html__('Terms', 'simple-tags'),
'description' => esc_html__('This feature allows you to search and edit all the terms on your site.', 'simple-tags'),
'option_key' => 'active_st_terms',
];
$features['st_posts'] = [
'label' => esc_html__('Posts', 'simple-tags'),
'description' => esc_html__('This feature allows you to search for terms and see all the posts attached to that term.', 'simple-tags'),
'option_key' => 'active_st_posts',
];
$features['st_terms_display'] = [
'label' => esc_html__('Terms Display', 'simple-tags'),
'description' => esc_html__('This feature allows you to create a customizable display of all the terms in one taxonomy.', 'simple-tags'),
'option_key' => 'active_terms_display',
];
$features['st_post_tags'] = [
'label' => esc_html__('Terms for Current Post', 'simple-tags'),
'description' => esc_html__('This feature allows you create a customizable display of all the terms assigned to the current post.', 'simple-tags'),
'option_key' => 'active_post_tags',
];
$features['st_related_posts'] = [
'label' => esc_html__('Related Posts', 'simple-tags'),
'description' => esc_html__('This feature creates a display of similar posts. If a post has the terms “WordPress” and “Website”, Related Posts will display other posts with those same terms.', 'simple-tags'),
'option_key' => 'active_related_posts_new',
];
$features['st_autolinks'] = [
'label' => esc_html__('Auto Links', 'simple-tags'),
'description' => esc_html__('This feature automatically adds links to your chosen terms. If you have a term called “WordPress”, Auto Links finds the word “WordPress” in your content and add links to the archive page for that term.', 'simple-tags'),
'option_key' => 'active_auto_links',
];
$features['st_autoterms'] = [
'label' => esc_html__('Auto Terms', 'simple-tags'),
'description' => esc_html__('Auto Terms can scan your content and automatically assign new and existing terms.', 'simple-tags'),
'option_key' => 'active_auto_terms',
];
$features['st_mass_terms'] = [
'label' => esc_html__('Mass Edit Terms', 'simple-tags'),
'description' => esc_html__('This feature allows you to quickly edit the terms attached to multiple posts at the same time.', 'simple-tags'),
'option_key' => 'active_mass_edit',
];
$features['st_manage'] = [
'label' => esc_html__('Manage Terms', 'simple-tags'),
'description' => esc_html__('This feature allows you to add, rename, merge, and delete terms for any taxonomy.', 'simple-tags'),
'option_key' => 'active_manage',
];
$features = apply_filters('taxopress_dashboard_features', $features);
return $features;
}
/**
* Check if current version of taxopress is
* pro version
*
* @return void
*/
function taxopress_is_pro_version()
{
return defined('TAXOPRESS_PRO_VERSION');
}
/**
* Case insensitive in_array function
*
* @param string $needle
* @param array $haystack
* @return bool
*/
function taxopress_in_array_i($needle, $haystack) {
return in_array(strtolower($needle), array_map('strtolower', $haystack));
}
/**
* Check if synonyms is enabled
*
* @return bool
*/
function taxopress_is_synonyms_enabled() {
return ((int) SimpleTags_Plugin::get_option_value('active_features_synonyms') === 1);
}
/**
* Check if linked term is enabled
*
* @return bool
*/
function taxopress_is_linked_terms_enabled() {
return ((int) SimpleTags_Plugin::get_option_value('active_features_linked_terms') === 1);
}
/**
* Get term synonyms
*
* @param string|integer $term
* @param string $taxonomy
* @return array $term_synonyms
*/
function taxopress_get_term_synonyms($term, $taxonomy = '') {
$term_synonyms = [];
if (!taxopress_is_synonyms_enabled()) {
// simply return empty array if feature is disabled
return $term_synonyms;
}
if ((int)$term > 0) {
$term_synonyms = (array) get_term_meta($term, '_taxopress_term_synonyms', true);
} else {
$terms_object = get_term_by('name', esc_attr($term), $taxonomy);
if (is_object($terms_object) && isset($terms_object->term_id)) {
$term_synonyms = (array) get_term_meta($terms_object->term_id, '_taxopress_term_synonyms', true);
}
}
$term_synonyms = array_filter($term_synonyms);
return $term_synonyms;
}
/**
* Get linked terms
*
* @param string|integer $term
* @param string $taxonomy
* @param string $taxonomy
* @return array $term_object
*/
function taxopress_get_linked_terms($term_id, $taxonomy = '', $term_object = false) {
global $wpdb;
$linked_terms = [];
if (!taxopress_is_linked_terms_enabled()) {
// simply return empty array if feature is disabled
return $linked_terms;
}
$table_name = $wpdb->prefix . 'taxopress_linked_terms';
$query = $wpdb->prepare(
"SELECT * FROM $table_name WHERE term_id = %d OR linked_term_id = %d",
$term_id,
$term_id
);
$linked_terms = $wpdb->get_results($query);
return $linked_terms;
}
/**
* Find out which is a linked term in our data
*/
function taxopress_get_linked_term_data($linked_term_option, $term_id) {
if ((int)$linked_term_option->linked_term_id === (int)$term_id) {
$taxopress_linked_term_id = $linked_term_option->term_id;
$taxopress_linked_term_name = $linked_term_option->term_name;
$taxopress_linked_term_taxonomy = $linked_term_option->term_taxonomy;
} else {
$taxopress_linked_term_id = $linked_term_option->linked_term_id;
$taxopress_linked_term_name = $linked_term_option->linked_term_name;
$taxopress_linked_term_taxonomy = $linked_term_option->linked_term_taxonomy;
}
$linked_term = (object) [
'term_id' => $taxopress_linked_term_id,
'term_name' => $taxopress_linked_term_name,
'term_taxonomy' => $taxopress_linked_term_taxonomy
];
return $linked_term;
}
/**
* Add linked terms and it synonyms to list
*
* @param array $lists
* @param string|integer $term
* @param string $lists
* @param bool $linked
* @param bool $named_term
*
* @return array $term_object
*/
function taxopress_add_linked_term_options($lists, $term, $taxonomy, $linked = false, $named_term = false) {
if (!taxopress_is_linked_terms_enabled()) {
// simply return $lists if feature is disabled
return $lists;
}
/**
* Linked term is no longer in option and it's
* now category wide. So, this function is useless until we
* think of how to make it work with our UI
*
* So, let return original $lists for now
*/
return $lists;
if ((int)$term > 0) {
$term_id = $term;
} else {
$terms_object = get_term_by('name', esc_attr($term), $taxonomy);
if (is_object($terms_object) && isset($terms_object->term_id)) {
$term_id = $terms_object->term_id;
} else {
$term_id = 0;
}
}
if ($term_id > 0) {
// get linked terms
$linked_terms = taxopress_get_linked_terms($term_id, $taxonomy, true);
if (!empty($linked_terms)) {
if (!empty($linked_terms)) {
foreach ($linked_terms as $linked_term) {
$linked_term_name = stripslashes($linked_term->name);
$linked_term_id = $linked_term->term_id;
if ($linked) {
$term_value = get_term_link($linked_term, $linked_term->taxonomy);
} elseif ($named_term) {
$term_value = $linked_term_name;
} else {
$term_value = $linked_term_id;
}
// add linked term
$lists[$linked_term_name] = $term_value;
// add linked term synonyms
$term_synonyms = taxopress_get_term_synonyms($linked_term_id);
if (!empty($term_synonyms)) {
foreach ($term_synonyms as $term_synonym) {
$lists[$term_synonym] = $term_value;
}
}
}
}
}
}
return $lists;
}
/**
* Fetch our TAXOPRESS SuggestTerms option.
* SuggestTerms screen has been removed but we need this function
* to migrate the needed settings.
*
* @return mixed
*/
function taxopress_get_suggestterm_data()
{
return array_filter((array)apply_filters('taxopress_get_suggestterm_data', get_option('taxopress_suggestterms', []),
get_current_blog_id()));
}