function new_duplicated_terms_filter($post_ids, $duplicates_only = true) { global $wpdb, $sitepress, $wpml_admin_notices; require_once ICL_PLUGIN_PATH . '/inc/taxonomy-term-translation/wpml-term-hierarchy-duplication.class.php'; $hier_dupl = new WPML_Term_Hierarchy_Duplication($wpdb, $sitepress); $taxonomies = $hier_dupl->duplicates_require_sync($post_ids, $duplicates_only); if ((bool) $taxonomies) { $text = __('<p>Some taxonomy terms are out of sync between languages. This means that content in some languages will not have the correct tags or categories.</p> <p>In order to synchronize the taxonomies, you need to go over each of them from the following list and click the "Update taxonomy hierarchy" button.</p>', 'wpml-translation-management'); $collapsed = 'Taxonomy sync problem'; foreach ($taxonomies as $taxonomy) { $text .= '<p><a href="admin.php?page=' . ICL_PLUGIN_FOLDER . '/menu/taxonomy-translation.php&taxonomy=' . $taxonomy . '&sync=1">' . get_taxonomy_labels(get_taxonomy($taxonomy))->name . '</a></p>'; } $text .= '<p align="right"><a target="_blank" href="https://wpml.org/documentation/getting-started-guide/translating-post-categories-and-custom-taxonomies/#synchronizing-hierarchical-taxonomies">Help about translating taxonomy >></a></p>'; $notice = new WPML_Notice('wpml-taxonomy-hierarchy-sync', $text, 'wpml-core'); $notice->set_css_class_types('info'); $notice->set_collapsed_text($collapsed); $notice->set_hideable(false); $notice->set_dismissible(false); $notice->set_collapsable(true); $wpml_admin_notices->add_notice($notice); } else { remove_taxonomy_hierarchy_message(); } }
function testFilterEventCategoryLabel() { add_filter('eventorganiser_register_taxonomy_event-category', array($this, '_filterCatLabels')); eventorganiser_create_event_taxonomies(); remove_filter('eventorganiser_register_taxonomy_event-category', array($this, '_filterCatLabels')); $tax = get_taxonomy('event-category'); $tax_labels = get_taxonomy_labels($tax); $this->assertEquals('Event Types', $tax_labels->name); }
public function setupRender(\WP_Post $post, array $box, \stdClass $taxonomy) { $labels = get_taxonomy_labels($taxonomy); $renderSettings = ['name' => 'tax_input[' . esc_attr($taxonomy->name) . ']', 'delimiter' => _x(',', 'tag delimiter'), 'options' => $this->get_options($post, $box, $taxonomy), 'items' => $this->get_items($post, $box, $taxonomy), 'disabled' => !current_user_can($taxonomy->cap->assign_terms)] + $this->settings; if (value($renderSettings, 'label') === true) { $renderSettings['label'] = $labels->{value($renderSettings, 'multiple', false) ? "singular_name" : "name"}; } $renderSettings = apply_filters('tf_setup_render', $renderSettings, $post, $box, $taxonomy); return apply_filters(sprintf('tf_%s_setup_render', $taxonomy->name), $renderSettings, $post, $box, $taxonomy); }
function wpml_new_duplicated_terms_filter($post_ids, $duplicates_only = true) { require_once ICL_PLUGIN_PATH . '/inc/taxonomy-term-translation/wpml-term-hierarchy-duplication.class.php'; $hier_dupl = new WPML_Term_Hierarchy_Duplication(); $taxonomies = $hier_dupl->duplicates_require_sync($post_ids, $duplicates_only); if ((bool) $taxonomies) { $text = __("The posts you just saved led to the creation of new hierarchical terms.\nTheir hierarchical relationship to one another is not yet synchronized with the original post's terms for the following taxonomies:", 'wpml-translation-management'); $text = '<p>' . $text . '</p>'; foreach ($taxonomies as $taxonomy) { $text .= '<p><a href="admin.php?page=' . ICL_PLUGIN_FOLDER . '/menu/taxonomy-translation.php&taxonomy=' . $taxonomy . '&sync=1">' . get_taxonomy_labels(get_taxonomy($taxonomy))->name . '</a></p>'; } $message_args = array('id' => 'duplication-tm-dashboard-notification', 'text' => $text, 'type' => 'information', 'group' => 'duplication-notification', 'admin_notice' => true, 'show_once' => true, 'hide_per_user' => true); ICL_AdminNotifier::add_message($message_args); } }
/** * Registers the taxonomy. * * If the taxonomy already exists, some of the arguments will be merged into the existing taxonomy object. * * @since 0.5.0 */ public function register() { if ($this->registered) { return; } if (!$this->is_already_added()) { $_taxonomy_args = $this->args; unset($_taxonomy_args['title']); unset($_taxonomy_args['singular_title']); unset($_taxonomy_args['title_gender']); unset($_taxonomy_args['messages']); unset($_taxonomy_args['help']); $_taxonomy_args['label'] = $this->args['title']; $taxonomy_args = array(); foreach ($_taxonomy_args as $key => $value) { if (null !== $value) { $taxonomy_args[$key] = $value; } } register_taxonomy($this->slug, null, $taxonomy_args); } else { // merge several properties into existing taxonomy global $wp_taxonomies; if ($this->args['labels']) { // merge the slug as $name into the arguments (required for `get_taxonomy_labels()`) $wp_taxonomies[$this->slug]->labels = get_taxonomy_labels((object) array_merge($this->args, array('name' => $this->slug))); $wp_taxonomies[$this->slug]->label = $wp_taxonomies[$this->slug]->labels->name; } } if (wpptd_supports_termmeta()) { add_action('wpptd_add_term_meta_boxes_' . $this->slug, array($this, 'add_meta_boxes'), 10, 1); } $this->registered = true; }
/** * Get attribute taxonomy label. * * @param string $name Taxonomy name. * @return string */ protected function get_attribute_taxonomy_label($name) { $tax = get_taxonomy($name); $labels = get_taxonomy_labels($tax); return $labels->singular_name; }
/** * Create or modify a taxonomy object. Do not use before init. * * A simple function for creating or modifying a taxonomy object based on the * parameters given. The function will accept an array (third optional * parameter), along with strings for the taxonomy name and another string for * the object type. * * Nothing is returned, so expect error maybe or use taxonomy_exists() to check * whether taxonomy exists. * * Optional $args contents: * * label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used. * * hierarchical - has some defined purpose at other parts of the API and is a * boolean value. * * update_count_callback - works much like a hook, in that it will be called * when the count is updated. * * rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize * permastruct; default will use $taxonomy as slug. * * query_var - false to prevent queries, or string to customize query var * (?$query_var=$term); default will use $taxonomy as query var. * * public - If the taxonomy should be publically queryable; //@TODO not implemented. * defaults to true. * * show_ui - If the WordPress UI admin tags UI should apply to this taxonomy; * defaults to public. * * show_in_nav_menus - true makes this taxonomy available for selection in navigation menus. * Defaults to public. * * show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget; * defaults to show_ui which defalts to public. * * labels - An array of labels for this taxonomy. You can see accepted values in {@link get_taxonomy_labels()}. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones. * * @package WordPress * @subpackage Taxonomy * @since 2.3.0 * @uses $wp_taxonomies Inserts new taxonomy object into the list * @uses $wp_rewrite Adds rewrite tags and permastructs * @uses $wp Adds query vars * * @param string $taxonomy Name of taxonomy object * @param array|string $object_type Name of the object type for the taxonomy object. * @param array|string $args See above description for the two keys values. */ function register_taxonomy($taxonomy, $object_type, $args = array()) { global $wp_taxonomies, $wp_rewrite, $wp; if (!is_array($wp_taxonomies)) { $wp_taxonomies = array(); } $defaults = array('hierarchical' => false, 'update_count_callback' => '', 'rewrite' => true, 'query_var' => $taxonomy, 'public' => true, 'show_ui' => null, 'show_tagcloud' => null, '_builtin' => false, 'labels' => array(), 'capabilities' => array(), 'show_in_nav_menus' => null); $args = wp_parse_args($args, $defaults); if (false !== $args['query_var'] && !empty($wp)) { if (true === $args['query_var']) { $args['query_var'] = $taxonomy; } $args['query_var'] = sanitize_title_with_dashes($args['query_var']); $wp->add_query_var($args['query_var']); } if (false !== $args['rewrite'] && '' != get_option('permalink_structure')) { $args['rewrite'] = wp_parse_args($args['rewrite'], array('slug' => sanitize_title_with_dashes($taxonomy), 'with_front' => true, 'hierarchical' => false)); if ($args['hierarchical'] && $args['rewrite']['hierarchical']) { $tag = '(.+?)'; } else { $tag = '([^/]+)'; } $wp_rewrite->add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term="); $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']['with_front']); } if (is_null($args['show_ui'])) { $args['show_ui'] = $args['public']; } // Whether to show this type in nav-menus.php. Defaults to the setting for public. if (null === $args['show_in_nav_menus']) { $args['show_in_nav_menus'] = $args['public']; } if (is_null($args['show_tagcloud'])) { $args['show_tagcloud'] = $args['show_ui']; } $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts'); $args['cap'] = (object) array_merge($default_caps, $args['capabilities']); unset($args['capabilities']); $args['name'] = $taxonomy; $args['object_type'] = array_unique((array) $object_type); $args['labels'] = get_taxonomy_labels((object) $args); $args['label'] = $args['labels']->name; $wp_taxonomies[$taxonomy] = (object) $args; // register callback handling for metabox add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term'); }
/** * Track changes to ACF values within rendered post meta forms * * @param string $type Type of object, post or user * @param string $action Added, updated, deleted * @param integer $meta_id * @param integer $object_id * @param string $key * @param mixed|null $value * * @return bool */ public function check_meta_values($type, $action, $meta_id, $object_id, $key, $value = null) { unset($action); unset($meta_id); if (empty($this->cached_field_values_updates)) { return false; } $object_key = $object_id; if ('user' === $type) { $object_key = 'user_' . $object_id; } elseif ('taxonomy' === $type) { if (0 === strpos($key, '_')) { // Ignore the 'revision' stuff! return false; } if (1 !== preg_match('#([a-z0-9_-]+)_([\\d]+)_([a-z0-9_-]+)#', $key, $matches)) { return false; } list(, $taxonomy, $term_id, $key) = $matches; // Skips 0 index $object_key = $taxonomy . '_' . $term_id; } if (isset($this->cached_field_values_updates[$object_key][$key])) { if ('post' === $type) { $posts_connector = new Connector_Posts(); $post = get_post($object_id); $title = $post->post_title; $type_name = strtolower($posts_connector->get_post_type_name($post->post_type)); } elseif ('user' === $type) { $user = new \WP_User($object_id); $title = $user->get('display_name'); $type_name = esc_html__('user', 'stream'); } elseif ('taxonomy' === $type && isset($term_id) && isset($taxonomy)) { $term = get_term($term_id, $taxonomy); $title = $term->name; $tax_obj = get_taxonomy($taxonomy); $type_name = strtolower(get_taxonomy_labels($tax_obj)->singular_name); } else { return false; } $cache = $this->cached_field_values_updates[$object_key][$key]; $this->log(esc_html_x('"%1$s" of "%2$s" %3$s updated', 'acf', 'stream'), array('field_label' => $cache['field']['label'], 'title' => $title, 'singular_name' => $type_name, 'meta_value' => $value, 'meta_key' => $key, 'meta_type' => $type), $object_id, 'values', 'updated'); } return true; }
/** * Catch registration of taxonomies after inital loading, so we can cache its labels * * @action registered_taxonomy * * @param string $taxonomy Taxonomy slug * @param array|string $object_type Object type or array of object types * @param array|string $args Array or string of taxonomy registration arguments */ public static function _registered_taxonomy($taxonomy, $object_type, $args) { $taxonomy_obj = (object) $args; $label = get_taxonomy_labels($taxonomy_obj)->name; self::$context_labels[$taxonomy] = $label; WP_Stream_Connectors::$term_labels['stream_context'][$taxonomy] = $label; }
function fwp_category_box($checked, $object, $tags = array(), $params = array()) { global $wp_db_version; if (is_string($params)) { $prefix = $params; $taxonomy = 'category'; } elseif (is_array($params)) { $prefix = isset($params['prefix']) ? $params['prefix'] : ''; $taxonomy = isset($params['taxonomy']) ? $params['taxonomy'] : 'category'; } $oTax = get_taxonomy($taxonomy); $oTaxLabels = get_taxonomy_labels($oTax); if (strlen($prefix) > 0) { $idPrefix = $prefix . '-'; $idSuffix = "-" . $prefix; $namePrefix = $prefix . '_'; } else { $idPrefix = 'feedwordpress-'; $idSuffix = "-feedwordpress"; $namePrefix = 'feedwordpress_'; } ?> <div id="<?php print $idPrefix; ?> taxonomy-<?php print $taxonomy; ?> " class="feedwordpress-category-div"> <ul id="<?php print $idPrefix; print $taxonomy; ?> -tabs" class="category-tabs"> <li class="ui-tabs-selected tabs"><a href="#<?php print $idPrefix; print $taxonomy; ?> -all" tabindex="3"><?php _e('All posts'); ?> </a> <p style="font-size:smaller;font-style:bold;margin:0">Give <?php print $object; ?> these <?php print $oTaxLabels->name; ?> </p> </li> </ul> <div id="<?php print $idPrefix; print $taxonomy; ?> -all" class="tabs-panel"> <input type="hidden" value="0" name="tax_input[<?php print $taxonomy; ?> ][]" /> <ul id="<?php print $idPrefix; print $taxonomy; ?> checklist" class="list:<?php print $taxonomy; ?> categorychecklist form-no-clear"> <?php fwp_category_checklist(NULL, false, $checked, $params); ?> </ul> </div> <div id="<?php print $idPrefix; print $taxonomy; ?> -adder" class="<?php print $taxonomy; ?> -adder wp-hidden-children"> <h4><a id="<?php print $idPrefix; print $taxonomy; ?> -add-toggle" class="category-add-toggle" href="#<?php print $idPrefix; print $taxonomy; ?> -add" class="hide-if-no-js" tabindex="3"><?php _e('+ Add New Category'); ?> </a></h4> <p id="<?php print $idPrefix; print $taxonomy; ?> -add" class="category-add wp-hidden-child"> <?php $newcat = 'new' . $taxonomy; ?> <label class="screen-reader-text" for="<?php print $idPrefix; ?> new<?php print $taxonomy; ?> "><?php _e('Add New Category'); ?> </label> <input id="<?php print $idPrefix; ?> new<?php print $taxonomy; ?> " class="new<?php print $taxonomy; ?> form-required form-input-tip" aria-required="true" tabindex="3" type="text" name="<?php print $newcat; ?> " value="<?php _e('New category name'); ?> " /> <label class="screen-reader-text" for="<?php print $idPrefix; ?> new<?php print $taxonomy; ?> -parent"><?php _e('Parent Category:'); ?> </label> <?php wp_dropdown_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'id' => $idPrefix . 'new' . $taxonomy . '-parent', 'class' => 'new' . $taxonomy . '-parent', 'name' => $newcat . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3)); ?> <input type="button" id="<?php print $idPrefix; print $taxonomy; ?> -add-sumbit" class="add:<?php print $idPrefix; print $taxonomy; ?> checklist:<?php print $idPrefix . $taxonomy; ?> -add add-categorychecklist-category-add button category-add-submit" value="<?php _e('Add'); ?> " tabindex="3" /> <?php /* wp_nonce_field currently doesn't let us set an id different from name, but we need a non-unique name and a unique id */ ?> <input type="hidden" id="_ajax_nonce<?php print esc_html($idSuffix); ?> " name="_ajax_nonce" value="<?php print wp_create_nonce('add-' . $taxonomy); ?> " /> <input type="hidden" id="_ajax_nonce-add-<?php print $taxonomy; print esc_html($idSuffix); ?> " name="_ajax_nonce-add-<?php print $taxonomy; ?> " value="<?php print wp_create_nonce('add-' . $taxonomy); ?> " /> <span id="<?php print $idPrefix; print $taxonomy; ?> -ajax-response" class="<?php print $taxonomy; ?> -ajax-response"></span> </p> </div> </div> <?php }
/** * Add action links to Stream drop row in admin list screen * * @filter wp_stream_action_links_{connector} * * @param array $links Previous links registered * @param object $record Stream record * * @return array Action links */ public static function action_links($links, $record) { if (in_array($record->context, array('downloads'))) { $links = WP_Stream_Connector_Posts::action_links($links, $record); } elseif (in_array($record->context, array('discounts'))) { $post_type_label = get_post_type_labels(get_post_type_object('edd_discount'))->singular_name; $base = admin_url('edit.php?post_type=download&page=edd-discounts'); $links[sprintf(__('Edit %s', 'stream'), $post_type_label)] = add_query_arg(array('edd-action' => 'edit_discount', 'discount' => $record->object_id), $base); if ('active' === get_post($record->object_id)->post_status) { $links[sprintf(__('Deactivate %s', 'stream'), $post_type_label)] = add_query_arg(array('edd-action' => 'deactivate_discount', 'discount' => $record->object_id), $base); } else { $links[sprintf(__('Activate %s', 'stream'), $post_type_label)] = add_query_arg(array('edd-action' => 'activate_discount', 'discount' => $record->object_id), $base); } } elseif (in_array($record->context, array('download_category', 'download_tag'))) { $tax_label = get_taxonomy_labels(get_taxonomy($record->context))->singular_name; $links[sprintf(__('Edit %s', 'stream'), $tax_label)] = get_edit_term_link($record->object_id, wp_stream_get_meta($record, 'taxonomy', true)); } elseif ('api_keys' === $record->context) { $user = new WP_User($record->object_id); if (apply_filters('edd_api_log_requests', true)) { $links[__('View API Log', 'stream')] = add_query_arg(array('view' => 'api_requests', 'post_type' => 'download', 'page' => 'edd-reports', 'tab' => 'logs', 's' => $user->user_email), 'edit.php'); } $links[__('Revoke', 'stream')] = add_query_arg(array('post_type' => 'download', 'user_id' => $record->object_id, 'edd_action' => 'process_api_key', 'edd_api_process' => 'revoke'), 'edit.php'); $links[__('Reissue', 'stream')] = add_query_arg(array('post_type' => 'download', 'user_id' => $record->object_id, 'edd_action' => 'process_api_key', 'edd_api_process' => 'regenerate'), 'edit.php'); } return $links; }
$labels = get_taxonomy_labels($tax); print_r($labels); </pre> <?php $tax = get_taxonomy('category'); $labels = get_taxonomy_labels($tax); print_r($labels); ?> <br /><br /><br /><br /> <pre> $tax = get_taxonomy('field'); $labels = get_taxonomy_labels($tax); print_r($labels); </pre> <?php $tax = get_taxonomy('field'); $labels = get_taxonomy_labels($tax); print_r($labels); ?> </p> </div> </div> <?php get_footer();
/** * Create the message to display when there are not terms on the other site * * @param int $site_id * @return string */ private function get_no_terms_found_message($site_id) { $taxonomy_name = $this->presenter->get_taxonomy(); $taxonomy_object = get_taxonomy($taxonomy_name); $taxonomy_labels = get_taxonomy_labels($taxonomy_object); $text = esc_html($taxonomy_labels->not_found); $admin_url = get_admin_url($site_id, 'edit-tags.php'); $taxonomy_edit_url = add_query_arg('taxonomy', $taxonomy_name, $admin_url); $url = esc_url($taxonomy_edit_url); return sprintf('<p><a href="%1$s">%2$s</a></p>', $url, $text); }
/** * Sets taxonomy properties. * * @since 4.7.0 * @access public * * @param array|string $object_type Name of the object type for the taxonomy object. * @param array|string $args Array or query string of arguments for registering a taxonomy. */ public function set_props($object_type, $args) { $args = wp_parse_args($args); /** * Filters the arguments for registering a taxonomy. * * @since 4.4.0 * * @param array $args Array of arguments for registering a taxonomy. * @param string $taxonomy Taxonomy key. * @param array $object_type Array of names of object types for the taxonomy. */ $args = apply_filters('register_taxonomy_args', $args, $this->name, (array) $object_type); $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'publicly_queryable' => null, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $this->name, 'update_count_callback' => '', '_builtin' => false); $args = array_merge($defaults, $args); // If not set, default to the setting for public. if (null === $args['publicly_queryable']) { $args['publicly_queryable'] = $args['public']; } if (false !== $args['query_var'] && (is_admin() || false !== $args['publicly_queryable'])) { if (true === $args['query_var']) { $args['query_var'] = $this->name; } else { $args['query_var'] = sanitize_title_with_dashes($args['query_var']); } } else { // Force query_var to false for non-public taxonomies. $args['query_var'] = false; } if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) { $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE)); if (empty($args['rewrite']['slug'])) { $args['rewrite']['slug'] = sanitize_title_with_dashes($this->name); } } // If not set, default to the setting for public. if (null === $args['show_ui']) { $args['show_ui'] = $args['public']; } // If not set, default to the setting for show_ui. if (null === $args['show_in_menu'] || !$args['show_ui']) { $args['show_in_menu'] = $args['show_ui']; } // If not set, default to the setting for public. if (null === $args['show_in_nav_menus']) { $args['show_in_nav_menus'] = $args['public']; } // If not set, default to the setting for show_ui. if (null === $args['show_tagcloud']) { $args['show_tagcloud'] = $args['show_ui']; } // If not set, default to the setting for show_ui. if (null === $args['show_in_quick_edit']) { $args['show_in_quick_edit'] = $args['show_ui']; } $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts'); $args['cap'] = (object) array_merge($default_caps, $args['capabilities']); unset($args['capabilities']); $args['object_type'] = array_unique((array) $object_type); // If not set, use the default meta box if (null === $args['meta_box_cb']) { if ($args['hierarchical']) { $args['meta_box_cb'] = 'post_categories_meta_box'; } else { $args['meta_box_cb'] = 'post_tags_meta_box'; } } foreach ($args as $property_name => $property_value) { $this->{$property_name} = $property_value; } $this->labels = get_taxonomy_labels($this); $this->label = $this->labels->name; }
/** * Generates a taxonomy metabox function callback together with seletize * @since 0.1.0 * * @global array $defaultSettings Default settings applied to all TSNS fields * @global wpdb $wpdb WordPress database abstraction object. * * @param array $settings { * Settings to describe how the TSNS fields should work * * @type string $ajax_url url ajax target. Defaults to `ajaxurl` * @type array $selector_setup Selectize Setup * @type array $ajax_data Aditional data to be served by ajax. * By default, wp_ajax settings are assumed. * @type string $ajax_query_field field in ajax data for the query, which * is overwrited in runtime by current one. * * @type int|bool $terms_limit defines how much terms can be assigned to * the post. Define *false* for no limit. * * } * * @return function Returns a function which should be passed to 'meta_box_cb' * of {@link register_taxonomy()}'s $args * if no taxonomy is specified and the term ID exists. Returns * an array of the term ID and the term taxonomy ID the taxonomy * is specified and the pairing exists. */ function searchNSelectField($settings = []) { global $defaultSettings, $tsns_initiated; $settings += ['selector_setup' => [], 'ajax_url' => false, 'ajax_query_field' => 'query', 'terms_limit' => false]; return function (\WP_Post $post, array $box) use($settings) { $tax_name = $box['args']['taxonomy']; $taxonomy = get_taxonomy($tax_name); $user_can_assign_terms = current_user_can($taxonomy->cap->assign_terms); $comma = _x(',', 'tag delimiter'); $terms = wp_get_object_terms($post->ID, $tax_name); $labels = get_taxonomy_labels($taxonomy); $new_label = $labels->add_new_item; $preload = []; if ($preload_length = value($settings, 'preload', 10)) { $preload = get_terms($tax_name, ['number' => $preload_length, 'hide_empty' => false, 'orderby' => 'count']); } /** * Filters the selectize settings before its conversion to JSON * * @since 0.1.0 * * @param array $settings Original settings to passed to selectize.js * @param WP_Post $post The post currently being edited * @param object $taxonomy Taxonomy for the current metabox * @param array $settings Options this current fields */ $config = apply_filters('tsns_selector_setup', $settings['selector_setup'] + ['loadThrottle' => 100, 'valueField' => 'term_id', 'labelField' => 'name', 'searchField' => 'name', 'maxOptions' => 10, 'optionsTemplate' => '<div class="option"><%- option.name %></div>', 'createTemplate' => "<div class='create'>{$new_label}: <%- input %></div>", 'itemsTemplate' => '<div class="item"><%- item.name %></div>', 'maxItems' => $settings['terms_limit'], 'delimiter' => $comma, 'options' => $terms + $preload, 'items' => array_map(function ($term) { return $term->term_id; }, $terms), 'create' => $user_can_assign_terms], $post, $taxonomy, $settings); /** * Filters the selectize settings before its conversion to JSON specifically * to {taxonomy}, after filtered by {@link tsns_selector_setup} * * @since 0.1.0 * * @param array $settings Original settings to passed to selectize.js * @param WP_Post $post The post currently being edited * @param object $taxonomy Taxonomy for the current metabox * @param array $settings Options this current fields */ $config = apply_filters(sprintf('tsns_%s_selector_setup', $tax_name), $config, $post, $taxonomy, $settings); /** * Filter ajax data to be sent along with the query * * @since 0.1.0 * * @param array $ajax_data Original ajax data * @param WP_Post $post The post currently being edited * @param object $taxonomy Taxonomy for the current metabox * @param array $settings Options this current fields */ $ajax_data = apply_filters('tsns_ajax_data', value($settings, 'ajax_data', ['action' => "tsns_search", 'taxonomy' => $tax_name]), $post, $taxonomy, $settings); /** * Filter ajax data to be sent along with the query specifically to * {taxonomy}, after filtered by {@link tsns_setup_selector} * * @since 0.1.0 * * @param array $settings Original settings to passed to selectize.js * @param WP_Post $post The post currently being edited * @param object $taxonomy Taxonomy for the current metabox * @param array $settings Options this current fields */ $ajax_data = apply_filters(sprintf('tsns_%s_ajax_data', $tax_name), $ajax_data, $post, $taxonomy, $settings); if ($ajax_url = value($settings, 'ajax_url', false)) { $ajax_url = json_encode($ajax_url); } else { $ajax_url = 'ajaxurl'; } ?> <div class="selectize-taxonomy"> <textarea name="<?php echo "tax_input_tsns[{$tax_name}]"; ?> " rows="3" cols="20" class="tsns" id="tax-input-<?php echo $tax_name; ?> " <?php disabled(!$user_can_assign_terms); ?> ><?php echo str_replace(',', $comma . ' ', get_terms_to_edit($post->ID, $tax_name)); ?> </textarea> <script type="text/javascript"> (function($, _) { var $el = $("script:last").prev(); <?php if (value($settings, 'required')) { ?> $el.closest("form").submit(function(e){ if (!$el.val()) { e.preventDefault(); e.stopPropagation(); alert(<?php if (value($settings, 'required') === true) { echo 'Required field is empty'; } else { echo json_encode(value($settings, 'required')); } ?> ); return false; } }); <?php } ?> // Settings var options = <?php echo json_encode($config); ?> ; var ajaxData = <?php echo json_encode($ajax_data); ?> ; if (!options.maxItems) delete options.maxItems; // Templates var optionsTemplate = (options.optionsTemplate && _.template(options.optionsTemplate)) || null; var itemsTemplate = (options.itemsTemplate && _.template(options.itemsTemplate)) || null; var createTemplate = (options.createTemplate && _.template(options.createTemplate)) || null; options.create = options.create && function(input) { return { term_id: input, name: input } }; // Methods options = $.extend({ load: function(query, done) { ajaxData['query'] = query; $.ajax({ url: <?php echo $ajax_url; ?> , type: 'GET', dataType: 'json', data: ajaxData, error: function() { done(); }, success: function(res) { done(res); } }); }, render: { item: (itemsTemplate && function(item, escape) { return itemsTemplate({item:item, escape:escape}); }) || undefined, option: (optionsTemplate && function(option, escape) { return optionsTemplate({option: option, escape:escape}); }) || undefined, option_create: (createTemplate && function(query, serialize) { query.serialize = serialize; return createTemplate(query); }) || undefined } }, options); $el.selectize(options); })(jQuery, _); </script> </div> <?php }; }
/** * Create or modify a taxonomy object. Do not use before init. * * A simple function for creating or modifying a taxonomy object based on the * parameters given. The function will accept an array (third optional * parameter), along with strings for the taxonomy name and another string for * the object type. * * Nothing is returned, so expect error maybe or use taxonomy_exists() to check * whether taxonomy exists. * * Optional $args contents: * * label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used. * * hierarchical - has some defined purpose at other parts of the API and is a * boolean value. * * update_count_callback - works much like a hook, in that it will be called when the count is updated. * Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms * that the objects are published before counting them. * Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links. * * rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize * permastruct; default will use $taxonomy as slug. * * query_var - false to prevent queries, or string to customize query var * (?$query_var=$term); default will use $taxonomy as query var. * * public - If the taxonomy should be publicly queryable; //@TODO not implemented. * defaults to true. * * show_ui - If the WordPress UI admin tags UI should apply to this taxonomy; * defaults to public. * * show_in_nav_menus - true makes this taxonomy available for selection in navigation menus. * Defaults to public. * * show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget; * defaults to show_ui which defaults to public. * * labels - An array of labels for this taxonomy. You can see accepted values in {@link get_taxonomy_labels()}. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones. * * @package WordPress * @subpackage Taxonomy * @since 2.3.0 * @uses $wp_taxonomies Inserts new taxonomy object into the list * @uses $wp Adds query vars * * @param string $taxonomy Name of taxonomy object * @param array|string $object_type Name of the object type for the taxonomy object. * @param array|string $args See above description for the two keys values. * @return null|WP_Error WP_Error if errors, otherwise null. */ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { global $wp_taxonomies, $wp; if ( ! is_array($wp_taxonomies) ) $wp_taxonomies = array(); $defaults = array( 'hierarchical' => false, 'update_count_callback' => '', 'rewrite' => true, 'query_var' => $taxonomy, 'public' => true, 'show_ui' => null, 'show_tagcloud' => null, '_builtin' => false, 'labels' => array(), 'capabilities' => array(), 'show_in_nav_menus' => null, ); $args = wp_parse_args($args, $defaults); if ( strlen( $taxonomy ) > 32 ) return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) ); if ( false !== $args['query_var'] && !empty($wp) ) { if ( true === $args['query_var'] ) $args['query_var'] = $taxonomy; else $args['query_var'] = sanitize_title_with_dashes($args['query_var']); $wp->add_query_var($args['query_var']); } if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option('permalink_structure') ) ) { $args['rewrite'] = wp_parse_args($args['rewrite'], array( 'slug' => sanitize_title_with_dashes($taxonomy), 'with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE, )); if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) $tag = '(.+?)'; else $tag = '([^/]+)'; add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" ); add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] ); } if ( is_null($args['show_ui']) ) $args['show_ui'] = $args['public']; // Whether to show this type in nav-menus.php. Defaults to the setting for public. if ( null === $args['show_in_nav_menus'] ) $args['show_in_nav_menus'] = $args['public']; if ( is_null($args['show_tagcloud']) ) $args['show_tagcloud'] = $args['show_ui']; $default_caps = array( 'manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts', ); $args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] ); unset( $args['capabilities'] ); $args['name'] = $taxonomy; $args['object_type'] = array_unique( (array)$object_type ); $args['labels'] = get_taxonomy_labels( (object) $args ); $args['label'] = $args['labels']->name; $wp_taxonomies[$taxonomy] = (object) $args; // register callback handling for metabox add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term'); do_action( 'registered_taxonomy', $taxonomy, $object_type, $args ); }
/** * Catch registration of taxonomies after inital loading, so we can cache its labels * * @action registered_taxonomy * * @param string $taxonomy Taxonomy slug * @param array|string $object_type Object type or array of object types * @param array|string $args Array or string of taxonomy registration arguments */ public function _registered_taxonomy($taxonomy, $object_type, $args) { unset($object_type); $taxonomy_obj = (object) $args; $label = get_taxonomy_labels($taxonomy_obj)->name; $this->context_labels[$taxonomy] = $label; wp_stream_get_instance()->connectors->term_labels['stream_context'][$taxonomy] = $label; }
function rtbiz_get_tex_diff($post_id, $texonomy) { $post_terms = wp_get_post_terms($post_id, $texonomy); $postterms = array_filter($_POST['tax_input'][$texonomy]); $termids = wp_list_pluck($post_terms, 'term_id'); $diff = array_diff($postterms, $termids); $diff2 = array_diff($termids, $postterms); $diff_tax1 = array(); $diff_tax2 = array(); foreach ($diff as $tax_id) { $tmp = get_term_by('id', $tax_id, $texonomy); $diff_tax1[] = $tmp->name; } foreach ($diff2 as $tax_id) { $tmp = get_term_by('id', $tax_id, $texonomy); $diff_tax2[] = $tmp->name; } $difftxt = rtbiz_text_diff(implode(' ', $diff_tax2), implode(' ', $diff_tax1)); if (!empty($difftxt) || '' != $difftxt) { $tax = get_taxonomy($texonomy); $lable = get_taxonomy_labels($tax); $body = '<strong>' . __($lable->name) . '</strong> : ' . $difftxt; return $body; } return ''; }
/** * Creates or modifies a taxonomy object. * * Note: Do not use before the {@see 'init'} hook. * * A simple function for creating or modifying a taxonomy object based on the * parameters given. The function will accept an array (third optional * parameter), along with strings for the taxonomy name and another string for * the object type. * * @since 2.3.0 * @since 4.2.0 Introduced `show_in_quick_edit` argument. * @since 4.4.0 The `show_ui` argument is now enforced on the term editing screen. * @since 4.4.0 The `public` argument now controls whether the taxonomy can be queried on the front-end. * * @global array $wp_taxonomies Registered taxonomies. * @global WP $wp WP instance. * * @param string $taxonomy Taxonomy key, must not exceed 32 characters. * @param array|string $object_type Name of the object type for the taxonomy object. * @param array|string $args { * Optional. Array or query string of arguments for registering a taxonomy. * * @type string $label Name of the taxonomy shown in the menu. Usually plural. If not set, * `$labels['name']` will be used. * @type array $labels An array of labels for this taxonomy. By default, Tag labels are used for * non-hierarchical taxonmies, and Category labels are used for hierarchical * taxonomies. See accepted values in get_taxonomy_labels(). * Default empty array. * @type string $description A short descriptive summary of what the taxonomy is for. Default empty. * @type bool $public Whether the taxonomy is publicly queryable. Default true. * @type bool $hierarchical Whether the taxonomy is hierarchical. Default false. * @type bool $show_ui Whether to generate and allow a UI for managing terms in this taxonomy in * the admin. If not set, the default is inherited from `$public` * (default true). * @type bool $show_in_menu Whether to show the taxonomy in the admin menu. If true, the taxonomy is * shown as a submenu of the object type menu. If false, no menu is shown. * `$show_ui` must be true. If not set, default is inherited from `$show_ui` * (default true). * @type bool $show_in_nav_menus Makes this taxonomy available for selection in navigation menus. If not * set, the default is inherited from `$public` (default true). * @type bool $show_tagcloud Whether to list the taxonomy in the Tag Cloud Widget controls. If not set, * the default is inherited from `$show_ui` (default true). * @type bool $show_in_quick_edit Whether to show the taxonomy in the quick/bulk edit panel. It not set, * the default is inherited from `$show_ui` (default true). * @type bool $show_admin_column Whether to display a column for the taxonomy on its post type listing * screens. Default false. * @type bool|callable $meta_box_cb Provide a callback function for the meta box display. If not set, * post_categories_meta_box() is used for hierarchical taxonomies, and * post_tags_meta_box() is used for non-hierarchical. If false, no meta * box is shown. * @type array $capabilities { * Array of capabilities for this taxonomy. * * @type string $manage_terms Default 'manage_categories'. * @type string $edit_terms Default 'manage_categories'. * @type string $delete_terms Default 'manage_categories'. * @type string $assign_terms Default 'edit_posts'. * } * @type bool|array $rewrite { * Triggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent * rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys: * * @type string $slug Customize the permastruct slug. Default `$taxonomy` key. * @type bool $with_front Should the permastruct be prepended with WP_Rewrite::$front. Default true. * @type bool $hierarchical Either hierarchical rewrite tag or not. Default false. * @type int $ep_mask Assign an endpoint mask. Default `EP_NONE`. * } * @type string $query_var Sets the query var key for this taxonomy. Default `$taxonomy` key. If * false, a taxonomy cannot be loaded at `?{query_var}={term_slug}`. If a * string, the query `?{query_var}={term_slug}` will be valid. * @type callable $update_count_callback Works much like a hook, in that it will be called when the count is * updated. Default _update_post_term_count() for taxonomies attached * to post types, which confirms that the objects are published before * counting them. Default _update_generic_term_count() for taxonomies * attached to other object types, such as users. * @type bool $_builtin This taxonomy is a "built-in" taxonomy. INTERNAL USE ONLY! * Default false. * } * @return WP_Error|void WP_Error, if errors. */ function register_taxonomy($taxonomy, $object_type, $args = array()) { global $wp_taxonomies, $wp; if (!is_array($wp_taxonomies)) { $wp_taxonomies = array(); } $args = wp_parse_args($args); /** * Filter the arguments for registering a taxonomy. * * @since 4.4.0 * * @param array $args Array of arguments for registering a taxonomy. * @param array $object_type Array of names of object types for the taxonomy. * @param string $taxonomy Taxonomy key. */ $args = apply_filters('register_taxonomy_args', $args, $taxonomy, (array) $object_type); $defaults = array('labels' => array(), 'description' => '', 'public' => true, 'hierarchical' => false, 'show_ui' => null, 'show_in_menu' => null, 'show_in_nav_menus' => null, 'show_tagcloud' => null, 'show_in_quick_edit' => null, 'show_admin_column' => false, 'meta_box_cb' => null, 'capabilities' => array(), 'rewrite' => true, 'query_var' => $taxonomy, 'update_count_callback' => '', '_builtin' => false); $args = array_merge($defaults, $args); if (empty($taxonomy) || strlen($taxonomy) > 32) { _doing_it_wrong(__FUNCTION__, __('Taxonomy names must be between 1 and 32 characters in length.'), '4.2'); return new WP_Error('taxonomy_length_invalid', __('Taxonomy names must be between 1 and 32 characters in length.')); } if (false !== $args['query_var'] && !empty($wp)) { if (true === $args['query_var']) { $args['query_var'] = $taxonomy; } else { $args['query_var'] = sanitize_title_with_dashes($args['query_var']); } $wp->add_query_var($args['query_var']); } if (false !== $args['rewrite'] && (is_admin() || '' != get_option('permalink_structure'))) { $args['rewrite'] = wp_parse_args($args['rewrite'], array('with_front' => true, 'hierarchical' => false, 'ep_mask' => EP_NONE)); if (empty($args['rewrite']['slug'])) { $args['rewrite']['slug'] = sanitize_title_with_dashes($taxonomy); } if ($args['hierarchical'] && $args['rewrite']['hierarchical']) { $tag = '(.+?)'; } else { $tag = '([^/]+)'; } add_rewrite_tag("%{$taxonomy}%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy={$taxonomy}&term="); add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%{$taxonomy}%", $args['rewrite']); } // If not set, default to the setting for public. if (null === $args['show_ui']) { $args['show_ui'] = $args['public']; } // If not set, default to the setting for show_ui. if (null === $args['show_in_menu'] || !$args['show_ui']) { $args['show_in_menu'] = $args['show_ui']; } // If not set, default to the setting for public. if (null === $args['show_in_nav_menus']) { $args['show_in_nav_menus'] = $args['public']; } // If not set, default to the setting for show_ui. if (null === $args['show_tagcloud']) { $args['show_tagcloud'] = $args['show_ui']; } // If not set, default to the setting for show_ui. if (null === $args['show_in_quick_edit']) { $args['show_in_quick_edit'] = $args['show_ui']; } $default_caps = array('manage_terms' => 'manage_categories', 'edit_terms' => 'manage_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_posts'); $args['cap'] = (object) array_merge($default_caps, $args['capabilities']); unset($args['capabilities']); $args['name'] = $taxonomy; $args['object_type'] = array_unique((array) $object_type); $args['labels'] = get_taxonomy_labels((object) $args); $args['label'] = $args['labels']->name; // If not set, use the default meta box if (null === $args['meta_box_cb']) { if ($args['hierarchical']) { $args['meta_box_cb'] = 'post_categories_meta_box'; } else { $args['meta_box_cb'] = 'post_tags_meta_box'; } } $wp_taxonomies[$taxonomy] = (object) $args; // register callback handling for metabox add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term'); /** * Fires after a taxonomy is registered. * * @since 3.3.0 * * @param string $taxonomy Taxonomy slug. * @param array|string $object_type Object type or array of object types. * @param array $args Array of taxonomy registration arguments. */ do_action('registered_taxonomy', $taxonomy, $object_type, $args); }
/** * {@inheritdoc} */ public static final function getLabels() { return get_taxonomy_labels(static::getDefinition()); }