web-dev-qa-db-ja.com

スクリプト内のハイフンとピリオドは、wp_register_scriptに含まれていますか。

wp_register_scriptwp_enqueue_scriptには、2つの異なる方法でスクリプトとスタイルのハンドルが書かれています(同じことがwp_register_stylewp_enqueue_styleにも当てはまります)。

  1. wp_register_script( 'jquery-someplugin', $location );
  2. wp_register_script( 'jquery.someplugin', $location );

#1はハイフンを使い、#2はピリオドを使います。ここでのベストプラクティスは何ですか?

どちらを使うべきですか?

4
supertrue

ハイフンのみを使用してください。

wp-includes/script-loader.phpを見てください。

$scripts->add( 'scriptaculous-sound', '/wp-in
$scripts->add( 'scriptaculous-controls', '/wp
$scripts->add( 'scriptaculous', '', array('sc

// not used in core, replaced by Jcrop.js
$scripts->add( 'cropper', '/wp-includes/js/cr

$scripts->add( 'jquery', '/wp-includes/js/jqu

// full jQuery UI
$scripts->add( 'jquery-ui-core', '/wp-include
$scripts->add( 'jquery-effects-core', '/wp-in

$scripts->add( 'jquery-effects-blind', '/wp-i
$scripts->add( 'jquery-effects-bounce', '/wp-
$scripts->add( 'jquery-effects-clip', '/wp-in
$scripts->add( 'jquery-effects-drop', '/wp-in
$scripts->add( 'jquery-effects-explode', '/wp
$scripts->add( 'jquery-effects-fade', '/wp-in
$scripts->add( 'jquery-effects-fold', '/wp-in
$scripts->add( 'jquery-effects-highlight', '/
$scripts->add( 'jquery-effects-pulsate', '/wp
$scripts->add( 'jquery-effects-scale', '/wp-i
$scripts->add( 'jquery-effects-shake', '/wp-i
$scripts->add( 'jquery-effects-slide', '/wp-i
$scripts->add( 'jquery-effects-transfer', '/w

$scripts->add( 'jquery-ui-accordion', '/wp-in
$scripts->add( 'jquery-ui-autocomplete', '/wp

はい、長方形をコピーしました。 :)

非公式の命名規則は、最初にメインライブラリ、次にpackage、そしてsub-packageの順で、すべてハイフンで区切られています。

もしあなたがこのスキームに従えば - そして他の開発者も同様です! - 同じライブラリを別のプラグインとして別の名前でエンキューするリスクを低くします。

残念ながら、コアであっても例外を見つけることができます:'suggest''schedule'はjQueryを使っています…

5
fuxia