From 4952e047a9ca9e1e3a760a146b6b9dd295f60dc9 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 16:38:10 -0400 Subject: [PATCH 01/11] Start construction of block and shortcode - pull the button and modal output out of the main widget() function of the widget and create them as static functions - move the widget's has_instance boolean property to the plugin class, for tracking whether widget/shortcode/block has created a modal - `wp scaffold` a block, using a shortcode as a render callback - add a shortcode to this plugin that outputs the button and enqueues necessary assets like the modal and its CSS and JavaScript files --- assets/widget.css | 2 +- blocks/button.php | 50 +++++++++++++++++++++ blocks/button/editor.css | 9 ++++ blocks/button/index.js | 82 ++++++++++++++++++++++++++++++++++ includes/class-shortcodes.php | 34 ++++++++++++++ includes/class-widget.php | 80 +++++++++++++++++++++++++-------- republication-tracker-tool.php | 5 +++ 7 files changed, 242 insertions(+), 20 deletions(-) create mode 100644 blocks/button.php create mode 100644 blocks/button/editor.css create mode 100644 blocks/button/index.js create mode 100644 includes/class-shortcodes.php diff --git a/assets/widget.css b/assets/widget.css index 6b79999..81aad92 100644 --- a/assets/widget.css +++ b/assets/widget.css @@ -116,4 +116,4 @@ .modal-open-disallow-scrolling { overflow: hidden; -} \ No newline at end of file +} diff --git a/blocks/button.php b/blocks/button.php new file mode 100644 index 0000000..59d0443 --- /dev/null +++ b/blocks/button.php @@ -0,0 +1,50 @@ + 'button-block-editor', + 'editor_style' => 'button-block-editor', + 'style' => 'republication-tracker-tool-css', + 'script' => 'republication-tracker-tool-js', + 'render_clalback' => array( 'Republication_Tracker_Tool_Shortcodes', 'button_shortcode' ); + ) ); +} +add_action( 'init', 'button_block_init' ); diff --git a/blocks/button/editor.css b/blocks/button/editor.css new file mode 100644 index 0000000..80006c7 --- /dev/null +++ b/blocks/button/editor.css @@ -0,0 +1,9 @@ +/** + * The following styles get applied inside the editor only. + * + * Replace them with your own styles or remove the file completely. + */ + +.wp-block-republication-tracker-tool-button { + border: 1px dotted #f00; +} diff --git a/blocks/button/index.js b/blocks/button/index.js new file mode 100644 index 0000000..5c13553 --- /dev/null +++ b/blocks/button/index.js @@ -0,0 +1,82 @@ +( function( wp ) { + /** + * Registers a new block provided a unique name and an object defining its behavior. + * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/#registering-a-block + */ + var registerBlockType = wp.blocks.registerBlockType; + /** + * Returns a new element of given type. Element is an abstraction layer atop React. + * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/packages/packages-element/ + */ + var el = wp.element.createElement; + /** + * Retrieves the translation of text. + * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/packages/packages-i18n/ + */ + var __ = wp.i18n.__; + + /** + * Every block starts by registering a new block type definition. + * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/#registering-a-block + */ + registerBlockType( 'republication-tracker-tool/button', { + /** + * This is the display title for your block, which can be translated with `i18n` functions. + * The block inserter will show this name. + */ + title: __( 'Republication Modal Button', 'republication-tracker-tool' ), + + /** + * An icon property should be specified to make it easier to identify a block. + * These can be any of WordPress’ Dashicons, or a custom svg element. + */ + icon: 'button', + + /** + * Blocks are grouped into categories to help users browse and discover them. + * The categories provided by core are `common`, `embed`, `formatting`, `layout` and `widgets`. + */ + category: 'widgets', + + /** + * Optional block extended support features. + */ + supports: { + // Removes support for an HTML mode. + html: false, + }, + + /** + * The edit function describes the structure of your block in the context of the editor. + * This represents what the editor will render when the block is used. + * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/block-edit-save/#edit + * + * @param {Object} [props] Properties passed from the editor. + * @return {Element} Element to render. + */ + edit: function( props ) { + return el( + 'p', + { className: props.className }, + __( 'Hello from the editor!', 'republication-tracker-tool' ) + ); + }, + + /** + * The save function defines the way in which the different attributes should be combined + * into the final markup, which is then serialized by Gutenberg into `post_content`. + * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/block-edit-save/#save + * + * @return {Element} Element to render. + */ + save: function() { + return el( + 'p', + {}, + __( 'Hello from the saved content!', 'republication-tracker-tool' ) + ); + } + } ); +} )( + window.wp +); diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php new file mode 100644 index 0000000..a9edc5e --- /dev/null +++ b/includes/class-shortcodes.php @@ -0,0 +1,34 @@ +'; - echo sprintf( - '

', - esc_html__( 'Republish This Story', 'republication-tracker-tool' ) - ); + echo $this->button_output(); echo sprintf( '

%s

', esc_html__( 'Creative Commons License', 'republication-tracker-tool' ), @@ -83,22 +74,73 @@ public function widget( $args, $instance ) { wp_kses_post( wpautop( esc_html( $instance['text'] ) ) ) ); + $this->maybe_print_modal_content(); + echo wp_kses_post( $args['after_widget'] ); + } + + /** + * Consider whether to output the markup for the button, and if so, do so + * + * @uses $this::print_modal_content() + * @return String Empty string if there is no need to output the modal contents, or + * the output of $this::print_modal_content() if there is a need. + */ + public static function maybe_print_modal_content() { + /** + * The parent singleton class, grabbed here so that we can check whether an instance already exists + */ + $Republication_Tracker_Tool = Republication_Tracker_Tool::get_instance(); + // if has_instance is false, we can continue with displaying the modal - if( isset( $this->has_instance ) && false === $this->has_instance ){ + if( isset( $Republication_Tracker_Tool->has_instance ) && false === $Republication_Tracker_Tool->has_instance ){ // update has_instance so the next time the widget is created on the same page, it does not create a second modal - $this->has_instance = true; + $Republication_Tracker_Tool->has_instance = true; - printf( - '', - esc_attr( $post->ID ), - esc_attr( plugins_url() ), - esc_html( include_once( $republication_plugin_path . 'shareable-content.php' ) ) - ); + error_log(var_export( 'aaa', true)); + return Republication_Tracker_Tool_Widget::modal_content(); + } else { + error_log(var_export( 'no need', true)); + return ''; + } + } + /** + * Output the markup for the button + * + * @global $post; + * @return String HTML of the modal contents. + */ + public static function modal_content() { + global $post; + // define our path to grab file content from + $republication_plugin_path = plugin_dir_path( __FILE__ ); + + return sprintf( + '', + esc_attr( $post->ID ), + esc_attr( plugins_url() ), + esc_html( include_once( $republication_plugin_path . 'shareable-content.php' ) ) + ); + } + + /** + * Output the modal-opening button. + * + * @param String $label The label for the button. Defaults to "Republish This Story". + * @return String HTML for the button. + */ + public static function button_output( $label = '' ) { + if ( empty( trim( $label ) ) ) { + $label = __( 'Republish This Story', 'republication-tracker-tool' ); } + + return sprintf( + '

', + esc_html( $label ) + ); } /** diff --git a/republication-tracker-tool.php b/republication-tracker-tool.php index c620c5c..32071f0 100644 --- a/republication-tracker-tool.php +++ b/republication-tracker-tool.php @@ -70,6 +70,11 @@ final class Republication_Tracker_Tool { */ protected $settings; + /** + * Has a widget or button been output upon the page? + */ + public $has_instance = false; + /** * Creates or returns an instance of this class. * From e5be9de724af7814edde590af2e225bbbffc4acb Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 16:55:22 -0400 Subject: [PATCH 02/11] move the modal content after the closing of the widget --- includes/class-widget.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/class-widget.php b/includes/class-widget.php index 848eda5..8976b3e 100644 --- a/includes/class-widget.php +++ b/includes/class-widget.php @@ -74,10 +74,9 @@ public function widget( $args, $instance ) { wp_kses_post( wpautop( esc_html( $instance['text'] ) ) ) ); - $this->maybe_print_modal_content(); - echo wp_kses_post( $args['after_widget'] ); + $this->maybe_print_modal_content(); } /** From 5b4067bc281e26d66324ff3e0cedf277d8e7f9e4 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 17:28:02 -0400 Subject: [PATCH 03/11] Fix widget output of Republication_Tracker_Tool_Widget::modal_content(); --- includes/class-widget.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/class-widget.php b/includes/class-widget.php index 8976b3e..65bc082 100644 --- a/includes/class-widget.php +++ b/includes/class-widget.php @@ -76,7 +76,7 @@ public function widget( $args, $instance ) { echo wp_kses_post( $args['after_widget'] ); - $this->maybe_print_modal_content(); + echo $this->maybe_print_modal_content(); } /** @@ -98,10 +98,8 @@ public static function maybe_print_modal_content() { // update has_instance so the next time the widget is created on the same page, it does not create a second modal $Republication_Tracker_Tool->has_instance = true; - error_log(var_export( 'aaa', true)); return Republication_Tracker_Tool_Widget::modal_content(); } else { - error_log(var_export( 'no need', true)); return ''; } } @@ -117,12 +115,14 @@ public static function modal_content() { // define our path to grab file content from $republication_plugin_path = plugin_dir_path( __FILE__ ); - return sprintf( + ob_start(); + printf( '', esc_attr( $post->ID ), esc_attr( plugins_url() ), esc_html( include_once( $republication_plugin_path . 'shareable-content.php' ) ) ); + return ob_get_clean(); } /** From 84409c9c318b19b49319daeb792e9decf885f5cc Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 17:38:48 -0400 Subject: [PATCH 04/11] Styles and docs for the button --- assets/widget.css | 8 ++++---- docs/adding-republish-button-to-posts.md | 8 +++++++- includes/class-shortcodes.php | 5 ++++- republication-tracker-tool.php | 1 + 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/assets/widget.css b/assets/widget.css index 81aad92..ffb907a 100644 --- a/assets/widget.css +++ b/assets/widget.css @@ -24,8 +24,8 @@ display: block; } -.side-widget.republication_tracker_tool button.republication-tracker-tool-button, -.widget.republication_tracker_tool button.republication-tracker-tool-button { +button.republication-tracker-tool-button, +button.republication-tracker-tool-button { width:100%; background-color: #5499db; border: 1px solid #2863a7; @@ -39,8 +39,8 @@ text-shadow: 1px 1px 1px #2863a7; } -.side-widget.republication_tracker_tool button.republication-tracker-tool-button:hover, -.widget.republication_tracker_tool button.republication-tracker-tool-button:hover { +button.republication-tracker-tool-button:hover, +button.republication-tracker-tool-button:hover { background-color: #2863a7; text-decoration: none; cursor: pointer; diff --git a/docs/adding-republish-button-to-posts.md b/docs/adding-republish-button-to-posts.md index 3f86302..f2e2f57 100644 --- a/docs/adding-republish-button-to-posts.md +++ b/docs/adding-republish-button-to-posts.md @@ -1,5 +1,7 @@ # Adding Republish button to posts +## The Republication Tracker Tool Widget + In order to add your `Republish` button to your posts, you will need to add the `Republication Tracker Tool` widget to the sidebar or widget area of your choice. Once this plugin is installed and activated, navigate to `Appearance` -> `Widgets`. ![navigating to widgets](img/widgets.png) @@ -18,4 +20,8 @@ Once you have added the `Republication Tracker Tool` widget to a widget area, yo ![default republish button](img/default-republish-button.png) -If you'd like to place the republication button within a post, but not in a sidebar, INN Labs' [Super Cool Ad Inserter Plugin](https://largo.inn.org/guides/administrators/plugins/super-cool-ad-inserter-plugin/) may be of use to you. +If you'd like to place the republication widget within a post, but not in a sidebar, INN Labs' [Super Cool Ad Inserter Plugin](https://largo.inn.org/guides/administrators/plugins/super-cool-ad-inserter-plugin/) may be of use to you. + +## The `[republication_modal_button]` shortcode + +Adding a `[republication_modal_button]` shortcode gets you just the button from the widget. This button will still open the modal. diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index a9edc5e..3a5ff16 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -28,7 +28,10 @@ public static function button_shortcode( $atts = array(), $content = '', $tag = add_action( 'wp_ajax_my_action', 'my_action' ); add_action( 'wp_ajax_nopriv_my_action', 'my_action' ); + ob_start(); echo Republication_Tracker_Tool_Widget::button_output(); - Republication_Tracker_Tool_Widget::maybe_print_modal_content(); + echo Republication_Tracker_Tool_Widget::maybe_print_modal_content(); + return ob_get_clean(); } } +add_shortcode( 'republication_modal_button', array( 'Republication_Tracker_Tool_Shortcodes', 'button_shortcode' ) ); diff --git a/republication-tracker-tool.php b/republication-tracker-tool.php index 32071f0..3dc6ece 100644 --- a/republication-tracker-tool.php +++ b/republication-tracker-tool.php @@ -14,6 +14,7 @@ require plugin_dir_path( __FILE__ ).'includes/class-settings.php'; require plugin_dir_path( __FILE__ ).'includes/class-article-settings.php'; require plugin_dir_path( __FILE__ ).'includes/class-widget.php'; +require plugin_dir_path( __FILE__ ).'includes/class-shortcodes.php'; /** * Main initiation class. From b8001c1cff6cc732f7163d87f1ed2fdd4ee96373 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 18:31:23 -0400 Subject: [PATCH 05/11] Add a 'label' attribute to the shortcode for the purposes of changing the button title --- includes/class-shortcodes.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index 3a5ff16..bcbb756 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -28,8 +28,14 @@ public static function button_shortcode( $atts = array(), $content = '', $tag = add_action( 'wp_ajax_my_action', 'my_action' ); add_action( 'wp_ajax_nopriv_my_action', 'my_action' ); + if ( isset( $atts['label'] ) ) { + $label = $atts['label']; + } else { + $label = null; + } + ob_start(); - echo Republication_Tracker_Tool_Widget::button_output(); + echo Republication_Tracker_Tool_Widget::button_output( $label ); echo Republication_Tracker_Tool_Widget::maybe_print_modal_content(); return ob_get_clean(); } From f11158bfdc68dd85c259c390018c23a90b1f3498 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 18:33:27 -0400 Subject: [PATCH 06/11] Having created the block files, now include them --- blocks/button.php | 6 +++--- blocks/button/index.js | 8 +++++++- republication-tracker-tool.php | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/blocks/button.php b/blocks/button.php index 59d0443..58a0db7 100644 --- a/blocks/button.php +++ b/blocks/button.php @@ -12,7 +12,7 @@ * * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/tutorials/block-tutorial/applying-styles-with-stylesheets/ */ -function button_block_init() { +function republication_tracker_tool_button_block_init() { // Skip block registration if Gutenberg is not enabled/merged. if ( ! function_exists( 'register_block_type' ) ) { return; @@ -44,7 +44,7 @@ function button_block_init() { 'editor_style' => 'button-block-editor', 'style' => 'republication-tracker-tool-css', 'script' => 'republication-tracker-tool-js', - 'render_clalback' => array( 'Republication_Tracker_Tool_Shortcodes', 'button_shortcode' ); + 'render_clalback' => array( 'Republication_Tracker_Tool_Shortcodes', 'button_shortcode' ), ) ); } -add_action( 'init', 'button_block_init' ); +add_action( 'init', 'republication_tracker_tool_button_block_init' ); diff --git a/blocks/button/index.js b/blocks/button/index.js index 5c13553..5ad82a3 100644 --- a/blocks/button/index.js +++ b/blocks/button/index.js @@ -42,8 +42,14 @@ * Optional block extended support features. */ supports: { - // Removes support for an HTML mode. + align: false, + alignWide: false, + anchor: false, + customClassName: false, + className: false, html: false, + multiple: true, + reusable: false, }, /** diff --git a/republication-tracker-tool.php b/republication-tracker-tool.php index 3dc6ece..197b059 100644 --- a/republication-tracker-tool.php +++ b/republication-tracker-tool.php @@ -15,6 +15,7 @@ require plugin_dir_path( __FILE__ ).'includes/class-article-settings.php'; require plugin_dir_path( __FILE__ ).'includes/class-widget.php'; require plugin_dir_path( __FILE__ ).'includes/class-shortcodes.php'; +require plugin_dir_path( __FILE__ ).'blocks/button.php'; /** * Main initiation class. From b1de2a17614ff6f297a0cbddf06586827292e49d Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 21:02:21 -0400 Subject: [PATCH 07/11] remove duplicate classes from widget CSS --- assets/widget.css | 2 -- 1 file changed, 2 deletions(-) diff --git a/assets/widget.css b/assets/widget.css index ffb907a..ed7dc48 100644 --- a/assets/widget.css +++ b/assets/widget.css @@ -24,7 +24,6 @@ display: block; } -button.republication-tracker-tool-button, button.republication-tracker-tool-button { width:100%; background-color: #5499db; @@ -39,7 +38,6 @@ button.republication-tracker-tool-button { text-shadow: 1px 1px 1px #2863a7; } -button.republication-tracker-tool-button:hover, button.republication-tracker-tool-button:hover { background-color: #2863a7; text-decoration: none; From f9c583ad2c28220ff83af358c3be3042d75bf52b Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 21:03:13 -0400 Subject: [PATCH 08/11] Button Block: declare all dependencies, fix typoed render_clalback, declare attribute --- blocks/button.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/blocks/button.php b/blocks/button.php index 58a0db7..06961ce 100644 --- a/blocks/button.php +++ b/blocks/button.php @@ -27,6 +27,7 @@ function republication_tracker_tool_button_block_init() { 'wp-blocks', 'wp-i18n', 'wp-element', + 'wp-components', ), filemtime( "$dir/$index_js" ) ); @@ -40,11 +41,16 @@ function republication_tracker_tool_button_block_init() { ); register_block_type( 'republication-tracker-tool/button', array( + 'attributes' => array( + 'label' => array( + 'type' => 'string', + ), + ), 'editor_script' => 'button-block-editor', 'editor_style' => 'button-block-editor', 'style' => 'republication-tracker-tool-css', 'script' => 'republication-tracker-tool-js', - 'render_clalback' => array( 'Republication_Tracker_Tool_Shortcodes', 'button_shortcode' ), + 'render_callback' => array( 'Republication_Tracker_Tool_Shortcodes', 'button_shortcode' ), ) ); } add_action( 'init', 'republication_tracker_tool_button_block_init' ); From dd20004f9d99d83da7dafeeab6ae8ee7b619eb12 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 21:12:57 -0400 Subject: [PATCH 09/11] Update to using WordPress' 'Placeholder' component for the placeholder. --- blocks/button/editor.css | 23 +++++++++++++++++++++-- blocks/button/index.js | 35 ++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/blocks/button/editor.css b/blocks/button/editor.css index 80006c7..fda5633 100644 --- a/blocks/button/editor.css +++ b/blocks/button/editor.css @@ -4,6 +4,25 @@ * Replace them with your own styles or remove the file completely. */ -.wp-block-republication-tracker-tool-button { - border: 1px dotted #f00; +.wp-block-republication-tracker-tool-button.components-placeholder { + min-height: unset; +} +.wp-block-republication-tracker-tool-button .components-base-control__field { + display: flex; + flex-direction: row; + width: 100%; +} +.wp-block-republication-tracker-tool-button .components-base-control__field label { + display: flex; + align-items: center; + margin-right: 10px; + white-space: nowrap; + flex-shrink: 0; + + margin-bottom: 0; + + font-size: 13px; +} +.wp-block-republication-tracker-tool-button .components-base-control__field input { + flex-grow: 1; } diff --git a/blocks/button/index.js b/blocks/button/index.js index 5ad82a3..fbe1545 100644 --- a/blocks/button/index.js +++ b/blocks/button/index.js @@ -15,6 +15,9 @@ */ var __ = wp.i18n.__; + var TextControl = wp.components.TextControl; + var Placeholder = wp.components.Placeholder; + /** * Every block starts by registering a new block type definition. * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/#registering-a-block @@ -26,6 +29,11 @@ */ title: __( 'Republication Modal Button', 'republication-tracker-tool' ), + /** + * Describe the block for the block inspector + */ + description: __( 'Add a button which opens the Republication Tracker Tool sharing modal.', 'republication-tracker-tool' ), + /** * An icon property should be specified to make it easier to identify a block. * These can be any of WordPress’ Dashicons, or a custom svg element. @@ -46,7 +54,7 @@ alignWide: false, anchor: false, customClassName: false, - className: false, + className: true, html: false, multiple: true, reusable: false, @@ -62,9 +70,17 @@ */ edit: function( props ) { return el( - 'p', - { className: props.className }, - __( 'Hello from the editor!', 'republication-tracker-tool' ) + Placeholder, + { + className: props.className + ' republication-tracker-tool-button', + label: __( 'Republication Modal Button', 'republication-tracker-tool' ), + }, + el ( TextControl, { + label: __( 'Button Label', 'republication-tracker-tool' ), + value: props.attributes.label, + placeholder: __( 'Republish This Story', 'republication-tracker-tool' ), + onChange: ( value ) => { props.setAttributes( { label: value } ); }, + } ) ); }, @@ -73,14 +89,11 @@ * into the final markup, which is then serialized by Gutenberg into `post_content`. * @see https://wordpress.org/gutenberg/handbook/designers-developers/developers/block-api/block-edit-save/#save * - * @return {Element} Element to render. + * @return {null} There is no element to render */ - save: function() { - return el( - 'p', - {}, - __( 'Hello from the saved content!', 'republication-tracker-tool' ) - ); + save: function( props ) { + // no element created here, but this function is needed in order to let the props get passed along. + return null; } } ); } )( From ff92f311ee74cd61189a45891a142cd4ec2f89b7 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 21 Aug 2020 21:41:26 -0400 Subject: [PATCH 10/11] Update readme.txt, edit docs, quick code standards pass --- blocks/button.php | 10 +++++----- blocks/button/editor.css | 8 -------- docs/adding-republish-button-to-posts.md | 6 ++++++ includes/class-shortcodes.php | 5 ++++- readme.txt | 10 ++++++++++ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/blocks/button.php b/blocks/button.php index 06961ce..0195af2 100644 --- a/blocks/button.php +++ b/blocks/button.php @@ -41,15 +41,15 @@ function republication_tracker_tool_button_block_init() { ); register_block_type( 'republication-tracker-tool/button', array( - 'attributes' => array( + 'attributes' => array( 'label' => array( 'type' => 'string', ), ), - 'editor_script' => 'button-block-editor', - 'editor_style' => 'button-block-editor', - 'style' => 'republication-tracker-tool-css', - 'script' => 'republication-tracker-tool-js', + 'editor_script' => 'button-block-editor', + 'editor_style' => 'button-block-editor', + 'style' => 'republication-tracker-tool-css', + 'script' => 'republication-tracker-tool-js', 'render_callback' => array( 'Republication_Tracker_Tool_Shortcodes', 'button_shortcode' ), ) ); } diff --git a/blocks/button/editor.css b/blocks/button/editor.css index fda5633..5ef7b9d 100644 --- a/blocks/button/editor.css +++ b/blocks/button/editor.css @@ -1,9 +1,3 @@ -/** - * The following styles get applied inside the editor only. - * - * Replace them with your own styles or remove the file completely. - */ - .wp-block-republication-tracker-tool-button.components-placeholder { min-height: unset; } @@ -20,8 +14,6 @@ flex-shrink: 0; margin-bottom: 0; - - font-size: 13px; } .wp-block-republication-tracker-tool-button .components-base-control__field input { flex-grow: 1; diff --git a/docs/adding-republish-button-to-posts.md b/docs/adding-republish-button-to-posts.md index f2e2f57..62c4799 100644 --- a/docs/adding-republish-button-to-posts.md +++ b/docs/adding-republish-button-to-posts.md @@ -25,3 +25,9 @@ If you'd like to place the republication widget within a post, but not in a side ## The `[republication_modal_button]` shortcode Adding a `[republication_modal_button]` shortcode gets you just the button from the widget. This button will still open the modal. + +Change the button's label like so: `[republication_modal_button label="A custom label!"]` + +## The Republication Modal Button Block + +As an alternative to the shortcode, users of the Block Editor can add a Republication Modal Button Block to posts, and configure the button's label. diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index bcbb756..847f487 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -1,11 +1,14 @@ has_instance` is now `Republication_Tracker_Tool->has_instance`. + = 1.0.2 = - Sets a default width for the site icon that is displayed at the bottom of republished articles. Previously it did not have a width set which was causing some sites to experience larger than expected images at the end of their republished articles. From c1259952bcb73aa898e6cdc83844270c55b03669 Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Thu, 27 Aug 2020 11:23:28 -0400 Subject: [PATCH 11/11] Skip trying to generate modal content if global post is not a WP_Post --- includes/class-widget.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/class-widget.php b/includes/class-widget.php index 65bc082..f05d697 100644 --- a/includes/class-widget.php +++ b/includes/class-widget.php @@ -112,6 +112,10 @@ public static function maybe_print_modal_content() { */ public static function modal_content() { global $post; + if ( ! is_a( $post, 'WP_Post' ) ) { + return; + } + // define our path to grab file content from $republication_plugin_path = plugin_dir_path( __FILE__ );