@@ -5,46 +5,46 @@ |
||
| 5 | 5 | |
| 6 | 6 | interface Register extends HasActions { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * Provides a method to register new scripts outside of the constructor. |
|
| 10 | - * |
|
| 11 | - * @param array $script |
|
| 12 | - */ |
|
| 13 | - public function register_script( $script ); |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * Provides a method to register new styles outside of the constructor. |
|
| 17 | - * |
|
| 18 | - * @param array $style |
|
| 19 | - */ |
|
| 20 | - public function register_style( $style ); |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Enqueues the web & shared scripts on the Register. |
|
| 24 | - */ |
|
| 25 | - public function enqueue_web_scripts(); |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Enqueues the web & shared styles on the Register. |
|
| 29 | - */ |
|
| 30 | - public function enqueue_web_styles(); |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Enqueues the admin & shared scripts on the Register. |
|
| 34 | - * |
|
| 35 | - * @param string $hook Passes a string representing the current page. |
|
| 36 | - */ |
|
| 37 | - public function enqueue_admin_scripts( $hook ); |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Enqueues the admin & shared styles on the Register. |
|
| 41 | - * |
|
| 42 | - * @param string $hook Passes a string representing the current page. |
|
| 43 | - */ |
|
| 44 | - public function enqueue_admin_styles( $hook ); |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Enqueues the block styles & registers the block. |
|
| 48 | - */ |
|
| 49 | - public function register_blocks(); |
|
| 8 | + /** |
|
| 9 | + * Provides a method to register new scripts outside of the constructor. |
|
| 10 | + * |
|
| 11 | + * @param array $script |
|
| 12 | + */ |
|
| 13 | + public function register_script( $script ); |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * Provides a method to register new styles outside of the constructor. |
|
| 17 | + * |
|
| 18 | + * @param array $style |
|
| 19 | + */ |
|
| 20 | + public function register_style( $style ); |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Enqueues the web & shared scripts on the Register. |
|
| 24 | + */ |
|
| 25 | + public function enqueue_web_scripts(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Enqueues the web & shared styles on the Register. |
|
| 29 | + */ |
|
| 30 | + public function enqueue_web_styles(); |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Enqueues the admin & shared scripts on the Register. |
|
| 34 | + * |
|
| 35 | + * @param string $hook Passes a string representing the current page. |
|
| 36 | + */ |
|
| 37 | + public function enqueue_admin_scripts( $hook ); |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Enqueues the admin & shared styles on the Register. |
|
| 41 | + * |
|
| 42 | + * @param string $hook Passes a string representing the current page. |
|
| 43 | + */ |
|
| 44 | + public function enqueue_admin_styles( $hook ); |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Enqueues the block styles & registers the block. |
|
| 48 | + */ |
|
| 49 | + public function register_blocks(); |
|
| 50 | 50 | } |
@@ -10,14 +10,14 @@ discard block |
||
| 10 | 10 | * |
| 11 | 11 | * @param array $script |
| 12 | 12 | */ |
| 13 | - public function register_script( $script ); |
|
| 13 | + public function register_script($script); |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Provides a method to register new styles outside of the constructor. |
| 17 | 17 | * |
| 18 | 18 | * @param array $style |
| 19 | 19 | */ |
| 20 | - public function register_style( $style ); |
|
| 20 | + public function register_style($style); |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Enqueues the web & shared scripts on the Register. |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param string $hook Passes a string representing the current page. |
| 36 | 36 | */ |
| 37 | - public function enqueue_admin_scripts( $hook ); |
|
| 37 | + public function enqueue_admin_scripts($hook); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Enqueues the admin & shared styles on the Register. |
| 41 | 41 | * |
| 42 | 42 | * @param string $hook Passes a string representing the current page. |
| 43 | 43 | */ |
| 44 | - public function enqueue_admin_styles( $hook ); |
|
| 44 | + public function enqueue_admin_styles($hook); |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Enqueues the block styles & registers the block. |
@@ -12,252 +12,252 @@ |
||
| 12 | 12 | * @subpackage Register |
| 13 | 13 | */ |
| 14 | 14 | class Register implements RegisterContract { |
| 15 | - /** |
|
| 16 | - * Url to the plugin directory. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $url; |
|
| 15 | + /** |
|
| 16 | + * Url to the plugin directory. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $url; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Script/plugin version. |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $version; |
|
| 22 | + /** |
|
| 23 | + * Script/plugin version. |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $version; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Array of script definition arrays. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - private $scripts = array(); |
|
| 29 | + /** |
|
| 30 | + * Array of script definition arrays. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + private $scripts = array(); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Array of style definition arrays. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 41 | - private $styles = array(); |
|
| 36 | + /** |
|
| 37 | + * Array of style definition arrays. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | + private $styles = array(); |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Instantiates a new instance of the Register class. |
|
| 45 | - * |
|
| 46 | - * The URL param should be relative to the plugin directory. The URL |
|
| 47 | - * form should always end with a '/'. All asset location definitions |
|
| 48 | - * should not begin with a slash and should be relative to the plugin's |
|
| 49 | - * root directory. The URL provided by default from the Application |
|
| 50 | - * class is compatible. |
|
| 51 | - * |
|
| 52 | - * @param string $url |
|
| 53 | - * @param string $version |
|
| 54 | - */ |
|
| 55 | - public function __construct( $url, $version = null ) { |
|
| 56 | - $this->url = $url; |
|
| 57 | - $this->version = $version ?: null; // Empty string should remain null. |
|
| 58 | - } |
|
| 43 | + /** |
|
| 44 | + * Instantiates a new instance of the Register class. |
|
| 45 | + * |
|
| 46 | + * The URL param should be relative to the plugin directory. The URL |
|
| 47 | + * form should always end with a '/'. All asset location definitions |
|
| 48 | + * should not begin with a slash and should be relative to the plugin's |
|
| 49 | + * root directory. The URL provided by default from the Application |
|
| 50 | + * class is compatible. |
|
| 51 | + * |
|
| 52 | + * @param string $url |
|
| 53 | + * @param string $version |
|
| 54 | + */ |
|
| 55 | + public function __construct( $url, $version = null ) { |
|
| 56 | + $this->url = $url; |
|
| 57 | + $this->version = $version ?: null; // Empty string should remain null. |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * {@inheritdoc} |
|
| 62 | - * |
|
| 63 | - * @param array $script |
|
| 64 | - */ |
|
| 65 | - public function register_script( $script ) { |
|
| 66 | - $this->scripts[] = $script; |
|
| 67 | - } |
|
| 60 | + /** |
|
| 61 | + * {@inheritdoc} |
|
| 62 | + * |
|
| 63 | + * @param array $script |
|
| 64 | + */ |
|
| 65 | + public function register_script( $script ) { |
|
| 66 | + $this->scripts[] = $script; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * {@inheritdoc} |
|
| 71 | - * |
|
| 72 | - * @param array $style |
|
| 73 | - */ |
|
| 74 | - public function register_style( $style ) { |
|
| 75 | - $this->styles[] = $style; |
|
| 76 | - } |
|
| 69 | + /** |
|
| 70 | + * {@inheritdoc} |
|
| 71 | + * |
|
| 72 | + * @param array $style |
|
| 73 | + */ |
|
| 74 | + public function register_style( $style ) { |
|
| 75 | + $this->styles[] = $style; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * {@inheritDoc} |
|
| 80 | - */ |
|
| 81 | - public function enqueue_web_scripts() { |
|
| 82 | - foreach ( $this->scripts as $script ) { |
|
| 83 | - if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) { |
|
| 84 | - $this->enqueue_script( $script ); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 78 | + /** |
|
| 79 | + * {@inheritDoc} |
|
| 80 | + */ |
|
| 81 | + public function enqueue_web_scripts() { |
|
| 82 | + foreach ( $this->scripts as $script ) { |
|
| 83 | + if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) { |
|
| 84 | + $this->enqueue_script( $script ); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * {@inheritDoc} |
|
| 91 | - */ |
|
| 92 | - public function enqueue_web_styles() { |
|
| 93 | - foreach ( $this->styles as $style ) { |
|
| 94 | - if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) { |
|
| 95 | - $this->enqueue_style( $style ); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 89 | + /** |
|
| 90 | + * {@inheritDoc} |
|
| 91 | + */ |
|
| 92 | + public function enqueue_web_styles() { |
|
| 93 | + foreach ( $this->styles as $style ) { |
|
| 94 | + if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) { |
|
| 95 | + $this->enqueue_style( $style ); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * {@inheritDoc} |
|
| 102 | - * |
|
| 103 | - * @param string $hook Passes a string representing the current page. |
|
| 104 | - */ |
|
| 105 | - public function enqueue_admin_scripts( $hook ) { |
|
| 106 | - foreach ( $this->scripts as $script ) { |
|
| 107 | - if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) { |
|
| 108 | - $this->enqueue_script( $script, $hook ); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 100 | + /** |
|
| 101 | + * {@inheritDoc} |
|
| 102 | + * |
|
| 103 | + * @param string $hook Passes a string representing the current page. |
|
| 104 | + */ |
|
| 105 | + public function enqueue_admin_scripts( $hook ) { |
|
| 106 | + foreach ( $this->scripts as $script ) { |
|
| 107 | + if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) { |
|
| 108 | + $this->enqueue_script( $script, $hook ); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * {@inheritDoc} |
|
| 115 | - * |
|
| 116 | - * @param string $hook Passes a string representing the current page. |
|
| 117 | - */ |
|
| 118 | - public function enqueue_admin_styles( $hook ) { |
|
| 119 | - foreach ( $this->styles as $style ) { |
|
| 120 | - if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) { |
|
| 121 | - $this->enqueue_style( $style, $hook ); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 113 | + /** |
|
| 114 | + * {@inheritDoc} |
|
| 115 | + * |
|
| 116 | + * @param string $hook Passes a string representing the current page. |
|
| 117 | + */ |
|
| 118 | + public function enqueue_admin_styles( $hook ) { |
|
| 119 | + foreach ( $this->styles as $style ) { |
|
| 120 | + if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) { |
|
| 121 | + $this->enqueue_style( $style, $hook ); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * {@inheritDoc} |
|
| 128 | - */ |
|
| 129 | - public function register_blocks() { |
|
| 130 | - $blocks = array(); |
|
| 126 | + /** |
|
| 127 | + * {@inheritDoc} |
|
| 128 | + */ |
|
| 129 | + public function register_blocks() { |
|
| 130 | + $blocks = array(); |
|
| 131 | 131 | |
| 132 | - foreach ( $this->styles as $style ) { |
|
| 133 | - if ( in_array( $style['type'], array( 'block' ) ) ) { |
|
| 134 | - wp_register_style( |
|
| 135 | - $style['handle'], |
|
| 136 | - $this->url . $style['src'], |
|
| 137 | - isset( $style['deps'] ) ? $style['deps'] : array(), |
|
| 138 | - $this->version, |
|
| 139 | - isset( $style['media'] ) ? $style['media'] : 'all' |
|
| 140 | - ); |
|
| 132 | + foreach ( $this->styles as $style ) { |
|
| 133 | + if ( in_array( $style['type'], array( 'block' ) ) ) { |
|
| 134 | + wp_register_style( |
|
| 135 | + $style['handle'], |
|
| 136 | + $this->url . $style['src'], |
|
| 137 | + isset( $style['deps'] ) ? $style['deps'] : array(), |
|
| 138 | + $this->version, |
|
| 139 | + isset( $style['media'] ) ? $style['media'] : 'all' |
|
| 140 | + ); |
|
| 141 | 141 | |
| 142 | - if ( ! isset( $blocks[ $style['block'] ] ) ) { |
|
| 143 | - $blocks[ $style['block'] ] = array(); |
|
| 144 | - } |
|
| 142 | + if ( ! isset( $blocks[ $style['block'] ] ) ) { |
|
| 143 | + $blocks[ $style['block'] ] = array(); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - $blocks[ $style['block'] ]['editor_style'] = $style['handle']; |
|
| 147 | - } |
|
| 148 | - } |
|
| 146 | + $blocks[ $style['block'] ]['editor_style'] = $style['handle']; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - foreach ( $this->scripts as $script ) { |
|
| 151 | - if ( in_array( $script['type'], array( 'block' ) ) ) { |
|
| 152 | - wp_register_script( |
|
| 153 | - $script['handle'], |
|
| 154 | - $this->url . $script['src'], |
|
| 155 | - isset( $script['deps'] ) ? $script['deps'] : array(), |
|
| 156 | - $this->version, |
|
| 157 | - isset( $script['footer'] ) ? $script['footer'] : false |
|
| 158 | - ); |
|
| 150 | + foreach ( $this->scripts as $script ) { |
|
| 151 | + if ( in_array( $script['type'], array( 'block' ) ) ) { |
|
| 152 | + wp_register_script( |
|
| 153 | + $script['handle'], |
|
| 154 | + $this->url . $script['src'], |
|
| 155 | + isset( $script['deps'] ) ? $script['deps'] : array(), |
|
| 156 | + $this->version, |
|
| 157 | + isset( $script['footer'] ) ? $script['footer'] : false |
|
| 158 | + ); |
|
| 159 | 159 | |
| 160 | - $this->localize_script( $script ); |
|
| 160 | + $this->localize_script( $script ); |
|
| 161 | 161 | |
| 162 | - if ( ! isset( $blocks[ $script['block'] ] ) ) { |
|
| 163 | - $blocks[ $script['block'] ] = array(); |
|
| 164 | - } |
|
| 162 | + if ( ! isset( $blocks[ $script['block'] ] ) ) { |
|
| 163 | + $blocks[ $script['block'] ] = array(); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - $blocks[ $script['block'] ]['editor_script'] = $script['handle']; |
|
| 167 | - } |
|
| 168 | - } |
|
| 166 | + $blocks[ $script['block'] ]['editor_script'] = $script['handle']; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - foreach ( $blocks as $slug => $opts ) { |
|
| 171 | - register_block_type( $slug, $opts ); |
|
| 172 | - } |
|
| 173 | - } |
|
| 170 | + foreach ( $blocks as $slug => $opts ) { |
|
| 171 | + register_block_type( $slug, $opts ); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * {@inheritDoc} |
|
| 177 | - * |
|
| 178 | - * @return array[] |
|
| 179 | - */ |
|
| 180 | - public function action_hooks() { |
|
| 181 | - return array( |
|
| 182 | - array( |
|
| 183 | - 'hook' => 'wp_enqueue_scripts', |
|
| 184 | - 'method' => 'enqueue_web_scripts', |
|
| 185 | - ), |
|
| 186 | - array( |
|
| 187 | - 'hook' => 'wp_enqueue_scripts', |
|
| 188 | - 'method' => 'enqueue_web_styles', |
|
| 189 | - ), |
|
| 190 | - array( |
|
| 191 | - 'hook' => 'admin_enqueue_scripts', |
|
| 192 | - 'method' => 'enqueue_admin_scripts', |
|
| 193 | - ), |
|
| 194 | - array( |
|
| 195 | - 'hook' => 'admin_enqueue_scripts', |
|
| 196 | - 'method' => 'enqueue_admin_styles', |
|
| 197 | - ), |
|
| 198 | - array( |
|
| 199 | - 'hook' => 'init', |
|
| 200 | - 'method' => 'register_blocks', |
|
| 201 | - ), |
|
| 202 | - ); |
|
| 203 | - } |
|
| 175 | + /** |
|
| 176 | + * {@inheritDoc} |
|
| 177 | + * |
|
| 178 | + * @return array[] |
|
| 179 | + */ |
|
| 180 | + public function action_hooks() { |
|
| 181 | + return array( |
|
| 182 | + array( |
|
| 183 | + 'hook' => 'wp_enqueue_scripts', |
|
| 184 | + 'method' => 'enqueue_web_scripts', |
|
| 185 | + ), |
|
| 186 | + array( |
|
| 187 | + 'hook' => 'wp_enqueue_scripts', |
|
| 188 | + 'method' => 'enqueue_web_styles', |
|
| 189 | + ), |
|
| 190 | + array( |
|
| 191 | + 'hook' => 'admin_enqueue_scripts', |
|
| 192 | + 'method' => 'enqueue_admin_scripts', |
|
| 193 | + ), |
|
| 194 | + array( |
|
| 195 | + 'hook' => 'admin_enqueue_scripts', |
|
| 196 | + 'method' => 'enqueue_admin_styles', |
|
| 197 | + ), |
|
| 198 | + array( |
|
| 199 | + 'hook' => 'init', |
|
| 200 | + 'method' => 'register_blocks', |
|
| 201 | + ), |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * Enqueues an individual script if the style's condition is met. |
|
| 207 | - * |
|
| 208 | - * @param array $script The script attachment callback. |
|
| 209 | - * @param string $hook The location hook. Only passed on admin side. |
|
| 210 | - */ |
|
| 211 | - protected function enqueue_script( $script, $hook = null ) { |
|
| 212 | - if ( $script['condition']( $hook ) ) { |
|
| 213 | - wp_enqueue_script( |
|
| 214 | - $script['handle'], |
|
| 215 | - $this->url . $script['src'], |
|
| 216 | - isset( $script['deps'] ) ? $script['deps'] : array(), |
|
| 217 | - $this->version, |
|
| 218 | - isset( $script['footer'] ) ? $script['footer'] : false |
|
| 219 | - ); |
|
| 205 | + /** |
|
| 206 | + * Enqueues an individual script if the style's condition is met. |
|
| 207 | + * |
|
| 208 | + * @param array $script The script attachment callback. |
|
| 209 | + * @param string $hook The location hook. Only passed on admin side. |
|
| 210 | + */ |
|
| 211 | + protected function enqueue_script( $script, $hook = null ) { |
|
| 212 | + if ( $script['condition']( $hook ) ) { |
|
| 213 | + wp_enqueue_script( |
|
| 214 | + $script['handle'], |
|
| 215 | + $this->url . $script['src'], |
|
| 216 | + isset( $script['deps'] ) ? $script['deps'] : array(), |
|
| 217 | + $this->version, |
|
| 218 | + isset( $script['footer'] ) ? $script['footer'] : false |
|
| 219 | + ); |
|
| 220 | 220 | |
| 221 | - $this->localize_script( $script ); |
|
| 222 | - } |
|
| 223 | - } |
|
| 221 | + $this->localize_script( $script ); |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Enqueues an individual stylesheet if the style's condition is met. |
|
| 227 | - * |
|
| 228 | - * @param array $style The style attachment callback. |
|
| 229 | - * @param string $hook The location hook. |
|
| 230 | - */ |
|
| 231 | - protected function enqueue_style( $style, $hook = null ) { |
|
| 232 | - if ( $style['condition']( $hook ) ) { |
|
| 233 | - wp_enqueue_style( |
|
| 234 | - $style['handle'], |
|
| 235 | - $this->url . $style['src'], |
|
| 236 | - isset( $style['deps'] ) ? $style['deps'] : array(), |
|
| 237 | - $this->version, |
|
| 238 | - isset( $style['media'] ) ? $style['media'] : 'all' |
|
| 239 | - ); |
|
| 240 | - } |
|
| 241 | - } |
|
| 225 | + /** |
|
| 226 | + * Enqueues an individual stylesheet if the style's condition is met. |
|
| 227 | + * |
|
| 228 | + * @param array $style The style attachment callback. |
|
| 229 | + * @param string $hook The location hook. |
|
| 230 | + */ |
|
| 231 | + protected function enqueue_style( $style, $hook = null ) { |
|
| 232 | + if ( $style['condition']( $hook ) ) { |
|
| 233 | + wp_enqueue_style( |
|
| 234 | + $style['handle'], |
|
| 235 | + $this->url . $style['src'], |
|
| 236 | + isset( $style['deps'] ) ? $style['deps'] : array(), |
|
| 237 | + $this->version, |
|
| 238 | + isset( $style['media'] ) ? $style['media'] : 'all' |
|
| 239 | + ); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Registers the localization of the provided script. |
|
| 245 | - * |
|
| 246 | - * @param array $script Script defintion. |
|
| 247 | - */ |
|
| 248 | - protected function localize_script( $script ) { |
|
| 249 | - if ( ! isset( $script['localize'] ) ) { |
|
| 250 | - return; |
|
| 251 | - } |
|
| 243 | + /** |
|
| 244 | + * Registers the localization of the provided script. |
|
| 245 | + * |
|
| 246 | + * @param array $script Script defintion. |
|
| 247 | + */ |
|
| 248 | + protected function localize_script( $script ) { |
|
| 249 | + if ( ! isset( $script['localize'] ) ) { |
|
| 250 | + return; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables |
|
| 254 | - $script['localize'] = call_user_func( $script['localize'] ); |
|
| 255 | - } |
|
| 253 | + if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables |
|
| 254 | + $script['localize'] = call_user_func( $script['localize'] ); |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - wp_localize_script( |
|
| 258 | - $script['handle'], |
|
| 259 | - $script['localize']['name'], |
|
| 260 | - $script['localize']['data'] |
|
| 261 | - ); |
|
| 262 | - } |
|
| 257 | + wp_localize_script( |
|
| 258 | + $script['handle'], |
|
| 259 | + $script['localize']['name'], |
|
| 260 | + $script['localize']['data'] |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | 263 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param string $url |
| 53 | 53 | * @param string $version |
| 54 | 54 | */ |
| 55 | - public function __construct( $url, $version = null ) { |
|
| 55 | + public function __construct($url, $version = null) { |
|
| 56 | 56 | $this->url = $url; |
| 57 | 57 | $this->version = $version ?: null; // Empty string should remain null. |
| 58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @param array $script |
| 64 | 64 | */ |
| 65 | - public function register_script( $script ) { |
|
| 65 | + public function register_script($script) { |
|
| 66 | 66 | $this->scripts[] = $script; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @param array $style |
| 73 | 73 | */ |
| 74 | - public function register_style( $style ) { |
|
| 74 | + public function register_style($style) { |
|
| 75 | 75 | $this->styles[] = $style; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | * {@inheritDoc} |
| 80 | 80 | */ |
| 81 | 81 | public function enqueue_web_scripts() { |
| 82 | - foreach ( $this->scripts as $script ) { |
|
| 83 | - if ( in_array( $script['type'], array( 'web', 'shared' ) ) ) { |
|
| 84 | - $this->enqueue_script( $script ); |
|
| 82 | + foreach ($this->scripts as $script) { |
|
| 83 | + if (in_array($script['type'], array('web', 'shared'))) { |
|
| 84 | + $this->enqueue_script($script); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | * {@inheritDoc} |
| 91 | 91 | */ |
| 92 | 92 | public function enqueue_web_styles() { |
| 93 | - foreach ( $this->styles as $style ) { |
|
| 94 | - if ( in_array( $style['type'], array( 'web', 'shared' ) ) ) { |
|
| 95 | - $this->enqueue_style( $style ); |
|
| 93 | + foreach ($this->styles as $style) { |
|
| 94 | + if (in_array($style['type'], array('web', 'shared'))) { |
|
| 95 | + $this->enqueue_style($style); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -102,10 +102,10 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @param string $hook Passes a string representing the current page. |
| 104 | 104 | */ |
| 105 | - public function enqueue_admin_scripts( $hook ) { |
|
| 106 | - foreach ( $this->scripts as $script ) { |
|
| 107 | - if ( in_array( $script['type'], array( 'admin', 'shared' ) ) ) { |
|
| 108 | - $this->enqueue_script( $script, $hook ); |
|
| 105 | + public function enqueue_admin_scripts($hook) { |
|
| 106 | + foreach ($this->scripts as $script) { |
|
| 107 | + if (in_array($script['type'], array('admin', 'shared'))) { |
|
| 108 | + $this->enqueue_script($script, $hook); |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @param string $hook Passes a string representing the current page. |
| 117 | 117 | */ |
| 118 | - public function enqueue_admin_styles( $hook ) { |
|
| 119 | - foreach ( $this->styles as $style ) { |
|
| 120 | - if ( in_array( $style['type'], array( 'admin', 'shared' ) ) ) { |
|
| 121 | - $this->enqueue_style( $style, $hook ); |
|
| 118 | + public function enqueue_admin_styles($hook) { |
|
| 119 | + foreach ($this->styles as $style) { |
|
| 120 | + if (in_array($style['type'], array('admin', 'shared'))) { |
|
| 121 | + $this->enqueue_style($style, $hook); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -129,46 +129,46 @@ discard block |
||
| 129 | 129 | public function register_blocks() { |
| 130 | 130 | $blocks = array(); |
| 131 | 131 | |
| 132 | - foreach ( $this->styles as $style ) { |
|
| 133 | - if ( in_array( $style['type'], array( 'block' ) ) ) { |
|
| 132 | + foreach ($this->styles as $style) { |
|
| 133 | + if (in_array($style['type'], array('block'))) { |
|
| 134 | 134 | wp_register_style( |
| 135 | 135 | $style['handle'], |
| 136 | - $this->url . $style['src'], |
|
| 137 | - isset( $style['deps'] ) ? $style['deps'] : array(), |
|
| 136 | + $this->url.$style['src'], |
|
| 137 | + isset($style['deps']) ? $style['deps'] : array(), |
|
| 138 | 138 | $this->version, |
| 139 | - isset( $style['media'] ) ? $style['media'] : 'all' |
|
| 139 | + isset($style['media']) ? $style['media'] : 'all' |
|
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | - if ( ! isset( $blocks[ $style['block'] ] ) ) { |
|
| 143 | - $blocks[ $style['block'] ] = array(); |
|
| 142 | + if (!isset($blocks[$style['block']])) { |
|
| 143 | + $blocks[$style['block']] = array(); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - $blocks[ $style['block'] ]['editor_style'] = $style['handle']; |
|
| 146 | + $blocks[$style['block']]['editor_style'] = $style['handle']; |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - foreach ( $this->scripts as $script ) { |
|
| 151 | - if ( in_array( $script['type'], array( 'block' ) ) ) { |
|
| 150 | + foreach ($this->scripts as $script) { |
|
| 151 | + if (in_array($script['type'], array('block'))) { |
|
| 152 | 152 | wp_register_script( |
| 153 | 153 | $script['handle'], |
| 154 | - $this->url . $script['src'], |
|
| 155 | - isset( $script['deps'] ) ? $script['deps'] : array(), |
|
| 154 | + $this->url.$script['src'], |
|
| 155 | + isset($script['deps']) ? $script['deps'] : array(), |
|
| 156 | 156 | $this->version, |
| 157 | - isset( $script['footer'] ) ? $script['footer'] : false |
|
| 157 | + isset($script['footer']) ? $script['footer'] : false |
|
| 158 | 158 | ); |
| 159 | 159 | |
| 160 | - $this->localize_script( $script ); |
|
| 160 | + $this->localize_script($script); |
|
| 161 | 161 | |
| 162 | - if ( ! isset( $blocks[ $script['block'] ] ) ) { |
|
| 163 | - $blocks[ $script['block'] ] = array(); |
|
| 162 | + if (!isset($blocks[$script['block']])) { |
|
| 163 | + $blocks[$script['block']] = array(); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $blocks[ $script['block'] ]['editor_script'] = $script['handle']; |
|
| 166 | + $blocks[$script['block']]['editor_script'] = $script['handle']; |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - foreach ( $blocks as $slug => $opts ) { |
|
| 171 | - register_block_type( $slug, $opts ); |
|
| 170 | + foreach ($blocks as $slug => $opts) { |
|
| 171 | + register_block_type($slug, $opts); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
@@ -208,17 +208,17 @@ discard block |
||
| 208 | 208 | * @param array $script The script attachment callback. |
| 209 | 209 | * @param string $hook The location hook. Only passed on admin side. |
| 210 | 210 | */ |
| 211 | - protected function enqueue_script( $script, $hook = null ) { |
|
| 212 | - if ( $script['condition']( $hook ) ) { |
|
| 211 | + protected function enqueue_script($script, $hook = null) { |
|
| 212 | + if ($script['condition']($hook)) { |
|
| 213 | 213 | wp_enqueue_script( |
| 214 | 214 | $script['handle'], |
| 215 | - $this->url . $script['src'], |
|
| 216 | - isset( $script['deps'] ) ? $script['deps'] : array(), |
|
| 215 | + $this->url.$script['src'], |
|
| 216 | + isset($script['deps']) ? $script['deps'] : array(), |
|
| 217 | 217 | $this->version, |
| 218 | - isset( $script['footer'] ) ? $script['footer'] : false |
|
| 218 | + isset($script['footer']) ? $script['footer'] : false |
|
| 219 | 219 | ); |
| 220 | 220 | |
| 221 | - $this->localize_script( $script ); |
|
| 221 | + $this->localize_script($script); |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | * @param array $style The style attachment callback. |
| 229 | 229 | * @param string $hook The location hook. |
| 230 | 230 | */ |
| 231 | - protected function enqueue_style( $style, $hook = null ) { |
|
| 232 | - if ( $style['condition']( $hook ) ) { |
|
| 231 | + protected function enqueue_style($style, $hook = null) { |
|
| 232 | + if ($style['condition']($hook)) { |
|
| 233 | 233 | wp_enqueue_style( |
| 234 | 234 | $style['handle'], |
| 235 | - $this->url . $style['src'], |
|
| 236 | - isset( $style['deps'] ) ? $style['deps'] : array(), |
|
| 235 | + $this->url.$style['src'], |
|
| 236 | + isset($style['deps']) ? $style['deps'] : array(), |
|
| 237 | 237 | $this->version, |
| 238 | - isset( $style['media'] ) ? $style['media'] : 'all' |
|
| 238 | + isset($style['media']) ? $style['media'] : 'all' |
|
| 239 | 239 | ); |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -245,13 +245,13 @@ discard block |
||
| 245 | 245 | * |
| 246 | 246 | * @param array $script Script defintion. |
| 247 | 247 | */ |
| 248 | - protected function localize_script( $script ) { |
|
| 249 | - if ( ! isset( $script['localize'] ) ) { |
|
| 248 | + protected function localize_script($script) { |
|
| 249 | + if (!isset($script['localize'])) { |
|
| 250 | 250 | return; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ( is_callable( $script['localize'] ) ) { // @todo make all properties callables |
|
| 254 | - $script['localize'] = call_user_func( $script['localize'] ); |
|
| 253 | + if (is_callable($script['localize'])) { // @todo make all properties callables |
|
| 254 | + $script['localize'] = call_user_func($script['localize']); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | wp_localize_script( |