Skip to:
Content

BuddyPress.org

Ticket #8525: 8525.patch

File 8525.patch, 32.3 KB (added by imath, 5 years ago)
  • .jshintignore

    diff --git .jshintignore .jshintignore
    index eeeb21557..e8d9c2857 100644
    src/**/js/friends.js  
    1212src/**/js/dynamic-members.js
    1313src/**/js/dynamic-groups.js
    1414src/**/js/dynamic-widget-block.js
     15src/**/js/sitewide-notices.js
  • Gruntfile.js

    diff --git Gruntfile.js Gruntfile.js
    index 7e4ecdae2..e470da5cd 100644
    module.exports = function( grunt ) {  
    2626                        '!**/js/friends.js',
    2727                        '!**/js/dynamic-members.js',
    2828                        '!**/js/dynamic-groups.js',
    29                         '!**/js/dynamic-widget-block.js'
     29                        '!**/js/dynamic-widget-block.js',
     30                        '!**/js/sitewide-notices.js'
    3031                ],
    3132
    3233                BP_EXCLUDED_MISC = [
    … … module.exports = function( grunt ) {  
    4748                        '!bp-activity/css/blocks/latest-activities.css',
    4849                        '!bp-friends/css/blocks/friends.css',
    4950                        '!bp-members/css/blocks/dynamic-members.css',
    50                         '!bp-groups/css/blocks/dynamic-groups.css'
     51                        '!bp-groups/css/blocks/dynamic-groups.css',
     52                        '!bp-messages/css/blocks/sitewide-notices.css'
    5153                ],
    5254
    5355                autoprefixer = require('autoprefixer');
    … … module.exports = function( grunt ) {  
    184186                                flatten: true,
    185187                                src: ['bp-friends/sass/blocks/*.scss'],
    186188                                dest: SOURCE_DIR + 'bp-friends/css/blocks/'
     189                        },
     190                        messages_blocks: {
     191                                cwd: SOURCE_DIR,
     192                                extDot: 'last',
     193                                expand: true,
     194                                ext: '.css',
     195                                flatten: true,
     196                                src: ['bp-messages/sass/blocks/*.scss'],
     197                                dest: SOURCE_DIR + 'bp-messages/css/blocks/'
    187198                        }
    188199                },
    189200                rtlcss: {
  • new file src/bp-messages/bp-messages-blocks.php

    diff --git src/bp-messages/bp-messages-blocks.php src/bp-messages/bp-messages-blocks.php
    new file mode 100644
    index 000000000..d7500ccfd
    - +  
     1<?php
     2/**
     3 * BP Messages Blocks Functions.
     4 *
     5 * @package BuddyPress
     6 * @subpackage MessagesBlocks
     7 * @since 9.0.0
     8 */
     9
     10// Exit if accessed directly.
     11if ( ! defined( 'ABSPATH' ) ) {
     12        exit;
     13}
     14
     15/**
     16 * Callback function to render the BP Sitewide Notices Block.
     17 *
     18 * @since 9.0.0
     19 *
     20 * @param array $attributes The block attributes.
     21 * @return string           HTML output.
     22 */
     23function bp_messages_render_sitewide_notices_block( $attributes = array() ) {
     24        $block_args = bp_parse_args(
     25                $attributes,
     26                array(
     27                        'title' => '',
     28                ),
     29                'widget_object_sitewide_messages'
     30        );
     31
     32        if ( ! is_user_logged_in() ) {
     33                return;
     34        }
     35
     36        $feedback_tpl  = '<div class="components-placeholder">' . "\n";
     37        $feedback_tpl .= '<div class="components-placeholder__label">%1$s</div>' . "\n";
     38        $feedback_tpl .= '<div class="components-placeholder__fieldset">%2$s</div>' . "\n";
     39        $feedback_tpl .= '</div>';
     40
     41        // Don't display the block if there are no Notices to show.
     42        $notice = \BP_Messages_Notice::get_active();
     43        if ( empty( $notice->id ) ) {
     44                // Previewing the Block inside the editor.
     45                if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
     46                        return sprintf(
     47                                $feedback_tpl,
     48                                esc_html__( 'Preview unavailable', 'buddypress' ),
     49                                esc_html__( 'No active sitewide notices.', 'buddypress' )
     50                        );
     51                }
     52
     53                return;
     54        }
     55
     56        // Only enqueue common/specific scripts and data once per page load.
     57        if ( ! wp_script_is( 'bp-sitewide-notices-script', 'enqueued' ) ) {
     58                $path = sprintf(
     59                        '/%1$s/%2$s/sitewide-notices/',
     60                        bp_rest_namespace(),
     61                        bp_rest_version()
     62                );
     63                wp_enqueue_script( 'bp-sitewide-notices-script' );
     64                wp_localize_script(
     65                        'bp-sitewide-notices-script',
     66                        'bpSitewideNoticeBlockSettings',
     67                        array(
     68                                'path'        => ltrim( $path, '/' ),
     69                                'dismissPath' => ltrim( $path, '/' ) . 'dismiss',
     70                                'root'        => esc_url_raw( get_rest_url() ),
     71                                'nonce'       => wp_create_nonce( 'wp_rest' ),
     72                        )
     73                );
     74        }
     75
     76        $closed_notices = (array) bp_get_user_meta( bp_loggedin_user_id(), 'closed_notices', true );
     77
     78        if ( in_array( $notice->id, $closed_notices, true ) ) {
     79                // Previewing the Block inside the editor.
     80                if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
     81                        return sprintf(
     82                                $feedback_tpl,
     83                                esc_html__( 'Preview unavailable', 'buddypress' ),
     84                                esc_html__( 'You dismissed the sitewide notice.', 'buddypress' )
     85                        );
     86                }
     87
     88                return;
     89        }
     90
     91        // There is an active, non-dismissed notice to show.
     92        $title = $block_args['title'];
     93
     94        $classnames         = 'widget_bp_core_sitewide_messages buddypress widget';
     95        $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) );
     96
     97        $widget_content = '<div class="bp-sitewide-notice-block">';
     98
     99        if ( $title ) {
     100                $widget_content .= sprintf(
     101                        '<h2 class="widget-title">%s</h2>',
     102                        esc_html( $title )
     103                );
     104        }
     105
     106        $widget_content .= sprintf(
     107                '<div class="bp-sitewide-notice-message info bp-notice" rel="n-%1$d">
     108                        <strong>%2$s</strong>
     109                        <a href="%3$s" class="bp-tooltip button dismiss-notice" data-bp-tooltip="%4$s" data-bp-sitewide-notice-id="%5$d"><span class="bp-screen-reader-text">%6$s</span> <span aria-hidden="true">&#x2716;</span></a>
     110                        %7$s
     111                </div>',
     112                esc_attr( $notice->id ),
     113                bp_get_message_notice_subject( $notice ),
     114                esc_url( bp_get_message_notice_dismiss_link() ),
     115                esc_attr__( 'Dismiss this notice', 'buddypress' ),
     116                esc_attr( $notice->id ),
     117                esc_html__( 'Dismiss this notice', 'buddypress' ),
     118                bp_get_message_notice_text( $notice )
     119        );
     120
     121        $widget_content .= '</div>';
     122
     123        if ( ! did_action( 'dynamic_sidebar_before' ) ) {
     124                return sprintf(
     125                        '<div %1$s>%2$s</div>',
     126                        $wrapper_attributes,
     127                        $widget_content
     128                );
     129        }
     130
     131        return $widget_content;
     132}
  • src/bp-messages/bp-messages-cssjs.php

    diff --git src/bp-messages/bp-messages-cssjs.php src/bp-messages/bp-messages-cssjs.php
    index 1e3d278e4..1fdd19431 100644
    function messages_autocomplete_init_jsblock() {  
    7373
    7474<?php
    7575}
     76
     77/**
     78 * Registers a new script to manage the dismissal action for the Sitewide notice widget/block.
     79 *
     80 * @since 9.0.0
     81 *
     82 * @param array $scripts Data about the scripts to register.
     83 * @return array Data about the scripts to register.
     84 */
     85function bp_messages_register_scripts( $scripts = array() ) {
     86        $scripts['bp-sitewide-notices-script'] = array(
     87                'file'         => plugins_url( 'js/sitewide-notices.js', __FILE__ ),
     88                'dependencies' => array(),
     89                'footer'       => true,
     90        );
     91
     92        return $scripts;
     93}
     94add_filter( 'bp_core_register_common_scripts', 'bp_messages_register_scripts', 9, 1 );
  • src/bp-messages/classes/class-bp-messages-component.php

    diff --git src/bp-messages/classes/class-bp-messages-component.php src/bp-messages/classes/class-bp-messages-component.php
    index f04c00c50..5271c00f6 100644
    class BP_Messages_Component extends BP_Component {  
    6262                        'template',
    6363                        'functions',
    6464                        'widgets',
     65                        'blocks',
    6566                );
    6667
    6768                // Conditional includes.
    … … class BP_Messages_Component extends BP_Component {  
    455456         *                      description.
    456457         */
    457458        public function blocks_init( $blocks = array() ) {
    458                 parent::blocks_init( array() );
     459                parent::blocks_init(
     460                        array(
     461                                'bp/sitewide-notices' => array(
     462                                        'name'               => 'bp/sitewide-notices',
     463                                        'editor_script'      => 'bp-sitewide-notices-block',
     464                                        'editor_script_url'  => plugins_url( 'js/blocks/sitewide-notices.js', dirname( __FILE__ ) ),
     465                                        'editor_script_deps' => array(
     466                                                'wp-blocks',
     467                                                'wp-element',
     468                                                'wp-components',
     469                                                'wp-i18n',
     470                                                'wp-block-editor',
     471                                                'bp-block-data',
     472                                                'bp-block-components',
     473                                        ),
     474                                        'style'              => 'bp-sitewide-notices-block',
     475                                        'style_url'          => plugins_url( 'css/blocks/sitewide-notices.css', dirname( __FILE__ ) ),
     476                                        'attributes'         => array(
     477                                                'title' => array(
     478                                                        'type'    => 'string',
     479                                                        'default' => '',
     480                                                ),
     481                                        ),
     482                                        'render_callback'    => 'bp_messages_render_sitewide_notices_block',
     483                                ),
     484                        )
     485                );
    459486        }
    460487}
  • new file src/bp-messages/css/blocks/sitewide-notices-rtl.css

    diff --git src/bp-messages/css/blocks/sitewide-notices-rtl.css src/bp-messages/css/blocks/sitewide-notices-rtl.css
    new file mode 100644
    index 000000000..fbae47d63
    - +  
     1[data-type="bp/sitewide-notices"] .bp-screen-reader-text {
     2        border: 0;
     3        clip: rect(0 0 0 0);
     4        height: 1px;
     5        margin: -1px;
     6        overflow: hidden;
     7        padding: 0;
     8        position: absolute;
     9        width: 1px;
     10        word-wrap: normal !important;
     11}
     12
     13[data-type="bp/sitewide-notices"] [data-bp-tooltip]::after {
     14        background-color: #fff;
     15        display: none;
     16        opacity: 0;
     17        position: absolute;
     18        transform: translate3d(0, 0, 0);
     19        visibility: hidden;
     20}
     21
     22[data-type="bp/sitewide-notices"] [data-bp-tooltip]::after {
     23        border: 1px solid #737373;
     24        border-radius: 1px;
     25        box-shadow: -4px 4px 8px rgba(0, 0, 0, 0.2);
     26        color: #333;
     27        content: attr(data-bp-tooltip);
     28        font-family: "Helvetica Neue", helvetica, arial, san-serif;
     29        font-size: 12px;
     30        font-weight: 400;
     31        letter-spacing: normal;
     32        line-height: 1.25;
     33        max-width: 200px;
     34        padding: 5px 8px;
     35        pointer-events: none;
     36        text-shadow: none;
     37        text-transform: none;
     38        transition: all 1.5s ease;
     39        white-space: nowrap;
     40        word-wrap: break-word;
     41        z-index: 100000;
     42}
     43
     44[data-type="bp/sitewide-notices"] .bp-tooltip::after {
     45        right: 50%;
     46        margin-top: 7px;
     47        top: 110%;
     48        transform: translate(50%, 0);
     49}
     50
     51.bp-sitewide-notice-block {
     52        position: relative;
     53        padding-right: 1em;
     54        border-right: solid 4px #ff853c;
     55}
     56
     57.bp-sitewide-notice-block h2:before {
     58        border: none;
     59        background: none;
     60}
     61
     62.bp-sitewide-notice-block .dismiss-notice {
     63        display: block;
     64        background-color: transparent;
     65        border: solid 1px #ff853c;
     66        color: #ff853c;
     67        padding: 0.2em 0.5em;
     68        width: fit-content;
     69        position: absolute;
     70        top: 0.5em;
     71        left: 0.5em;
     72}
     73
     74.bp-sitewide-notice-block .dismiss-notice:hover {
     75        background-color: #ff853c;
     76        color: #fff;
     77}
  • new file src/bp-messages/css/blocks/sitewide-notices.css

    diff --git src/bp-messages/css/blocks/sitewide-notices.css src/bp-messages/css/blocks/sitewide-notices.css
    new file mode 100644
    index 000000000..64af1c61b
    - +  
     1[data-type="bp/sitewide-notices"] .bp-screen-reader-text {
     2        border: 0;
     3        clip: rect(0 0 0 0);
     4        height: 1px;
     5        margin: -1px;
     6        overflow: hidden;
     7        padding: 0;
     8        position: absolute;
     9        width: 1px;
     10        word-wrap: normal !important;
     11}
     12
     13[data-type="bp/sitewide-notices"] [data-bp-tooltip]::after {
     14        background-color: #fff;
     15        display: none;
     16        opacity: 0;
     17        position: absolute;
     18        transform: translate3d(0, 0, 0);
     19        visibility: hidden;
     20}
     21
     22[data-type="bp/sitewide-notices"] [data-bp-tooltip]::after {
     23        border: 1px solid #737373;
     24        border-radius: 1px;
     25        box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.2);
     26        color: #333;
     27        content: attr(data-bp-tooltip);
     28        font-family: "Helvetica Neue", helvetica, arial, san-serif;
     29        font-size: 12px;
     30        font-weight: 400;
     31        letter-spacing: normal;
     32        line-height: 1.25;
     33        max-width: 200px;
     34        padding: 5px 8px;
     35        pointer-events: none;
     36        text-shadow: none;
     37        text-transform: none;
     38        transition: all 1.5s ease;
     39        white-space: nowrap;
     40        word-wrap: break-word;
     41        z-index: 100000;
     42}
     43
     44[data-type="bp/sitewide-notices"] .bp-tooltip::after {
     45        left: 50%;
     46        margin-top: 7px;
     47        top: 110%;
     48        transform: translate(-50%, 0);
     49}
     50
     51.bp-sitewide-notice-block {
     52        position: relative;
     53        padding-left: 1em;
     54        border-left: solid 4px #ff853c;
     55}
     56
     57.bp-sitewide-notice-block h2:before {
     58        border: none;
     59        background: none;
     60}
     61
     62.bp-sitewide-notice-block .dismiss-notice {
     63        display: block;
     64        background-color: transparent;
     65        border: solid 1px #ff853c;
     66        color: #ff853c;
     67        padding: 0.2em 0.5em;
     68        width: fit-content;
     69        position: absolute;
     70        top: 0.5em;
     71        right: 0.5em;
     72}
     73
     74.bp-sitewide-notice-block .dismiss-notice:hover {
     75        background-color: #ff853c;
     76        color: #fff;
     77}
  • new file src/bp-messages/js/blocks/sitewide-notices.js

    diff --git src/bp-messages/js/blocks/sitewide-notices.js src/bp-messages/js/blocks/sitewide-notices.js
    new file mode 100644
    index 000000000..683f80566
    - +  
     1// modules are defined as an array
     2// [ module function, map of requires ]
     3//
     4// map of requires is short require name -> numeric require
     5//
     6// anything defined in a previous bundle is accessed via the
     7// orig method which is the require for previous bundles
     8parcelRequire = (function (modules, cache, entry, globalName) {
     9  // Save the require from previous bundle to this closure if any
     10  var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
     11  var nodeRequire = typeof require === 'function' && require;
     12
     13  function newRequire(name, jumped) {
     14    if (!cache[name]) {
     15      if (!modules[name]) {
     16        // if we cannot find the module within our internal map or
     17        // cache jump to the current global require ie. the last bundle
     18        // that was added to the page.
     19        var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
     20        if (!jumped && currentRequire) {
     21          return currentRequire(name, true);
     22        }
     23
     24        // If there are other bundles on this page the require from the
     25        // previous one is saved to 'previousRequire'. Repeat this as
     26        // many times as there are bundles until the module is found or
     27        // we exhaust the require chain.
     28        if (previousRequire) {
     29          return previousRequire(name, true);
     30        }
     31
     32        // Try the node require function if it exists.
     33        if (nodeRequire && typeof name === 'string') {
     34          return nodeRequire(name);
     35        }
     36
     37        var err = new Error('Cannot find module \'' + name + '\'');
     38        err.code = 'MODULE_NOT_FOUND';
     39        throw err;
     40      }
     41
     42      localRequire.resolve = resolve;
     43      localRequire.cache = {};
     44
     45      var module = cache[name] = new newRequire.Module(name);
     46
     47      modules[name][0].call(module.exports, localRequire, module, module.exports, this);
     48    }
     49
     50    return cache[name].exports;
     51
     52    function localRequire(x){
     53      return newRequire(localRequire.resolve(x));
     54    }
     55
     56    function resolve(x){
     57      return modules[name][1][x] || x;
     58    }
     59  }
     60
     61  function Module(moduleName) {
     62    this.id = moduleName;
     63    this.bundle = newRequire;
     64    this.exports = {};
     65  }
     66
     67  newRequire.isParcelRequire = true;
     68  newRequire.Module = Module;
     69  newRequire.modules = modules;
     70  newRequire.cache = cache;
     71  newRequire.parent = previousRequire;
     72  newRequire.register = function (id, exports) {
     73    modules[id] = [function (require, module) {
     74      module.exports = exports;
     75    }, {}];
     76  };
     77
     78  var error;
     79  for (var i = 0; i < entry.length; i++) {
     80    try {
     81      newRequire(entry[i]);
     82    } catch (e) {
     83      // Save first error but execute all entries
     84      if (!error) {
     85        error = e;
     86      }
     87    }
     88  }
     89
     90  if (entry.length) {
     91    // Expose entry point to Node, AMD or browser globals
     92    // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
     93    var mainExports = newRequire(entry[entry.length - 1]);
     94
     95    // CommonJS
     96    if (typeof exports === "object" && typeof module !== "undefined") {
     97      module.exports = mainExports;
     98
     99    // RequireJS
     100    } else if (typeof define === "function" && define.amd) {
     101     define(function () {
     102       return mainExports;
     103     });
     104
     105    // <script>
     106    } else if (globalName) {
     107      this[globalName] = mainExports;
     108    }
     109  }
     110
     111  // Override the current require with this new one
     112  parcelRequire = newRequire;
     113
     114  if (error) {
     115    // throw error from earlier, _after updating parcelRequire_
     116    throw error;
     117  }
     118
     119  return newRequire;
     120})({"HPdN":[function(require,module,exports) {
     121"use strict";
     122
     123Object.defineProperty(exports, "__esModule", {
     124  value: true
     125});
     126exports.default = void 0;
     127
     128/**
     129 * WordPress dependencies.
     130 */
     131var _wp = wp,
     132    InspectorControls = _wp.blockEditor.InspectorControls,
     133    _wp$components = _wp.components,
     134    Disabled = _wp$components.Disabled,
     135    PanelBody = _wp$components.PanelBody,
     136    TextControl = _wp$components.TextControl,
     137    _wp$element = _wp.element,
     138    Fragment = _wp$element.Fragment,
     139    createElement = _wp$element.createElement,
     140    __ = _wp.i18n.__;
     141/**
     142 * BuddyPress dependencies.
     143 */
     144
     145var _bp = bp,
     146    ServerSideRender = _bp.blockComponents.ServerSideRender;
     147
     148var editSitewideNoticesBlock = function editSitewideNoticesBlock(_ref) {
     149  var attributes = _ref.attributes,
     150      setAttributes = _ref.setAttributes;
     151  var title = attributes.title;
     152  return createElement(Fragment, null, createElement(InspectorControls, null, createElement(PanelBody, {
     153    title: __('Settings', 'buddypress'),
     154    initialOpen: true
     155  }, createElement(TextControl, {
     156    label: __('Title', 'buddypress'),
     157    value: title,
     158    onChange: function onChange(text) {
     159      setAttributes({
     160        title: text
     161      });
     162    }
     163  }))), createElement(Disabled, null, createElement(ServerSideRender, {
     164    block: "bp/sitewide-notices",
     165    attributes: attributes
     166  })));
     167};
     168
     169var _default = editSitewideNoticesBlock;
     170exports.default = _default;
     171},{}],"lnNZ":[function(require,module,exports) {
     172"use strict";
     173
     174Object.defineProperty(exports, "__esModule", {
     175  value: true
     176});
     177exports.default = void 0;
     178
     179/**
     180 * WordPress dependencies.
     181 */
     182var _wp = wp,
     183    createBlock = _wp.blocks.createBlock;
     184/**
     185 * Transforms Legacy Widget to Friends Block.
     186 *
     187 * @type {Object}
     188 */
     189
     190var transforms = {
     191  from: [{
     192    type: 'block',
     193    blocks: ['core/legacy-widget'],
     194    isMatch: function isMatch(_ref) {
     195      var idBase = _ref.idBase,
     196          instance = _ref.instance;
     197
     198      if (!(instance !== null && instance !== void 0 && instance.raw)) {
     199        return false;
     200      }
     201
     202      return idBase === 'bp_messages_sitewide_notices_widget';
     203    },
     204    transform: function transform(_ref2) {
     205      var instance = _ref2.instance;
     206      return createBlock('bp/sitewide-notices', {
     207        title: instance.raw.title
     208      });
     209    }
     210  }]
     211};
     212var _default = transforms;
     213exports.default = _default;
     214},{}],"kd3Z":[function(require,module,exports) {
     215"use strict";
     216
     217var _edit = _interopRequireDefault(require("./sitewide-notices/edit"));
     218
     219var _transforms = _interopRequireDefault(require("./sitewide-notices/transforms"));
     220
     221function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
     222
     223/**
     224 * WordPress dependencies.
     225 */
     226var _wp = wp,
     227    registerBlockType = _wp.blocks.registerBlockType,
     228    __ = _wp.i18n.__;
     229/**
     230 * Internal dependencies.
     231 */
     232
     233registerBlockType('bp/sitewide-notices', {
     234  title: __('Sitewide Notices', 'buddypress'),
     235  description: __('Display Sitewide Notices posted by the site administrator', 'buddypress'),
     236  icon: {
     237    background: '#fff',
     238    foreground: '#d84800',
     239    src: 'megaphone'
     240  },
     241  category: 'buddypress',
     242  attributes: {
     243    title: {
     244      type: 'string',
     245      default: ''
     246    }
     247  },
     248  edit: _edit.default,
     249  transforms: _transforms.default
     250});
     251},{"./sitewide-notices/edit":"HPdN","./sitewide-notices/transforms":"lnNZ"}]},{},["kd3Z"], null)
     252 No newline at end of file
  • new file src/bp-messages/js/sitewide-notices.js

    diff --git src/bp-messages/js/sitewide-notices.js src/bp-messages/js/sitewide-notices.js
    new file mode 100644
    index 000000000..d027afa70
    - +  
     1// modules are defined as an array
     2// [ module function, map of requires ]
     3//
     4// map of requires is short require name -> numeric require
     5//
     6// anything defined in a previous bundle is accessed via the
     7// orig method which is the require for previous bundles
     8parcelRequire = (function (modules, cache, entry, globalName) {
     9  // Save the require from previous bundle to this closure if any
     10  var previousRequire = typeof parcelRequire === 'function' && parcelRequire;
     11  var nodeRequire = typeof require === 'function' && require;
     12
     13  function newRequire(name, jumped) {
     14    if (!cache[name]) {
     15      if (!modules[name]) {
     16        // if we cannot find the module within our internal map or
     17        // cache jump to the current global require ie. the last bundle
     18        // that was added to the page.
     19        var currentRequire = typeof parcelRequire === 'function' && parcelRequire;
     20        if (!jumped && currentRequire) {
     21          return currentRequire(name, true);
     22        }
     23
     24        // If there are other bundles on this page the require from the
     25        // previous one is saved to 'previousRequire'. Repeat this as
     26        // many times as there are bundles until the module is found or
     27        // we exhaust the require chain.
     28        if (previousRequire) {
     29          return previousRequire(name, true);
     30        }
     31
     32        // Try the node require function if it exists.
     33        if (nodeRequire && typeof name === 'string') {
     34          return nodeRequire(name);
     35        }
     36
     37        var err = new Error('Cannot find module \'' + name + '\'');
     38        err.code = 'MODULE_NOT_FOUND';
     39        throw err;
     40      }
     41
     42      localRequire.resolve = resolve;
     43      localRequire.cache = {};
     44
     45      var module = cache[name] = new newRequire.Module(name);
     46
     47      modules[name][0].call(module.exports, localRequire, module, module.exports, this);
     48    }
     49
     50    return cache[name].exports;
     51
     52    function localRequire(x){
     53      return newRequire(localRequire.resolve(x));
     54    }
     55
     56    function resolve(x){
     57      return modules[name][1][x] || x;
     58    }
     59  }
     60
     61  function Module(moduleName) {
     62    this.id = moduleName;
     63    this.bundle = newRequire;
     64    this.exports = {};
     65  }
     66
     67  newRequire.isParcelRequire = true;
     68  newRequire.Module = Module;
     69  newRequire.modules = modules;
     70  newRequire.cache = cache;
     71  newRequire.parent = previousRequire;
     72  newRequire.register = function (id, exports) {
     73    modules[id] = [function (require, module) {
     74      module.exports = exports;
     75    }, {}];
     76  };
     77
     78  var error;
     79  for (var i = 0; i < entry.length; i++) {
     80    try {
     81      newRequire(entry[i]);
     82    } catch (e) {
     83      // Save first error but execute all entries
     84      if (!error) {
     85        error = e;
     86      }
     87    }
     88  }
     89
     90  if (entry.length) {
     91    // Expose entry point to Node, AMD or browser globals
     92    // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
     93    var mainExports = newRequire(entry[entry.length - 1]);
     94
     95    // CommonJS
     96    if (typeof exports === "object" && typeof module !== "undefined") {
     97      module.exports = mainExports;
     98
     99    // RequireJS
     100    } else if (typeof define === "function" && define.amd) {
     101     define(function () {
     102       return mainExports;
     103     });
     104
     105    // <script>
     106    } else if (globalName) {
     107      this[globalName] = mainExports;
     108    }
     109  }
     110
     111  // Override the current require with this new one
     112  parcelRequire = newRequire;
     113
     114  if (error) {
     115    // throw error from earlier, _after updating parcelRequire_
     116    throw error;
     117  }
     118
     119  return newRequire;
     120})({"nIsC":[function(require,module,exports) {
     121function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
     122
     123function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
     124
     125function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
     126
     127/**
     128 * Front-end Sitewide notices block class.
     129 *
     130 * @since 9.0.0
     131 */
     132var bpSitewideNoticeBlock = /*#__PURE__*/function () {
     133  function bpSitewideNoticeBlock(settings) {
     134    _classCallCheck(this, bpSitewideNoticeBlock);
     135
     136    var path = settings.path,
     137        dismissPath = settings.dismissPath,
     138        root = settings.root,
     139        nonce = settings.nonce;
     140    this.path = path;
     141    this.dismissPath = dismissPath;
     142    this.root = root;
     143    this.nonce = nonce;
     144  }
     145
     146  _createClass(bpSitewideNoticeBlock, [{
     147    key: "start",
     148    value: function start() {
     149      var _this = this;
     150
     151      // Listen to each Block's dismiss button clicks
     152      document.querySelectorAll('.bp-sitewide-notice-block a.dismiss-notice').forEach(function (dismissButton) {
     153        dismissButton.addEventListener('click', function (event) {
     154          event.preventDefault();
     155          fetch(_this.root + _this.dismissPath, {
     156            method: 'POST',
     157            headers: {
     158              'X-WP-Nonce': _this.nonce
     159            }
     160          }).then(function (response) {
     161            return response.json();
     162          }).then(function (data) {
     163            if ('undefined' !== typeof data && 'undefined' !== typeof data.dismissed && data.dismissed) {
     164              document.querySelectorAll('.bp-sitewide-notice-block').forEach(function (elem) {
     165                elem.remove();
     166              });
     167            }
     168          });
     169        });
     170      });
     171    }
     172  }]);
     173
     174  return bpSitewideNoticeBlock;
     175}(); // widget_bp_core_sitewide_messages buddypress widget wp-block-bp-sitewide-notices > bp-sitewide-notice > a.dismiss-notice
     176
     177
     178var settings = window.bpSitewideNoticeBlockSettings || {};
     179var bpSitewideNotice = new bpSitewideNoticeBlock(settings);
     180
     181if ('loading' === document.readyState) {
     182  document.addEventListener('DOMContentLoaded', bpSitewideNotice.start());
     183} else {
     184  bpSitewideNotice.start();
     185}
     186},{}]},{},["nIsC"], null)
     187 No newline at end of file
  • new file src/bp-messages/sass/blocks/sitewide-notices.scss

    diff --git src/bp-messages/sass/blocks/sitewide-notices.scss src/bp-messages/sass/blocks/sitewide-notices.scss
    new file mode 100644
    index 000000000..4dc21cf7e
    - +  
     1[data-type="bp/sitewide-notices"] {
     2
     3        .bp-screen-reader-text {
     4                border: 0;
     5                clip: rect(0 0 0 0);
     6                height: 1px;
     7                margin: -1px;
     8                overflow: hidden;
     9                padding: 0;
     10                position: absolute;
     11                width: 1px;
     12                word-wrap: normal !important;
     13        }
     14
     15        [data-bp-tooltip]::after {
     16                background-color: #fff;
     17                display: none;
     18                opacity: 0;
     19                position: absolute;
     20                transform: translate3d(0, 0, 0);
     21                visibility: hidden;
     22        }
     23
     24        [data-bp-tooltip]::after {
     25                border: 1px solid #737373;
     26                border-radius: 1px;
     27                box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.2);
     28                color: #333;
     29                content: attr(data-bp-tooltip);
     30                font-family: "Helvetica Neue", helvetica, arial, san-serif;
     31                font-size: 12px;
     32                font-weight: 400;
     33                letter-spacing: normal;
     34                line-height: 1.25;
     35                max-width: 200px;
     36                padding: 5px 8px;
     37                pointer-events: none;
     38                text-shadow: none;
     39                text-transform: none;
     40                transition: all 1.5s ease;
     41                white-space: nowrap;
     42                word-wrap: break-word;
     43                z-index: 100000;
     44        }
     45
     46        .bp-tooltip::after {
     47                left: 50%;
     48                margin-top: 7px;
     49                top: 110%;
     50                transform: translate(-50%, 0);
     51        }
     52}
     53
     54.bp-sitewide-notice-block {
     55        position: relative;
     56        padding-left: 1em;
     57        border-left: solid 4px #ff853c;
     58
     59        h2:before {
     60                border: none;
     61                background: none;
     62        }
     63
     64        .dismiss-notice {
     65                display: block;
     66                background-color: transparent;
     67                border: solid 1px #ff853c;
     68                color: #ff853c;
     69                padding: 0.2em 0.5em;
     70                width: fit-content;
     71                position: absolute;
     72                top: 0.5em;
     73                right: 0.5em;
     74
     75                &:hover {
     76                        background-color: #ff853c;
     77                        color: #fff;
     78                }
     79        }
     80}
  • src/bp-templates/bp-legacy/buddypress-functions.php

    diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php
    index 3a1a43556..44db3a2e7 100644
    class BP_Legacy extends BP_Theme_Compat {  
    490490         */
    491491        public function sitewide_notices() {
    492492                // Do not show notices if user is not logged in.
    493                 if ( ! is_user_logged_in() )
     493                if ( ! is_user_logged_in() || is_admin() ) {
    494494                        return;
     495                }
    495496
    496497                // Add a class to determine if the admin bar is on or not.
    497498                $class = did_action( 'admin_bar_menu' ) ? 'admin-bar-on' : 'admin-bar-off';
  • new file src/js/bp-messages/js/blocks/.babelrc

    diff --git src/js/bp-messages/js/blocks/.babelrc src/js/bp-messages/js/blocks/.babelrc
    new file mode 100644
    index 000000000..ab258a69c
    - +  
     1{
     2        "presets": ["@wordpress/default"]
     3}
  • new file src/js/bp-messages/js/blocks/sitewide-notices.js

    diff --git src/js/bp-messages/js/blocks/sitewide-notices.js src/js/bp-messages/js/blocks/sitewide-notices.js
    new file mode 100644
    index 000000000..e9d63ff13
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4const {
     5        blocks: {
     6                registerBlockType,
     7        },
     8        i18n: {
     9                __,
     10        },
     11} = wp;
     12
     13/**
     14 * Internal dependencies.
     15 */
     16import editSitewideNoticesBlock from './sitewide-notices/edit';
     17import transforms from './sitewide-notices/transforms';
     18
     19registerBlockType( 'bp/sitewide-notices', {
     20        title: __( 'Sitewide Notices', 'buddypress' ),
     21        description: __( 'Display Sitewide Notices posted by the site administrator', 'buddypress' ),
     22        icon: {
     23                background: '#fff',
     24                foreground: '#d84800',
     25                src: 'megaphone',
     26        },
     27        category: 'buddypress',
     28        attributes: {
     29                title: {
     30                        type: 'string',
     31                        default: '',
     32                },
     33        },
     34        edit: editSitewideNoticesBlock,
     35        transforms: transforms,
     36} );
  • new file src/js/bp-messages/js/blocks/sitewide-notices/edit.js

    diff --git src/js/bp-messages/js/blocks/sitewide-notices/edit.js src/js/bp-messages/js/blocks/sitewide-notices/edit.js
    new file mode 100644
    index 000000000..7c82d7bfc
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4 const {
     5        blockEditor: {
     6                InspectorControls,
     7        },
     8        components: {
     9                Disabled,
     10                PanelBody,
     11                TextControl,
     12        },
     13        element: {
     14                Fragment,
     15                createElement,
     16        },
     17        i18n: {
     18                __,
     19        },
     20} = wp;
     21
     22/**
     23 * BuddyPress dependencies.
     24 */
     25 const {
     26        blockComponents: {
     27                ServerSideRender,
     28        },
     29} = bp;
     30
     31const editSitewideNoticesBlock = ( { attributes, setAttributes } ) => {
     32        const { title } = attributes;
     33
     34        return (
     35                <Fragment>
     36                        <InspectorControls>
     37                                <PanelBody title={ __( 'Settings', 'buddypress' ) } initialOpen={ true }>
     38                                        <TextControl
     39                                                label={ __( 'Title', 'buddypress' ) }
     40                                                value={ title }
     41                                                onChange={ ( text ) => {
     42                                                        setAttributes( { title: text } );
     43                                                } }
     44                                        />
     45                                </PanelBody>
     46                        </InspectorControls>
     47                        <Disabled>
     48                                <ServerSideRender block="bp/sitewide-notices" attributes={ attributes } />
     49                        </Disabled>
     50                </Fragment>
     51        );
     52};
     53
     54export default editSitewideNoticesBlock;
  • new file src/js/bp-messages/js/blocks/sitewide-notices/transforms.js

    diff --git src/js/bp-messages/js/blocks/sitewide-notices/transforms.js src/js/bp-messages/js/blocks/sitewide-notices/transforms.js
    new file mode 100644
    index 000000000..caf10b80b
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4 const {
     5        blocks: {
     6                createBlock,
     7        },
     8} = wp;
     9
     10/**
     11 * Transforms Legacy Widget to Friends Block.
     12 *
     13 * @type {Object}
     14 */
     15const transforms = {
     16        from: [
     17                {
     18                        type: 'block',
     19                        blocks: [ 'core/legacy-widget' ],
     20                        isMatch: ( { idBase, instance } ) => {
     21                                if ( ! instance?.raw ) {
     22                                        return false;
     23                                }
     24
     25                                return idBase === 'bp_messages_sitewide_notices_widget';
     26                        },
     27                        transform: ( { instance } ) => {
     28                                return createBlock( 'bp/sitewide-notices', {
     29                                        title: instance.raw.title
     30                                } );
     31                        },
     32                },
     33        ],
     34};
     35
     36export default transforms;
  • new file src/js/bp-messages/js/sitewide-notices.js

    diff --git src/js/bp-messages/js/sitewide-notices.js src/js/bp-messages/js/sitewide-notices.js
    new file mode 100644
    index 000000000..3557c8a08
    - +  
     1/**
     2 * Front-end Sitewide notices block class.
     3 *
     4 * @since 9.0.0
     5 */
     6class bpSitewideNoticeBlock {
     7        constructor( settings ) {
     8                const { path, dismissPath, root, nonce } = settings;
     9                this.path = path;
     10                this.dismissPath = dismissPath;
     11                this.root = root;
     12                this.nonce = nonce;
     13        }
     14
     15        start() {
     16                // Listen to each Block's dismiss button clicks
     17                document.querySelectorAll( '.bp-sitewide-notice-block a.dismiss-notice' ).forEach( ( dismissButton ) => {
     18                        dismissButton.addEventListener( 'click', ( event ) => {
     19                                event.preventDefault();
     20
     21                                fetch( this.root + this.dismissPath, {
     22                                        method: 'POST',
     23                                        headers: {
     24                                                'X-WP-Nonce' : this.nonce,
     25                                        }
     26                                } ).then(
     27                                        ( response ) => response.json()
     28                                ).then(
     29                                        ( data ) => {
     30                                                if ( 'undefined' !== typeof data && 'undefined' !== typeof data.dismissed && data.dismissed ) {
     31                                                        document.querySelectorAll( '.bp-sitewide-notice-block' ).forEach( ( elem ) => {
     32                                                                elem.remove();
     33                                                        } );
     34                                                }
     35                                        }
     36                                );
     37                        } );
     38                } );
     39        }
     40}
     41
     42// widget_bp_core_sitewide_messages buddypress widget wp-block-bp-sitewide-notices > bp-sitewide-notice > a.dismiss-notice
     43const settings = window.bpSitewideNoticeBlockSettings || {};
     44const bpSitewideNotice = new bpSitewideNoticeBlock( settings );
     45
     46if ( 'loading' === document.readyState ) {
     47        document.addEventListener( 'DOMContentLoaded', bpSitewideNotice.start() );
     48} else {
     49        bpSitewideNotice.start();
     50}