Skip to content

Commit

Permalink
More triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Dec 11, 2024
1 parent 6c89dcf commit a653465
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
4 changes: 4 additions & 0 deletions src/wp-admin/includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@ function wp_delete_user( $id, $reassign = null ) {

clean_user_cache( $user );

foreach( get_post_types() as $post_type ) {

Check failure on line 448 in src/wp-admin/includes/user.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Space after opening control structure is required

Check failure on line 448 in src/wp-admin/includes/user.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

No space before opening parenthesis is prohibited

Check failure on line 448 in src/wp-admin/includes/user.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 space after FOREACH keyword; 0 found
clear_user_posts_count_cache( $user->ID, $post_type );
}

/**
* Fires immediately after a user is deleted from the site.
*
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
}

// User post counts.
add_action( 'attachment_updated', '_clear_user_posts_count_cache_on_author_change', 10, 3 );
add_action( 'post_updated', '_clear_user_posts_count_cache_on_author_change', 10, 3 );
add_action( 'save_post', '_clear_user_posts_count_cache_on_update', 10, 2 );

// Post meta.
add_action( 'added_post_meta', 'wp_cache_set_posts_last_changed' );
Expand Down
6 changes: 6 additions & 0 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -3819,6 +3819,8 @@ function wp_delete_post( $post_id = 0, $force_delete = false ) {
}
}

clear_user_posts_count_cache( $post->post_author, $post->post_type );

wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) );

/**
Expand Down Expand Up @@ -5070,6 +5072,8 @@ function wp_insert_post( $postarr, $wp_error = false, $fire_after_hooks = true )
*/
do_action( 'wp_insert_post', $post_id, $post, $update );

clear_user_posts_count_cache( $post->post_author, $post_type );

if ( $fire_after_hooks ) {
wp_after_insert_post( $post, $update, $post_before );
}
Expand Down Expand Up @@ -5236,6 +5240,8 @@ function wp_publish_post( $post ) {
/** This action is documented in wp-includes/post.php */
do_action( 'wp_insert_post', $post->ID, $post, true );

clear_user_posts_count_cache( $post->post_author, $post->post_type );

wp_after_insert_post( $post, true, $post_before );
}

Expand Down
21 changes: 0 additions & 21 deletions src/wp-includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,27 +635,6 @@ function _clear_user_posts_count_cache_on_author_change( $post_id, $post_after,
}
}

/**
* When the post is created, clear the cache.
*
* @since 6.8.0
* @access private
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
function _clear_user_posts_count_cache_on_update( $post_id, $post ) {
// Don't do anything if revision is being saved.
if ( wp_is_post_revision( $post_id ) ) {
return;
}

$post_type = $post->post_type;
$author_id = $post->post_author;

clear_user_posts_count_cache( $author_id, $post_type );
}

/**
* Gets the number of posts a user has written.
*
Expand Down

0 comments on commit a653465

Please sign in to comment.