Skip to content

Commit

Permalink
Merge pull request #15 from DLXPlugins/feature/deregister-uncategoriz…
Browse files Browse the repository at this point in the history
…ed-patterns

Hide all unregistered patterns.
  • Loading branch information
ronalfy authored Jan 30, 2024
2 parents 604fff9 + c8d7038 commit bb39546
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
standard_repo: '' # Public (git) repository URL of the coding standard
repo_branch: 'master' # Branch of Standard repository
phpcs_bin_path: 'phpcs' # Custom PHPCS bin path
use_local_config: 'false' # Use local config if available
use_local_config: 'true' # Use local config if available
extra_args: '--report-json=./phpcs.json'
- name: Update summary
run: |
Expand Down
2 changes: 0 additions & 2 deletions pattern-wrangler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public function plugins_loaded() {
basename( __DIR__ ) . '/languages'
);

// Blocks::run();

$admin = new Admin();
$admin->run();

Expand Down
4 changes: 2 additions & 2 deletions php/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ public function output_pattern_sync_column( $column, $post_id ) {
* Add the admin menu.
*/
public function add_admin_menu() {
$options = Options::get_options();
$hide_all_patterns = (bool) $options['hideAllPatterns'] ?? false;
$options = Options::get_options();
$hide_all_patterns = (bool) $options['hideAllPatterns'] ?? false;
$hide_patterns_menu = (bool) $options['hidePatternsMenu'] ?? false;

if ( $hide_all_patterns && $hide_patterns_menu ) {
Expand Down
1 change: 0 additions & 1 deletion php/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ public function init() {
);

// Enqueue block assets.
// add_action( 'enqueue_block_assets', array( $this, 'register_block_styles' ) );
add_action( 'enqueue_block_editor_assets', array( $this, 'register_block_editor_scripts' ) );
}

Expand Down
25 changes: 25 additions & 0 deletions php/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,31 @@ function ( $a, $b ) {
return $all_categories;
}

/**
* Get the plugin's supported file extensions.
*
* @since 1.0.0
*
* @return array The supported file extensions.
*/
public static function get_supported_file_extensions() {
$file_extensions = array(
'jpeg',
'jpg',
'gif',
'png',
'webp',
);
/**
* Filter the valid file extensions for the photo block.
*
* @param array $file_extensions The valid mime types.
*/
$file_extensions = apply_filters( 'wppic_block_file_extensions', $file_extensions );

return $file_extensions;
}

/**
* Get the current admin tab.
*
Expand Down
3 changes: 0 additions & 3 deletions php/Options.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Options class.
*
Expand Down Expand Up @@ -75,8 +74,6 @@ public static function update_options( $options ) {
* @return array Array of options.
*/
public static function get_options( $force = false ) {
// delete_option( self::$options_key );
// die( '' );
if ( is_array( self::$options ) && ! $force ) {
return self::$options;
}
Expand Down
27 changes: 26 additions & 1 deletion php/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,22 @@ public function run() {

$hide_all_patterns = (bool) $options['hideAllPatterns'];
if ( $hide_all_patterns ) {
add_action( 'init', array( $this, 'remove_core_patterns' ), 1004 );
add_action( 'init', array( $this, 'remove_core_patterns' ), 9 );
add_filter( 'should_load_remote_block_patterns', '__return_false' );
}

// Check if remote patterns is disabled.
$hide_remote_patterns = (bool) $options['hideRemotePatterns'];
if ( $hide_remote_patterns ) {
add_filter( 'should_load_remote_block_patterns', '__return_false' );
}

// Check if core patterns is disabled.
$hide_core_patterns = (bool) $options['hideCorePatterns'];
if ( $hide_core_patterns ) {
add_action( 'init', array( $this, 'remove_core_patterns' ), 9 );
remove_action( 'init', '_register_core_block_patterns_and_categories' );
}
}

/**
Expand Down Expand Up @@ -155,6 +168,18 @@ public function maybe_deregister_uncategorized_patterns() {
foreach ( $all_patterns as $index => $pattern ) {
if ( ! isset( $pattern['categories'] ) || empty( $pattern['categories'] ) ) {
unregister_block_pattern( $pattern['slug'] );
} else {
$found = false;
$block_categories = $pattern['categories'] ?? array();
foreach ( $block_categories as $block_category ) {
$categories = \WP_Block_Pattern_Categories_Registry::get_instance();
if ( $categories->is_registered( $block_category ) ) {
$found = true;
}
}
if ( ! $found ) {
unregister_block_pattern( $pattern['name'] );
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions php/Plugin_License.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function perform_action( string $action, string $license = '', bool $forc
*/
private function perform_license_action( string $action, bool $force ) {

$options = Options::get_options();
$maybe_check = get_site_transient( 'dlxgbhacks_core_license_check' );
$options = Options::get_options();
$maybe_check = get_site_transient( 'dlxgbhacks_core_license_check' );

if ( 'check_license' === $action && ! $force && $maybe_check ) {
return $maybe_check;
Expand Down
4 changes: 4 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@

<exclude-pattern>/node_modules/</exclude-pattern>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/lib/</exclude-pattern>
<exclude-pattern>/build/</exclude-pattern>
<exclude-pattern>/dist/</exclude-pattern>
<exclude-pattern>/php/Plugin_Updater.php</exclude-pattern>
</ruleset>

0 comments on commit bb39546

Please sign in to comment.