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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dlxPatternWranglerNetworkAdminSettings": "readonly",
"dlxEnhancedPatternsView": "readonly",
"ajaxurl": "readonly",
"dlxPatternPreviewVars": "readonly"
"dlxPatternPreviewVars": "readonly",
"dlxEnhancedCategoriesView": "readonly"
},
"env": {
"browser": true,
Expand Down
2 changes: 2 additions & 0 deletions build/dlx-pw-categories-view-rtl.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/dlx-pw-categories-view.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-a11y', 'wp-api-fetch', 'wp-blob', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-escape-html', 'wp-i18n', 'wp-url'), 'version' => 'f6b04ed8a7e553678c0d');
2 changes: 2 additions & 0 deletions build/dlx-pw-categories-view.css

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions build/dlx-pw-categories-view.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/dlx-pw-fancybox-rtl.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/dlx-pw-fancybox.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'bad5a743eede878200a1');
<?php return array('dependencies' => array(), 'version' => 'e4cbeae86aee5c3db3b1');
2 changes: 1 addition & 1 deletion build/dlx-pw-fancybox.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/dlx-pw-fancybox.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/dlx-pw-patterns-view-rtl.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/dlx-pw-patterns-view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-blob', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-escape-html', 'wp-i18n', 'wp-primitives', 'wp-private-apis', 'wp-url', 'wp-warning'), 'version' => 'f5ce2d81a65fd019f1a6');
<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-blob', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-escape-html', 'wp-i18n', 'wp-primitives', 'wp-private-apis', 'wp-url', 'wp-warning'), 'version' => '5bf26e3e2a1a9ff7192d');
4 changes: 2 additions & 2 deletions build/dlx-pw-patterns-view.css

Large diffs are not rendered by default.

71 changes: 38 additions & 33 deletions build/dlx-pw-patterns-view.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-i18n', 'wp-url'), 'version' => '134b5ca906a63eab1257');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-i18n', 'wp-url'), 'version' => 'd7be0f1991637158b4ab');
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dlx-pw-admin-css.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '76069a08eb155534d8a6');
<?php return array('dependencies' => array(), 'version' => '87f9f9bcd1bfdacc18a9');
84 changes: 33 additions & 51 deletions dist/dlx-pw-admin-css.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dlx-pw-admin.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-a11y', 'wp-components', 'wp-i18n'), 'version' => '24775400f5ea69837f49');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-a11y', 'wp-components', 'wp-i18n'), 'version' => '8d1ce550426fad6ced15');
2 changes: 1 addition & 1 deletion dist/dlx-pw-admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dlx-pw-admin.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
http://jedwatson.github.io/classnames
*/

/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */

/**
* @license lucide-react v0.468.0 - ISC
Expand Down
2 changes: 1 addition & 1 deletion dist/dlx-pw-network-admin-settings.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-a11y', 'wp-components', 'wp-compose', 'wp-i18n', 'wp-keycodes', 'wp-url'), 'version' => '14610467a9de86d99cc7');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-a11y', 'wp-components', 'wp-compose', 'wp-i18n', 'wp-keycodes', 'wp-url'), 'version' => '3f47258acb34fbe5aa0d');
2 changes: 1 addition & 1 deletion dist/dlx-pw-network-admin-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dlx-pw-network-admin-settings.js.LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
http://jedwatson.github.io/classnames
*/

/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */

/**
* @license lucide-react v0.468.0 - ISC
Expand Down
2 changes: 1 addition & 1 deletion dist/dlx-pw-post-utilities.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'e33b47d4856904d146da');
<?php return array('dependencies' => array(), 'version' => '831421f59846c19817f0');
2 changes: 1 addition & 1 deletion dist/dlx-pw-post-utilities.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pattern-wrangler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Pattern Wrangler
* Plugin URI: https://dlxplugins.com/plugins/pattern-wrangler/
* Description: Manage your block patterns.
* Version: 2.2.2
* Version: 2.3.0
* Requires at least: 6.8
* Requires PHP: 7.2
* Author: DLX Plugins
Expand All @@ -24,7 +24,7 @@

require_once __DIR__ . '/functions.php';

define( 'DLXPW_PATTERN_WRANGLER_VERSION', '2.2.2' );
define( 'DLXPW_PATTERN_WRANGLER_VERSION', '2.3.0' );
define( 'DLXPW_PATTERN_WRANGLER_FILE', __FILE__ );

// Support for site-level autoloading.
Expand Down
113 changes: 93 additions & 20 deletions php/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,28 @@ public function add_admin_menu() {
add_action( 'admin_print_scripts-' . $enhanced_patterns_hook, array( $this, 'enqueue_admin_scripts_patterns' ) );
}

add_submenu_page(
$enable_enhanced_view ? 'pattern-wrangler-view' : 'edit.php?post_type=wp_block',
__( 'Categories', 'pattern-wrangler' ),
__( 'Categories', 'pattern-wrangler' ),
'edit_others_posts',
'edit-tags.php?taxonomy=wp_pattern_category&post_type=wp_block',
'',
5
);
if ( ! $enable_enhanced_view ) {
add_submenu_page(
$enable_enhanced_view ? 'pattern-wrangler-view' : 'edit.php?post_type=wp_block',
__( 'Categories', 'pattern-wrangler' ),
__( 'Categories', 'pattern-wrangler' ),
'edit_others_posts',
'edit-tags.php?taxonomy=wp_pattern_category&post_type=wp_block',
'',
5
);
} else {
$enhanced_categories_hook = add_submenu_page(
$enable_enhanced_view ? 'pattern-wrangler-view' : 'edit.php?post_type=wp_block',
__( 'Categories', 'pattern-wrangler' ),
__( 'Categories', 'pattern-wrangler' ),
'edit_others_posts',
'pattern-wrangler-categories-view',
array( $this, 'enhanced_categories_view' ),
5
);
add_action( 'admin_print_scripts-' . $enhanced_categories_hook, array( $this, 'enqueue_admin_scripts_categories' ) );
}

$hook = add_submenu_page(
$enable_enhanced_view ? 'pattern-wrangler-view' : 'edit.php?post_type=wp_block',
Expand Down Expand Up @@ -563,17 +576,19 @@ public function enqueue_admin_scripts_patterns() {
'dlx-pw-patterns-view',
'dlxEnhancedPatternsView',
array(
'getNonce' => wp_create_nonce( 'dlx-pw-patterns-view-get-patterns' ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
'createNonce' => wp_create_nonce( 'dlx-pw-patterns-view-create-pattern' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'options' => $options,
'networkOptions' => Options::get_network_options(),
'isMultisite' => is_multisite(),
'networkAdminSettingsUrl' => Functions::get_network_settings_url(),
'isUserNetworkAdmin' => current_user_can( 'manage_network' ),
'getSiteBaseUrl' => esc_url( admin_url() ),
'doNotShowAgain' => get_user_meta( get_current_user_id(), 'dlx_pw_do_not_show_again', true ) ?? false,
'getNonce' => wp_create_nonce( 'dlx-pw-patterns-view-get-patterns' ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
'createNonce' => wp_create_nonce( 'dlx-pw-patterns-view-create-pattern' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'options' => $options,
'networkOptions' => Options::get_network_options(),
'isMultisite' => is_multisite(),
'networkAdminSettingsUrl' => Functions::get_network_settings_url(),
'isUserNetworkAdmin' => current_user_can( 'manage_network' ),
'getSiteBaseUrl' => esc_url( admin_url() ),
'doNotShowAgain' => get_user_meta( get_current_user_id(), 'dlx_pw_do_not_show_again', true ) ?? false,
'syncedPatternPopupsActive' => Functions::is_activated( 'synced-pattern-popups/sppopups.php' ),
'syncedPatternPopupsUrl' => esc_url_raw( admin_url( 'themes.php?page=simplest-popup-patterns' ) ),
)
);
\wp_set_script_translations( 'dlx-pw-patterns-view', 'pattern-wrangler' );
Expand All @@ -589,6 +604,55 @@ public function enqueue_admin_scripts_patterns() {
);
}

/**
* Enqueue scripts for the enhanced categories view.
*/
public function enqueue_admin_scripts_categories() {
// Retrieve local options.
$options = Options::get_options();
$enable_enhanced_view = (bool) $options['enableEnhancedView'] ?? false;

if ( $enable_enhanced_view ) {
// Enqueue main scripts.
$deps = require_once Functions::get_plugin_dir( 'build/dlx-pw-categories-view.asset.php' );
wp_enqueue_script(
'dlx-pw-categories-view',
Functions::get_plugin_url( 'build/dlx-pw-categories-view.js' ),
$deps['dependencies'],
$deps['version'],
true
);

wp_localize_script(
'dlx-pw-categories-view',
'dlxEnhancedCategoriesView',
array(
'getNonce' => wp_create_nonce( 'dlx-pw-categories-view-get-categories' ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
'createNonce' => wp_create_nonce( 'dlx-pw-categories-view-create-category' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'options' => $options,
'networkOptions' => Options::get_network_options(),
'isMultisite' => is_multisite(),
'networkAdminSettingsUrl' => Functions::get_network_settings_url(),
'isUserNetworkAdmin' => current_user_can( 'manage_network' ),
'getSiteBaseUrl' => esc_url( admin_url() ),
'doNotShowAgain' => get_user_meta( get_current_user_id(), 'dlx_pw_do_not_show_again', true ) ?? false,
)
);
\wp_set_script_translations( 'dlx-pw-categories-view', 'pattern-wrangler' );

// Enqueue admin styles.
wp_enqueue_style(
'dlx-pw-categories-view-css',
Functions::get_plugin_url( 'build/dlx-pw-categories-view.css' ),
array(),
$deps['version'],
'all'
);
}
}

/**
* Render the admin page.
*/
Expand Down Expand Up @@ -650,4 +714,13 @@ public function enhanced_patterns_view() {
<div id="dlx-pattern-wrangler-view"></div>
<?php
}

/**
* Render the enhanced categories view page.
*/
public function enhanced_categories_view() {
?>
<div id="dlx-pattern-wrangler-categories-view"></div>
<?php
}
}
52 changes: 33 additions & 19 deletions php/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public static function get_pattern_categories_from_taxonomy() {
'count' => true,
)
);

// Get lables into shape.
$categories_arr = array();
foreach ( $categories as &$category ) {
$category->name = html_entity_decode( $category->name, ENT_QUOTES );
}
return $categories;
}

Expand All @@ -129,16 +135,18 @@ public static function get_pattern_categories( $after_filters = false ) {
$pattern_categories = Patterns::get_instance();
$pattern_categories = $pattern_categories->get_registered_categories();

// Get registered patterns.
$pattern_registry = Patterns::get_instance();
$pattern_registry = $pattern_registry->get_registered_patterns();

// If after filters, get registered categories *after* filters.
if ( $after_filters ) {
$pattern_categories = \WP_Block_Pattern_Categories_Registry::get_instance();
$pattern_categories = $pattern_categories->get_all_registered();
$pattern_registry = \WP_Block_Patterns_Registry::get_instance();
$pattern_registry = $pattern_registry->get_all_registered();
}

// Get all registered block patterns. We'll use this for a count.
$pattern_registry = \WP_Block_Patterns_Registry::get_instance();
$pattern_registry = $pattern_registry->get_all_registered();

// Get all pattern categories from the built-in WP taxonomy.
$pattern_categories_taxonomy = self::get_pattern_categories_from_taxonomy();

Expand All @@ -161,6 +169,15 @@ public static function get_pattern_categories( $after_filters = false ) {
continue;
}

// Get category count from registered patterns.
$category_count = 0;
foreach ( $pattern_registry as $pattern ) {
$pattern_categories = isset( $pattern['categories'] ) ? $pattern['categories'] : array();
if ( in_array( $category['name'], $pattern_categories, true ) ) {
++$category_count;
}
}

// Loop through custom categories, and determine if a category is on or off.
$category_enabled = isset( $custom_pattern_categories[ $category['name'] ]['enabled'] ) ? (bool) $custom_pattern_categories[ $category['name'] ]['enabled'] : true;
// Decode HTML entities to prevent double encoding in React.
Expand All @@ -174,7 +191,7 @@ public static function get_pattern_categories( $after_filters = false ) {
'customLabel' => $category_custom,
'enabled' => $category_enabled,
'slug' => $category['name'],
'count' => $category['count'] ?? 0,
'count' => $category_count,
'mappedTo' => $category_mapped_to,
);
}
Expand All @@ -190,17 +207,6 @@ function ( $a, $b ) {
}
);

// Loop through all patterns and increment a count for each category. Since core tax pattern categories have a count for core patterns.
foreach ( $pattern_registry as $pattern ) {
$pattern_categories = isset( $pattern['categories'] ) ? $pattern['categories'] : array();

foreach ( $pattern_categories as $category ) {
if ( isset( $all_categories[ $category ] ) ) {
++$all_categories[ $category ]['count'];
}
}
}

return array(
'registered' => $all_categories,
'categories' => $pattern_categories_taxonomy,
Expand Down Expand Up @@ -365,7 +371,7 @@ public static function is_core_patterns_enabled_for_site( $site_id = 1 ) {
*
* @return bool true if hiding patterns, false if not.
*/
$hide_core_patterns = apply_filters( 'dlxpw_hide_core_patterns', $hide_core_patterns, $site_id, true );
$hide_core_patterns = apply_filters( 'dlxpw_hide_core_patterns', $hide_core_patterns, $site_id, $is_multisite );

// Return the value.
if ( $hide_core_patterns ) {
Expand Down Expand Up @@ -595,8 +601,16 @@ public static function get_network_settings_url( $tab = '', $sub_tab = '' ) {
public static function is_activated( $path, $type = 'plugin' ) {

// Gets all active plugins on the current site.
$active_plugins = self::is_multisite() ? get_site_option( 'active_sitewide_plugins' ) : get_option( 'active_plugins', array() );
if ( in_array( $path, $active_plugins, true ) ) {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}

if ( is_multisite() ) {
if ( is_plugin_active_for_network( $path ) ) {
return true;
}
}
if ( is_plugin_active( $path ) ) {
return true;
}
return false;
Expand Down
26 changes: 25 additions & 1 deletion php/Patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class Patterns {
*/
private static $registered_categories_registry = null;

/**
* Holds the registered patterns *before* filters. Can access after `init` action.
*
* @var WP_Block_Patterns_Registry $registered_patterns_registry
*/
private static $registered_patterns_registry = null;

/**
* Return an instance of the class
*
Expand Down Expand Up @@ -78,6 +85,9 @@ public function run() {
// Get registered categories *before* filters.
add_action( 'init', array( $this, 'get_registered_categories' ), 800 );

// Get registered patterns *before* filters.
add_action( 'init', array( $this, 'get_registered_patterns' ), 801 );

// Deregister all pattenrs if all patterns are disabled.
add_action( 'init', array( $this, 'maybe_deregister_all_patterns' ), 2000 );

Expand Down Expand Up @@ -154,7 +164,7 @@ function ( $caps, $cap ) {
}

// Check if core patterns is disabled.
if ( Functions::is_core_patterns_enabled_for_site() ) {
if ( ! Functions::is_core_patterns_enabled_for_site() ) {
add_action( 'init', array( $this, 'remove_core_patterns' ), 9 );
remove_action( 'init', '_register_core_block_patterns_and_categories' );
}
Expand All @@ -177,6 +187,20 @@ public function get_registered_categories() {
return self::$registered_categories_registry;
}

/**
* Get registered patterns.
*
* @return WP_Block_Patterns_Registry
*/
public function get_registered_patterns() {
if ( null === self::$registered_patterns_registry ) {
$patterns = \WP_Block_Patterns_Registry::get_instance();
$patterns = $patterns->get_all_registered();
self::$registered_patterns_registry = $patterns;
}
return self::$registered_patterns_registry;
}

/**
* Add admin notices to the patterns post type list view.
*/
Expand Down
Loading