Skip to:
Content

BuddyPress.org

Ticket #8517: 8517.patch

File 8517.patch, 26.6 KB (added by imath, 4 years ago)
  • Gruntfile.js

    diff --git Gruntfile.js Gruntfile.js
    index 6f9861f6c..8841c2358 100644
    module.exports = function( grunt ) { 
    3737                        '!bp-members/css/blocks/member.css',
    3838                        '!bp-groups/css/blocks/group.css',
    3939                        '!bp-members/css/blocks/members.css',
    40                         '!bp-groups/css/blocks/groups.css'
     40                        '!bp-groups/css/blocks/groups.css',
     41                        '!bp-core/css/blocks/login-form.css'
    4142                ],
    4243
    4344                autoprefixer = require('autoprefixer');
    module.exports = function( grunt ) { 
    147148                                flatten: true,
    148149                                src: ['bp-groups/sass/blocks/*.scss'],
    149150                                dest: SOURCE_DIR + 'bp-groups/css/blocks/'
     151                        },
     152                        core_blocks: {
     153                                cwd: SOURCE_DIR,
     154                                extDot: 'last',
     155                                expand: true,
     156                                ext: '.css',
     157                                flatten: true,
     158                                src: ['bp-core/sass/blocks/*.scss'],
     159                                dest: SOURCE_DIR + 'bp-core/css/blocks/'
    150160                        }
    151161                },
    152162                rtlcss: {
  • src/bp-core/bp-core-blocks.php

    diff --git src/bp-core/bp-core-blocks.php src/bp-core/bp-core-blocks.php
    index 85217e4ce..94e485dbc 100644
    function bp_widget_block_dynamic_classname( $classname, $block_name ) { 
    210210        return $classname;
    211211}
    212212add_filter( 'widget_block_dynamic_classname', 'bp_widget_block_dynamic_classname', 10, 2 );
     213
     214/**
     215 * Create a link to the registration form for use on the bottom of the login form widget.
     216 *
     217 * @since 9.0.0
     218 *
     219 * @param string $content Content to display. Default empty.
     220 * @param array  $args    Array of login form arguments.
     221 * @return string         HTML output.
     222 */
     223function bp_blocks_get_login_widget_registration_link( $content = '', $args = array() ) {
     224        if ( isset( $args['form_id'] ) && 'bp-login-widget-form' === $args['form_id'] && bp_get_signup_allowed() ) {
     225                $content .= sprintf(
     226                        '<p class="bp-login-widget-register-link"><a href="%1$s">%2$s</a></p>',
     227                        esc_url( bp_get_signup_page() ),
     228                        esc_html__( 'Register', 'buddypress' )
     229                );
     230        }
     231
     232        $action_output = '';
     233        if ( has_action( 'bp_login_widget_form' ) ) {
     234                ob_start();
     235                /**
     236                 * Fires inside the display of the login widget form.
     237                 *
     238                 * @since 2.4.0
     239                 */
     240                do_action( 'bp_login_widget_form' );
     241                $action_output = ob_get_clean();
     242        }
     243
     244        if ( $action_output ) {
     245                $content .= $action_output;
     246        }
     247
     248        return $content;
     249}
     250
     251/**
     252 * Callback function to render the BP Login Form.
     253 *
     254 * @since 9.0.0
     255 *
     256 * @param array $attributes The block attributes.
     257 * @return string           HTML output.
     258 */
     259function bp_block_render_login_form_block( $attributes = array() ) {
     260        $block_args = wp_parse_args(
     261                $attributes,
     262                array(
     263                        'title' => '',
     264                )
     265        );
     266
     267        $title = $block_args['title'];
     268
     269        $classnames         = 'widget_bp_core_login_widget buddypress widget';
     270        $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) );
     271
     272        $widget_content = '';
     273
     274        if ( $title ) {
     275                $widget_content .= sprintf(
     276                        '<h2 class="widget-title">%s</h2>',
     277                        esc_html( $title )
     278                );
     279        }
     280
     281        if ( is_user_logged_in() ) {
     282                $action_output = '';
     283                if ( has_action( 'bp_before_login_widget_loggedin' ) ) {
     284                        ob_start();
     285                        /**
     286                         * Fires before the display of widget content if logged in.
     287                         *
     288                         * @since 1.9.0
     289                         */
     290                        do_action( 'bp_before_login_widget_loggedin' );
     291                        $action_output = ob_get_clean();
     292                }
     293
     294                if ( $action_output ) {
     295                        $widget_content .= $action_output;
     296                }
     297
     298                $widget_content .= sprintf(
     299                        '<div class="bp-login-widget-user-avatar">
     300                                <a href="%1$s">
     301                                        %2$s
     302                                </a>
     303                        </div>',
     304                        bp_loggedin_user_domain(),
     305                        bp_get_loggedin_user_avatar(
     306                                array(
     307                                        'type'   => 'thumb',
     308                                        'width'  => 50,
     309                                        'height' => 50,
     310                                )
     311                        )
     312                );
     313
     314                $widget_content .= sprintf(
     315                        '<div class="bp-login-widget-user-links">
     316                                <div class="bp-login-widget-user-link">%1$s</div>
     317                                <div class="bp-login-widget-user-logout"><a class="logout" href="%2$s">%3$s</a></div>
     318                        </div>',
     319                        bp_core_get_userlink( bp_loggedin_user_id() ),
     320                        wp_logout_url( bp_get_requested_url() ),
     321                        __( 'Log Out', 'buddypress' )
     322                );
     323
     324                $action_output = '';
     325                if ( has_action( 'bp_after_login_widget_loggedin' ) ) {
     326                        ob_start();
     327                        /**
     328                         * Fires after the display of widget content if logged in.
     329                         *
     330                         * @since 1.9.0
     331                         */
     332                        do_action( 'bp_after_login_widget_loggedin' );
     333                        $action_output = ob_get_clean();
     334                }
     335
     336                if ( $action_output ) {
     337                        $widget_content .= $action_output;
     338                }
     339        } else {
     340                $action_output = '';
     341                if ( has_action( 'bp_before_login_widget_loggedout' ) ) {
     342                        ob_start();
     343                        /**
     344                         * Fires before the display of widget content if logged out.
     345                         *
     346                         * @since 1.9.0
     347                         */
     348                        do_action( 'bp_before_login_widget_loggedout' );
     349                        $action_output = ob_get_clean();
     350                }
     351
     352                if ( $action_output ) {
     353                        $widget_content .= $action_output;
     354                }
     355
     356                add_filter( 'login_form_bottom', 'bp_blocks_get_login_widget_registration_link', 10, 2 );
     357
     358                $widget_content .= wp_login_form(
     359                        array(
     360                                'echo'           => false,
     361                                'form_id'        => 'bp-login-widget-form',
     362                                'id_username'    => 'bp-login-widget-user-login',
     363                                'label_username' => __( 'Username', 'buddypress' ),
     364                                'id_password'    => 'bp-login-widget-user-pass',
     365                                'label_password' => __( 'Password', 'buddypress' ),
     366                                'id_remember'    => 'bp-login-widget-rememberme',
     367                                'id_submit'      => 'bp-login-widget-submit',
     368                        )
     369                );
     370
     371                remove_filter( 'login_form_bottom', 'bp_blocks_get_login_widget_registration_link', 10, 2 );
     372
     373                $action_output = '';
     374                if ( has_action( 'bp_after_login_widget_loggedout' ) ) {
     375                        ob_start();
     376                        /**
     377                         * Fires after the display of widget content if logged out.
     378                         *
     379                         * @since 1.9.0
     380                         */
     381                        do_action( 'bp_after_login_widget_loggedout' );
     382                        $action_output = ob_get_clean();
     383                }
     384
     385                if ( $action_output ) {
     386                        $widget_content .= $action_output;
     387                }
     388        }
     389
     390        if ( ! did_action( 'dynamic_sidebar_before' ) ) {
     391                return sprintf(
     392                        '<div %1$s>%2$s</div>',
     393                        $wrapper_attributes,
     394                        $widget_content
     395                );
     396        }
     397
     398        return $widget_content;
     399}
  • src/bp-core/classes/class-bp-component.php

    diff --git src/bp-core/classes/class-bp-component.php src/bp-core/classes/class-bp-component.php
    index b1b13341f..626fa2fcf 100644
    class BP_Component { 
    234234         * }
    235235         */
    236236        public function setup_globals( $args = array() ) {
    237 
    238                 /** Slugs ************************************************************
    239                  */
    240 
    241                 // If a WP directory page exists for the component, it should
    242                 // be the default value of 'root_slug'.
    243                 $default_root_slug = isset( buddypress()->pages->{$this->id}->slug ) ? buddypress()->pages->{$this->id}->slug : '';
    244 
    245237                $r = wp_parse_args( $args, array(
    246238                        'slug'                  => $this->id,
    247                         'root_slug'             => $default_root_slug,
     239                        'root_slug'             => '',
    248240                        'has_directory'         => false,
    249241                        'directory_title'       => '',
    250242                        'notification_callback' => '',
    class BP_Component { 
    254246                        'block_globals'         => array(),
    255247                ) );
    256248
    257                 /**
    258                  * Filters the slug to be used for the permalink URI chunk after root.
    259                  *
    260                  * @since 1.5.0
    261                  *
    262                  * @param string $value Slug to use in permalink URI chunk.
     249                /** Slugs ************************************************************
    263250                 */
    264                 $this->slug                  = apply_filters( 'bp_' . $this->id . '_slug',                  $r['slug']                  );
    265251
    266                 /**
    267                  * Filters the slug used for root directory.
    268                  *
    269                  * @since 1.5.0
    270                  *
    271                  * @param string $value Root directory slug.
    272                  */
    273                 $this->root_slug             = apply_filters( 'bp_' . $this->id . '_root_slug',             $r['root_slug']             );
     252                // For all Components except Core.
     253                if ( 'core' !== $this->id ) {
     254                        /**
     255                         * If a WP directory page exists for the component, it should
     256                         * be the default value of 'root_slug'.
     257                         */
     258                        if ( isset( buddypress()->pages->{$this->id}->slug ) ) {
     259                                $r['root_slug'] = buddypress()->pages->{$this->id}->slug;
     260                        }
    274261
    275                 /**
    276                  * Filters the component's top-level directory if available.
    277                 *
    278                 * @since 1.5.0
    279                 *
    280                  * @param bool $value Whether or not there is a top-level directory.
    281                 */
    282                 $this->has_directory         = apply_filters( 'bp_' . $this->id . '_has_directory',         $r['has_directory']        );
     262                        /**
     263                         * Filters the slug to be used for the permalink URI chunk after root.
     264                        *
     265                        * @since 1.5.0
     266                        *
     267                         * @param string $value Slug to use in permalink URI chunk.
     268                        */
     269                        $this->slug = apply_filters( 'bp_' . $this->id . '_slug', $r['slug'] );
    283270
    284                 /**
    285                  * Filters the component's directory title.
    286                 *
    287                  * @since 2.0.0
    288                 *
    289                  * @param string $value Title to use for the directory.
    290                 */
    291                 $this->directory_title       = apply_filters( 'bp_' . $this->id . '_directory_title',       $r['directory_title']        );
     271                        /**
     272                         * Filters the slug used for root directory.
     273                        *
     274                         * @since 1.5.0
     275                        *
     276                         * @param string $value Root directory slug.
     277                        */
     278                        $this->root_slug = apply_filters( 'bp_' . $this->id . '_root_slug', $r['root_slug'] );
    292279
    293                 /**
    294                  * Filters the placeholder text for search inputs for component.
    295                 *
    296                 * @since 1.5.0
    297                 *
    298                  * @param string $value Name to use in search input placeholders.
    299                 */
    300                 $this->search_string         = apply_filters( 'bp_' . $this->id . '_search_string',         $r['search_string']        );
     280                        /**
     281                         * Filters the component's top-level directory if available.
     282                        *
     283                        * @since 1.5.0
     284                        *
     285                         * @param bool $value Whether or not there is a top-level directory.
     286                        */
     287                        $this->has_directory = apply_filters( 'bp_' . $this->id . '_has_directory', $r['has_directory'] );
    301288
    302                 /**
    303                  * Filters the callable function that formats the component's notifications.
    304                 *
    305                  * @since 1.5.0
    306                 *
    307                  * @param string $value Function callback.
    308                 */
    309                 $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] );
     289                        /**
     290                         * Filters the component's directory title.
     291                        *
     292                         * @since 2.0.0
     293                        *
     294                         * @param string $value Title to use for the directory.
     295                        */
     296                        $this->directory_title = apply_filters( 'bp_' . $this->id . '_directory_title', $r['directory_title'] );
    310297
    311                 // Set the global table names, if applicable.
    312                 if ( ! empty( $r['global_tables'] ) ) {
    313                         $this->register_global_tables( $r['global_tables'] );
    314                 }
     298                        /**
     299                         * Filters the placeholder text for search inputs for component.
     300                         *
     301                         * @since 1.5.0
     302                         *
     303                         * @param string $value Name to use in search input placeholders.
     304                         */
     305                        $this->search_string = apply_filters( 'bp_' . $this->id . '_search_string', $r['search_string'] );
    315306
    316                 // Set the metadata table, if applicable.
    317                 if ( ! empty( $r['meta_tables'] ) ) {
    318                         $this->register_meta_tables( $r['meta_tables'] );
     307                        /**
     308                         * Filters the callable function that formats the component's notifications.
     309                         *
     310                         * @since 1.5.0
     311                         *
     312                         * @param string $value Function callback.
     313                         */
     314                        $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] );
     315
     316                        // Set the global table names, if applicable.
     317                        if ( ! empty( $r['global_tables'] ) ) {
     318                                $this->register_global_tables( $r['global_tables'] );
     319                        }
     320
     321                        // Set the metadata table, if applicable.
     322                        if ( ! empty( $r['meta_tables'] ) ) {
     323                                $this->register_meta_tables( $r['meta_tables'] );
     324                        }
     325
     326                        // Register this component in the loaded components array.
     327                        buddypress()->loaded_components[ $this->slug ] = $this->id;
    319328                }
    320329
    321330                /**
    class BP_Component { 
    339348                        }
    340349                }
    341350
    342                 /** BuddyPress *******************************************************
    343                  */
    344 
    345                 // Register this component in the loaded components array.
    346                 buddypress()->loaded_components[$this->slug] = $this->id;
    347 
    348351                /**
    349352                 * Fires at the end of the setup_globals method inside BP_Component.
    350353                 *
  • src/bp-core/classes/class-bp-core.php

    diff --git src/bp-core/classes/class-bp-core.php src/bp-core/classes/class-bp-core.php
    index 6030eb0e0..c8b1e924b 100644
    class BP_Core extends BP_Component { 
    289289                bp_update_is_item_admin( bp_user_has_access(), 'core' );
    290290
    291291                // Is the logged in user is a mod for the current item?
    292                 bp_update_is_item_mod( false,                  'core' );
    293 
    294                 /**
    295                  * Fires at the end of the setup of bp-core globals setting.
    296                  *
    297                  * @since 1.1.0
    298                  */
    299                 do_action( 'bp_core_setup_globals' );
     292                bp_update_is_item_mod( false, 'core' );
     293
     294                parent::setup_globals(
     295                        array(
     296                                'block_globals' => array(
     297                                        'bp/login-form' => array(
     298                                                'widget_classnames' => array ( 'widget_bp_core_login_widget', 'buddypress' ),
     299                                        )
     300                                )
     301                        )
     302                );
    300303        }
    301304
    302305        /**
    class BP_Core extends BP_Component { 
    377380         *                      description.
    378381         */
    379382        public function blocks_init( $blocks = array() ) {
    380                 parent::blocks_init( array() );
     383                parent::blocks_init(
     384                        array(
     385                                'bp/login-form' => array(
     386                                        'name'               => 'bp/login-form',
     387                                        'editor_script'      => 'bp-login-form-block',
     388                                        'editor_script_url'  => plugins_url( 'js/blocks/login-form.js', dirname( __FILE__ ) ),
     389                                        'editor_script_deps' => array(
     390                                                'wp-blocks',
     391                                                'wp-element',
     392                                                'wp-components',
     393                                                'wp-i18n',
     394                                                'wp-block-editor',
     395                                                'bp-block-components',
     396                                        ),
     397                                        'style'              => 'bp-login-form-block',
     398                                        'style_url'          => plugins_url( 'css/blocks/login-form.css', dirname( __FILE__ ) ),
     399                                        'attributes'         => array(
     400                                                'title' => array(
     401                                                        'type'    => 'string',
     402                                                        'default' => '',
     403                                                ),
     404                                        ),
     405                                        'render_callback'    => 'bp_block_render_login_form_block',
     406                                ),
     407                        )
     408                );
    381409        }
    382410}
  • new file src/bp-core/css/blocks/login-form-rtl.css

    diff --git src/bp-core/css/blocks/login-form-rtl.css src/bp-core/css/blocks/login-form-rtl.css
    new file mode 100644
    index 000000000..f25ff8d9b
    - +  
     1.widget_bp_core_login_widget .bp-login-widget-user-avatar {
     2        float: right;
     3}
     4
     5.widget_bp_core_login_widget .bp-login-widget-user-links {
     6        margin-right: 70px;
     7}
     8
     9#bp-login-widget-form label {
     10        display: block;
     11        font-weight: 600;
     12        margin: 15px 0 5px;
     13        width: auto;
     14}
     15
     16#bp-login-widget-form input[type="text"],
     17#bp-login-widget-form input[type="password"] {
     18        width: 100%;
     19        background-color: #fafafa;
     20        border: 1px solid #d6d6d6;
     21        border-radius: 0;
     22        font: inherit;
     23        font-size: 100%;
     24        padding: 0.5em;
     25}
     26
     27#bp-login-widget-form .login-submit,
     28#bp-login-widget-form .bp-login-widget-register-link {
     29        width: fit-content;
     30        display: inline;
     31}
     32
     33#bp-login-widget-form .bp-login-widget-register-link {
     34        margin-right: 1em;
     35        vertical-align: super;
     36}
  • new file src/bp-core/css/blocks/login-form.css

    diff --git src/bp-core/css/blocks/login-form.css src/bp-core/css/blocks/login-form.css
    new file mode 100644
    index 000000000..a86ac020f
    - +  
     1.widget_bp_core_login_widget .bp-login-widget-user-avatar {
     2        float: left;
     3}
     4
     5.widget_bp_core_login_widget .bp-login-widget-user-links {
     6        margin-left: 70px;
     7}
     8
     9#bp-login-widget-form label {
     10        display: block;
     11        font-weight: 600;
     12        margin: 15px 0 5px;
     13        width: auto;
     14}
     15
     16#bp-login-widget-form input[type="text"],
     17#bp-login-widget-form input[type="password"] {
     18        width: 100%;
     19        background-color: #fafafa;
     20        border: 1px solid #d6d6d6;
     21        border-radius: 0;
     22        font: inherit;
     23        font-size: 100%;
     24        padding: 0.5em;
     25}
     26
     27#bp-login-widget-form .login-submit,
     28#bp-login-widget-form .bp-login-widget-register-link {
     29        width: fit-content;
     30        display: inline;
     31}
     32
     33#bp-login-widget-form .bp-login-widget-register-link {
     34        margin-left: 1em;
     35        vertical-align: super;
     36}
  • new file src/bp-core/js/blocks/login-form.js

    diff --git src/bp-core/js/blocks/login-form.js src/bp-core/js/blocks/login-form.js
    new file mode 100644
    index 000000000..303925005
    - +  
     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})({"ploe":[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 editLoginForm = function editLoginForm(_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/login-form",
     165    attributes: attributes
     166  })));
     167};
     168
     169var _default = editLoginForm;
     170exports.default = _default;
     171},{}],"RDNZ":[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 Login Form Widget to Login Form 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_core_login_widget';
     203    },
     204    transform: function transform(_ref2) {
     205      var instance = _ref2.instance;
     206      return createBlock('bp/login-form', {
     207        title: instance.raw.title
     208      });
     209    }
     210  }]
     211};
     212var _default = transforms;
     213exports.default = _default;
     214},{}],"A1QM":[function(require,module,exports) {
     215"use strict";
     216
     217var _edit = _interopRequireDefault(require("./login-form/edit"));
     218
     219var _transforms = _interopRequireDefault(require("./login-form/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/login-form', {
     234  title: __('Login Form', 'buddypress'),
     235  description: __('Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress'),
     236  icon: {
     237    background: '#fff',
     238    foreground: '#d84800',
     239    src: 'admin-users'
     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},{"./login-form/edit":"ploe","./login-form/transforms":"RDNZ"}]},{},["A1QM"], null)
     252 No newline at end of file
  • new file src/bp-core/sass/blocks/login-form.scss

    diff --git src/bp-core/sass/blocks/login-form.scss src/bp-core/sass/blocks/login-form.scss
    new file mode 100644
    index 000000000..f92840150
    - +  
     1// BP login form widget
     2.widget_bp_core_login_widget {
     3
     4        .bp-login-widget-user-avatar {
     5                float: left;
     6        }
     7
     8        .bp-login-widget-user-links {
     9                margin-left: 70px;
     10        }
     11}
     12
     13#bp-login-widget-form {
     14
     15        label {
     16                display: block;
     17                font-weight: 600;
     18                margin: 15px 0 5px;
     19                width: auto;
     20        }
     21
     22        input[type="text"],
     23        input[type="password"] {
     24                width: 100%;
     25                background-color: #fafafa;
     26                border: 1px solid #d6d6d6;
     27                border-radius: 0;
     28                font: inherit;
     29                font-size: 100%;
     30                padding: 0.5em;
     31        }
     32
     33        .login-submit,
     34        .bp-login-widget-register-link {
     35                width: fit-content;
     36                display: inline;
     37        }
     38
     39        .bp-login-widget-register-link {
     40                margin-left: 1em;
     41                vertical-align: super;
     42        }
     43}
  • new file src/js/bp-core/js/blocks/.babelrc

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

    diff --git src/js/bp-core/js/blocks/login-form.js src/js/bp-core/js/blocks/login-form.js
    new file mode 100644
    index 000000000..61092ff62
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4const {
     5        blocks: {
     6                registerBlockType,
     7        },
     8        i18n: {
     9                __,
     10        },
     11} = wp;
     12
     13/**
     14 * Internal dependencies.
     15 */
     16import editLoginForm from './login-form/edit';
     17import transforms from './login-form/transforms';
     18
     19registerBlockType( 'bp/login-form', {
     20        title: __( 'Login Form', 'buddypress' ),
     21        description: __( 'Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress' ),
     22        icon: {
     23                background: '#fff',
     24                foreground: '#d84800',
     25                src: 'admin-users',
     26        },
     27        category: 'buddypress',
     28        attributes: {
     29                title: {
     30                        type: 'string',
     31                        default: '',
     32                },
     33        },
     34        edit: editLoginForm,
     35        transforms: transforms,
     36} );
  • new file src/js/bp-core/js/blocks/login-form/edit.js

    diff --git src/js/bp-core/js/blocks/login-form/edit.js src/js/bp-core/js/blocks/login-form/edit.js
    new file mode 100644
    index 000000000..9c124885f
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4const {
     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 */
     25const {
     26        blockComponents: {
     27                ServerSideRender,
     28        },
     29} = bp;
     30
     31const editLoginForm = ( { 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/login-form" attributes={ attributes } />
     49                        </Disabled>
     50                </Fragment>
     51        );
     52};
     53
     54export default editLoginForm;
  • new file src/js/bp-core/js/blocks/login-form/transforms.js

    diff --git src/js/bp-core/js/blocks/login-form/transforms.js src/js/bp-core/js/blocks/login-form/transforms.js
    new file mode 100644
    index 000000000..f491e489b
    - +  
     1/**
     2 * WordPress dependencies.
     3 */
     4 const {
     5        blocks: {
     6                createBlock,
     7        },
     8} = wp;
     9
     10/**
     11 * Transforms Legacy Login Form Widget to Login Form 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_core_login_widget';
     26                        },
     27                        transform: ( { instance } ) => {
     28                                return createBlock( 'bp/login-form', {
     29                                        title: instance.raw.title,
     30                                } );
     31                        },
     32                },
     33        ],
     34};
     35
     36export default transforms;