WordPress.org

Make WordPress Core

Ticket #6593: match_tag_names.diff

File match_tag_names.diff, 2.5 KB (added by jhodgdon, 10 years ago)

Patch to allow matching of tag names when saving post

  • opt/www/eclipsework/WPDev/wp-includes/post.php

     
    14691469        if ( empty($tags) )
    14701470                $tags = array();
    14711471        $tags = (is_array($tags)) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
    1472         wp_set_object_terms($post_id, $tags, 'post_tag', $append);
     1472        wp_set_object_terms($post_id, $tags, 'post_tag', $append, true);
    14731473}
    14741474
    14751475/**
  • opt/www/eclipsework/WPDev/wp-includes/taxonomy.php

     
    735735 * @param string $taxonomy The taxonomy name to use
    736736 * @return mixed Get the term id or Term Object, if exists.
    737737 */
    738 function is_term($term, $taxonomy = '') {
     738function is_term($term, $taxonomy = '', $allow_match_name = false) {
    739739        global $wpdb;
    740740
    741741        if ( is_int($term) ) {
     
    743743                        return 0;
    744744                $where = $wpdb->prepare( "t.term_id = %d", $term );
    745745        } else {
     746                $tname = $term;
    746747                if ( '' === $term = sanitize_title($term) )
    747748                        return 0;
    748749                $where = $wpdb->prepare( "t.slug = %s", $term );
     750                if( $allow_match_name ) {
     751                        $where .= ' OR ' . $wpdb->prepare( "t.name = %s", $tname );
     752                }
    749753        }
    750754
    751755        if ( !empty($taxonomy) )
     
    12481252 * @uses $wpdb
    12491253 *
    12501254 * @param int $object_id The object to relate to.
    1251  * @param array|int|string $term The slug or id of the term.
     1255 * @param array|int|string $terms The slugs or ids of the terms (or names if $allow_match_names is true).
    12521256 * @param array|string $taxonomy The context in which to relate the term to the object.
    12531257 * @param bool $append If false will delete difference of terms.
     1258 * @param bool $allow_match_names If true, $terms can contain term names as well as slugs or IDs
    12541259 * @return array|WP_Error Affected Term IDs
    12551260 */
    1256 function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
     1261function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false, $allow_match_names = false) {
    12571262        global $wpdb;
    12581263
    12591264        $object_id = (int) $object_id;
     
    12741279                if ( !strlen(trim($term)) )
    12751280                        continue;
    12761281
    1277                 if ( !$id = is_term($term, $taxonomy) )
     1282                if ( !$id = is_term($term, $taxonomy, $allow_match_names) )
    12781283                        $id = wp_insert_term($term, $taxonomy);
    12791284                if ( is_wp_error($id) )
    12801285                        return $id;