Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/23/2021 06:24:36 AM (4 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

File:
1 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 );
Note: See TracChangeset for help on using the changeset viewer.