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-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.