wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_random_content_flush_rewrite_rules_for_post › WordPress Function

Since7.2.0
Deprecatedn/a
› wp_random_content_flush_rewrite_rules_for_post ( $post_id, $post, $update = false, $post_before = null )
Parameters: (4)
  • (int) $post_id Post ID.
    Required: Yes
  • (WP_Post) $post Post object.
    Required: Yes
  • (bool) $update Optional. Whether this is an existing post being updated. Default false.
    Required: No
    Default: false
  • (WP_Post|null) $post_before Optional. Post object before the update, null for new posts. Default null.
    Required: No
    Default: null
See:
  • WP_Rewrite::random_rewrite_rules()
Defined at:
Codex:

Flushes the rewrite rules when a page or post at the random content base changes.

A published page at the random base, for example example.com/random/, takes precedence over random content redirects. So does a published post when the permalink structure places posts at the same URL, for example /%postname%/, see WP_Rewrite::post_permalinks_share_random_base. As the rewrite rules account for the page or post, they need to be regenerated when it is published, unpublished, renamed, moved or deleted. Runs on the {@see 'wp_after_insert_post'} and {@see 'after_delete_post'} actions.


Source

function wp_random_content_flush_rewrite_rules_for_post( int $post_id, WP_Post $post, bool $update = false, ?WP_Post $post_before = null ): void {
	global $wp_rewrite;

	if ( ! $wp_rewrite->using_permalinks() || ! wp_is_random_content_redirect_enabled() ) {
		return;
	}

	foreach ( array( $post, $post_before ) as $page ) {
		if (
			$page instanceof WP_Post
			&& $wp_rewrite->get_random_base() === $page->post_name
			&& (
				( 'page' === $page->post_type && 0 === (int) $page->post_parent )
				|| ( 'post' === $page->post_type && $wp_rewrite->post_permalinks_share_random_base() )
			)
		) {
			flush_rewrite_rules( false );
			return;
		}
	}
}