Changeset 2076075
- Timestamp:
- 04/27/2019 10:33:49 PM (7 years ago)
- Location:
- block-style-guides
- Files:
-
- 2 added
- 2 deleted
- 8 edited
- 26 copied
-
tags/1.1.0/block-style-guides.php (modified) (1 diff)
-
tags/1.2.0 (copied) (copied from block-style-guides/trunk)
-
tags/1.2.0/README.md (copied) (copied from block-style-guides/trunk/README.md) (1 diff)
-
tags/1.2.0/add-bsg-posts.php (copied) (copied from block-style-guides/trunk/add-bsg-posts.php) (5 diffs)
-
tags/1.2.0/admin-menu-functions.php (copied) (copied from block-style-guides/trunk/admin-menu-functions.php) (7 diffs)
-
tags/1.2.0/autoload.php (copied) (copied from block-style-guides/trunk/autoload.php)
-
tags/1.2.0/block-style-guides.php (copied) (copied from block-style-guides/trunk/block-style-guides.php) (2 diffs)
-
tags/1.2.0/delete-bsg-posts.php (added)
-
tags/1.2.0/general.php (copied) (copied from block-style-guides/trunk/general.php) (1 diff)
-
tags/1.2.0/js (copied) (copied from block-style-guides/trunk/js)
-
tags/1.2.0/js/bsg.js (copied) (copied from block-style-guides/trunk/js/bsg.js) (3 diffs)
-
tags/1.2.0/js/sgb.js (deleted)
-
tags/1.2.0/readme.txt (copied) (copied from block-style-guides/trunk/readme.txt) (1 diff)
-
tags/1.2.0/src (copied) (copied from block-style-guides/trunk/src)
-
tags/1.2.0/src/AtomicBlocks/class-atomicblocks.php (copied) (copied from block-style-guides/trunk/src/AtomicBlocks/class-atomicblocks.php)
-
tags/1.2.0/src/Base/class-abstract-markup.php (copied) (copied from block-style-guides/trunk/src/Base/class-abstract-markup.php)
-
tags/1.2.0/src/BlockGallery/class-blockgallery.php (copied) (copied from block-style-guides/trunk/src/BlockGallery/class-blockgallery.php)
-
tags/1.2.0/src/CoBlocks/class-coblocks.php (copied) (copied from block-style-guides/trunk/src/CoBlocks/class-coblocks.php)
-
tags/1.2.0/src/CoreWP/class-audio-video.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-audio-video.php)
-
tags/1.2.0/src/CoreWP/class-columns.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-columns.php)
-
tags/1.2.0/src/CoreWP/class-covers.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-covers.php)
-
tags/1.2.0/src/CoreWP/class-galleries.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-galleries.php)
-
tags/1.2.0/src/CoreWP/class-images.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-images.php)
-
tags/1.2.0/src/CoreWP/class-other-layouts.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-other-layouts.php)
-
tags/1.2.0/src/CoreWP/class-other-typographical.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-other-typographical.php)
-
tags/1.2.0/src/CoreWP/class-paragraphs-headers.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-paragraphs-headers.php)
-
tags/1.2.0/src/CoreWP/class-quotes-pullquotes.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-quotes-pullquotes.php)
-
tags/1.2.0/src/CoreWP/class-read-more.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-read-more.php)
-
tags/1.2.0/src/CoreWP/class-standard-widgets.php (copied) (copied from block-style-guides/trunk/src/CoreWP/class-standard-widgets.php)
-
tags/1.2.0/src/UltimateAddons (deleted)
-
trunk/README.md (modified) (1 diff)
-
trunk/add-bsg-posts.php (modified) (5 diffs)
-
trunk/admin-menu-functions.php (modified) (7 diffs)
-
trunk/block-style-guides.php (modified) (2 diffs)
-
trunk/delete-bsg-posts.php (added)
-
trunk/general.php (modified) (1 diff)
-
trunk/js/bsg.js (modified) (3 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
block-style-guides/tags/1.1.0/block-style-guides.php
r2074113 r2076075 4 4 * Plugin Name: Block Style Guides for Gutenberg 5 5 * Description: Creates posts in draft mode showcasing all default Gutenberg blocks, for styling purposes. 6 * Version: 1. 06 * Version: 1.1.0 7 7 * Author: Robert Gillmer 8 8 * Author URI: https://www.robertgillmer.com -
block-style-guides/tags/1.2.0/README.md
r2074389 r2076075 91 91 * Added filters for a buncha placeholder variables. 92 92 * Used those variables throughout the markup. 93 94 **1.2.0** 95 96 * Error reporting is now 927% betterer. 97 * Form submits via AJAX, which is why the error reporting is so much betterer. 98 * Split list of CPT's up into groups based on ability to use the Gutenberg editor. 99 * "Delete all the things!" button added. (Not all the things, just all the things this plugin created, but that's wordy.) -
block-style-guides/tags/1.2.0/add-bsg-posts.php
r2074113 r2076075 2 2 3 3 function bsg_add_posts() { 4 5 4 $error_messages = array(); 6 5 $nonce = $_REQUEST[ 'bsgAddNonce' ]; … … 78 77 // If it *still* doesn't exist, it just wasn't meant to be, man. 79 78 if( ! class_exists( $v ) ) { 80 $error_messages[ 'class _does_not_exist' ][] = $v;79 $error_messages[ 'classDoesNotExist' ][] = $k; 81 80 continue; 82 81 } … … 86 85 // Does the post exist? If so, skip it 87 86 if( $wpdb->get_row( "SELECT post_title FROM wp_posts WHERE post_title = '" . $k . "' AND post_type = '" . $post_type . "'", 'ARRAY_A' ) ) { 88 89 $error_messages[ 'post_already_exists' ][] = $post_type; 87 $post_type_object = get_post_type_object( $post_type ); 88 $post_type_name = $post_type_object->labels->name; 89 $error_messages[ 'postAlreadyExists' ][] = $post_type_name; 90 90 continue; 91 91 } … … 107 107 108 108 if( is_wp_error( $maybe_error ) ) { 109 $error_messages[ 'could _not_create_posts'] = $k;109 $error_messages[ 'couldNotCreatePosts' ][] = $k; 110 110 } 111 111 } … … 114 114 if( $error_messages ) { 115 115 foreach( $error_messages as $k => $v ) { 116 $ error_message_transient[ $k ] = array_unique( $v);116 $unique_error_messages[ $k ] = array_values( array_unique( $v ) ); 117 117 } 118 set_transient( 'bsg-errors', $error_message_transient, DAY_IN_SECONDS );119 118 } 120 119 121 wp_send_json_success(); 120 if( empty( $unique_error_messages ) ) { 121 wp_send_json_success( true ); 122 } else { 123 wp_send_json_success( $unique_error_messages ); 124 } 122 125 123 126 /* -
block-style-guides/tags/1.2.0/admin-menu-functions.php
r2074113 r2076075 13 13 14 14 function bsg_settings_init() { 15 register_setting( 'bsg_plugin_page', 'bsg_post_types', 'bsg_admin_notices' );16 17 15 add_settings_section( 18 16 'bsg_plugin_page_section', … … 31 29 } 32 30 33 function bsg_admin_notices( $input ) {34 $message = '';35 $type = '';36 $error_transient = get_transient( 'bsg-errors' );37 38 if( $error_transient ) {39 $errors = ( $error_transient );40 41 foreach( $errors as $k => $v ) {42 43 switch( $k ) {44 case 'nonce_failed':45 $message .= 'Your request has timed out. Please refresh the page and try again.<br />';46 break;47 48 case 'class_does_not_exist':49 foreach( $v as $class ) {50 $full_class_name = $class;51 $class_name_array = explode( '\\', $full_class_name );52 $class_name = array_pop( $class_name_array );53 54 // @TODO - Make this error message suck 87% less.55 $message .= 'The ' . $class_name . ' class could not be created, so the page(s) associated with it has not been created.<br />';56 57 }58 59 break;60 61 case 'post_already_exists':62 foreach( $v as $post_type ) {63 $post_type_obj = get_post_type_object( $post_type );64 $post_type_name = $post_type_obj->labels->singular_name;65 $message .= 'The posts for the ' . ( $post_type_name ) . ' post type already existed, so they have not be created.<br />';66 }67 break;68 69 case 'could_not_create_posts':70 $message .= 'The system could not create your posts. Please refresh and try again.<br />';71 break;72 }73 }74 75 add_settings_error( 'bsg_post_types', 'bsg-update', $message, 'error' );76 } else {77 $message = 'Your posts have been created!';78 $type = 'updated';79 add_settings_error( 'bsg_post_types', 'bsg-update', $message, $type );80 }81 82 delete_transient( 'bsg-errors' );83 84 return $input;85 }86 87 31 function bsg_cpt_selection_render() { 32 $out = ''; 33 $builtin_cpts = array(); 34 $gutenbergable_cpts = array(); // If that's not a word, it should be 35 $non_gutenbergable_cpts = array(); 36 $non_contentable_cpts = array(); // That one too 88 37 $all_post_types = get_post_types( 89 38 array( … … 93 42 ); 94 43 44 // Attachments are public but neither Gutenbergable nor contentable. 95 45 unset( $all_post_types[ 'attachment' ] ); 96 46 47 foreach( $all_post_types as $cpt ) { 48 if( $cpt->_builtin ) { 49 $builtin_cpts[] = $cpt; 50 } else if( ! post_type_supports( $cpt->name, 'editor' ) ) { 51 $non_contentable_cpts[] = $cpt; 52 } else if( ! $cpt->show_in_rest ) { 53 $non_gutenbergable_cpts[] = $cpt; 54 } else { 55 $gutenbergable_cpts[] = $cpt; 56 } 57 } 58 59 if( is_array( $builtin_cpts ) && ! empty( $builtin_cpts ) ) { 60 $out .= '<h4>Built-in post types</h4>'; 61 $out .= '<p style="margin-bottom: 10px;">These post types are part of WordPress core.</p>'; 62 $out .= bsg_display_checkboxes( $builtin_cpts ); 63 } 64 65 if( is_array( $gutenbergable_cpts ) && ! empty( $gutenbergable_cpts ) ) { 66 $out .= '<h4>Custom post types</h4>'; 67 $out .= '<p style="margin-bottom: 10px;">These post types currently support the Gutenberg editor.</p>'; 68 $out .= bsg_display_checkboxes( $gutenbergable_cpts ); 69 } 70 71 if( is_array( $non_gutenbergable_cpts ) && ! empty( $non_gutenbergable_cpts ) ) { 72 $out .= '<h4>Custom post types with no Gutenberg support</h4>'; 73 $out .= '<p style="margin-bottom: 10px;">These posts types do not currently support the Gutenberg editor. You can still create style guides for them to see what they will look like if/when they declare support.</p>'; 74 $out .= bsg_display_checkboxes( $non_gutenbergable_cpts ); 75 } 76 77 if( is_array( $non_contentable_cpts ) && ! empty( $non_contentable_cpts ) ) { 78 $out .= '<h4>Custom post types with no support for content</h4>'; 79 $out .= '<p style="margin-bottom: 10px;">These post types don\'t display <code>the_content</code> as part of their output. You can still create style guides for them, but they likely won\'t display the style guides correctly or at all.</p>'; 80 $out .= bsg_display_checkboxes( $non_contentable_cpts ); 81 } 82 83 echo $out; 84 } 85 86 function bsg_display_checkboxes( $cpts = array() ) { 87 $out = ''; 97 88 $options = get_option( 'bsg_post_types' ); 98 foreach( $all_post_types as $cpt ) { 89 90 if( ! is_array( $cpts ) || empty( $cpts ) ) { 91 return; 92 } 93 94 foreach( $cpts as $cpt ) { 99 95 if( isset( $options[ $cpt->name ] ) ) { 100 96 $checked = $options[ $cpt->name ]; … … 102 98 $checked = ''; 103 99 } 100 101 ob_start(); 104 102 ?> 105 <input class="bsg-cpt-type" data-cpt="<?php echo $cpt->name; ?>" type='checkbox' name='bsg_post_types[<?php echo $cpt->name; ?>]'<?php checked( $checked, 1 ); ?> value='1'>106 <label for='bsg_post_types[<?php echo $cpt->name; ?>]'><?php echo $cpt->label; ?></label>107 <br />103 <input class="bsg-cpt-type" data-cpt="<?php echo $cpt->name; ?>" type='checkbox' name='bsg_post_types[<?php echo $cpt->name; ?>]' id="bsg_post_types[<?php echo $cpt->name; ?>]" <?php checked( $checked, 1 ); ?> value='1'> 104 <label for='bsg_post_types[<?php echo $cpt->name; ?>]'><?php echo $cpt->label; ?></label> 105 <br /> 108 106 <?php 107 $out .= ob_get_clean(); 109 108 } 109 110 return $out; 110 111 } 111 112 … … 116 117 function bsg_options_page() { 117 118 wp_enqueue_script( 'bsg-ajax' ); 119 wp_enqueue_script( 'json-form' ); 118 120 119 121 $script_params = array( 120 122 'bsgAddNonce' => wp_create_nonce( 'bsg-add-nonce' ), 121 'bsgDeleteNonce' => wp_create_nonce( 'bsg-delete-nonce' ), // upcoming123 'bsgDeleteNonce' => wp_create_nonce( 'bsg-delete-nonce' ), 122 124 ); 123 125 … … 125 127 126 128 ?> 127 <h2 >Gutenberg Block Style Guides</h2>129 <h2 class="bsg-title">Block Style Guides for Gutenberg</h2> 128 130 <?php settings_errors(); ?> 129 131 <form action='options.php' method='post' name="bsg-form" id="bsg-form"> … … 134 136 ?> 135 137 </form> 138 <p>If you want to delete all the posts created by this plugin, click the button below.</p> 139 <button id="bsg-delete" class="button button-secondary">Delete all Block Style Guide posts</button> 136 140 <?php 137 141 } -
block-style-guides/tags/1.2.0/block-style-guides.php
r2074113 r2076075 4 4 * Plugin Name: Block Style Guides for Gutenberg 5 5 * Description: Creates posts in draft mode showcasing all default Gutenberg blocks, for styling purposes. 6 * Version: 1. 06 * Version: 1.2.0 7 7 * Author: Robert Gillmer 8 8 * Author URI: https://www.robertgillmer.com … … 28 28 include_once( plugin_dir_path( __FILE__ ) . 'admin-menu-functions.php' ); 29 29 include_once( plugin_dir_path( __FILE__ ) . 'add-bsg-posts.php'); 30 include_once( plugin_dir_path( __FILE__ ) . 'delete-bsg-posts.php'); -
block-style-guides/tags/1.2.0/general.php
r2074113 r2076075 2 2 3 3 function bsg_enqueue_scripts() { 4 wp_register_script( 'bsg-ajax', plugin_dir_url( __FILE__ ) . '/js/bsg.js', array( 'jquery' ), false, true );4 wp_register_script( 'bsg-ajax', plugin_dir_url( __FILE__ ) . '/js/bsg.js', array( 'jquery', 'jquery-form' ), false, true ); 5 5 } 6 6 -
block-style-guides/tags/1.2.0/js/bsg.js
r2074113 r2076075 1 1 (function($) { 2 2 var bsgAddNonce = bsgAjax.bsgAddNonce; 3 var bsgDeleteNonce = bsgAjax.bsgDeleteNonce; // Upcoming3 var bsgDeleteNonce = bsgAjax.bsgDeleteNonce; 4 4 5 5 $( '#bsg-form' ).submit( function( e ) { 6 e.preventDefault(); // Submitting via AJAX 7 $(this).ajaxSubmit(); // See? 8 6 9 var selectedTypes = []; 7 10 jQuery( '.bsg-cpt-type' ).each( function() { … … 21 24 }) 22 25 23 .done( function( data ) { 26 .done( function( response ) { 27 $( '.setting-error-bsg-update' ).remove(); 28 var data = response[ 'data' ]; 29 hasError = false, 30 banners = ''; 31 32 if( data === true ) { // true means there were no errors 33 banners = makeBanner( 'Posts were created successfully.', 'updated' ) + banners; 34 } else { 35 if( 'couldNotCreatePosts' in data ) { 36 var message = 'The following post(s) could not be created due to internal errors: ', 37 errorArray = data[ 'couldNotCreatePosts' ]; 38 banners += makeErrorBanner( message, errorArray );; 39 hasError = true; 40 } 41 42 if( 'postAlreadyExists' in data ) { 43 var message = 'Posts already existed for the following post type(s), so new posts were not created: ', 44 errorArray = data[ 'postAlreadyExists' ]; 45 banners += makeErrorBanner( message, errorArray );; 46 hasError = true; 47 } 48 49 if( 'classDoesNotExist' in data ) { 50 var message = 'The following page(s) could not be created because the class doesn\'t exist: ', 51 errorArray = data[ 'classDoesNotExist' ]; 52 banners += makeErrorBanner( message, errorArray );; 53 hasError = true; 54 } 55 // Success messages should be above the error messages, hence the no += operator. 56 banners = makeBanner( 'Posts were created successfully, with the exceptions listed below.', 'updated' ) + banners; 57 } 58 59 $( '.bsg-title' ).after( banners ); 60 24 61 return true; 25 62 }) … … 29 66 }) 30 67 } ); 68 69 $( '#bsg-delete' ).click( function( e ) { 70 e.preventDefault(); 71 $( '.setting-error-bsg-update' ).remove(); 72 73 $.ajax({ 74 url: ajaxurl, 75 type: 'post', 76 data: { 77 action: 'bsg_delete_posts', 78 bsgDeleteNonce: bsgDeleteNonce, 79 } 80 }) 81 82 .done( function( data ) { 83 var banner = makeBanner( 'All posts created by Block Style Guides have been successfully deleted.', 'updated' ); 84 $( '.bsg-title' ).after( banner ); 85 return true; 86 }) 87 88 .fail( function() { 89 var banner = makeBanner( 'There was an issue deleting the posts created by Block Style Guides.', 'error' ); 90 $( '.bsg-title' ).after( banner ); 91 return false; // More here too 92 }) 93 94 return false; 95 } ); 96 97 function makeBanner( text, type="updated" ) { 98 if( ! text ) { 99 return; 100 } 101 102 var banner = '<div class="setting-error-bsg-update ' + type + ' settings-error notice is-dismissible">'; 103 banner += '<p><strong>' + text + '</strong></p>'; 104 banner += '<button type="button" class="notice-dismiss">'; 105 banner += '<span class="screen-reader-text">Dismiss this notice.</span>'; 106 banner += '</button>'; 107 banner += '</div>'; 108 109 return banner; 110 } 111 112 function makeErrorBanner( text, errorArray ) { 113 var message = text + errorArray.join( ', ' ); 114 115 return makeBanner( message, 'error' ); 116 } 31 117 })( jQuery ); -
block-style-guides/tags/1.2.0/readme.txt
r2074389 r2076075 91 91 * Added filters for a buncha placeholder variables. 92 92 * Used those variables throughout the markup. 93 94 = 1.2.0 = 95 96 * Error reporting is now 927% betterer. 97 * Form submits via AJAX, which is why the error reporting is so much betterer. 98 * Split list of CPT's up into groups based on ability to use the Gutenberg editor. 99 * "Delete all the things!" button added. (Not all the things, just all the things this plugin created, but that's wordy.) -
block-style-guides/trunk/README.md
r2074389 r2076075 91 91 * Added filters for a buncha placeholder variables. 92 92 * Used those variables throughout the markup. 93 94 **1.2.0** 95 96 * Error reporting is now 927% betterer. 97 * Form submits via AJAX, which is why the error reporting is so much betterer. 98 * Split list of CPT's up into groups based on ability to use the Gutenberg editor. 99 * "Delete all the things!" button added. (Not all the things, just all the things this plugin created, but that's wordy.) -
block-style-guides/trunk/add-bsg-posts.php
r2074113 r2076075 2 2 3 3 function bsg_add_posts() { 4 5 4 $error_messages = array(); 6 5 $nonce = $_REQUEST[ 'bsgAddNonce' ]; … … 78 77 // If it *still* doesn't exist, it just wasn't meant to be, man. 79 78 if( ! class_exists( $v ) ) { 80 $error_messages[ 'class _does_not_exist' ][] = $v;79 $error_messages[ 'classDoesNotExist' ][] = $k; 81 80 continue; 82 81 } … … 86 85 // Does the post exist? If so, skip it 87 86 if( $wpdb->get_row( "SELECT post_title FROM wp_posts WHERE post_title = '" . $k . "' AND post_type = '" . $post_type . "'", 'ARRAY_A' ) ) { 88 89 $error_messages[ 'post_already_exists' ][] = $post_type; 87 $post_type_object = get_post_type_object( $post_type ); 88 $post_type_name = $post_type_object->labels->name; 89 $error_messages[ 'postAlreadyExists' ][] = $post_type_name; 90 90 continue; 91 91 } … … 107 107 108 108 if( is_wp_error( $maybe_error ) ) { 109 $error_messages[ 'could _not_create_posts'] = $k;109 $error_messages[ 'couldNotCreatePosts' ][] = $k; 110 110 } 111 111 } … … 114 114 if( $error_messages ) { 115 115 foreach( $error_messages as $k => $v ) { 116 $ error_message_transient[ $k ] = array_unique( $v);116 $unique_error_messages[ $k ] = array_values( array_unique( $v ) ); 117 117 } 118 set_transient( 'bsg-errors', $error_message_transient, DAY_IN_SECONDS );119 118 } 120 119 121 wp_send_json_success(); 120 if( empty( $unique_error_messages ) ) { 121 wp_send_json_success( true ); 122 } else { 123 wp_send_json_success( $unique_error_messages ); 124 } 122 125 123 126 /* -
block-style-guides/trunk/admin-menu-functions.php
r2074113 r2076075 13 13 14 14 function bsg_settings_init() { 15 register_setting( 'bsg_plugin_page', 'bsg_post_types', 'bsg_admin_notices' );16 17 15 add_settings_section( 18 16 'bsg_plugin_page_section', … … 31 29 } 32 30 33 function bsg_admin_notices( $input ) {34 $message = '';35 $type = '';36 $error_transient = get_transient( 'bsg-errors' );37 38 if( $error_transient ) {39 $errors = ( $error_transient );40 41 foreach( $errors as $k => $v ) {42 43 switch( $k ) {44 case 'nonce_failed':45 $message .= 'Your request has timed out. Please refresh the page and try again.<br />';46 break;47 48 case 'class_does_not_exist':49 foreach( $v as $class ) {50 $full_class_name = $class;51 $class_name_array = explode( '\\', $full_class_name );52 $class_name = array_pop( $class_name_array );53 54 // @TODO - Make this error message suck 87% less.55 $message .= 'The ' . $class_name . ' class could not be created, so the page(s) associated with it has not been created.<br />';56 57 }58 59 break;60 61 case 'post_already_exists':62 foreach( $v as $post_type ) {63 $post_type_obj = get_post_type_object( $post_type );64 $post_type_name = $post_type_obj->labels->singular_name;65 $message .= 'The posts for the ' . ( $post_type_name ) . ' post type already existed, so they have not be created.<br />';66 }67 break;68 69 case 'could_not_create_posts':70 $message .= 'The system could not create your posts. Please refresh and try again.<br />';71 break;72 }73 }74 75 add_settings_error( 'bsg_post_types', 'bsg-update', $message, 'error' );76 } else {77 $message = 'Your posts have been created!';78 $type = 'updated';79 add_settings_error( 'bsg_post_types', 'bsg-update', $message, $type );80 }81 82 delete_transient( 'bsg-errors' );83 84 return $input;85 }86 87 31 function bsg_cpt_selection_render() { 32 $out = ''; 33 $builtin_cpts = array(); 34 $gutenbergable_cpts = array(); // If that's not a word, it should be 35 $non_gutenbergable_cpts = array(); 36 $non_contentable_cpts = array(); // That one too 88 37 $all_post_types = get_post_types( 89 38 array( … … 93 42 ); 94 43 44 // Attachments are public but neither Gutenbergable nor contentable. 95 45 unset( $all_post_types[ 'attachment' ] ); 96 46 47 foreach( $all_post_types as $cpt ) { 48 if( $cpt->_builtin ) { 49 $builtin_cpts[] = $cpt; 50 } else if( ! post_type_supports( $cpt->name, 'editor' ) ) { 51 $non_contentable_cpts[] = $cpt; 52 } else if( ! $cpt->show_in_rest ) { 53 $non_gutenbergable_cpts[] = $cpt; 54 } else { 55 $gutenbergable_cpts[] = $cpt; 56 } 57 } 58 59 if( is_array( $builtin_cpts ) && ! empty( $builtin_cpts ) ) { 60 $out .= '<h4>Built-in post types</h4>'; 61 $out .= '<p style="margin-bottom: 10px;">These post types are part of WordPress core.</p>'; 62 $out .= bsg_display_checkboxes( $builtin_cpts ); 63 } 64 65 if( is_array( $gutenbergable_cpts ) && ! empty( $gutenbergable_cpts ) ) { 66 $out .= '<h4>Custom post types</h4>'; 67 $out .= '<p style="margin-bottom: 10px;">These post types currently support the Gutenberg editor.</p>'; 68 $out .= bsg_display_checkboxes( $gutenbergable_cpts ); 69 } 70 71 if( is_array( $non_gutenbergable_cpts ) && ! empty( $non_gutenbergable_cpts ) ) { 72 $out .= '<h4>Custom post types with no Gutenberg support</h4>'; 73 $out .= '<p style="margin-bottom: 10px;">These posts types do not currently support the Gutenberg editor. You can still create style guides for them to see what they will look like if/when they declare support.</p>'; 74 $out .= bsg_display_checkboxes( $non_gutenbergable_cpts ); 75 } 76 77 if( is_array( $non_contentable_cpts ) && ! empty( $non_contentable_cpts ) ) { 78 $out .= '<h4>Custom post types with no support for content</h4>'; 79 $out .= '<p style="margin-bottom: 10px;">These post types don\'t display <code>the_content</code> as part of their output. You can still create style guides for them, but they likely won\'t display the style guides correctly or at all.</p>'; 80 $out .= bsg_display_checkboxes( $non_contentable_cpts ); 81 } 82 83 echo $out; 84 } 85 86 function bsg_display_checkboxes( $cpts = array() ) { 87 $out = ''; 97 88 $options = get_option( 'bsg_post_types' ); 98 foreach( $all_post_types as $cpt ) { 89 90 if( ! is_array( $cpts ) || empty( $cpts ) ) { 91 return; 92 } 93 94 foreach( $cpts as $cpt ) { 99 95 if( isset( $options[ $cpt->name ] ) ) { 100 96 $checked = $options[ $cpt->name ]; … … 102 98 $checked = ''; 103 99 } 100 101 ob_start(); 104 102 ?> 105 <input class="bsg-cpt-type" data-cpt="<?php echo $cpt->name; ?>" type='checkbox' name='bsg_post_types[<?php echo $cpt->name; ?>]'<?php checked( $checked, 1 ); ?> value='1'>106 <label for='bsg_post_types[<?php echo $cpt->name; ?>]'><?php echo $cpt->label; ?></label>107 <br />103 <input class="bsg-cpt-type" data-cpt="<?php echo $cpt->name; ?>" type='checkbox' name='bsg_post_types[<?php echo $cpt->name; ?>]' id="bsg_post_types[<?php echo $cpt->name; ?>]" <?php checked( $checked, 1 ); ?> value='1'> 104 <label for='bsg_post_types[<?php echo $cpt->name; ?>]'><?php echo $cpt->label; ?></label> 105 <br /> 108 106 <?php 107 $out .= ob_get_clean(); 109 108 } 109 110 return $out; 110 111 } 111 112 … … 116 117 function bsg_options_page() { 117 118 wp_enqueue_script( 'bsg-ajax' ); 119 wp_enqueue_script( 'json-form' ); 118 120 119 121 $script_params = array( 120 122 'bsgAddNonce' => wp_create_nonce( 'bsg-add-nonce' ), 121 'bsgDeleteNonce' => wp_create_nonce( 'bsg-delete-nonce' ), // upcoming123 'bsgDeleteNonce' => wp_create_nonce( 'bsg-delete-nonce' ), 122 124 ); 123 125 … … 125 127 126 128 ?> 127 <h2 >Gutenberg Block Style Guides</h2>129 <h2 class="bsg-title">Block Style Guides for Gutenberg</h2> 128 130 <?php settings_errors(); ?> 129 131 <form action='options.php' method='post' name="bsg-form" id="bsg-form"> … … 134 136 ?> 135 137 </form> 138 <p>If you want to delete all the posts created by this plugin, click the button below.</p> 139 <button id="bsg-delete" class="button button-secondary">Delete all Block Style Guide posts</button> 136 140 <?php 137 141 } -
block-style-guides/trunk/block-style-guides.php
r2074113 r2076075 4 4 * Plugin Name: Block Style Guides for Gutenberg 5 5 * Description: Creates posts in draft mode showcasing all default Gutenberg blocks, for styling purposes. 6 * Version: 1. 06 * Version: 1.2.0 7 7 * Author: Robert Gillmer 8 8 * Author URI: https://www.robertgillmer.com … … 28 28 include_once( plugin_dir_path( __FILE__ ) . 'admin-menu-functions.php' ); 29 29 include_once( plugin_dir_path( __FILE__ ) . 'add-bsg-posts.php'); 30 include_once( plugin_dir_path( __FILE__ ) . 'delete-bsg-posts.php'); -
block-style-guides/trunk/general.php
r2074113 r2076075 2 2 3 3 function bsg_enqueue_scripts() { 4 wp_register_script( 'bsg-ajax', plugin_dir_url( __FILE__ ) . '/js/bsg.js', array( 'jquery' ), false, true );4 wp_register_script( 'bsg-ajax', plugin_dir_url( __FILE__ ) . '/js/bsg.js', array( 'jquery', 'jquery-form' ), false, true ); 5 5 } 6 6 -
block-style-guides/trunk/js/bsg.js
r2074113 r2076075 1 1 (function($) { 2 2 var bsgAddNonce = bsgAjax.bsgAddNonce; 3 var bsgDeleteNonce = bsgAjax.bsgDeleteNonce; // Upcoming3 var bsgDeleteNonce = bsgAjax.bsgDeleteNonce; 4 4 5 5 $( '#bsg-form' ).submit( function( e ) { 6 e.preventDefault(); // Submitting via AJAX 7 $(this).ajaxSubmit(); // See? 8 6 9 var selectedTypes = []; 7 10 jQuery( '.bsg-cpt-type' ).each( function() { … … 21 24 }) 22 25 23 .done( function( data ) { 26 .done( function( response ) { 27 $( '.setting-error-bsg-update' ).remove(); 28 var data = response[ 'data' ]; 29 hasError = false, 30 banners = ''; 31 32 if( data === true ) { // true means there were no errors 33 banners = makeBanner( 'Posts were created successfully.', 'updated' ) + banners; 34 } else { 35 if( 'couldNotCreatePosts' in data ) { 36 var message = 'The following post(s) could not be created due to internal errors: ', 37 errorArray = data[ 'couldNotCreatePosts' ]; 38 banners += makeErrorBanner( message, errorArray );; 39 hasError = true; 40 } 41 42 if( 'postAlreadyExists' in data ) { 43 var message = 'Posts already existed for the following post type(s), so new posts were not created: ', 44 errorArray = data[ 'postAlreadyExists' ]; 45 banners += makeErrorBanner( message, errorArray );; 46 hasError = true; 47 } 48 49 if( 'classDoesNotExist' in data ) { 50 var message = 'The following page(s) could not be created because the class doesn\'t exist: ', 51 errorArray = data[ 'classDoesNotExist' ]; 52 banners += makeErrorBanner( message, errorArray );; 53 hasError = true; 54 } 55 // Success messages should be above the error messages, hence the no += operator. 56 banners = makeBanner( 'Posts were created successfully, with the exceptions listed below.', 'updated' ) + banners; 57 } 58 59 $( '.bsg-title' ).after( banners ); 60 24 61 return true; 25 62 }) … … 29 66 }) 30 67 } ); 68 69 $( '#bsg-delete' ).click( function( e ) { 70 e.preventDefault(); 71 $( '.setting-error-bsg-update' ).remove(); 72 73 $.ajax({ 74 url: ajaxurl, 75 type: 'post', 76 data: { 77 action: 'bsg_delete_posts', 78 bsgDeleteNonce: bsgDeleteNonce, 79 } 80 }) 81 82 .done( function( data ) { 83 var banner = makeBanner( 'All posts created by Block Style Guides have been successfully deleted.', 'updated' ); 84 $( '.bsg-title' ).after( banner ); 85 return true; 86 }) 87 88 .fail( function() { 89 var banner = makeBanner( 'There was an issue deleting the posts created by Block Style Guides.', 'error' ); 90 $( '.bsg-title' ).after( banner ); 91 return false; // More here too 92 }) 93 94 return false; 95 } ); 96 97 function makeBanner( text, type="updated" ) { 98 if( ! text ) { 99 return; 100 } 101 102 var banner = '<div class="setting-error-bsg-update ' + type + ' settings-error notice is-dismissible">'; 103 banner += '<p><strong>' + text + '</strong></p>'; 104 banner += '<button type="button" class="notice-dismiss">'; 105 banner += '<span class="screen-reader-text">Dismiss this notice.</span>'; 106 banner += '</button>'; 107 banner += '</div>'; 108 109 return banner; 110 } 111 112 function makeErrorBanner( text, errorArray ) { 113 var message = text + errorArray.join( ', ' ); 114 115 return makeBanner( message, 'error' ); 116 } 31 117 })( jQuery ); -
block-style-guides/trunk/readme.txt
r2074389 r2076075 91 91 * Added filters for a buncha placeholder variables. 92 92 * Used those variables throughout the markup. 93 94 = 1.2.0 = 95 96 * Error reporting is now 927% betterer. 97 * Form submits via AJAX, which is why the error reporting is so much betterer. 98 * Split list of CPT's up into groups based on ability to use the Gutenberg editor. 99 * "Delete all the things!" button added. (Not all the things, just all the things this plugin created, but that's wordy.)
Note: See TracChangeset
for help on using the changeset viewer.