Skip to content

Commit c1aafa6

Browse files
committed
chore: autoformat
1 parent b561a3f commit c1aafa6

22 files changed

+1037
-988
lines changed

assets/src/admin/multisite-plugin/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const OneDesignMultisiteGoverningSiteSelection = () => {
7070
setGoverningSite( data.governing_site );
7171
currentGoverningSiteID.current = data.governing_site;
7272
}
73-
return;
7473
} catch {
7574
setNotice( {
7675
type: 'error',
@@ -116,7 +115,6 @@ const OneDesignMultisiteGoverningSiteSelection = () => {
116115
setIsSaving( false );
117116
window.location.reload();
118117
}, 1000 );
119-
return;
120118
} catch {
121119
setNotice( {
122120
type: 'error',

assets/src/css/admin.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ body.onedesign-site-selection-modal {
113113
[id="toplevel_page_onedesign"] {
114114

115115
.dashicons-admin-generic::before {
116-
content: url("../images/logo.svg") !important;
116+
content: url(../images/logo.svg) !important;
117117
}
118118
}

inc/classes/class-assets.php

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Assets {
2626
*
2727
* @var array
2828
*/
29-
private static array $localized_data = array();
29+
private static array $localized_data = [];
3030

3131
/**
3232
* Protected class constructor
@@ -40,8 +40,8 @@ protected function __construct() {
4040
* Setup WordPress hooks
4141
*/
4242
public function setup_hooks(): void {
43-
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts' ), 20, 1 );
44-
add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts' ), 20, 1 );
43+
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_scripts' ], 20, 1 );
44+
add_action( 'admin_enqueue_scripts', [ $this, 'add_admin_scripts' ], 20, 1 );
4545
}
4646

4747
/**
@@ -50,12 +50,12 @@ public function setup_hooks(): void {
5050
* @return void
5151
*/
5252
private static function build_localized_data(): void {
53-
self::$localized_data = array(
53+
self::$localized_data = [
5454
'restUrl' => esc_url( home_url( '/wp-json' ) ),
5555
'restNonce' => wp_create_nonce( 'wp_rest' ),
5656
'apiKey' => get_option( Constants::ONEDESIGN_API_KEY, 'default_api_key' ),
5757
'settingsLink' => esc_url( admin_url( 'admin.php?page=onedesign-settings' ) ),
58-
);
58+
];
5959
}
6060

6161
/**
@@ -84,12 +84,12 @@ public function add_admin_scripts( $hook_suffix ): void {
8484
'OneDesignSettings',
8585
array_merge(
8686
self::$localized_data,
87-
array(
87+
[
8888
'multisites' => Utils::get_all_multisites_info(),
8989
'isMultisite' => Utils::is_multisite(),
9090
'isGoverningSiteSelected' => Utils::is_governing_site_selected(),
9191
'currentSiteId' => Utils::is_multisite() ? get_current_blog_id() : null,
92-
)
92+
]
9393
)
9494
);
9595

@@ -122,7 +122,6 @@ public function add_admin_scripts( $hook_suffix ): void {
122122
);
123123

124124
wp_enqueue_script( 'onedesign-setup-script' );
125-
126125
}
127126

128127
if ( Utils::is_multisite() && 'plugins-network' === $current_screen->id && ! Utils::is_governing_site_selected() ) {
@@ -140,14 +139,13 @@ public function add_admin_scripts( $hook_suffix ): void {
140139
'OneDesignMultiSiteSettings',
141140
array_merge(
142141
self::$localized_data,
143-
array(
142+
[
144143
'multisites' => Utils::get_all_multisites_info(),
145-
)
144+
]
146145
)
147146
);
148147

149148
wp_enqueue_script( 'onedesign-multisite-setup-script' );
150-
151149
}
152150

153151
$this->register_style( 'onedesign-admin-style', 'admin.css' );
@@ -164,7 +162,6 @@ public function enqueue_scripts(): void {
164162
$current_screen = Utils::get_current_screen();
165163

166164
if ( $current_screen && Pattern::SLUG === $current_screen->id ) {
167-
168165
$this->register_script(
169166
'onedesign-patterns-library-script',
170167
'patterns-library.js'
@@ -182,24 +179,25 @@ public function enqueue_scripts(): void {
182179
wp_enqueue_style( 'onedesign-editor-style' );
183180
}
184181

185-
if ( Template::SLUG === $current_screen->id ) {
182+
if ( Template::SLUG !== $current_screen->id ) {
183+
return;
184+
}
186185

187-
$this->register_script(
188-
'onedesign-templates-library-script',
189-
'templates-library.js'
190-
);
186+
$this->register_script(
187+
'onedesign-templates-library-script',
188+
'templates-library.js'
189+
);
191190

192-
wp_localize_script(
193-
'onedesign-templates-library-script',
194-
'TemplateLibraryData',
195-
self::$localized_data
196-
);
191+
wp_localize_script(
192+
'onedesign-templates-library-script',
193+
'TemplateLibraryData',
194+
self::$localized_data
195+
);
197196

198-
wp_enqueue_script( 'onedesign-templates-library-script' );
197+
wp_enqueue_script( 'onedesign-templates-library-script' );
199198

200-
$this->register_style( 'onedesign-template-style', 'template.css' );
201-
wp_enqueue_style( 'onedesign-template-style' );
202-
}
199+
$this->register_style( 'onedesign-template-style', 'template.css' );
200+
wp_enqueue_style( 'onedesign-template-style' );
203201
}
204202

205203
/**
@@ -211,14 +209,14 @@ public function enqueue_scripts(): void {
211209
*
212210
* @return array
213211
*/
214-
public function get_asset_meta( $file, $deps = array(), $ver = false ): array {
212+
public function get_asset_meta( $file, $deps = [], $ver = false ): array {
215213
$asset_meta_file = sprintf( '%s/%s.asset.php', untrailingslashit( ONEDESIGN_BUILD_PATH ), basename( $file, '.' . pathinfo( $file )['extension'] ) );
216214
$asset_meta = is_readable( $asset_meta_file )
217215
? require_once $asset_meta_file
218-
: array(
219-
'dependencies' => array(),
216+
: [
217+
'dependencies' => [],
220218
'version' => $this->get_file_version( $file, $ver ),
221-
);
219+
];
222220

223221
$asset_meta['dependencies'] = array_merge( $deps, $asset_meta['dependencies'] );
224222

@@ -236,7 +234,7 @@ public function get_asset_meta( $file, $deps = array(), $ver = false ): array {
236234
* Default 'false'.
237235
* @return bool Whether the script has been registered. True on success, false on failure.
238236
*/
239-
public function register_script( $handle, $file, $deps = array(), $ver = false, $in_footer = true ): bool {
237+
public function register_script( $handle, $file, $deps = [], $ver = false, $in_footer = true ): bool {
240238

241239
$file_path = sprintf( '%s/%s', ONEDESIGN_BUILD_PATH, $file );
242240

@@ -270,7 +268,7 @@ public function register_script( $handle, $file, $deps = array(), $ver = false,
270268
*
271269
* @return bool Whether the style has been registered. True on success, false on failure.
272270
*/
273-
public function register_style( $handle, $file, $deps = array(), $ver = false, $media = 'all' ): bool {
271+
public function register_style( $handle, $file, $deps = [], $ver = false, $media = 'all' ): bool {
274272

275273
$file_path = sprintf( '%s/%s', ONEDESIGN_BUILD_PATH, $file );
276274

@@ -287,8 +285,8 @@ public function register_style( $handle, $file, $deps = array(), $ver = false, $
287285
/**
288286
* Get file version.
289287
*
290-
* @param string $file File path.
291-
* @param int|string|boolean $ver File version.
288+
* @param string $file File path.
289+
* @param int|string|bool $ver File version.
292290
*
293291
* @return bool|int|string
294292
*/

inc/classes/class-cpt-restriction.php

Lines changed: 71 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ protected function __construct() {
3838
* Function to setup hooks.
3939
*/
4040
public function setup_hooks(): void {
41-
add_filter( 'register_post_type_args', array( $this, 'restrict_cpt' ), 5, 2 );
42-
add_action( 'init', array( $this, 'unregister_cpt' ), 20 );
43-
add_action( 'current_screen', array( $this, 'limit_pattern_library_posts' ) );
44-
add_action( 'current_screen', array( $this, 'limit_template_posts' ) );
45-
add_filter( 'register_post_type_args', array( $this, 'modify_pattern_library_labels' ), 10, 2 );
46-
add_action( 'admin_menu', array( $this, 'modify_pattern_library_admin_menu' ), 999 );
47-
add_filter( 'default_content', array( $this, 'add_default_content_to_editor' ), 10, 2 );
48-
add_filter( 'default_title', array( $this, 'add_default_title_to_editor' ), 10, 2 );
41+
add_filter( 'register_post_type_args', [ $this, 'restrict_cpt' ], 5, 2 );
42+
add_action( 'init', [ $this, 'unregister_cpt' ], 20 );
43+
add_action( 'current_screen', [ $this, 'limit_pattern_library_posts' ] );
44+
add_action( 'current_screen', [ $this, 'limit_template_posts' ] );
45+
add_filter( 'register_post_type_args', [ $this, 'modify_pattern_library_labels' ], 10, 2 );
46+
add_action( 'admin_menu', [ $this, 'modify_pattern_library_admin_menu' ], 999 );
47+
add_filter( 'default_content', [ $this, 'add_default_content_to_editor' ], 10, 2 );
48+
add_filter( 'default_title', [ $this, 'add_default_title_to_editor' ], 10, 2 );
4949
}
5050

5151
/**
@@ -72,7 +72,7 @@ public function add_default_title_to_editor( string $title ): string {
7272
* @return array Modified arguments.
7373
*/
7474
public function restrict_cpt( array $args, string $post_type ): array {
75-
if ( ! in_array( $post_type, array( Pattern::SLUG, Template::SLUG ), true ) ) {
75+
if ( ! in_array( $post_type, [ Pattern::SLUG, Template::SLUG ], true ) ) {
7676
return $args;
7777
}
7878

@@ -88,7 +88,7 @@ public function restrict_cpt( array $args, string $post_type ): array {
8888
return $args;
8989
}
9090

91-
if ( in_array( $post_type, array( Pattern::SLUG, Template::SLUG ), true ) ) {
91+
if ( in_array( $post_type, [ Pattern::SLUG, Template::SLUG ], true ) ) {
9292
$args['public'] = false;
9393
$args['show_ui'] = false;
9494
$args['show_in_menu'] = false;
@@ -99,15 +99,15 @@ public function restrict_cpt( array $args, string $post_type ): array {
9999
$args['exclude_from_search'] = true;
100100
$args['publicly_queryable'] = false;
101101
$args['show_in_rest'] = false;
102-
$args['capabilities'] = array(
102+
$args['capabilities'] = [
103103
'edit_post' => 'do_not_allow',
104104
'read_post' => 'do_not_allow',
105105
'delete_post' => 'do_not_allow',
106106
'edit_posts' => 'do_not_allow',
107107
'edit_others_posts' => 'do_not_allow',
108108
'publish_posts' => 'do_not_allow',
109109
'read_private_posts' => 'do_not_allow',
110-
);
110+
];
111111
}
112112

113113
return $args;
@@ -142,22 +142,24 @@ public function limit_pattern_library_posts(): void {
142142
$post_count = $existing_posts->publish + $existing_posts->draft + $existing_posts->pending + $existing_posts->private;
143143

144144
// If a post already exists, redirect to edit screen.
145-
if ( $post_count > 0 ) {
146-
// Get the existing post.
147-
$existing_post = get_posts(
148-
array(
149-
'post_type' => Pattern::SLUG,
150-
'post_status' => array( 'publish', 'draft', 'pending', 'private' ),
151-
'numberposts' => 1,
152-
'suppress_filters' => false,
153-
)
154-
);
145+
if ( $post_count <= 0 ) {
146+
return;
147+
}
155148

156-
if ( ! empty( $existing_post ) ) {
157-
// Redirect to edit screen of the existing post.
158-
wp_safe_redirect( admin_url( 'post.php?post=' . $existing_post[0]->ID . '&action=edit' ) );
159-
exit;
160-
}
149+
// Get the existing post.
150+
$existing_post = get_posts(
151+
[
152+
'post_type' => Pattern::SLUG,
153+
'post_status' => [ 'publish', 'draft', 'pending', 'private' ],
154+
'numberposts' => 1,
155+
'suppress_filters' => false,
156+
]
157+
);
158+
159+
if ( ! empty( $existing_post ) ) {
160+
// Redirect to edit screen of the existing post.
161+
wp_safe_redirect( admin_url( 'post.php?post=' . $existing_post[0]->ID . '&action=edit' ) );
162+
exit;
161163
}
162164
}
163165

@@ -183,22 +185,24 @@ public function limit_template_posts(): void {
183185
$post_count = $existing_posts->publish + $existing_posts->draft + $existing_posts->pending + $existing_posts->private;
184186

185187
// If a post already exists, redirect to edit screen.
186-
if ( $post_count > 0 ) {
187-
// Get the existing post.
188-
$existing_post = get_posts(
189-
array(
190-
'post_type' => Template::SLUG,
191-
'post_status' => array( 'publish', 'draft', 'pending', 'private' ),
192-
'numberposts' => 1,
193-
'suppress_filters' => false,
194-
)
195-
);
188+
if ( $post_count <= 0 ) {
189+
return;
190+
}
196191

197-
if ( ! empty( $existing_post ) ) {
198-
// Redirect to edit screen of the existing post.
199-
wp_safe_redirect( admin_url( 'post.php?post=' . $existing_post[0]->ID . '&action=edit' ) );
200-
exit;
201-
}
192+
// Get the existing post.
193+
$existing_post = get_posts(
194+
[
195+
'post_type' => Template::SLUG,
196+
'post_status' => [ 'publish', 'draft', 'pending', 'private' ],
197+
'numberposts' => 1,
198+
'suppress_filters' => false,
199+
]
200+
);
201+
202+
if ( ! empty( $existing_post ) ) {
203+
// Redirect to edit screen of the existing post.
204+
wp_safe_redirect( admin_url( 'post.php?post=' . $existing_post[0]->ID . '&action=edit' ) );
205+
exit;
202206
}
203207
}
204208

@@ -257,28 +261,32 @@ public function modify_pattern_library_admin_menu(): void {
257261

258262
$post_count = $existing_posts->publish + $existing_posts->draft + $existing_posts->pending + $existing_posts->private;
259263

260-
if ( $post_count > 0 ) {
261-
// Find the "Add New" menu item.
262-
foreach ( $submenu[ 'edit.php?post_type=' . Pattern::SLUG ] as $key => $item ) {
263-
if ( 'post-new.php?post_type=' . Pattern::SLUG === $item[2] ) {
264-
// Get the existing post.
265-
$existing_post = get_posts(
266-
array(
267-
'post_type' => Pattern::SLUG,
268-
'post_status' => array( 'publish', 'draft', 'pending', 'private' ),
269-
'numberposts' => 1,
270-
'suppress_filters' => false,
271-
)
272-
);
273-
274-
if ( ! empty( $existing_post ) ) {
275-
// Change the "Add New" link to edit the existing post.
276-
$submenu['edit.php?post_type=onedesign-pattern'][ $key ][2] = 'post.php?post=' . $existing_post[0]->ID . '&action=edit'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- We need to modify for pattern library post type.
277-
$submenu['edit.php?post_type=onedesign-pattern'][ $key ][0] = esc_html__( 'Edit Pattern Library', 'onedesign' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- We need to modify for pattern library post type.
278-
}
279-
break;
280-
}
264+
if ( $post_count <= 0 ) {
265+
return;
266+
}
267+
268+
// Find the "Add New" menu item.
269+
foreach ( $submenu[ 'edit.php?post_type=' . Pattern::SLUG ] as $key => $item ) {
270+
if ( 'post-new.php?post_type=' . Pattern::SLUG !== $item[2] ) {
271+
continue;
272+
}
273+
274+
// Get the existing post.
275+
$existing_post = get_posts(
276+
[
277+
'post_type' => Pattern::SLUG,
278+
'post_status' => [ 'publish', 'draft', 'pending', 'private' ],
279+
'numberposts' => 1,
280+
'suppress_filters' => false,
281+
]
282+
);
283+
284+
if ( ! empty( $existing_post ) ) {
285+
// Change the "Add New" link to edit the existing post.
286+
$submenu['edit.php?post_type=onedesign-pattern'][ $key ][2] = 'post.php?post=' . $existing_post[0]->ID . '&action=edit'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- We need to modify for pattern library post type.
287+
$submenu['edit.php?post_type=onedesign-pattern'][ $key ][0] = esc_html__( 'Edit Pattern Library', 'onedesign' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- We need to modify for pattern library post type.
281288
}
289+
break;
282290
}
283291
}
284292

0 commit comments

Comments
 (0)