Update shortcodes library

This commit is contained in:
Robin Cornett
2018-11-17 11:02:06 -05:00
parent 467a60b585
commit c6c0c71a53
3 changed files with 33 additions and 12 deletions
@@ -102,6 +102,9 @@ If an image ID is required, Six/Ten Press image fields in a group will work, as
### Changelog
#### 0.7.0
* changed: moved all actions past a block editor/Gutenberg check to prevent media button scripts/modals loading when they shouldn't
#### 0.6.0
* added: custom enqueue hook `sixtenpress_shortcodes_enqueue` to allow loading dependent scripts without having to check if we're on a block editor page
* changed: enqueue scripts/styles for shortcode button only if not in the block editor
@@ -130,10 +130,7 @@ class SixTenPressShortcodes {
* Load all needful functions for the editor.
*/
public function start_editor() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
add_action( 'media_buttons', array( $this, 'media_buttons' ), 98 );
add_action( 'admin_footer', array( $this, 'widget_builder_modal' ) );
add_filter( 'sixtenpress_admin_color_picker', '__return_true' );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 4 );
do_action( 'sixtenpress_shortcode_load' );
}
@@ -141,9 +138,12 @@ class SixTenPressShortcodes {
* Do not enqueue scripts if we're on a block editor page.
*/
public function enqueue() {
if ( ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) || ( function_exists( 'is_block_editor' ) && is_block_editor() ) ) {
if ( $this->quit() ) {
return;
}
add_action( 'media_buttons', array( $this, 'media_buttons' ), 98 );
add_action( 'admin_footer', array( $this, 'widget_builder_modal' ) );
add_filter( 'sixtenpress_admin_color_picker', '__return_true' );
do_action( 'sixtenpress_shortcode_enqueue' );
add_filter( 'sixtenpress_shortcode_localization', array( $this, 'localization_args' ) );
$this->enqueue_script();
@@ -258,4 +258,22 @@ class SixTenPressShortcodes {
$this->loaded = true;
include plugin_dir_path( __FILE__ ) . 'modal.php';
}
/**
* Check if we are on a Gutenberg/block editor screen.
* @since 0.7.0
*
* @return bool
*/
private function quit() {
if ( ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) ) {
return true;
}
$screen = get_current_screen();
if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) {
return true;
}
return false;
}
}
@@ -10,7 +10,7 @@
* @author Robin Cornett <hello@robincornett.com>
* @copyright 2017-2018 Robin Cornett <hello@robincornett.com>
* @license GPL-2.0+
* @version 0.6.0
* @version 0.7.0
* @link https://gitlab.com/robincornett/sixtenpress-shortcodes
* @since 0.1.0
*/
@@ -37,7 +37,7 @@
* Loader versioning: http://jtsternberg.github.io/wp-lib-loader/
*/
if ( ! class_exists( 'SixTenPressShortcodes_060', false ) ) {
if ( ! class_exists( 'SixTenPressShortcodes_070', false ) ) {
/**
* Versioned loader class-name
@@ -48,18 +48,18 @@ if ( ! class_exists( 'SixTenPressShortcodes_060', false ) ) {
* @package SixTenPressShortcodes
* @author Robin Cornett <hello@robincornett.com>
* @license GPL-2.0+
* @version 0.6.0
* @version 0.7.0
* @link https://gitlab.com/robincornett/sixtenpress-shortcodes
* @since 0.1.0
*/
class SixTenPressShortcodes_060 {
class SixTenPressShortcodes_070 {
/**
* SixTenPressShortcodes version number
* @var string
* @since 0.1.0
*/
const VERSION = '0.6.0';
const VERSION = '0.7.0';
/**
* Current version hook priority.
@@ -68,7 +68,7 @@ if ( ! class_exists( 'SixTenPressShortcodes_060', false ) ) {
* @var int
* @since 0.1.0
*/
const PRIORITY = 9981;
const PRIORITY = 9980;
/**
* Starts the version checking process.
@@ -156,5 +156,5 @@ if ( ! class_exists( 'SixTenPressShortcodes_060', false ) ) {
}
// Kick it off.
new SixTenPressShortcodes_060();
new SixTenPressShortcodes_070();
}