Ticket #3403: blocks.9oct2020.diff
File blocks.9oct2020.diff, 15.7 KB (added by , 5 years ago) |
---|
-
package.json
27 27 "grunt-wp-i18n": "~1.0.3", 28 28 "matchdep": "~2.0.0", 29 29 "node-sass": "~4.14.1", 30 "parcel-bundler": "^1.10.1", 30 31 "postcss-scss": "~1.0.2", 31 32 "stylelint": "~13.6.1", 32 33 "stylelint-config-wordpress": "~15.0.0" … … 35 36 "node": ">=12.0.0", 36 37 "npm": ">=6.9.0" 37 38 }, 39 "scripts": { 40 "blocks": "parcel build src/includes/admin/assets/js/blocks.jsx --out-dir src/includes/admin/assets/js --public-url ." 41 }, 38 42 "keywords": [ 39 43 "community", 40 44 "forums", -
src/bbpress.php
340 340 require $this->includes_dir . 'common/template.php'; 341 341 require $this->includes_dir . 'common/widgets.php'; 342 342 require $this->includes_dir . 'common/shortcodes.php'; 343 require $this->includes_dir . 'common/blocks.php'; 343 344 344 345 // Forums 345 346 require $this->includes_dir . 'forums/capabilities.php'; … … 521 522 'show_in_nav_menus' => true, 522 523 'public' => true, 523 524 'show_ui' => current_user_can( 'bbp_forums_admin' ), 525 'show_in_rest' => true, 524 526 'can_export' => true, 525 527 'hierarchical' => true, 526 528 'query_var' => true, … … 734 736 } 735 737 736 738 /** 737 * Register the bbPress shortcodes 739 * Register the bbPress shortcodes and blocks 738 740 * 739 741 * @since 2.0.0 bbPress (r3031) 740 742 */ 741 743 public function register_shortcodes() { 742 744 $this->shortcodes = new BBP_Shortcodes(); 745 $this->blocks = new BBP_Blocks( $this->shortcodes ); 743 746 } 744 747 745 748 /** -
src/includes/admin/assets/css/blocks.css
1 2 .bbpress-block { 3 background: #fff; 4 border: 1px solid #888; 5 padding: 1em 2em; 6 } 7 8 .bbpress-block h3 { 9 color: #444; 10 cursor: default; 11 } -
src/includes/admin/assets/js/blocks.js
Property changes on: src/includes/admin/assets/css/blocks.css ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
1 parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"aE2q":[function(require,module,exports) { 2 var e=wp.blocks.registerBlockType,t=wp.components.SelectControl,n=wp.i18n.__;e("bbpress/forum-index",{title:n("Forums List"),icon:"buddicons-bbpress-logo",category:"common",attributes:{},edit:function(){return React.createElement("div",{class:"bbpress-block"},React.createElement("h3",null,n("bbPress Forum Index")))},save:function(){return null}}),e("bbpress/forum",{title:n("Single Forum"),icon:"buddicons-bbpress-logo",category:"common",attributes:{id:{type:"integer",default:0}},edit:function(e){return React.createElement("div",{class:"bbpress-block"},React.createElement("h3",null,n("bbPress Single Forum")),React.createElement(t,{label:n("Forum"),labelPosition:"top",value:e.attributes.id,options:bbpBlocks.data.forums,onChange:function(t){e.setAttributes({id:t})}}))},save:function(){return null}}); 3 },{}]},{},["aE2q"], null) 4 //# sourceMappingURL=blocks.js.map 5 No newline at end of file -
src/includes/admin/assets/js/blocks.js.map
Property changes on: src/includes/admin/assets/js/blocks.js ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
1 {"version":3,"sources":["blocks.jsx"],"names":["registerBlockType","wp","blocks","SelectControl","components","__","i18n","title","icon","category","attributes","edit","save","id","type","default","props","bbpBlocks","data","forums","handleForumChange","setAttributes"],"mappings":";AAGCA,IAAAA,EACGC,GAAGC,OADNF,kBAIAG,EACGF,GAAGG,WADND,cAIAE,EACGJ,GAAGK,KADND,GAIDL,EAAmB,sBAAuB,CACzCO,MAAOF,EAAI,eACXG,KAAM,yBACNC,SAAU,SAEVC,WAAY,GAEZC,KAAM,WAEJ,OAAA,MAAA,cAAA,MAAA,CAAK,MAAM,iBACV,MAAMN,cAAAA,KAAAA,KAAAA,EAAI,0BAKbO,KAAM,WAAM,OAAA,QAObZ,EAAmB,gBAAiB,CACnCO,MAAOF,EAAI,gBACXG,KAAM,yBACNC,SAAU,SAEVC,WAAY,CACXG,GAAI,CACHC,KAAM,UACNC,QAAS,IAIXJ,KAAM,SAAUK,GAMd,OAAA,MAAA,cAAA,MAAA,CAAK,MAAM,iBACV,MAAMX,cAAAA,KAAAA,KAAAA,EAAI,yBACV,MAAC,cAAA,EAAD,CACC,MAAQA,EAAI,SACZ,cAAc,MACd,MAAQW,EAAMN,WAAWG,GACzB,QAAUI,UAAUC,KAAKC,OACzB,SAZMC,SAAmBP,GAC3BG,EAAMK,cAAc,CAAER,GAAAA,SAiBxBD,KAAM,WAAM,OAAA","file":"blocks.js","sourceRoot":"","sourcesContent":["/* global bbpBlocks */\n\nconst {\n\tregisterBlockType\n} = wp.blocks;\n\nconst {\n\tSelectControl\n} = wp.components;\n\nconst {\n\t__\n} = wp.i18n;\n\n// Replaces [bbp-forum-index] – This will display your entire forum index.\nregisterBlockType( 'bbpress/forum-index', {\n\ttitle: __( 'Forums List' ),\n\ticon: 'buddicons-bbpress-logo',\n\tcategory: 'common',\n\n\tattributes: {},\n\n\tedit: function() {\n\t\treturn (\n\t\t\t<div class=\"bbpress-block\">\n\t\t\t\t<h3>{ __( 'bbPress Forum Index' ) }</h3>\n\t\t\t</div>\n\t\t);\n\t},\n\n\tsave: () => null\n} );\n\n// Replaces [bbp-forum-form] – Display the ‘New Forum’ form.\n\n\n// Replaces [bbp-single-forum id=$forum_id] – Display a single forums topics. eg. [bbp-single-forum id=32]\nregisterBlockType( 'bbpress/forum', {\n\ttitle: __( 'Single Forum' ),\n\ticon: 'buddicons-bbpress-logo',\n\tcategory: 'common',\n\n\tattributes: {\n\t\tid: {\n\t\t\ttype: 'integer',\n\t\t\tdefault: 0,\n\t\t}\n\t},\n\n\tedit: function( props ) {\n\t\tfunction handleForumChange( id ) {\n\t\t\tprops.setAttributes({ id })\n\t\t}\n\n\t\treturn (\n\t\t\t<div class=\"bbpress-block\">\n\t\t\t\t<h3>{ __( 'bbPress Single Forum' ) }</h3>\n\t\t\t\t<SelectControl\n\t\t\t\t\tlabel={ __( 'Forum' ) }\n\t\t\t\t\tlabelPosition=\"top\"\n\t\t\t\t\tvalue={ props.attributes.id }\n\t\t\t\t\toptions={ bbpBlocks.data.forums }\n\t\t\t\t\tonChange={ handleForumChange }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t},\n\n\tsave: () => null\n\n} );\n\n// Topics\n// Replaces [bbp-topic-index] – Display the most recent 15 topics across all your forums with pagination.\n// Replaces [bbp-topic-form] – Display the ‘New Topic’ form where you can choose from a drop down menu the forum that this topic is to be associated with.\n// Replaces [bbp-topic-form forum_id=$forum_id] – Display the ‘New Topic Form’ for a specific forum ID.\n// Replaces [bbp-single-topic id=$topic_id] – Display a single topic. eg. [bbp-single-topic id=4096]\n\n// Replies\n// Replaces [bbp-reply-form] – Display the ‘New Reply’ form.\n// Replaces [bbp-single-reply id=$reply_id] – Display a single reply eg. [bbp-single-reply id=32768]\n\n// Topic Tags\n// Replaces [bbp-topic-tags] – Display a tag cloud of all topic tags.\n// Replaces [bbp-single-tag id=$tag_id] – Display a list of all topics associated with a specific tag. eg. [bbp-single-tag id=64]\n\n// Views\n// Replaces [bbp-single-view] – Single view – Display topics associated with a specific view. Current included ‘views’ with bbPress are “popular” [bbp-single-view id=’popular’] and “No Replies” [bbp-single-view id=’no-replies’]\n\n// Search\n// Replaces [bbp-search] – Display the search input form.\n// Replaces [bbp-search-form] – Display the search form template.\n\n// Account\n// Replaces [bbp-login] – Display the login screen.\n// Replaces [bbp-register] – Display the register screen.\n// Replaces [bbp-lost-pass] – Display the lost password screen.\n\n// Statistics\n// Replaces [bbp-stats] – Display the forum statistics.\n\n\n"]} 2 No newline at end of file -
src/includes/admin/assets/js/blocks.jsx
1 /* global bbpBlocks */ 2 3 const { 4 registerBlockType 5 } = wp.blocks; 6 7 const { 8 SelectControl 9 } = wp.components; 10 11 const { 12 __ 13 } = wp.i18n; 14 15 // Replaces [bbp-forum-index] – This will display your entire forum index. 16 registerBlockType( 'bbpress/forum-index', { 17 title: __( 'Forums List' ), 18 icon: 'buddicons-bbpress-logo', 19 category: 'common', 20 21 attributes: {}, 22 23 edit: function() { 24 return ( 25 <div class="bbpress-block"> 26 <h3>{ __( 'bbPress Forum Index' ) }</h3> 27 </div> 28 ); 29 }, 30 31 save: () => null 32 } ); 33 34 // Replaces [bbp-forum-form] – Display the ‘New Forum’ form. 35 36 37 // Replaces [bbp-single-forum id=$forum_id] – Display a single forums topics. eg. [bbp-single-forum id=32] 38 registerBlockType( 'bbpress/forum', { 39 title: __( 'Single Forum' ), 40 icon: 'buddicons-bbpress-logo', 41 category: 'common', 42 43 attributes: { 44 id: { 45 type: 'integer', 46 default: 0, 47 } 48 }, 49 50 edit: function( props ) { 51 function handleForumChange( id ) { 52 props.setAttributes({ id }) 53 } 54 55 return ( 56 <div class="bbpress-block"> 57 <h3>{ __( 'bbPress Single Forum' ) }</h3> 58 <SelectControl 59 label={ __( 'Forum' ) } 60 labelPosition="top" 61 value={ props.attributes.id } 62 options={ bbpBlocks.data.forums } 63 onChange={ handleForumChange } 64 /> 65 </div> 66 ); 67 }, 68 69 save: () => null 70 71 } ); 72 73 // Topics 74 // Replaces [bbp-topic-index] – Display the most recent 15 topics across all your forums with pagination. 75 // Replaces [bbp-topic-form] – Display the ‘New Topic’ form where you can choose from a drop down menu the forum that this topic is to be associated with. 76 // Replaces [bbp-topic-form forum_id=$forum_id] – Display the ‘New Topic Form’ for a specific forum ID. 77 // Replaces [bbp-single-topic id=$topic_id] – Display a single topic. eg. [bbp-single-topic id=4096] 78 79 // Replies 80 // Replaces [bbp-reply-form] – Display the ‘New Reply’ form. 81 // Replaces [bbp-single-reply id=$reply_id] – Display a single reply eg. [bbp-single-reply id=32768] 82 83 // Topic Tags 84 // Replaces [bbp-topic-tags] – Display a tag cloud of all topic tags. 85 // Replaces [bbp-single-tag id=$tag_id] – Display a list of all topics associated with a specific tag. eg. [bbp-single-tag id=64] 86 87 // Views 88 // Replaces [bbp-single-view] – Single view – Display topics associated with a specific view. Current included ‘views’ with bbPress are “popular” [bbp-single-view id=’popular’] and “No Replies” [bbp-single-view id=’no-replies’] 89 90 // Search 91 // Replaces [bbp-search] – Display the search input form. 92 // Replaces [bbp-search-form] – Display the search form template. 93 94 // Account 95 // Replaces [bbp-login] – Display the login screen. 96 // Replaces [bbp-register] – Display the register screen. 97 // Replaces [bbp-lost-pass] – Display the lost password screen. 98 99 // Statistics 100 // Replaces [bbp-stats] – Display the forum statistics. 101 102 -
src/includes/common/blocks.php
1 <?php 2 3 /** 4 * bbPress Blocks 5 * 6 * @package bbPress 7 * @subpackage Blocks 8 */ 9 10 // Exit if accessed directly 11 defined( 'ABSPATH' ) || exit; 12 13 if ( ! class_exists( 'BBP_Blocks' ) ) : 14 /** 15 * bbPress Shortcode Class 16 * 17 * @since 2.0.0 bbPress (r3031) 18 */ 19 class BBP_Blocks { 20 21 /** Vars ******************************************************************/ 22 23 /** 24 * @var BBP_Shortcodes Most of our blocks are just visual representations of existing shortcodes. 25 */ 26 public $shortcodes; 27 28 /** Functions *************************************************************/ 29 30 /** 31 * Set up the blocks for the Block Editor. 32 */ 33 public function __construct( BBP_Shortcodes $shortcodes = NULL ) { 34 $this->shortcodes = $shortcodes; 35 $this->register_blocks(); 36 } 37 38 public function register_blocks() { 39 if ( ! function_exists( 'register_block_type' ) ) { 40 return; 41 } 42 43 wp_register_style( 'bbp-blocks', plugins_url( '../admin/assets/css/blocks.css', __FILE__ ) ); 44 45 wp_register_script( 'bbp-blocks', plugins_url( '../admin/assets/js/blocks.js', __FILE__ ), [ 'wp-blocks', 'wp-components', 'wp-i18n' ], filemtime( __DIR__ . '/../admin/assets/js/blocks.js' ) ); 46 wp_localize_script( 'bbp-blocks', 'bbpBlocks', array( 47 'data' => array( 48 'forum_post_type' => bbp_get_forum_post_type(), 49 'forums' => self::get_localize_script_data( 'forums' ), 50 ) 51 ) ); 52 53 // Note: While not ideal, we're storing all of our block js in the same file. Fewer assets to load, but 54 // it does mean that if the block is deregistered in php, it will still exist in js in the block editor. 55 56 register_block_type( 'bbpress/forum-index', array( 57 'render_callback' => array( $this, 'display_forum_index' ), 58 'editor_script' => 'bbp-blocks', 59 'editor_style' => 'bbp-blocks', 60 ) ); 61 62 register_block_type( 'bbpress/forum', array( 63 'render_callback' => array( $this, 'display_forum' ), 64 'editor_script' => 'bbp-blocks', 65 'editor_style' => 'bbp-blocks', 66 ) ); 67 } 68 69 public static function get_localize_script_data( $data ) { 70 switch( $data ) { 71 case 'forums': 72 $forums = get_pages( array( 73 'post_type' => bbp_get_forum_post_type(), 74 'numberposts' => -1, 75 'post_status' => array( 'publish', 'private' ), 76 ) ); 77 78 $return = array( array( 'value' => 0, 'label' => __( '« Select a Forum »' ) ) ); 79 foreach ( $forums as $forum ) { 80 $return[] = array( 81 'value' => (int) $forum->ID, 82 'label' => $forum->post_title, 83 ); 84 } 85 return $return; 86 break; 87 default: 88 return null; 89 } 90 } 91 92 /** 93 * Passthrough function for `display_forum_index` -- the forum list view. 94 * 95 * @return string The markup for the forum list view. 96 */ 97 public function display_forum_index() { 98 return $this->shortcodes->display_forum_index(); 99 } 100 101 /** 102 * Passthrough function for `display_forum` -- the single forum view. 103 * 104 * @param $attributes (array) An array with -- at minimum -- an `id` key set to the forum id. 105 * @return string The markup for the single forum. 106 */ 107 public function display_forum( $attributes ) { 108 // If for some reason there isn't a forum id, just display it all. 109 if ( empty( $attributes['id'] ) ) { 110 return $this->display_forum_index(); 111 } 112 113 return $this->shortcodes->display_forum( $attributes ); 114 } 115 116 } 117 endif; 118 No newline at end of file