Skip to:
Content

BuddyPress.org

Changeset 13194


Ignore:
Timestamp:
12/23/2021 06:24:36 AM (5 years ago)
Author:
imath
Message:

BP Blocks: localize dynamic Blocks script data into site's footer

These script data were not printed into themes using the Full Site Editing feature, like Twenty Twenty-Two, which was generated a JavaScript error as soon as the user clicked on one of the links to filter the loop's items (friends, members or groups).
Moving the script localization to the site's footer makes sure the JavaScript error disappears and that links are fully functional. This change has also been successfully tested on regular WordPress themes.

See #8474

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/bp-friends-blocks.php

    r13185 r13194  
    2424                return;
    2525        }
     26
     27        $path = sprintf(
     28                '/%1$s/%2$s/%3$s',
     29                bp_rest_namespace(),
     30                bp_rest_version(),
     31                buddypress()->members->id
     32        );
     33
     34        wp_localize_script(
     35                'bp-friends-script',
     36                'bpFriendsSettings',
     37                array(
     38                        'path'  => ltrim( $path, '/' ),
     39                        'root'  => esc_url_raw( get_rest_url() ),
     40                        'nonce' => wp_create_nonce( 'wp_rest' ),
     41                )
     42        );
    2643
    2744        // Include the common JS template.
     
    220237                        wp_set_script_translations( 'bp-friends-script', 'buddypress' );
    221238                        wp_enqueue_script( 'bp-friends-script' );
    222                         wp_localize_script(
    223                                 'bp-friends-script',
    224                                 'bpFriendsSettings',
    225                                 array(
    226                                         'path'  => ltrim( $path, '/' ),
    227                                         'root'  => esc_url_raw( get_rest_url() ),
    228                                         'nonce' => wp_create_nonce( 'wp_rest' ),
    229                                 )
    230                         );
    231239
    232240                        add_action( 'wp_footer', 'bp_friends_blocks_add_script_data', 1 );
  • trunk/src/bp-groups/bp-groups-blocks.php

    r13185 r13194  
    325325                return;
    326326        }
     327
     328        $path = sprintf(
     329                '/%1$s/%2$s/%3$s',
     330                bp_rest_namespace(),
     331                bp_rest_version(),
     332                buddypress()->groups->id
     333        );
     334
     335        wp_localize_script(
     336                'bp-dynamic-groups-script',
     337                'bpDynamicGroupsSettings',
     338                array(
     339                        'path'  => ltrim( $path, '/' ),
     340                        'root'  => esc_url_raw( get_rest_url() ),
     341                        'nonce' => wp_create_nonce( 'wp_rest' ),
     342                )
     343        );
    327344
    328345        // Include the common JS template.
     
    496513                        wp_set_script_translations( 'bp-dynamic-groups-script', 'buddypress' );
    497514                        wp_enqueue_script( 'bp-dynamic-groups-script' );
    498                         wp_localize_script(
    499                                 'bp-dynamic-groups-script',
    500                                 'bpDynamicGroupsSettings',
    501                                 array(
    502                                         'path'  => ltrim( $path, '/' ),
    503                                         'root'  => esc_url_raw( get_rest_url() ),
    504                                         'nonce' => wp_create_nonce( 'wp_rest' ),
    505                                 )
    506                         );
    507515
    508516                        add_action( 'wp_footer', 'bp_groups_blocks_add_script_data', 1 );
  • trunk/src/bp-members/bp-members-blocks.php

    r13185 r13194  
    346346                return;
    347347        }
     348
     349        $path = sprintf(
     350                '/%1$s/%2$s/%3$s',
     351                bp_rest_namespace(),
     352                bp_rest_version(),
     353                buddypress()->members->id
     354        );
     355
     356        wp_localize_script(
     357                'bp-dynamic-members-script',
     358                'bpDynamicMembersSettings',
     359                array(
     360                        'path'  => ltrim( $path, '/' ),
     361                        'root'  => esc_url_raw( get_rest_url() ),
     362                        'nonce' => wp_create_nonce( 'wp_rest' ),
     363                )
     364        );
    348365
    349366        // Include the common JS template.
     
    513530                        wp_set_script_translations( 'bp-dynamic-members-script', 'buddypress' );
    514531                        wp_enqueue_script( 'bp-dynamic-members-script' );
    515                         wp_localize_script(
    516                                 'bp-dynamic-members-script',
    517                                 'bpDynamicMembersSettings',
    518                                 array(
    519                                         'path'  => ltrim( $path, '/' ),
    520                                         'root'  => esc_url_raw( get_rest_url() ),
    521                                         'nonce' => wp_create_nonce( 'wp_rest' ),
    522                                 )
    523                         );
    524532
    525533                        add_action( 'wp_footer', 'bp_members_blocks_add_script_data', 1 );
Note: See TracChangeset for help on using the changeset viewer.