wpsc_admin_bar_render()WPSCache 1.0

Adds "Delete Cache" button in WP Toolbar.

Хуков нет.

Возвращает

null. Ничего (null).

Использование

wpsc_admin_bar_render( $wp_admin_bar );
$wp_admin_bar (обязательный)
-

Код wpsc_admin_bar_render() WPSCache 1.12.0

function wpsc_admin_bar_render( $wp_admin_bar ) {

	if ( ! function_exists( 'current_user_can' ) || ! is_user_logged_in() ) {
		return false;
	}

	$path_to_home = rtrim( (string) parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' );
	if ( ( is_singular() || is_archive() || is_front_page() || is_search() ) && current_user_can(  'delete_others_posts' ) ) {

		$site_regex = preg_quote( $path_to_home, '`' );
		$req_uri    = preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] );
		$path       = preg_replace( '`^' . $site_regex . '`', '', $req_uri );

		$wp_admin_bar->add_menu( array(
					'parent' => '',
					'id' => 'delete-cache',
					'title' => __( 'Delete Cache', 'wp-super-cache' ),
					'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
					'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . rawurlencode( $path ) ), 'delete-cache-' . $path . '_0', 'nonce' )
					) );
	}

	if ( is_admin() && ( wpsupercache_site_admin() || current_user_can( 'delete_others_posts' ) ) ) {
		$wp_admin_bar->add_menu( array(
					'parent' => '',
					'id' => 'delete-cache',
					'title' => __( 'Delete Cache', 'wp-super-cache' ),
					'meta' => array( 'title' => __( 'Delete Super Cache cached files', 'wp-super-cache' ) ),
					'href' => wp_nonce_url( admin_url( 'index.php?admin=1&action=delcachepage&path=' . rawurlencode( trailingslashit( $path_to_home ) ) ), 'delete-cache-' . trailingslashit( $path_to_home ) . '_1', 'nonce'  )
					) );
	}
}