diff --git a/includes/sixtenpress-shortcodes/README.md b/includes/sixtenpress-shortcodes/README.md
index fd0fadd..889069b 100644
--- a/includes/sixtenpress-shortcodes/README.md
+++ b/includes/sixtenpress-shortcodes/README.md
@@ -102,6 +102,22 @@ If an image ID is required, Six/Ten Press image fields in a group will work, as
### Changelog
+#### 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
+
+#### 0.5.1
+* changed: block helper enqueue method
+
+#### 0.5.0
+* added: abstract block helper class
+
+#### 0.4.0
+* added: hook just after editor initialization (currently load-post.php and load-post-new.php)
+
+#### 0.3.9
+* fixed: disappearing values if a field type changed (via ajax)
+
#### 0.3.8
* fixed: content now copies to editor with formatting
diff --git a/includes/sixtenpress-shortcodes/includes/class-sixtenpress-blocks.php b/includes/sixtenpress-shortcodes/includes/class-sixtenpress-blocks.php
new file mode 100644
index 0000000..4575697
--- /dev/null
+++ b/includes/sixtenpress-shortcodes/includes/class-sixtenpress-blocks.php
@@ -0,0 +1,114 @@
+register_script_style();
+ register_block_type(
+ $this->name,
+ array(
+ 'editor_script' => $this->block,
+ 'editor_style' => $this->block,
+ 'attributes' => $this->get_attributes(),
+ 'render_callback' => array( $this, 'render' ),
+ )
+ );
+ }
+
+ /**
+ * Build the rendering function.
+ *
+ * @param $atts
+ */
+ abstract public function render( $atts );
+
+ /**
+ * Register the admin editor assets. They do not need to be enqueued
+ * as that's handled by the block registration.
+ * Example usage:
+ * public function register_script_style() {
+ * wp_register_style( $this->block', plugin_dir_url( __FILE__ ) . 'css/block.css', array(), $this->version, 'all' );
+ * $minify = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
+ * $version = $minify ? $this->version : $this->version . current_time( 'gmt' );
+ * wp_register_script(
+ * $this->block',
+ * plugin_dir_url( __FILE__ ) . "js/index{$minify}.js",
+ * array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor' ),
+ * $version,
+ * false
+ * );
+ * }
+ */
+ abstract public function register_script_style();
+
+ /**
+ * Define the panels for the block.
+ *
+ * @uses get_individual_field_attributes
+ *
+ * @return array
+ */
+ abstract protected function get_panels();
+
+ /**
+ * Define the attributes for the block.
+ *
+ * @return array
+ */
+ abstract protected function get_attributes();
+
+ /**
+ * Define the array of individual field attributes.
+ *
+ * @param $field
+ * @param $id
+ *
+ * @return array
+ */
+ abstract protected function get_individual_field_attributes( $field, $id );
+
+ /**
+ * Define the type of field for our script.
+ *
+ * @param $method
+ *
+ * @return string
+ */
+ protected function get_field_type( $method ) {
+ $type = 'string';
+ if ( 'number' === $method ) {
+ return $method;
+ }
+ if ( 'checkbox' === $method ) {
+ return 'boolean';
+ }
+
+ return $type;
+ }
+}
diff --git a/includes/sixtenpress-shortcodes/includes/class-sixtenpress-shortcodes.php b/includes/sixtenpress-shortcodes/includes/class-sixtenpress-shortcodes.php
index 0aee8e4..68258b6 100644
--- a/includes/sixtenpress-shortcodes/includes/class-sixtenpress-shortcodes.php
+++ b/includes/sixtenpress-shortcodes/includes/class-sixtenpress-shortcodes.php
@@ -1,6 +1,6 @@
enqueue_script();
+ $this->enqueue_style();
}
/**
@@ -152,7 +164,8 @@ class SixTenPressShortcodes {
return;
}
do_action( 'sixtenpress_shortcode_before_media_button', $this->shortcode_args, $id );
- printf( '',
+ printf(
+ '',
esc_attr( $this->shortcode_args['button']['id'] ),
esc_attr( $this->shortcode_args['button']['class'] ),
$this->shortcode_args['button']['dashicon'] ? sprintf( ' ', esc_attr( $this->shortcode_args['button']['dashicon'] ) ) : '',
@@ -201,7 +214,7 @@ class SixTenPressShortcodes {
$css = str_replace( "\t", '', $css );
$css = str_replace( array( "\n", "\r" ), ' ', $css );
- return sanitize_text_field( strip_tags( $css ) );
+ return sanitize_text_field( wp_strip_all_tags( $css ) );
}
/**
diff --git a/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.js b/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.js
index bca52bf..51286ea 100644
--- a/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.js
+++ b/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.js
@@ -168,7 +168,7 @@
var output = '';
$( inputs ).each( function ( index ) {
var original_id = $( this ).attr( 'id' ),
- value = $( this ).val(),
+ value = $( '#' + original_id ).val(),
type = this.type;
if ( original_id ) {
var id = original_id.substr( original_id.lastIndexOf( '-' ) + 1 );
diff --git a/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.min.js b/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.min.js
index 6c9cb24..3aa161d 100644
--- a/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.min.js
+++ b/includes/sixtenpress-shortcodes/includes/js/shortcode-editor.min.js
@@ -1 +1 @@
-!function(t,e,i){"use strict";function n(t){var n=[];return e(t).each(function(t){var r=e(this).attr("id");i!==r&&(n[r]=e(this).val()),e(this).is(":checked")&&(n[r]="checked")}),n}function r(t,i){var n="";return e(t).each(function(t){var r=e(this).attr("id"),a=e(this).val(),c=this.type;if(r){var o=r.substr(r.lastIndexOf("-")+1);if(o.includes("nonce")&&(a=""),"checkbox"===c)if(i.group.length&&o.includes(i.group))a="";else if(e(this).is(":checked")){var s=[1,"1","on"],d=s.indexOf(a);a=-1!==d?"true":a}else a=e(this).is(":required")?"false":"";"button"===c&&(a=""),"textarea"!==c||i.self||(a=""),(a||e(this).is(":required"))&&(n+=" "+o+'="'+a+'"')}}),n}function a(t,i){var n=e("#"+i),r=n.find("textarea").val();if(!r){var a=n.find("textarea[id*='"+t+"']").attr("id");"undefined"!==a&&a.length&&(r=tinymce.get(a).getContent({format:"raw"}))}return r}function c(t,i){var n="";return e(t).each(function(t,r){var a=e("#"+i).find("[id*='"+r+"']"),c=[];e(a).each(function(t){e(this).is(":checked")&&c.push(e(this).val())}),n+=c.length?" "+r+'="'+c.toString()+'"':""}),n}var o={};o.init=function(){Object.keys(o.params).forEach(function(i){function s(i){i.preventDefault(),v=i.target,m=!0,e(k).show(),e(".media-modal-close, .media-modal-backdrop, .sixtenpress-cancel-insertion").click(u),e(t).on("keydown",function(t){27===t.keyCode&&m&&u(t)})}function d(t){if(t.preventDefault(),e(v).hasClass(p.button)){var i=r(g,p),n=p.group?c(p.group,p.slug):"",o="";i&&(o="["+p.shortcode+n+i+"]",p.self||(o+=a(p.slug,p.modal)+"[/"+p.shortcode+"]"),tinymce.get(e(v).attr("data-editor")).execCommand("mceInsertContent",!1,o))}u(t)}function u(t){t.preventDefault(),e(k).hide(),f(),v=m=!1}function f(){e(g).each(function(t){var i=e(this).attr("id");if("checkbox"===this.type){var n="checked"===x[i];e(this).attr("checked",n)}else e(this).val(x[i])}),e(k+" .upload-file-preview").remove(),h(),l()}function h(){var t=e(k).find(".wp-picker-container");t.length&&t.each(function(){var t=e(this).parent();t.html(t.find('input[type="text"].color-field').attr("style","")),t.find('input[type="text"].wp-color-picker').each(function(){var t=e(this),i=t.data("colorpicker")||{};t.wpColorPicker(e.extend({},!1,i))})})}function l(){var t=e(k).find("textarea[id*='"+p.slug+"']");if(t.length){var i=t.attr("id");tinymce.get(i).setContent("")}}if(o.params.hasOwnProperty(i)){var p=o.params[i],v=!1,m=!1,k="."+p.modal,g=e("#"+p.modal).find(":input"),x=n(g),y=p.button.replace(" ",".");e("."+y).click(s),e(k+".sixtenpress-default-ui .sixtenpress-insert").click(d)}})},o.params="undefined"==typeof SixTenShortcodes?"":SixTenShortcodes,void 0!==o.params&&o.init()}(document,jQuery);
\ No newline at end of file
+!function(t,e,i){"use strict";var n={};n.init=function(){Object.keys(n.params).forEach(function(r){if(n.params.hasOwnProperty(r)){var a=n.params[r],c=!1,o=!1,s="."+a.modal,d=e("#"+a.modal).find(":input"),u=function(t){var n=[];return e(t).each(function(t){var r=e(this).attr("id");i!==r&&(n[r]=e(this).val()),e(this).is(":checked")&&(n[r]="checked")}),n}(d),f=a.button.replace(" ",".");e("."+f).click(function(i){i.preventDefault(),c=i.target,o=!0,e(s).show(),e(".media-modal-close, .media-modal-backdrop, .sixtenpress-cancel-insertion").click(h),e(t).on("keydown",function(t){27===t.keyCode&&o&&h(t)})}),e(s+".sixtenpress-default-ui .sixtenpress-insert").click(function(t){if(t.preventDefault(),e(c).hasClass(a.button)){var i=function(t,i){var n="";return e(t).each(function(t){var r=e(this).attr("id"),a=e("#"+r).val(),c=this.type;if(r){var o=r.substr(r.lastIndexOf("-")+1);o.includes("nonce")&&(a=""),"checkbox"===c&&(a=i.group.length&&o.includes(i.group)?"":e(this).is(":checked")?-1!==[1,"1","on"].indexOf(a)?"true":a:e(this).is(":required")?"false":""),"button"===c&&(a=""),"textarea"!==c||i.self||(a=""),(a||e(this).is(":required"))&&(n+=" "+o+'="'+a+'"')}}),n}(d,a),n=a.group?function(t,i){var n="";return e(t).each(function(t,r){var a=e("#"+i).find("[id*='"+r+"']"),c=[];e(a).each(function(t){e(this).is(":checked")&&c.push(e(this).val())}),n+=c.length?" "+r+'="'+c.toString()+'"':""}),n}(a.group,a.slug):"",r="";i&&(r="["+a.shortcode+n+i+"]",a.self||(r+=function(t,i){var n=e("#"+i),r=n.find("textarea").val();if(!r){var a=n.find("textarea[id*='"+t+"']").attr("id");"undefined"!==a&&a.length&&(r=tinymce.get(a).getContent({format:"raw"}))}return r}(a.slug,a.modal)+"[/"+a.shortcode+"]"),tinymce.get(e(c).attr("data-editor")).execCommand("mceInsertContent",!1,r))}h(t)})}function h(t){var i;t.preventDefault(),e(s).hide(),e(d).each(function(t){var i=e(this).attr("id"),n=this.type;if("checkbox"===n){var r="checked"===u[i];e(this).attr("checked",r)}else e(this).val(u[i])}),e(s+" .upload-file-preview").remove(),(i=e(s).find(".wp-picker-container")).length&&i.each(function(){var t=e(this).parent();t.html(t.find('input[type="text"].color-field').attr("style","")),t.find('input[type="text"].wp-color-picker').each(function(){var t=e(this),i=t.data("colorpicker")||{};t.wpColorPicker(e.extend({},!1,i))})}),function(){var t=e(s).find("textarea[id*='"+a.slug+"']");if(t.length){var i=t.attr("id");tinymce.get(i).setContent("")}}(),c=o=!1}})},n.params="undefined"==typeof SixTenShortcodes?"":SixTenShortcodes,void 0!==n.params&&n.init()}(document,jQuery);
\ No newline at end of file
diff --git a/includes/sixtenpress-shortcodes/sixtenpress-shortcodes.php b/includes/sixtenpress-shortcodes/sixtenpress-shortcodes.php
index d635214..8c3d996 100644
--- a/includes/sixtenpress-shortcodes/sixtenpress-shortcodes.php
+++ b/includes/sixtenpress-shortcodes/sixtenpress-shortcodes.php
@@ -8,15 +8,15 @@
* @category WordPressLibrary
* @package SixTenPressShortcodes
* @author Robin Cornett
- * @copyright 2016 Robin Cornett
+ * @copyright 2017-2018 Robin Cornett
* @license GPL-2.0+
- * @version 0.3.8
+ * @version 0.6.0
* @link https://gitlab.com/robincornett/sixtenpress-shortcodes
* @since 0.1.0
*/
/**
- * Copyright (c) 2017 Robin Cornett (email : hello@robincornett.com)
+ * Copyright (c) 2017-2018 Robin Cornett (email : hello@robincornett.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
@@ -37,7 +37,7 @@
* Loader versioning: http://jtsternberg.github.io/wp-lib-loader/
*/
-if ( ! class_exists( 'SixTenPressShortcodes_038', false ) ) {
+if ( ! class_exists( 'SixTenPressShortcodes_060', false ) ) {
/**
* Versioned loader class-name
@@ -48,18 +48,18 @@ if ( ! class_exists( 'SixTenPressShortcodes_038', false ) ) {
* @package SixTenPressShortcodes
* @author Robin Cornett
* @license GPL-2.0+
- * @version 0.3.8
+ * @version 0.6.0
* @link https://gitlab.com/robincornett/sixtenpress-shortcodes
* @since 0.1.0
*/
- class SixTenPressShortcodes_038 {
+ class SixTenPressShortcodes_060 {
/**
* SixTenPressShortcodes version number
* @var string
* @since 0.1.0
*/
- const VERSION = '0.3.8';
+ const VERSION = '0.6.0';
/**
* Current version hook priority.
@@ -68,7 +68,7 @@ if ( ! class_exists( 'SixTenPressShortcodes_038', false ) ) {
* @var int
* @since 0.1.0
*/
- const PRIORITY = 9986;
+ const PRIORITY = 9981;
/**
* Starts the version checking process.
@@ -147,10 +147,14 @@ if ( ! class_exists( 'SixTenPressShortcodes_038', false ) ) {
// Include and initiate SixTenPressShortcodes.
require_once SIXTENPRESSSHORTCODES_DIR . 'includes/class-sixtenpress-shortcodes.php';
+
+ if ( function_exists( 'register_block_type' ) ) {
+ require_once SIXTENPRESSSHORTCODES_DIR . 'includes/class-sixtenpress-blocks.php';
+ }
}
}
// Kick it off.
- new SixTenPressShortcodes_038();
+ new SixTenPressShortcodes_060();
}