WordPress.org

Make WordPress Core

Changeset 38484


Ignore:
Timestamp:
08/31/2016 09:40:18 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Taxonomy: Introduce wp_insert_term_data and wp_update_term_data filters for altering term data before it is inserted/updated in the database.

Props atimmer, SergeyBiryukov.
Fixes #22293.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r38307 r38484  
    23412341    $slug = wp_unique_term_slug( $slug, (object) $args );
    23422342
    2343     if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) {
     2343    $data = compact( 'name', 'slug', 'term_group' );
     2344
     2345    /**
     2346     * Filters term data before it is inserted into the database.
     2347     *
     2348     * @since 4.7.0
     2349     *
     2350     * @param array  $data     Term data to be inserted.
     2351     * @param string $taxonomy Taxonomy slug.
     2352     * @param array  $args     Arguments passed to wp_insert_term().
     2353     */
     2354    $data = apply_filters( 'wp_insert_term_data', $data, $taxonomy, $args );
     2355
     2356    if ( false === $wpdb->insert( $wpdb->terms, $data ) ) {
    23442357        return new WP_Error( 'db_insert_error', __( 'Could not insert term into the database' ), $wpdb->last_error );
    23452358    }
     
    29282941     */
    29292942    do_action( 'edit_terms', $term_id, $taxonomy );
    2930     $wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );
     2943
     2944    $data = compact( 'name', 'slug', 'term_group' );
     2945
     2946    /**
     2947     * Filters term data before it is updated in the database.
     2948     *
     2949     * @since 4.7.0
     2950     *
     2951     * @param array  $data     Term data to be updated.
     2952     * @param int    $term_id  Term ID.
     2953     * @param string $taxonomy Taxonomy slug.
     2954     * @param array  $args     Arguments passed to wp_update_term().
     2955     */
     2956    $data = apply_filters( 'wp_update_term_data', $data, $term_id, $taxonomy, $args );
     2957
     2958    $wpdb->update( $wpdb->terms, $data, compact( 'term_id' ) );
    29312959    if ( empty($slug) ) {
    29322960        $slug = sanitize_title($name, $term_id);
Note: See TracChangeset for help on using the changeset viewer.