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.
Built from https://develop.svn.wordpress.org/trunk@38484


git-svn-id: http://core.svn.wordpress.org/trunk@38425 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2016-08-31 21:41:27 +00:00
parent c451e71d42
commit a4f8854a46
2 changed files with 31 additions and 3 deletions

View File

@ -2340,7 +2340,20 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) {
$slug = wp_unique_term_slug( $slug, (object) $args );
if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) {
$data = compact( 'name', 'slug', 'term_group' );
/**
* Filters term data before it is inserted into the database.
*
* @since 4.7.0
*
* @param array $data Term data to be inserted.
* @param string $taxonomy Taxonomy slug.
* @param array $args Arguments passed to wp_insert_term().
*/
$data = apply_filters( 'wp_insert_term_data', $data, $taxonomy, $args );
if ( false === $wpdb->insert( $wpdb->terms, $data ) ) {
return new WP_Error( 'db_insert_error', __( 'Could not insert term into the database' ), $wpdb->last_error );
}
@ -2927,7 +2940,22 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) {
* @param string $taxonomy Taxonomy slug.
*/
do_action( 'edit_terms', $term_id, $taxonomy );
$wpdb->update($wpdb->terms, compact( 'name', 'slug', 'term_group' ), compact( 'term_id' ) );
$data = compact( 'name', 'slug', 'term_group' );
/**
* Filters term data before it is updated in the database.
*
* @since 4.7.0
*
* @param array $data Term data to be updated.
* @param int $term_id Term ID.
* @param string $taxonomy Taxonomy slug.
* @param array $args Arguments passed to wp_update_term().
*/
$data = apply_filters( 'wp_update_term_data', $data, $term_id, $taxonomy, $args );
$wpdb->update( $wpdb->terms, $data, compact( 'term_id' ) );
if ( empty($slug) ) {
$slug = sanitize_title($name, $term_id);
$wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38483';
$wp_version = '4.7-alpha-38484';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.