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