Edit File by line
/home/zeestwma/richards.../wp-inclu...
File: taxonomy.php
* and add the alias to it.
[2500] Fix | Delete
*/
[2501] Fix | Delete
$term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms" ) + 1;
[2502] Fix | Delete
[2503] Fix | Delete
wp_update_term(
[2504] Fix | Delete
$alias->term_id,
[2505] Fix | Delete
$taxonomy,
[2506] Fix | Delete
array(
[2507] Fix | Delete
'term_group' => $term_group,
[2508] Fix | Delete
)
[2509] Fix | Delete
);
[2510] Fix | Delete
}
[2511] Fix | Delete
}
[2512] Fix | Delete
[2513] Fix | Delete
/*
[2514] Fix | Delete
* Prevent the creation of terms with duplicate names at the same level of a taxonomy hierarchy,
[2515] Fix | Delete
* unless a unique slug has been explicitly provided.
[2516] Fix | Delete
*/
[2517] Fix | Delete
$name_matches = get_terms(
[2518] Fix | Delete
array(
[2519] Fix | Delete
'taxonomy' => $taxonomy,
[2520] Fix | Delete
'name' => $name,
[2521] Fix | Delete
'hide_empty' => false,
[2522] Fix | Delete
'parent' => $args['parent'],
[2523] Fix | Delete
'update_term_meta_cache' => false,
[2524] Fix | Delete
)
[2525] Fix | Delete
);
[2526] Fix | Delete
[2527] Fix | Delete
/*
[2528] Fix | Delete
* The `name` match in `get_terms()` doesn't differentiate accented characters,
[2529] Fix | Delete
* so we do a stricter comparison here.
[2530] Fix | Delete
*/
[2531] Fix | Delete
$name_match = null;
[2532] Fix | Delete
if ( $name_matches ) {
[2533] Fix | Delete
foreach ( $name_matches as $_match ) {
[2534] Fix | Delete
if ( strtolower( $name ) === strtolower( $_match->name ) ) {
[2535] Fix | Delete
$name_match = $_match;
[2536] Fix | Delete
break;
[2537] Fix | Delete
}
[2538] Fix | Delete
}
[2539] Fix | Delete
}
[2540] Fix | Delete
[2541] Fix | Delete
if ( $name_match ) {
[2542] Fix | Delete
$slug_match = get_term_by( 'slug', $slug, $taxonomy );
[2543] Fix | Delete
if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) {
[2544] Fix | Delete
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
[2545] Fix | Delete
$siblings = get_terms(
[2546] Fix | Delete
array(
[2547] Fix | Delete
'taxonomy' => $taxonomy,
[2548] Fix | Delete
'get' => 'all',
[2549] Fix | Delete
'parent' => $parent,
[2550] Fix | Delete
'update_term_meta_cache' => false,
[2551] Fix | Delete
)
[2552] Fix | Delete
);
[2553] Fix | Delete
[2554] Fix | Delete
$existing_term = null;
[2555] Fix | Delete
$sibling_names = wp_list_pluck( $siblings, 'name' );
[2556] Fix | Delete
$sibling_slugs = wp_list_pluck( $siblings, 'slug' );
[2557] Fix | Delete
[2558] Fix | Delete
if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, $sibling_names, true ) ) {
[2559] Fix | Delete
$existing_term = $name_match;
[2560] Fix | Delete
} elseif ( $slug_match && in_array( $slug, $sibling_slugs, true ) ) {
[2561] Fix | Delete
$existing_term = $slug_match;
[2562] Fix | Delete
}
[2563] Fix | Delete
[2564] Fix | Delete
if ( $existing_term ) {
[2565] Fix | Delete
return new WP_Error( 'term_exists', __( 'A term with the name provided already exists with this parent.' ), $existing_term->term_id );
[2566] Fix | Delete
}
[2567] Fix | Delete
} else {
[2568] Fix | Delete
return new WP_Error( 'term_exists', __( 'A term with the name provided already exists in this taxonomy.' ), $name_match->term_id );
[2569] Fix | Delete
}
[2570] Fix | Delete
}
[2571] Fix | Delete
}
[2572] Fix | Delete
[2573] Fix | Delete
$slug = wp_unique_term_slug( $slug, (object) $args );
[2574] Fix | Delete
[2575] Fix | Delete
$data = compact( 'name', 'slug', 'term_group' );
[2576] Fix | Delete
[2577] Fix | Delete
/**
[2578] Fix | Delete
* Filters term data before it is inserted into the database.
[2579] Fix | Delete
*
[2580] Fix | Delete
* @since 4.7.0
[2581] Fix | Delete
*
[2582] Fix | Delete
* @param array $data Term data to be inserted.
[2583] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2584] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2585] Fix | Delete
*/
[2586] Fix | Delete
$data = apply_filters( 'wp_insert_term_data', $data, $taxonomy, $args );
[2587] Fix | Delete
[2588] Fix | Delete
if ( false === $wpdb->insert( $wpdb->terms, $data ) ) {
[2589] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not insert term into the database.' ), $wpdb->last_error );
[2590] Fix | Delete
}
[2591] Fix | Delete
[2592] Fix | Delete
$term_id = (int) $wpdb->insert_id;
[2593] Fix | Delete
[2594] Fix | Delete
// Seems unreachable. However, is used in the case that a term name is provided, which sanitizes to an empty string.
[2595] Fix | Delete
if ( empty( $slug ) ) {
[2596] Fix | Delete
$slug = sanitize_title( $slug, $term_id );
[2597] Fix | Delete
[2598] Fix | Delete
/** This action is documented in wp-includes/taxonomy.php */
[2599] Fix | Delete
do_action( 'edit_terms', $term_id, $taxonomy );
[2600] Fix | Delete
$wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
[2601] Fix | Delete
[2602] Fix | Delete
/** This action is documented in wp-includes/taxonomy.php */
[2603] Fix | Delete
do_action( 'edited_terms', $term_id, $taxonomy );
[2604] Fix | Delete
}
[2605] Fix | Delete
[2606] Fix | Delete
$tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) );
[2607] Fix | Delete
[2608] Fix | Delete
if ( ! empty( $tt_id ) ) {
[2609] Fix | Delete
return array(
[2610] Fix | Delete
'term_id' => $term_id,
[2611] Fix | Delete
'term_taxonomy_id' => $tt_id,
[2612] Fix | Delete
);
[2613] Fix | Delete
}
[2614] Fix | Delete
[2615] Fix | Delete
if ( false === $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ) + array( 'count' => 0 ) ) ) {
[2616] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not insert term taxonomy into the database.' ), $wpdb->last_error );
[2617] Fix | Delete
}
[2618] Fix | Delete
[2619] Fix | Delete
$tt_id = (int) $wpdb->insert_id;
[2620] Fix | Delete
[2621] Fix | Delete
/*
[2622] Fix | Delete
* Confidence check: if we just created a term with the same parent + taxonomy + slug but a higher term_id than
[2623] Fix | Delete
* an existing term, then we have unwittingly created a duplicate term. Delete the dupe, and use the term_id
[2624] Fix | Delete
* and term_taxonomy_id of the older term instead. Then return out of the function so that the "create" hooks
[2625] Fix | Delete
* are not fired.
[2626] Fix | Delete
*/
[2627] Fix | Delete
$duplicate_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, t.slug, tt.term_taxonomy_id, tt.taxonomy FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON ( tt.term_id = t.term_id ) WHERE t.slug = %s AND tt.parent = %d AND tt.taxonomy = %s AND t.term_id < %d AND tt.term_taxonomy_id != %d", $slug, $parent, $taxonomy, $term_id, $tt_id ) );
[2628] Fix | Delete
[2629] Fix | Delete
/**
[2630] Fix | Delete
* Filters the duplicate term check that takes place during term creation.
[2631] Fix | Delete
*
[2632] Fix | Delete
* Term parent + taxonomy + slug combinations are meant to be unique, and wp_insert_term()
[2633] Fix | Delete
* performs a last-minute confirmation of this uniqueness before allowing a new term
[2634] Fix | Delete
* to be created. Plugins with different uniqueness requirements may use this filter
[2635] Fix | Delete
* to bypass or modify the duplicate-term check.
[2636] Fix | Delete
*
[2637] Fix | Delete
* @since 5.1.0
[2638] Fix | Delete
*
[2639] Fix | Delete
* @param object $duplicate_term Duplicate term row from terms table, if found.
[2640] Fix | Delete
* @param string $term Term being inserted.
[2641] Fix | Delete
* @param string $taxonomy Taxonomy name.
[2642] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2643] Fix | Delete
* @param int $tt_id term_taxonomy_id for the newly created term.
[2644] Fix | Delete
*/
[2645] Fix | Delete
$duplicate_term = apply_filters( 'wp_insert_term_duplicate_term_check', $duplicate_term, $term, $taxonomy, $args, $tt_id );
[2646] Fix | Delete
[2647] Fix | Delete
if ( $duplicate_term ) {
[2648] Fix | Delete
$wpdb->delete( $wpdb->terms, array( 'term_id' => $term_id ) );
[2649] Fix | Delete
$wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) );
[2650] Fix | Delete
[2651] Fix | Delete
$term_id = (int) $duplicate_term->term_id;
[2652] Fix | Delete
$tt_id = (int) $duplicate_term->term_taxonomy_id;
[2653] Fix | Delete
[2654] Fix | Delete
clean_term_cache( $term_id, $taxonomy );
[2655] Fix | Delete
return array(
[2656] Fix | Delete
'term_id' => $term_id,
[2657] Fix | Delete
'term_taxonomy_id' => $tt_id,
[2658] Fix | Delete
);
[2659] Fix | Delete
}
[2660] Fix | Delete
[2661] Fix | Delete
/**
[2662] Fix | Delete
* Fires immediately after a new term is created, before the term cache is cleaned.
[2663] Fix | Delete
*
[2664] Fix | Delete
* The {@see 'create_$taxonomy'} hook is also available for targeting a specific
[2665] Fix | Delete
* taxonomy.
[2666] Fix | Delete
*
[2667] Fix | Delete
* @since 2.3.0
[2668] Fix | Delete
* @since 6.1.0 The `$args` parameter was added.
[2669] Fix | Delete
*
[2670] Fix | Delete
* @param int $term_id Term ID.
[2671] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2672] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2673] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2674] Fix | Delete
*/
[2675] Fix | Delete
do_action( 'create_term', $term_id, $tt_id, $taxonomy, $args );
[2676] Fix | Delete
[2677] Fix | Delete
/**
[2678] Fix | Delete
* Fires after a new term is created for a specific taxonomy.
[2679] Fix | Delete
*
[2680] Fix | Delete
* The dynamic portion of the hook name, `$taxonomy`, refers
[2681] Fix | Delete
* to the slug of the taxonomy the term was created for.
[2682] Fix | Delete
*
[2683] Fix | Delete
* Possible hook names include:
[2684] Fix | Delete
*
[2685] Fix | Delete
* - `create_category`
[2686] Fix | Delete
* - `create_post_tag`
[2687] Fix | Delete
*
[2688] Fix | Delete
* @since 2.3.0
[2689] Fix | Delete
* @since 6.1.0 The `$args` parameter was added.
[2690] Fix | Delete
*
[2691] Fix | Delete
* @param int $term_id Term ID.
[2692] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2693] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2694] Fix | Delete
*/
[2695] Fix | Delete
do_action( "create_{$taxonomy}", $term_id, $tt_id, $args );
[2696] Fix | Delete
[2697] Fix | Delete
/**
[2698] Fix | Delete
* Filters the term ID after a new term is created.
[2699] Fix | Delete
*
[2700] Fix | Delete
* @since 2.3.0
[2701] Fix | Delete
* @since 6.1.0 The `$args` parameter was added.
[2702] Fix | Delete
*
[2703] Fix | Delete
* @param int $term_id Term ID.
[2704] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2705] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2706] Fix | Delete
*/
[2707] Fix | Delete
$term_id = apply_filters( 'term_id_filter', $term_id, $tt_id, $args );
[2708] Fix | Delete
[2709] Fix | Delete
clean_term_cache( $term_id, $taxonomy );
[2710] Fix | Delete
[2711] Fix | Delete
/**
[2712] Fix | Delete
* Fires after a new term is created, and after the term cache has been cleaned.
[2713] Fix | Delete
*
[2714] Fix | Delete
* The {@see 'created_$taxonomy'} hook is also available for targeting a specific
[2715] Fix | Delete
* taxonomy.
[2716] Fix | Delete
*
[2717] Fix | Delete
* @since 2.3.0
[2718] Fix | Delete
* @since 6.1.0 The `$args` parameter was added.
[2719] Fix | Delete
*
[2720] Fix | Delete
* @param int $term_id Term ID.
[2721] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2722] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2723] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2724] Fix | Delete
*/
[2725] Fix | Delete
do_action( 'created_term', $term_id, $tt_id, $taxonomy, $args );
[2726] Fix | Delete
[2727] Fix | Delete
/**
[2728] Fix | Delete
* Fires after a new term in a specific taxonomy is created, and after the term
[2729] Fix | Delete
* cache has been cleaned.
[2730] Fix | Delete
*
[2731] Fix | Delete
* The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
[2732] Fix | Delete
*
[2733] Fix | Delete
* Possible hook names include:
[2734] Fix | Delete
*
[2735] Fix | Delete
* - `created_category`
[2736] Fix | Delete
* - `created_post_tag`
[2737] Fix | Delete
*
[2738] Fix | Delete
* @since 2.3.0
[2739] Fix | Delete
* @since 6.1.0 The `$args` parameter was added.
[2740] Fix | Delete
*
[2741] Fix | Delete
* @param int $term_id Term ID.
[2742] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2743] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2744] Fix | Delete
*/
[2745] Fix | Delete
do_action( "created_{$taxonomy}", $term_id, $tt_id, $args );
[2746] Fix | Delete
[2747] Fix | Delete
/**
[2748] Fix | Delete
* Fires after a term has been saved, and the term cache has been cleared.
[2749] Fix | Delete
*
[2750] Fix | Delete
* The {@see 'saved_$taxonomy'} hook is also available for targeting a specific
[2751] Fix | Delete
* taxonomy.
[2752] Fix | Delete
*
[2753] Fix | Delete
* @since 5.5.0
[2754] Fix | Delete
* @since 6.1.0 The `$args` parameter was added.
[2755] Fix | Delete
*
[2756] Fix | Delete
* @param int $term_id Term ID.
[2757] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2758] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2759] Fix | Delete
* @param bool $update Whether this is an existing term being updated.
[2760] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2761] Fix | Delete
*/
[2762] Fix | Delete
do_action( 'saved_term', $term_id, $tt_id, $taxonomy, false, $args );
[2763] Fix | Delete
[2764] Fix | Delete
/**
[2765] Fix | Delete
* Fires after a term in a specific taxonomy has been saved, and the term
[2766] Fix | Delete
* cache has been cleared.
[2767] Fix | Delete
*
[2768] Fix | Delete
* The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
[2769] Fix | Delete
*
[2770] Fix | Delete
* Possible hook names include:
[2771] Fix | Delete
*
[2772] Fix | Delete
* - `saved_category`
[2773] Fix | Delete
* - `saved_post_tag`
[2774] Fix | Delete
*
[2775] Fix | Delete
* @since 5.5.0
[2776] Fix | Delete
* @since 6.1.0 The `$args` parameter was added.
[2777] Fix | Delete
*
[2778] Fix | Delete
* @param int $term_id Term ID.
[2779] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2780] Fix | Delete
* @param bool $update Whether this is an existing term being updated.
[2781] Fix | Delete
* @param array $args Arguments passed to wp_insert_term().
[2782] Fix | Delete
*/
[2783] Fix | Delete
do_action( "saved_{$taxonomy}", $term_id, $tt_id, false, $args );
[2784] Fix | Delete
[2785] Fix | Delete
return array(
[2786] Fix | Delete
'term_id' => $term_id,
[2787] Fix | Delete
'term_taxonomy_id' => $tt_id,
[2788] Fix | Delete
);
[2789] Fix | Delete
}
[2790] Fix | Delete
[2791] Fix | Delete
/**
[2792] Fix | Delete
* Creates term and taxonomy relationships.
[2793] Fix | Delete
*
[2794] Fix | Delete
* Relates an object (post, link, etc.) to a term and taxonomy type. Creates the
[2795] Fix | Delete
* term and taxonomy relationship if it doesn't already exist. Creates a term if
[2796] Fix | Delete
* it doesn't exist (using the slug).
[2797] Fix | Delete
*
[2798] Fix | Delete
* A relationship means that the term is grouped in or belongs to the taxonomy.
[2799] Fix | Delete
* A term has no meaning until it is given context by defining which taxonomy it
[2800] Fix | Delete
* exists under.
[2801] Fix | Delete
*
[2802] Fix | Delete
* @since 2.3.0
[2803] Fix | Delete
*
[2804] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[2805] Fix | Delete
*
[2806] Fix | Delete
* @param int $object_id The object to relate to.
[2807] Fix | Delete
* @param string|int|array $terms A single term slug, single term ID, or array of either term slugs or IDs.
[2808] Fix | Delete
* Will replace all existing related terms in this taxonomy. Passing an
[2809] Fix | Delete
* empty array will remove all related terms.
[2810] Fix | Delete
* @param string $taxonomy The context in which to relate the term to the object.
[2811] Fix | Delete
* @param bool $append Optional. If false will delete difference of terms. Default false.
[2812] Fix | Delete
* @return array|WP_Error Term taxonomy IDs of the affected terms or WP_Error on failure.
[2813] Fix | Delete
*/
[2814] Fix | Delete
function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) {
[2815] Fix | Delete
global $wpdb;
[2816] Fix | Delete
[2817] Fix | Delete
$object_id = (int) $object_id;
[2818] Fix | Delete
[2819] Fix | Delete
if ( ! taxonomy_exists( $taxonomy ) ) {
[2820] Fix | Delete
return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
[2821] Fix | Delete
}
[2822] Fix | Delete
[2823] Fix | Delete
if ( empty( $terms ) ) {
[2824] Fix | Delete
$terms = array();
[2825] Fix | Delete
} elseif ( ! is_array( $terms ) ) {
[2826] Fix | Delete
$terms = array( $terms );
[2827] Fix | Delete
}
[2828] Fix | Delete
[2829] Fix | Delete
if ( ! $append ) {
[2830] Fix | Delete
$old_tt_ids = wp_get_object_terms(
[2831] Fix | Delete
$object_id,
[2832] Fix | Delete
$taxonomy,
[2833] Fix | Delete
array(
[2834] Fix | Delete
'fields' => 'tt_ids',
[2835] Fix | Delete
'orderby' => 'none',
[2836] Fix | Delete
'update_term_meta_cache' => false,
[2837] Fix | Delete
)
[2838] Fix | Delete
);
[2839] Fix | Delete
} else {
[2840] Fix | Delete
$old_tt_ids = array();
[2841] Fix | Delete
}
[2842] Fix | Delete
[2843] Fix | Delete
$tt_ids = array();
[2844] Fix | Delete
$new_tt_ids = array();
[2845] Fix | Delete
[2846] Fix | Delete
foreach ( (array) $terms as $term ) {
[2847] Fix | Delete
if ( '' === trim( $term ) ) {
[2848] Fix | Delete
continue;
[2849] Fix | Delete
}
[2850] Fix | Delete
[2851] Fix | Delete
$term_info = term_exists( $term, $taxonomy );
[2852] Fix | Delete
[2853] Fix | Delete
if ( ! $term_info ) {
[2854] Fix | Delete
// Skip if a non-existent term ID is passed.
[2855] Fix | Delete
if ( is_int( $term ) ) {
[2856] Fix | Delete
continue;
[2857] Fix | Delete
}
[2858] Fix | Delete
[2859] Fix | Delete
$term_info = wp_insert_term( $term, $taxonomy );
[2860] Fix | Delete
}
[2861] Fix | Delete
[2862] Fix | Delete
if ( is_wp_error( $term_info ) ) {
[2863] Fix | Delete
return $term_info;
[2864] Fix | Delete
}
[2865] Fix | Delete
[2866] Fix | Delete
$tt_id = $term_info['term_taxonomy_id'];
[2867] Fix | Delete
$tt_ids[] = $tt_id;
[2868] Fix | Delete
[2869] Fix | Delete
if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) ) {
[2870] Fix | Delete
continue;
[2871] Fix | Delete
}
[2872] Fix | Delete
[2873] Fix | Delete
/**
[2874] Fix | Delete
* Fires immediately before an object-term relationship is added.
[2875] Fix | Delete
*
[2876] Fix | Delete
* @since 2.9.0
[2877] Fix | Delete
* @since 4.7.0 Added the `$taxonomy` parameter.
[2878] Fix | Delete
*
[2879] Fix | Delete
* @param int $object_id Object ID.
[2880] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2881] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2882] Fix | Delete
*/
[2883] Fix | Delete
do_action( 'add_term_relationship', $object_id, $tt_id, $taxonomy );
[2884] Fix | Delete
[2885] Fix | Delete
$wpdb->insert(
[2886] Fix | Delete
$wpdb->term_relationships,
[2887] Fix | Delete
array(
[2888] Fix | Delete
'object_id' => $object_id,
[2889] Fix | Delete
'term_taxonomy_id' => $tt_id,
[2890] Fix | Delete
)
[2891] Fix | Delete
);
[2892] Fix | Delete
[2893] Fix | Delete
/**
[2894] Fix | Delete
* Fires immediately after an object-term relationship is added.
[2895] Fix | Delete
*
[2896] Fix | Delete
* @since 2.9.0
[2897] Fix | Delete
* @since 4.7.0 Added the `$taxonomy` parameter.
[2898] Fix | Delete
*
[2899] Fix | Delete
* @param int $object_id Object ID.
[2900] Fix | Delete
* @param int $tt_id Term taxonomy ID.
[2901] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2902] Fix | Delete
*/
[2903] Fix | Delete
do_action( 'added_term_relationship', $object_id, $tt_id, $taxonomy );
[2904] Fix | Delete
[2905] Fix | Delete
$new_tt_ids[] = $tt_id;
[2906] Fix | Delete
}
[2907] Fix | Delete
[2908] Fix | Delete
if ( $new_tt_ids ) {
[2909] Fix | Delete
wp_update_term_count( $new_tt_ids, $taxonomy );
[2910] Fix | Delete
}
[2911] Fix | Delete
[2912] Fix | Delete
if ( ! $append ) {
[2913] Fix | Delete
$delete_tt_ids = array_diff( $old_tt_ids, $tt_ids );
[2914] Fix | Delete
[2915] Fix | Delete
if ( $delete_tt_ids ) {
[2916] Fix | Delete
$in_delete_tt_ids = "'" . implode( "', '", $delete_tt_ids ) . "'";
[2917] Fix | Delete
$delete_term_ids = $wpdb->get_col( $wpdb->prepare( "SELECT tt.term_id FROM $wpdb->term_taxonomy AS tt WHERE tt.taxonomy = %s AND tt.term_taxonomy_id IN ($in_delete_tt_ids)", $taxonomy ) );
[2918] Fix | Delete
$delete_term_ids = array_map( 'intval', $delete_term_ids );
[2919] Fix | Delete
[2920] Fix | Delete
$remove = wp_remove_object_terms( $object_id, $delete_term_ids, $taxonomy );
[2921] Fix | Delete
if ( is_wp_error( $remove ) ) {
[2922] Fix | Delete
return $remove;
[2923] Fix | Delete
}
[2924] Fix | Delete
}
[2925] Fix | Delete
}
[2926] Fix | Delete
[2927] Fix | Delete
$t = get_taxonomy( $taxonomy );
[2928] Fix | Delete
[2929] Fix | Delete
if ( ! $append && isset( $t->sort ) && $t->sort ) {
[2930] Fix | Delete
$values = array();
[2931] Fix | Delete
$term_order = 0;
[2932] Fix | Delete
[2933] Fix | Delete
$final_tt_ids = wp_get_object_terms(
[2934] Fix | Delete
$object_id,
[2935] Fix | Delete
$taxonomy,
[2936] Fix | Delete
array(
[2937] Fix | Delete
'fields' => 'tt_ids',
[2938] Fix | Delete
'update_term_meta_cache' => false,
[2939] Fix | Delete
)
[2940] Fix | Delete
);
[2941] Fix | Delete
[2942] Fix | Delete
foreach ( $tt_ids as $tt_id ) {
[2943] Fix | Delete
if ( in_array( (int) $tt_id, $final_tt_ids, true ) ) {
[2944] Fix | Delete
$values[] = $wpdb->prepare( '(%d, %d, %d)', $object_id, $tt_id, ++$term_order );
[2945] Fix | Delete
}
[2946] Fix | Delete
}
[2947] Fix | Delete
[2948] Fix | Delete
if ( $values ) {
[2949] Fix | Delete
if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . implode( ',', $values ) . ' ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)' ) ) {
[2950] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database.' ), $wpdb->last_error );
[2951] Fix | Delete
}
[2952] Fix | Delete
}
[2953] Fix | Delete
}
[2954] Fix | Delete
[2955] Fix | Delete
wp_cache_delete( $object_id, $taxonomy . '_relationships' );
[2956] Fix | Delete
wp_cache_set_terms_last_changed();
[2957] Fix | Delete
[2958] Fix | Delete
/**
[2959] Fix | Delete
* Fires after an object's terms have been set.
[2960] Fix | Delete
*
[2961] Fix | Delete
* @since 2.8.0
[2962] Fix | Delete
*
[2963] Fix | Delete
* @param int $object_id Object ID.
[2964] Fix | Delete
* @param array $terms An array of object term IDs or slugs.
[2965] Fix | Delete
* @param array $tt_ids An array of term taxonomy IDs.
[2966] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[2967] Fix | Delete
* @param bool $append Whether to append new terms to the old terms.
[2968] Fix | Delete
* @param array $old_tt_ids Old array of term taxonomy IDs.
[2969] Fix | Delete
*/
[2970] Fix | Delete
do_action( 'set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids );
[2971] Fix | Delete
[2972] Fix | Delete
return $tt_ids;
[2973] Fix | Delete
}
[2974] Fix | Delete
[2975] Fix | Delete
/**
[2976] Fix | Delete
* Adds term(s) associated with a given object.
[2977] Fix | Delete
*
[2978] Fix | Delete
* @since 3.6.0
[2979] Fix | Delete
*
[2980] Fix | Delete
* @param int $object_id The ID of the object to which the terms will be added.
[2981] Fix | Delete
* @param string|int|array $terms The slug(s) or ID(s) of the term(s) to add.
[2982] Fix | Delete
* @param array|string $taxonomy Taxonomy name.
[2983] Fix | Delete
* @return array|WP_Error Term taxonomy IDs of the affected terms.
[2984] Fix | Delete
*/
[2985] Fix | Delete
function wp_add_object_terms( $object_id, $terms, $taxonomy ) {
[2986] Fix | Delete
return wp_set_object_terms( $object_id, $terms, $taxonomy, true );
[2987] Fix | Delete
}
[2988] Fix | Delete
[2989] Fix | Delete
/**
[2990] Fix | Delete
* Removes term(s) associated with a given object.
[2991] Fix | Delete
*
[2992] Fix | Delete
* @since 3.6.0
[2993] Fix | Delete
*
[2994] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[2995] Fix | Delete
*
[2996] Fix | Delete
* @param int $object_id The ID of the object from which the terms will be removed.
[2997] Fix | Delete
* @param string|int|array $terms The slug(s) or ID(s) of the term(s) to remove.
[2998] Fix | Delete
* @param string $taxonomy Taxonomy name.
[2999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function