wp_check_widget_editor_deps

函式
wp_check_widget_editor_deps ( No parameters )

wp_check_widget_editor_deps: 這是一個檢查WordPress小工具編輯器所需依賴性的函式。它可以用來確保在使用小工具編輯器時,所有必要的指令碼和樣式都被載入。

顯示一個_doing_it_wrong()的資訊,用於衝突的小工具編輯器指令碼。

wp-editor”指令碼模組被暴露為window.wp.editor。這覆蓋了傳統的TinyMCE編輯器模組,它是小工具編輯器所需要的。因為這個衝突,這兩者不應該被排在一起。見https://core.trac.wordpress.org/ticket/53569。

還有一個與樣式有關的衝突,如果一個區塊引用了”wp-edit-post”樣式表,那麼區塊小工具編輯器就會被隱藏。見https://core.trac.wordpress.org/ticket/53569。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_check_widget_editor_deps() {
global $wp_scripts, $wp_styles;
if (
$wp_scripts->query( 'wp-edit-widgets', 'enqueued' ) ||
$wp_scripts->query( 'wp-customize-widgets', 'enqueued' )
) {
if ( $wp_scripts->query( 'wp-editor', 'enqueued' ) ) {
_doing_it_wrong(
'wp_enqueue_script()',
sprintf(
/* translators: 1: 'wp-editor', 2: 'wp-edit-widgets', 3: 'wp-customize-widgets'. */
__( '"%1$s" script should not be enqueued together with the new widgets editor (%2$s or %3$s).' ),
'wp-editor',
'wp-edit-widgets',
'wp-customize-widgets'
),
'5.8.0'
);
}
if ( $wp_styles->query( 'wp-edit-post', 'enqueued' ) ) {
_doing_it_wrong(
'wp_enqueue_style()',
sprintf(
/* translators: 1: 'wp-edit-post', 2: 'wp-edit-widgets', 3: 'wp-customize-widgets'. */
__( '"%1$s" style should not be enqueued together with the new widgets editor (%2$s or %3$s).' ),
'wp-edit-post',
'wp-edit-widgets',
'wp-customize-widgets'
),
'5.8.0'
);
}
}
}
function wp_check_widget_editor_deps() { global $wp_scripts, $wp_styles; if ( $wp_scripts->query( 'wp-edit-widgets', 'enqueued' ) || $wp_scripts->query( 'wp-customize-widgets', 'enqueued' ) ) { if ( $wp_scripts->query( 'wp-editor', 'enqueued' ) ) { _doing_it_wrong( 'wp_enqueue_script()', sprintf( /* translators: 1: 'wp-editor', 2: 'wp-edit-widgets', 3: 'wp-customize-widgets'. */ __( '"%1$s" script should not be enqueued together with the new widgets editor (%2$s or %3$s).' ), 'wp-editor', 'wp-edit-widgets', 'wp-customize-widgets' ), '5.8.0' ); } if ( $wp_styles->query( 'wp-edit-post', 'enqueued' ) ) { _doing_it_wrong( 'wp_enqueue_style()', sprintf( /* translators: 1: 'wp-edit-post', 2: 'wp-edit-widgets', 3: 'wp-customize-widgets'. */ __( '"%1$s" style should not be enqueued together with the new widgets editor (%2$s or %3$s).' ), 'wp-edit-post', 'wp-edit-widgets', 'wp-customize-widgets' ), '5.8.0' ); } } }
function wp_check_widget_editor_deps() {
	global $wp_scripts, $wp_styles;

	if (
		$wp_scripts->query( 'wp-edit-widgets', 'enqueued' ) ||
		$wp_scripts->query( 'wp-customize-widgets', 'enqueued' )
	) {
		if ( $wp_scripts->query( 'wp-editor', 'enqueued' ) ) {
			_doing_it_wrong(
				'wp_enqueue_script()',
				sprintf(
					/* translators: 1: 'wp-editor', 2: 'wp-edit-widgets', 3: 'wp-customize-widgets'. */
					__( '"%1$s" script should not be enqueued together with the new widgets editor (%2$s or %3$s).' ),
					'wp-editor',
					'wp-edit-widgets',
					'wp-customize-widgets'
				),
				'5.8.0'
			);
		}
		if ( $wp_styles->query( 'wp-edit-post', 'enqueued' ) ) {
			_doing_it_wrong(
				'wp_enqueue_style()',
				sprintf(
					/* translators: 1: 'wp-edit-post', 2: 'wp-edit-widgets', 3: 'wp-customize-widgets'. */
					__( '"%1$s" style should not be enqueued together with the new widgets editor (%2$s or %3$s).' ),
					'wp-edit-post',
					'wp-edit-widgets',
					'wp-customize-widgets'
				),
				'5.8.0'
			);
		}
	}
}

常見問題

FAQs
檢視更多 >