Skip to:
Content

BuddyPress.org

Changeset 14038


Ignore:
Timestamp:
10/05/2024 09:39:23 AM (19 months ago)
Author:
imath
Message:

Documentation: explain Activity Embeds for users & developers

  • Split @vapvarun’s PR to create docs/developer/components/activity/embeds and docs/user/components/activity/embeds.
  • Update the Activity Embed Block’s documentation link in favor of the updated one.
  • Deprecate docs/developer/group-extension/README.md in favor of docs/developer/components/groups/extension leaving a link to the second documentation page in the first one.
  • Initialize a documentation page to explain how to override BP Styles to advanced users, see https://github.com/buddypress/bp-documentation/issues/297

Props vapvarun

Closes https://github.com/buddypress/buddypress/pull/376

Location:
trunk
Files:
14 added
4 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/developer/README.md

    r13620 r14038  
    1010
    11111. [BuddyPress Functions](./functions/README.md)
    12 2. [BuddyPress Components](./component/README.md)
    13 3. [BuddyPress Group Extension API](./group-extension/README.md)
    14 4. [BuddyPress Theme Compatibility](./theme-compat/README.md)
     122. [BuddyPress Components](./components/README.md)
     133. [BuddyPress Theme Compatibility](./theme-compat/README.md)
     144. [BuddyPress execution contexts](./execution-contexts/README.md)
  • trunk/docs/developer/execution-contexts/README.md

    r13591 r14038  
    662. [Ajax](./ajax.md)
    773. REST API
    8 3. Administration
     84. Administration
  • trunk/docs/developer/group-extension/README.md

    r13769 r14038  
    11# Group Extension API
    22
    3 The group extension API makes it very easy to add custom creation steps, edit screens, navigation items and pages to a group. It essentially allows you to create fully functional extensions to BuddyPress created groups.
     3<!-- deprecated: this file remains here to inform about the new page URL. -->
    44
    5 The Group Extension API consists of a base class called `BP_Group_Extension`, which you extend in your own add-on. `BP_Group_Extension` does most of the work necessary to integrate your content into BP group – creating new navigation tabs, registering a step during group creation, etc.
    6 
    7 **NB**: the group extension requires the Groups component to be active. Please make sure to wrap your extended class in a `if ( bp_is_active( 'groups' ) ) :` check.
    8 
    9 Located inside the `/bp-groups/classes` directory, the `BP_Group_Extension` class will help you to organize your custom group extension. BuddyPress group extensions are registered into the `$group_extensions` property of the `buddypress()->groups` global using the name of your custom class. This registration step needs to be hooked to the `bp_init` action at a priority lower than `11` (you can omit the hook `$priority` argument to use the default one - `10`) and is done passing the name of your class to the `bp_register_group_extension()` function. Below is an example of how you can register your group extension in BuddyPress.
    10 
    11 ```php
    12 /**
    13  * Registers the custom group extension.
    14  */
    15 function bp_custom_add_on_register_group_extension() {
    16     bp_register_group_extension( 'BP_Custom_AddOn_Group_Extension' );
    17 }
    18 add_action( 'bp_init', 'bp_custom_add_on_register_group_extension' );
    19 ```
    20 
    21 ## Building your group extension’s class
    22 
    23 It’s a [WordPress good practice](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions) to put the code of your class into a file having a `class-` prefix followed by your class name where caps are replaced by their corresponding lower case value and underscores by dashes. As our custom group extension's class is named `BP_Custom_Group_Extension`, we are putting its code inside a `class-bp-custom-group-extension.php` file. Let's built it making sure you will inherit from the `BP_Component` parent class using the `extends` keyword.
    24 
    25 ```php
    26 class BP_Custom_Group_Extension extends BP_Group_Extension {
    27     /*
    28      * The properties and methods of for your group extension's class.
    29      */
    30 }
    31 ```
    32 
    33 ### Adding the constructor of your class
    34 
    35 This is where you are using the `BP_Group_Extension::init()` method to configure your custom group extension. This method expects an associative array where specific keys will be used to define the name & URL slug for your group extension tab within groups, who can access to it, and init additional screens such as the one BuddyPress can load during the group's creation process, or the one to let group Administrators customize some settings about your group extension. Let's build a very basic tab that will be displayed on each single groups.
    36 
    37 ![Basic group extension](../assets/bp-custom-basic-group-extension.png)
    38 
    39 To get this result, here's how you need to define the arguments of the parameter you will send to the `parent::init()`  method at the end of your constructor.
    40 
    41 ```php
    42 if ( bp_is_active( 'groups' ) ) {
    43     /**
    44      * BP Custom group extension Class.
    45      */
    46     class BP_Custom_AddOn_Group_Extension extends BP_Group_Extension {
    47         /**
    48          * Your group extension's constructor.
    49          */
    50         public function __construct() {
    51             $args = array(
    52                 'slug'              => 'custom-group-extension',
    53                 'name'              => __( 'Custom group extension', 'custom-text-domain' ),
    54                 'nav_item_position' => 105,
    55                 'access'            => 'anyone',
    56                 'show_tab'          => 'anyone',
    57             );
    58 
    59             parent::init( $args );
    60         }
    61 
    62         /**
    63          * Outputs the content of your group extension tab.
    64          *
    65          * @param int|null $group_id ID of the displayed group.
    66          */
    67         public function display( $group_id = null ) {
    68             printf( '<p>%1$s %2$s</p>', esc_html__( 'It works! The displayed group ID is', 'custom-text-domain' ), $group_id );
    69         }
    70     }
    71 }
    72 ```
    73 
    74 The above code early introduced the `display()`  method of your group extension's class so that something is actually displayed into groups! Before looking to it more in details, let's first list all possible keys and values for the `$args` configuration array.
    75 
    76 ### Possible arguments for your configuration array
    77 
    78 As we've just seen, the `__construct()` method of your group extension class should be used to pass a set of arguments to the `parent::init( $args )` method. Below are these `$args` possible keys and values:
    79 
    80 #### `slug`
    81 
    82 **(required)** A unique string identifier for your group extension. Used, among other places, in the construction of URLs.
    83 
    84 #### `name`
    85 
    86 **(required)** The translatable name of your extension. Used as the default value for navigation items and page titles.
    87 
    88 #### `access`
    89 
    90 _(optional)_ Which users can visit the group extension’s tab. Possible values: 'anyone', 'loggedin', 'member', 'mod', 'admin' or 'noone'. ('member', 'mod', 'admin' refer to user’s role in the current group.) Defaults to 'anyone' for public groups and 'member' for private groups. Note that the 'mod' level targets only moderators, so if you want to allow access for group moderators and administrators, specify `array( 'mod', 'admin' )`. **This argument was introduced in BuddyPress 2.1.0.**
    91 
    92 #### `show_tab`
    93 
    94 _(optional)_ Which users can see the group extension’s navigation tab. Possible values: 'anyone', 'loggedin', 'member', 'mod', 'admin' or 'noone'. ('member', 'mod', 'admin' refer to user’s role in the current group.) Defaults to 'anyone' for public groups and 'member' for private groups. Note that the 'mod' level targets only moderators, so if you want to show the tab to group moderators and administrators, specify `array( 'mod', 'admin' )`. **This argument was introduced in BuddyPress 2.1.0.**
    95 
    96 #### `show_tab_callback`
    97 
    98 _(optional)_ The name of the function to use to define the `show_tab` argument. If you need to check for a specific setting to define whether or not your group extension tab should be shown to members, the static `show_tab` argument won't reply to your need. Use the `show_tab_callback` argument so that your callback function will be called once BuddyPress has set everything about the displayed group. Your callback function needs to return one of the possible values of the `show_tab` one. **This argument was introduced in BuddyPress 12.0.0.**
    99 
    100 #### `nav_item_position`
    101 
    102 _(optional)_ An integer describing where your extension’s tab should appear. A number between `1` and `100` is recommended. Defaults to `81`.
    103 
    104 #### `nav_item_name`
    105 
    106 _(optional)_ The string you want to appear in the navigation tab for your group extension. Defaults to the value of the `name` argument, described above.
    107 
    108 #### `template_file`
    109 
    110 _(optional)_ The template file that BuddyPress will use as a wrapper to display the content of your group extension. Defaults to  `groups/single/plugins.php`. This template is provided by built-in BP Template Packs (nouveau & legacy). If you are building a BuddyPress standalone theme, please make sure to provide this template.
    111 
    112 #### `screens`
    113 
    114 _(optional)_ A multi-dimensional array of options related to the three secondary “screens” available to group extensions: `create` (the step dedicated to the extension during the group creation process), `edit` (the subtab dedicated to the extension under the Admin tab of the group), and `admin` (the extension’s metabox that appears on the group page when editing via the Groups Administration Dashboard panels). Each of these screens has a set of configuration options, to be described below. Note that all config values are optional, and you only need to override those values where you want to change the default – BuddyPress will parse your `screens` array, using your provided values when available, otherwise falling back on the defaults.
    115 
    116 - `create` – Config options for the `create` screen
    117   - `position` – The position of the group extension’s step in the Create a Group process. An integer between `1` and `100` is recommended. Defaults to `81`.
    118   - `enabled` – `true` if you want your group extension to have a Create step, otherwise `false`. Defaults to `true`.
    119   - `name` – The name of the creation step, as it appears in the step’s navigation tab. Defaults to the general `name` value described above.
    120   - `slug` – The string used to create the URL of the creation step. Defaults to the general `slug` value described above.
    121   - `screen_callback` – The function BuddyPress will call to display the content of your create screen. BuddyPress attempts to determine this function
    122   automatically; see Methods below. Do not change this value unless you know what you’re doing.
    123   - `screen_save_callback` – The function BuddyPress will call after the group extension’s create step has been saved. BuddyPress attempts to determine this
    124   function automatically; see Methods below. Do not change this value unless you know what you’re doing.
    125 
    126 - `edit` – Config options for the ‘edit’ screen, a sub item of the Group's Manage item on the front-end.
    127   - `submit_text` – The text of the submit button on the edit screen. Defaults to 'Edit'.
    128   - `enabled` – `true` if you want your group extension to have a subtab in the Group Admin area, otherwise `false`. Defaults to `true`.
    129   - `name` – The text that appears in the navigation tab for the group extension’s Edit screen. Defaults to the general `name` value described above.
    130   - `slug` – The string used to create the URL of the admin tab. Defaults to the general `slug` value described above.
    131   - `screen_callback` – The function BuddyPress will call to display the content of your admin tab. BuddyPress attempts to determine this function automatically;
    132   see Methods below. Do not change this value unless you know what you’re doing.
    133   - `screen_save_callback` – The function BuddyPress will call after the group extension’s admin tab has been saved. BuddyPress attempts to determine this
    134   function automatically; see Methods below. Do not change this value unless you know what you’re doing.
    135 
    136 - `admin` – Config options for the `admin` screen, available from the "Groups" administration menu of your WordPress Dashboard (_Group Admin area_). 
    137   - `metabox_context` – The context for your group extension’s metabox. Defaults to `'normal'`. (See [add_meta_box()](https://developer.wordpress.org/reference/functions/add_meta_box/) for more details.)
    138   - `metabox_priority` – The priority for your group extension’s metabox. Defaults to `''`. (See [add_meta_box()](https://developer.wordpress.org/reference/functions/add_meta_box/) for more details.)
    139   - `enabled` – `true` if you want your group extension to have a subtab in the _Group Admin area_, otherwise `false`. Defaults to `true`.
    140   - `name` – The text used as the title for the meta box of your group extension’s Admin screen. Defaults to the general `name` value described above.
    141   - `slug` – The string used as the meta box ID (used in the `id` attribute for the meta box). Defaults to the general `slug` value described above.
    142   - `screen_callback` – The function BuddyPress will call to display the content for the meta box of your group extension’s Admin screen. BuddyPress attempts to
    143   determine this function automatically; see Methods below. Do not change this value unless you know what you’re doing.
    144   - `screen_save_callback` – The function BuddyPress will call to save your group extension’s admin settings during the Group admin settings update. BuddyPress
    145   attempts to determine this function automatically; see Methods below. Do not change this value unless you know what you’re doing.
    146 
    147 ### Available Methods for your group extension’s class
    148 
    149 `BP_Group_Extension` has built-in support for a number of different customization methods, which you can override in your group extension’s class as needed.
    150 
    151 #### `display()`
    152 The most prominent of these methods is `display()`, which BuddyPress uses to generate the output of the add-on’s main tab. It includes the `$group_id` argument so that you can customize your output according to the current displayed group. Your `display()` method should echo markup, which BuddyPress will automatically place into the proper template. As a reminder, below is the code we used in our very basic example of a group extension's class.
    153 
    154 ```php
    155 if ( bp_is_active( 'groups' ) ) {
    156     class BP_Custom_AddOn_Group_Extension extends BP_Group_Extension {
    157         public function __construct() { /* Your group extension's constructor. */ }
    158 
    159         /**
    160          * Outputs the content of your group extension tab.
    161          *
    162          * @param int|null $group_id ID of the displayed group.
    163          */
    164         public function display( $group_id = null ) {
    165             // You need to echo the markup.
    166             printf( '<p>%1$s %2$s</p>', esc_html__( 'It works! The displayed group ID is', 'custom-text-domain' ), $group_id );
    167         }
    168     }
    169 }
    170 ```
    171 
    172 #### Other screen methods
    173 For the three “screen” contexts – `create`, `edit`, and `admin` – a flexible system allows you to customize the way that your group extension’s screens work, without unnecessary reproduction of code. Your group extension should, **at minimum**, provide the following two methods if you defined one or more screen context into your configuration array:
    174 
    175 - `settings_screen()`: outputs the fallback markup for your `create` / `edit` / `admin` screens.
    176 - `settings_screen_save()`: called after changes are submitted from the `create` / `edit` / `admin` screens. This method should contain the logic necessary to catch settings form submits, validate submitted settings, and save them to the database.
    177 
    178 **NB**: these 2 methods include the `$group_id` argument so that you can customize your output/handler according to the current group being created, edited or administrated.
    179 
    180 Let's improve our example of basic group extension including a feature to let the creator/administrator of the group decide whether they want to "activate" the group extension main tab for their group.
    181 
    182 |![Create Screen](../assets/bp-custom-group-extension-create-screen.png)|![Edit Screen](../assets/bp-custom-group-extension-edit-screen.png)|![Admin Screen](../assets/bp-custom-group-extension-admin-screen.png)|
    183 |:-:|:-:|:-:|
    184 |Create screen|Edit screen|Admin screen|
    185 
    186 As shown above, we need to output a form on the group’s `create`, `edit` & `admin` screens. The first step is to edit the configuration array (`$args`) the `__construct()` method is sending to `BP_Group_Extension::init()` so that it includes a `$screens` argument and a `$show_tab_callback` argument. The first will define the screens we need to add, and the second one will set the callback function to use to check whether to display the group’s extension main tab or not. Here's how the configuration array should look like:
    187 
    188 ```php
    189 $args = array(
    190     'slug'              => 'custom-group-extension',
    191     'name'              => __( 'Custom group extension', 'custom-text-domain' ),
    192     'nav_item_position' => 105,
    193     'access'            => 'anyone',
    194 
    195     // Set the callback function defining the `$show_tab` argument dynamically.
    196     'show_tab_callback' => array( $this, 'show_tab' ),
    197 
    198     // Define the screens using default screen settings.
    199     'screens'           => array(
    200         'edit'   => array(),
    201         'create' => array(),
    202         'admin'  => array(),
    203     ),
    204 );
    205 ```
    206 
    207 **NB**: if you need your group extension to be back compatible with version of BuddyPress < 12.0.0, you'll need to add a conditional statement to use the `$show_tab` argument instead of the `$show_tab_callback` one. Here’s an example of how to add it:
    208 
    209 ```php
    210 // BuddyPress < 12.0.0 or BuddyPress >= 12.0.0 with the BP Classic backcompat plugin active.
    211 if ( ! function_exists( 'bp_core_get_query_parser' ) || 'legacy' === bp_core_get_query_parser() ) {
    212     $args['show_tab'] = $this->show_tab();
    213     unset( $args['show_tab_callback'] );
    214 }
    215 ```
    216 
    217 **NB**: note that in the above code, we are not setting the callback function but running it. This means as it doesn’t include the `$group_id` in this case, you’ll need to use the `bp_get_current_group_id()` to set it within your `show_tab()` method. For example:
    218 
    219 ```php
    220 /**
    221  * Checks whether the main group extension’s tab should be displayed.
    222  *
    223  * @param int|null $group_id ID of the displayed group.
    224  * @return string 'anyone' if the group extension’s tab should be displayed. 'noone' otherwise.
    225  */
    226 public function show_tab( $group_id = null ) {
    227     if ( ! $group_id ) {
    228         $group_id = bp_get_current_group_id();
    229     }
    230 
    231     $show_tab = 'noone';
    232     if ( $group_id && groups_get_groupmeta( $group_id, 'bp_custom_group_extension_is_active' ) ) {
    233         $show_tab = 'anyone';
    234     }
    235 
    236     return $show_tab;
    237 }
    238 ```
    239 
    240 The second step is to code the `settings_screen()` & `settings_screen_save()` methods so that each screen will output a form and handle its submission. Here's how these should look like into your group extension’s class:
    241 
    242 ```php
    243 if ( bp_is_active( 'groups' ) ) {
    244     class BP_Custom_AddOn_Group_Extension extends BP_Group_Extension {
    245         public function __construct() { /* Your group extension's constructor. */ }
    246         public function display( $group_id = null ) { /* Outputs the content of your group extension tab. */ }
    247 
    248         /**
    249          * Outputs a form to activate the extension on 'edit', 'create' & 'admin' screens.
    250          *
    251          * @param int|null $group_id ID of the displayed group.
    252          */
    253         public function settings_screen( $group_id = null ) {
    254             $active = (int) groups_get_groupmeta( $group_id, 'bp_custom_group_extension_is_active' );
    255             printf(
    256                 '<label><input type="checkbox" name="bp_custom_group_extension_is_active" value="1" %1$s>%2$s</input></label>
    257                 <input type="hidden" name="bp_custom_group_extension_was_active" value="%3$s">',
    258                 checked( $active, true, false ),
    259                 esc_html__( 'I want to activate the custom group extension!', 'custom-text-domain' ),
    260                 $active
    261             );
    262         }
    263 
    264         /**
    265          * Activate or Deactivate the group extension from 'edit', 'create' or 'admin' screens.
    266          *
    267          * @param int|null $group_id ID of the displayed group.
    268          */
    269         public function settings_screen_save( $group_id = null ) {
    270             $was_active = 0;
    271             $is_active  = 0;
    272 
    273             if ( isset( $_REQUEST['bp_custom_group_extension_was_active'] ) ) {
    274                 $was_active = intval( wp_unslash( $_REQUEST['bp_custom_group_extension_was_active'] ) );
    275 
    276                 if ( isset( $_REQUEST['bp_custom_group_extension_is_active'] ) ) {
    277                     $is_active = intval( wp_unslash( $_REQUEST['bp_custom_group_extension_is_active'] ) );
    278                 }
    279 
    280                 if ( $was_active && ! $is_active ) {
    281                     groups_delete_groupmeta( $group_id, 'bp_custom_group_extension_is_active' );
    282                 } elseif ( ! $was_active && $is_active ) {
    283                     groups_update_groupmeta( $group_id, 'bp_custom_group_extension_is_active', $is_active );
    284                 }
    285             }
    286         }
    287     }
    288 }
    289 ```
    290 
    291 Finally, If your extension requires further customization to one or more of the screens, BuddyPress provides the following methods, which are context-specific:
    292 
    293 - `create_screen()`: outputs the fallback markup for your `create` screen.
    294 - `create_screen_save()`: called after changes are submitted from the `create` screen. This method should contain the logic necessary to catch settings form submits, validate submitted settings, and save them to the database.
    295 - `edit_screen()`: outputs the fallback markup for your `edit` screen.
    296 - `edit_screen_save()`: called after changes are submitted from the `edit` screen. This method should contain the logic necessary to catch settings form submits, validate submitted settings, and save them to the database.
    297 - `admin_screen()`: outputs the fallback markup for your `admin` screen.
    298 - `admin_screen_save()`: called after changes are submitted from the `admin` screen. This method should contain the logic necessary to catch settings form submits, validate submitted settings, and save them to the database.
    299 
    300 **NB**: these methods include the `$group_id` argument so that you can customize your output/handler according to the current group being updated.
    301 
    302 If your extension contains any of these methods, BuddyPress will use them when appropriate. Otherwise, the generic `settings_screen()` or `settings_screen_save()` will be used.
     5This documentation page has moved: read about the [Group Extension API](../components/groups/extension.md).
  • trunk/docs/developer/manifest.json

    r13924 r14038  
    1515        "title": "BuddyPress Components",
    1616        "slug": "bp-components",
    17         "markdown_source": "../developer/component/README.md",
     17        "markdown_source": "../developer/components/README.md",
    1818        "parent": null
    1919    },
     
    2121        "title": "Building a custom BuddyPress component",
    2222        "slug": "build-bp-component",
    23         "markdown_source": "../developer/component/build-component.md",
     23        "markdown_source": "../developer/components/build-component.md",
     24        "parent": null
     25    },
     26    {
     27        "title": "Extending BuddyPress Activity",
     28        "slug": "extend-bp-activity",
     29        "markdown_source": "../developer/components/activity/README.md",
     30        "parent": null
     31    },
     32    {
     33        "title": "Extending BuddyPress Activity Embeds",
     34        "slug": "extend-bp-activity-embeds",
     35        "markdown_source": "../developer/components/activity/embeds.md",
     36        "parent": null
     37    },
     38    {
     39        "title": "Extending BuddyPress Groups",
     40        "slug": "extend-bp-groups",
     41        "markdown_source": "../developer/components/groups/README.md",
    2442        "parent": null
    2543    },
     
    2745        "title": "Group Extension API",
    2846        "slug": "bp-group-extension",
    29         "markdown_source": "../developer/group-extension/README.md",
     47        "markdown_source": "../developer/components/groups/extension.md",
    3048        "parent": null
    3149    },
  • trunk/docs/user/advanced/README.md

    r14023 r14038  
    22
    33- [Customizing templates](template-hierarchy.md)
     4- [Customizing styles](styles.md)
    45- [Customizing functionalities](functionalities.md)
    56- [Customizing texts](texts.md)
  • trunk/docs/user/components/README.md

    r13995 r14038  
    77- Account Settings
    88- [User Groups](./groups/README.md)
    9 - Activity Streams
     9- [Activity Streams](./activity/README.md)
    1010- Private Messages
    1111- Notifications
  • trunk/docs/user/manifest.json

    r14023 r14038  
    176176    {
    177177        "title": "Customizing templates",
    178         "slug": "advanced-templacte-hierarchy",
     178        "slug": "advanced-template-hierarchy",
    179179        "markdown_source": "../user/advanced/template-hierarchy.md",
     180        "parent": null
     181    },
     182    {
     183        "title": "Customizing styles",
     184        "slug": "advanced-styles",
     185        "markdown_source": "../user/advanced/styles.md",
    180186        "parent": null
    181187    },
     
    197203        "markdown_source": "../user/components/groups/joining-groups.md",
    198204        "parent": null
     205    },
     206    {
     207        "title": "Activity Streams",
     208        "slug": "activity-component",
     209        "markdown_source": "../user/components/activity/README.md",
     210        "parent": null
     211    },
     212    {
     213        "title": "Activity Embeds",
     214        "slug": "embedding-activity",
     215        "markdown_source": "../user/components/activity/embeds.md",
     216        "parent": null
    199217    }
    200218]
  • trunk/src/bp-activity/blocks/embed-activity/index.asset.php

    r13684 r14038  
    1 <?php return array('dependencies' => array('bp-block-data', 'react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'edbbeeacb401a96e999b');
     1<?php return array('dependencies' => array('bp-block-data', 'react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'e952653ea51184faab49');
  • trunk/src/bp-activity/blocks/embed-activity/index.js

    r13684 r14038  
    1 (()=>{"use strict";const e=window.wp.blocks,t=window.React,i=window.wp.blockEditor,a=window.wp.components,r=window.wp.compose,n=window.wp.data,s=window.wp.element,c=window.wp.i18n,o=window.bp.blockData,l=(0,r.compose)([(0,n.withSelect)(((e,t)=>{const{url:i}=t.attributes,{getEmbedPreview:a,isRequestingEmbedPreview:r}=e("core");return{preview:!!i&&a(i),fetching:!!i&&r(i)}}))])((({attributes:e,setAttributes:r,isSelected:n,preview:l,fetching:d})=>{const p=(0,i.useBlockProps)(),{url:m,caption:u}=e,b=(0,c.__)("BuddyPress Activity URL","buddypress"),[y,w]=(0,s.useState)(m),[v,E]=(0,s.useState)(!m),h=(0,t.createElement)(i.BlockControls,null,(0,t.createElement)(a.ToolbarGroup,null,(0,t.createElement)(a.ToolbarButton,{icon:"edit",title:(0,c.__)("Edit URL","buddypress"),onClick:e=>{e&&e.preventDefault(),E(!0)}})));return v?(0,t.createElement)("div",{...p},(0,t.createElement)(a.Placeholder,{icon:"buddicons-activity",label:b,className:"wp-block-embed",instructions:(0,c.__)("Paste the link to the activity content you want to display on your site.","buddypress")},(0,t.createElement)("form",{onSubmit:e=>{e&&e.preventDefault(),E(!1),r({url:y})}},(0,t.createElement)("input",{type:"url",value:y||"",className:"components-placeholder__input","aria-label":b,placeholder:(0,c.__)("Enter URL to embed here…","buddypress"),onChange:e=>w(e.target.value)}),(0,t.createElement)(a.Button,{variant:"primary",type:"submit"},(0,c.__)("Embed","buddypress"))),(0,t.createElement)("div",{className:"components-placeholder__learn-more"},(0,t.createElement)(a.ExternalLink,{href:(0,c.__)("https://codex.buddypress.org/activity-embeds/","buddypress")},(0,c.__)("Learn more about activity embeds","buddypress"))))):d?(0,t.createElement)("div",{className:"wp-block-embed is-loading"},(0,t.createElement)(a.Spinner,null),(0,t.createElement)("p",null,(0,c.__)("Embedding…","buddypress"))):l&&l.x_buddypress&&"activity"===l.x_buddypress?(0,t.createElement)("div",{...p},!v&&h,(0,t.createElement)("figure",{className:"wp-block-embed is-type-bp-activity"},(0,t.createElement)("div",{className:"wp-block-embed__wrapper"},(0,t.createElement)(a.Disabled,null,(0,t.createElement)(a.SandBox,{html:l&&l.html?l.html:"",scripts:[o.embedScriptURL]}))),(!i.RichText.isEmpty(u)||n)&&(0,t.createElement)(i.RichText,{tagName:"figcaption",placeholder:(0,c.__)("Write caption…","buddypress"),value:u,onChange:e=>r({caption:e}),inlineToolbar:!0}))):(0,t.createElement)("div",{...p},h,(0,t.createElement)(a.Placeholder,{icon:"buddicons-activity",label:b},(0,t.createElement)("p",{className:"components-placeholder__error"},(0,c.__)("The URL you provided is not a permalink to a public BuddyPress Activity. Please use another URL.","buddypress"))))})),d=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"bp/embed-activity","title":"Embed an activity","category":"embed","icon":"buddicons-activity","description":"Add a block that displays the activity content pulled from this or other community sites.","keywords":["BuddyPress","activity","community"],"textdomain":"buddypress","attributes":{"url":{"type":"string"},"caption":{"type":"string","source":"html","selector":"figcaption"}},"supports":{"align":true},"editorScript":"file:index.js","style":"file:index.css"}');(0,e.registerBlockType)(d,{icon:{background:"#fff",foreground:"#d84800",src:"buddicons-activity"},edit:l,save:({attributes:e})=>{const a=i.useBlockProps.save({className:"wp-block-embed is-type-bp-activity"}),{url:r,caption:n}=e;return r?(0,t.createElement)("figure",{...a},(0,t.createElement)("div",{className:"wp-block-embed__wrapper"},`\n${r}\n`),!i.RichText.isEmpty(n)&&(0,t.createElement)(i.RichText.Content,{tagName:"figcaption",value:n})):null}})})();
     1(()=>{"use strict";const e=window.wp.blocks,t=window.React,i=window.wp.blockEditor,r=window.wp.components,a=window.wp.compose,s=window.wp.data,n=window.wp.element,c=window.wp.i18n,o=window.bp.blockData,l=(0,a.compose)([(0,s.withSelect)(((e,t)=>{const{url:i}=t.attributes,{getEmbedPreview:r,isRequestingEmbedPreview:a}=e("core");return{preview:!!i&&r(i),fetching:!!i&&a(i)}}))])((({attributes:e,setAttributes:a,isSelected:s,preview:l,fetching:d})=>{const p=(0,i.useBlockProps)(),{url:m,caption:u}=e,b=(0,c.__)("BuddyPress Activity URL","buddypress"),[y,w]=(0,n.useState)(m),[v,E]=(0,n.useState)(!m),h=(0,t.createElement)(i.BlockControls,null,(0,t.createElement)(r.ToolbarGroup,null,(0,t.createElement)(r.ToolbarButton,{icon:"edit",title:(0,c.__)("Edit URL","buddypress"),onClick:e=>{e&&e.preventDefault(),E(!0)}})));return v?(0,t.createElement)("div",{...p},(0,t.createElement)(r.Placeholder,{icon:"buddicons-activity",label:b,className:"wp-block-embed",instructions:(0,c.__)("Paste the link to the activity content you want to display on your site.","buddypress")},(0,t.createElement)("form",{onSubmit:e=>{e&&e.preventDefault(),E(!1),a({url:y})}},(0,t.createElement)("input",{type:"url",value:y||"",className:"components-placeholder__input","aria-label":b,placeholder:(0,c.__)("Enter URL to embed here…","buddypress"),onChange:e=>w(e.target.value)}),(0,t.createElement)(r.Button,{variant:"primary",type:"submit"},(0,c.__)("Embed","buddypress"))),(0,t.createElement)("div",{className:"components-placeholder__learn-more"},(0,t.createElement)(r.ExternalLink,{href:(0,c.__)("https://github.com/buddypress/buddypress/tree/master/docs/user/components/activity/embeds.md","buddypress")},(0,c.__)("Learn more about activity embeds","buddypress"))))):d?(0,t.createElement)("div",{className:"wp-block-embed is-loading"},(0,t.createElement)(r.Spinner,null),(0,t.createElement)("p",null,(0,c.__)("Embedding…","buddypress"))):l&&l.x_buddypress&&"activity"===l.x_buddypress?(0,t.createElement)("div",{...p},!v&&h,(0,t.createElement)("figure",{className:"wp-block-embed is-type-bp-activity"},(0,t.createElement)("div",{className:"wp-block-embed__wrapper"},(0,t.createElement)(r.Disabled,null,(0,t.createElement)(r.SandBox,{html:l&&l.html?l.html:"",scripts:[o.embedScriptURL]}))),(!i.RichText.isEmpty(u)||s)&&(0,t.createElement)(i.RichText,{tagName:"figcaption",placeholder:(0,c.__)("Write caption…","buddypress"),value:u,onChange:e=>a({caption:e}),inlineToolbar:!0}))):(0,t.createElement)("div",{...p},h,(0,t.createElement)(r.Placeholder,{icon:"buddicons-activity",label:b},(0,t.createElement)("p",{className:"components-placeholder__error"},(0,c.__)("The URL you provided is not a permalink to a public BuddyPress Activity. Please use another URL.","buddypress"))))})),d=JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"bp/embed-activity","title":"Embed an activity","category":"embed","icon":"buddicons-activity","description":"Add a block that displays the activity content pulled from this or other community sites.","keywords":["BuddyPress","activity","community"],"textdomain":"buddypress","attributes":{"url":{"type":"string"},"caption":{"type":"string","source":"html","selector":"figcaption"}},"supports":{"align":true},"editorScript":"file:index.js","style":"file:index.css"}');(0,e.registerBlockType)(d,{icon:{background:"#fff",foreground:"#d84800",src:"buddicons-activity"},edit:l,save:({attributes:e})=>{const r=i.useBlockProps.save({className:"wp-block-embed is-type-bp-activity"}),{url:a,caption:s}=e;return a?(0,t.createElement)("figure",{...r},(0,t.createElement)("div",{className:"wp-block-embed__wrapper"},`\n${a}\n`),!i.RichText.isEmpty(s)&&(0,t.createElement)(i.RichText.Content,{tagName:"figcaption",value:s})):null}})})();
  • trunk/src/js/blocks/bp-activity/embed-activity/edit.js

    r13463 r14038  
    9393                    <div className="components-placeholder__learn-more">
    9494                        <ExternalLink
    95                             href={ __( 'https://codex.buddypress.org/activity-embeds/', 'buddypress' ) }
     95                            href={ __( 'https://github.com/buddypress/buddypress/tree/master/docs/user/components/activity/embeds.md', 'buddypress' ) }
    9696                        >
    9797                            { __( 'Learn more about activity embeds', 'buddypress' ) }
Note: See TracChangeset for help on using the changeset viewer.