Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions assets/src/admin/multisite-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const OneDesignMultisiteGoverningSiteSelection = () => {
setGoverningSite( data.governing_site );
currentGoverningSiteID.current = data.governing_site;
}
return;
} catch {
setNotice( {
type: 'error',
Expand Down Expand Up @@ -116,7 +115,6 @@ const OneDesignMultisiteGoverningSiteSelection = () => {
setIsSaving( false );
window.location.reload();
}, 1000 );
return;
} catch {
setNotice( {
type: 'error',
Expand Down
2 changes: 1 addition & 1 deletion assets/src/css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ body.onedesign-site-selection-modal {
[id="toplevel_page_onedesign"] {

.dashicons-admin-generic::before {
content: url("../images/logo.svg") !important;
content: url(../images/logo.svg) !important;
}
}
66 changes: 32 additions & 34 deletions inc/classes/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @var array
*/
private static array $localized_data = array();
private static array $localized_data = [];

Check failure on line 29 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Property OneDesign\Assets::$localized_data type has no value type specified in iterable type array.

/**
* Protected class constructor
Expand All @@ -40,8 +40,8 @@
* Setup WordPress hooks
*/
public function setup_hooks(): void {
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts' ), 20, 1 );
add_action( 'admin_enqueue_scripts', array( $this, 'add_admin_scripts' ), 20, 1 );
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_scripts' ], 20, 1 );
add_action( 'admin_enqueue_scripts', [ $this, 'add_admin_scripts' ], 20, 1 );
}

/**
Expand All @@ -50,12 +50,12 @@
* @return void
*/
private static function build_localized_data(): void {
self::$localized_data = array(
self::$localized_data = [
'restUrl' => esc_url( home_url( '/wp-json' ) ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
'apiKey' => get_option( Constants::ONEDESIGN_API_KEY, 'default_api_key' ),
'settingsLink' => esc_url( admin_url( 'admin.php?page=onedesign-settings' ) ),
);
];
}

/**
Expand Down Expand Up @@ -84,12 +84,12 @@
'OneDesignSettings',
array_merge(
self::$localized_data,
array(
[
'multisites' => Utils::get_all_multisites_info(),
'isMultisite' => Utils::is_multisite(),
'isGoverningSiteSelected' => Utils::is_governing_site_selected(),
'currentSiteId' => Utils::is_multisite() ? get_current_blog_id() : null,
)
]
)
);

Expand Down Expand Up @@ -122,10 +122,9 @@
);

wp_enqueue_script( 'onedesign-setup-script' );

}

if ( Utils::is_multisite() && 'plugins-network' === $current_screen->id && ! Utils::is_governing_site_selected() ) {

Check failure on line 127 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Cannot access property $id on WP_Screen|null.

// remove all notices.
remove_all_actions( 'admin_notices' );
Expand All @@ -140,14 +139,13 @@
'OneDesignMultiSiteSettings',
array_merge(
self::$localized_data,
array(
[
'multisites' => Utils::get_all_multisites_info(),
)
]
)
);

wp_enqueue_script( 'onedesign-multisite-setup-script' );

}

$this->register_style( 'onedesign-admin-style', 'admin.css' );
Expand All @@ -164,7 +162,6 @@
$current_screen = Utils::get_current_screen();

if ( $current_screen && Pattern::SLUG === $current_screen->id ) {

$this->register_script(
'onedesign-patterns-library-script',
'patterns-library.js'
Expand All @@ -182,24 +179,25 @@
wp_enqueue_style( 'onedesign-editor-style' );
}

if ( Template::SLUG === $current_screen->id ) {
if ( Template::SLUG !== $current_screen->id ) {

Check failure on line 182 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Cannot access property $id on WP_Screen|null.
return;
}

$this->register_script(
'onedesign-templates-library-script',
'templates-library.js'
);
$this->register_script(
'onedesign-templates-library-script',
'templates-library.js'
);

wp_localize_script(
'onedesign-templates-library-script',
'TemplateLibraryData',
self::$localized_data
);
wp_localize_script(
'onedesign-templates-library-script',
'TemplateLibraryData',
self::$localized_data
);

wp_enqueue_script( 'onedesign-templates-library-script' );
wp_enqueue_script( 'onedesign-templates-library-script' );

$this->register_style( 'onedesign-template-style', 'template.css' );
wp_enqueue_style( 'onedesign-template-style' );
}
$this->register_style( 'onedesign-template-style', 'template.css' );
wp_enqueue_style( 'onedesign-template-style' );
}

/**
Expand All @@ -211,14 +209,14 @@
*
* @return array
*/
public function get_asset_meta( $file, $deps = array(), $ver = false ): array {
public function get_asset_meta( $file, $deps = [], $ver = false ): array {

Check failure on line 212 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Method OneDesign\Assets::get_asset_meta() return type has no value type specified in iterable type array.

Check failure on line 212 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Method OneDesign\Assets::get_asset_meta() has parameter $deps with no value type specified in iterable type array.

Check failure on line 212 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Default value of the parameter #3 $ver (false) of method OneDesign\Assets::get_asset_meta() is incompatible with type string.
$asset_meta_file = sprintf( '%s/%s.asset.php', untrailingslashit( ONEDESIGN_BUILD_PATH ), basename( $file, '.' . pathinfo( $file )['extension'] ) );

Check failure on line 213 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Offset 'extension' might not exist on array{dirname?: string, basename: string, extension?: string, filename: string}.
$asset_meta = is_readable( $asset_meta_file )
? require_once $asset_meta_file

Check warning on line 215 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHPCS coding standards checks

File inclusion using variable (`$asset_meta_file`). Probably needs manual inspection.
: array(
'dependencies' => array(),
: [
'dependencies' => [],
'version' => $this->get_file_version( $file, $ver ),
);
];

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

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

Check failure on line 237 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Method OneDesign\Assets::register_script() has parameter $deps with no value type specified in iterable type array.

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

Expand All @@ -245,7 +243,7 @@
}

$src = sprintf( ONEDESIGN_BUILD_URI . '/%s', $file );
$asset_meta = $this->get_asset_meta( $file, $deps );

Check failure on line 246 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Parameter #1 $file of method OneDesign\Assets::get_asset_meta() expects string, bool|string given.

// register each dependency styles.
if ( ! empty( $asset_meta['dependencies'] ) ) {
Expand All @@ -270,7 +268,7 @@
*
* @return bool Whether the style has been registered. True on success, false on failure.
*/
public function register_style( $handle, $file, $deps = array(), $ver = false, $media = 'all' ): bool {
public function register_style( $handle, $file, $deps = [], $ver = false, $media = 'all' ): bool {

Check failure on line 271 in inc/classes/class-assets.php

View workflow job for this annotation

GitHub Actions / Run PHP static analysis

Method OneDesign\Assets::register_style() has parameter $deps with no value type specified in iterable type array.

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

Expand All @@ -287,8 +285,8 @@
/**
* Get file version.
*
* @param string $file File path.
* @param int|string|boolean $ver File version.
* @param string $file File path.
* @param int|string|bool $ver File version.
*
* @return bool|int|string
*/
Expand Down
134 changes: 71 additions & 63 deletions inc/classes/class-cpt-restriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace OneDesign;

use OneDesign\Traits\Singleton;
use OneDesign\Post_Types\{ Pattern, Template };

Check failure on line 11 in inc/classes/class-cpt-restriction.php

View workflow job for this annotation

GitHub Actions / Run PHPCS coding standards checks

Group use declaration is disallowed, use single use for every import.

/**
* Class CPT_Restriction
Expand All @@ -25,7 +25,7 @@
*
* @var string
*/
const MENU_SLUG = 'onedesign-design-sync';

Check failure on line 28 in inc/classes/class-cpt-restriction.php

View workflow job for this annotation

GitHub Actions / Run PHPCS coding standards checks

Constant \OneDesign\CPT_Restriction::MENU_SLUG visibility missing.

/**
* Protected class constructor
Expand All @@ -38,14 +38,14 @@
* Function to setup hooks.
*/
public function setup_hooks(): void {
add_filter( 'register_post_type_args', array( $this, 'restrict_cpt' ), 5, 2 );
add_action( 'init', array( $this, 'unregister_cpt' ), 20 );
add_action( 'current_screen', array( $this, 'limit_pattern_library_posts' ) );
add_action( 'current_screen', array( $this, 'limit_template_posts' ) );
add_filter( 'register_post_type_args', array( $this, 'modify_pattern_library_labels' ), 10, 2 );
add_action( 'admin_menu', array( $this, 'modify_pattern_library_admin_menu' ), 999 );
add_filter( 'default_content', array( $this, 'add_default_content_to_editor' ), 10, 2 );
add_filter( 'default_title', array( $this, 'add_default_title_to_editor' ), 10, 2 );
add_filter( 'register_post_type_args', [ $this, 'restrict_cpt' ], 5, 2 );
add_action( 'init', [ $this, 'unregister_cpt' ], 20 );
add_action( 'current_screen', [ $this, 'limit_pattern_library_posts' ] );
add_action( 'current_screen', [ $this, 'limit_template_posts' ] );
add_filter( 'register_post_type_args', [ $this, 'modify_pattern_library_labels' ], 10, 2 );
add_action( 'admin_menu', [ $this, 'modify_pattern_library_admin_menu' ], 999 );
add_filter( 'default_content', [ $this, 'add_default_content_to_editor' ], 10, 2 );
add_filter( 'default_title', [ $this, 'add_default_title_to_editor' ], 10, 2 );
}

/**
Expand All @@ -72,7 +72,7 @@
* @return array Modified arguments.
*/
public function restrict_cpt( array $args, string $post_type ): array {
if ( ! in_array( $post_type, array( Pattern::SLUG, Template::SLUG ), true ) ) {
if ( ! in_array( $post_type, [ Pattern::SLUG, Template::SLUG ], true ) ) {
return $args;
}

Expand All @@ -88,7 +88,7 @@
return $args;
}

if ( in_array( $post_type, array( Pattern::SLUG, Template::SLUG ), true ) ) {
if ( in_array( $post_type, [ Pattern::SLUG, Template::SLUG ], true ) ) {
$args['public'] = false;
$args['show_ui'] = false;
$args['show_in_menu'] = false;
Expand All @@ -99,15 +99,15 @@
$args['exclude_from_search'] = true;
$args['publicly_queryable'] = false;
$args['show_in_rest'] = false;
$args['capabilities'] = array(
$args['capabilities'] = [
'edit_post' => 'do_not_allow',
'read_post' => 'do_not_allow',
'delete_post' => 'do_not_allow',
'edit_posts' => 'do_not_allow',
'edit_others_posts' => 'do_not_allow',
'publish_posts' => 'do_not_allow',
'read_private_posts' => 'do_not_allow',
);
];
}

return $args;
Expand Down Expand Up @@ -142,22 +142,24 @@
$post_count = $existing_posts->publish + $existing_posts->draft + $existing_posts->pending + $existing_posts->private;

// If a post already exists, redirect to edit screen.
if ( $post_count > 0 ) {
// Get the existing post.
$existing_post = get_posts(
array(
'post_type' => Pattern::SLUG,
'post_status' => array( 'publish', 'draft', 'pending', 'private' ),
'numberposts' => 1,
'suppress_filters' => false,
)
);
if ( $post_count <= 0 ) {
return;
}

if ( ! empty( $existing_post ) ) {
// Redirect to edit screen of the existing post.
wp_safe_redirect( admin_url( 'post.php?post=' . $existing_post[0]->ID . '&action=edit' ) );
exit;
}
// Get the existing post.
$existing_post = get_posts(

Check warning on line 150 in inc/classes/class-cpt-restriction.php

View workflow job for this annotation

GitHub Actions / Run PHPCS coding standards checks

get_posts() is uncached unless the "suppress_filters" parameter is set to false. If the suppress_filter parameter is set to false this can be safely ignored. More Info: https://docs.wpvip.com/technical-references/caching/uncached-functions/.
[
'post_type' => Pattern::SLUG,
'post_status' => [ 'publish', 'draft', 'pending', 'private' ],
'numberposts' => 1,
'suppress_filters' => false,
]
);

if ( ! empty( $existing_post ) ) {
// Redirect to edit screen of the existing post.
wp_safe_redirect( admin_url( 'post.php?post=' . $existing_post[0]->ID . '&action=edit' ) );
exit;
}
}

Expand All @@ -183,22 +185,24 @@
$post_count = $existing_posts->publish + $existing_posts->draft + $existing_posts->pending + $existing_posts->private;

// If a post already exists, redirect to edit screen.
if ( $post_count > 0 ) {
// Get the existing post.
$existing_post = get_posts(
array(
'post_type' => Template::SLUG,
'post_status' => array( 'publish', 'draft', 'pending', 'private' ),
'numberposts' => 1,
'suppress_filters' => false,
)
);
if ( $post_count <= 0 ) {
return;
}

if ( ! empty( $existing_post ) ) {
// Redirect to edit screen of the existing post.
wp_safe_redirect( admin_url( 'post.php?post=' . $existing_post[0]->ID . '&action=edit' ) );
exit;
}
// Get the existing post.
$existing_post = get_posts(

Check warning on line 193 in inc/classes/class-cpt-restriction.php

View workflow job for this annotation

GitHub Actions / Run PHPCS coding standards checks

get_posts() is uncached unless the "suppress_filters" parameter is set to false. If the suppress_filter parameter is set to false this can be safely ignored. More Info: https://docs.wpvip.com/technical-references/caching/uncached-functions/.
[
'post_type' => Template::SLUG,
'post_status' => [ 'publish', 'draft', 'pending', 'private' ],
'numberposts' => 1,
'suppress_filters' => false,
]
);

if ( ! empty( $existing_post ) ) {
// Redirect to edit screen of the existing post.
wp_safe_redirect( admin_url( 'post.php?post=' . $existing_post[0]->ID . '&action=edit' ) );
exit;
}
}

Expand Down Expand Up @@ -257,28 +261,32 @@

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

if ( $post_count > 0 ) {
// Find the "Add New" menu item.
foreach ( $submenu[ 'edit.php?post_type=' . Pattern::SLUG ] as $key => $item ) {
if ( 'post-new.php?post_type=' . Pattern::SLUG === $item[2] ) {
// Get the existing post.
$existing_post = get_posts(
array(
'post_type' => Pattern::SLUG,
'post_status' => array( 'publish', 'draft', 'pending', 'private' ),
'numberposts' => 1,
'suppress_filters' => false,
)
);

if ( ! empty( $existing_post ) ) {
// Change the "Add New" link to edit the existing post.
$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.
$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.
}
break;
}
if ( $post_count <= 0 ) {
return;
}

// Find the "Add New" menu item.
foreach ( $submenu[ 'edit.php?post_type=' . Pattern::SLUG ] as $key => $item ) {
if ( 'post-new.php?post_type=' . Pattern::SLUG !== $item[2] ) {
continue;
}

// Get the existing post.
$existing_post = get_posts(

Check warning on line 275 in inc/classes/class-cpt-restriction.php

View workflow job for this annotation

GitHub Actions / Run PHPCS coding standards checks

get_posts() is uncached unless the "suppress_filters" parameter is set to false. If the suppress_filter parameter is set to false this can be safely ignored. More Info: https://docs.wpvip.com/technical-references/caching/uncached-functions/.
[
'post_type' => Pattern::SLUG,
'post_status' => [ 'publish', 'draft', 'pending', 'private' ],
'numberposts' => 1,
'suppress_filters' => false,
]
);

if ( ! empty( $existing_post ) ) {
// Change the "Add New" link to edit the existing post.
$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.
$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.
}
break;
}
}

Expand Down
Loading
Loading