wp_get_theme_preview_path

函数
wp_get_theme_preview_path ( $current_stylesheet = null )
参数
  • (string) $current_stylesheet The current theme's stylesheet or template path.
    Required:
    Default: null
返回值
  • (string) The previewed theme's stylesheet or template path.
定义位置
相关方法
get_theme_file_path_wp_get_attachment_relative_pathwp_initialize_theme_preview_hookswp_attach_theme_preview_middlewareget_parent_theme_file_path
引入
6.3.0
弃用
-

过滤博客选项,返回预览主题的路径。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_get_theme_preview_path( $current_stylesheet = null ) {
if ( ! current_user_can( 'switch_themes' ) ) {
return $current_stylesheet;
}
$preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) : null;
$wp_theme = wp_get_theme( $preview_stylesheet );
if ( ! is_wp_error( $wp_theme->errors() ) ) {
if ( current_filter() === 'template' ) {
$theme_path = $wp_theme->get_template();
} else {
$theme_path = $wp_theme->get_stylesheet();
}
return sanitize_text_field( $theme_path );
}
return $current_stylesheet;
}
function wp_get_theme_preview_path( $current_stylesheet = null ) { if ( ! current_user_can( 'switch_themes' ) ) { return $current_stylesheet; } $preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) : null; $wp_theme = wp_get_theme( $preview_stylesheet ); if ( ! is_wp_error( $wp_theme->errors() ) ) { if ( current_filter() === 'template' ) { $theme_path = $wp_theme->get_template(); } else { $theme_path = $wp_theme->get_stylesheet(); } return sanitize_text_field( $theme_path ); } return $current_stylesheet; }
function wp_get_theme_preview_path( $current_stylesheet = null ) {
	if ( ! current_user_can( 'switch_themes' ) ) {
		return $current_stylesheet;
	}

	$preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) : null;
	$wp_theme           = wp_get_theme( $preview_stylesheet );
	if ( ! is_wp_error( $wp_theme->errors() ) ) {
		if ( current_filter() === 'template' ) {
			$theme_path = $wp_theme->get_template();
		} else {
			$theme_path = $wp_theme->get_stylesheet();
		}

		return sanitize_text_field( $theme_path );
	}

	return $current_stylesheet;
}

常见问题

FAQs
查看更多 >