Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/07/2023 10:41:34 PM (3 years ago)
Author:
imath
Message:

Improve the favorites management using the WP Meta API

  • Introduce bp_activity_register_user_favorites_meta() to register the user meta and define sanitization callback.
  • Introduce bp_activity_sanitize_user_favorites_meta() to do the sanitization job.
  • Improve Ajax callbacks about favoriting/unfavoriting activities in template packs.

Props emaralive, dcavins

Fixes #9021
Closes https://github.com/buddypress/buddypress/pull/189

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r13526 r13636  
    12781278        $activity_id   = (int) $_POST['id'];
    12791279        $activity_item = new BP_Activity_Activity( $activity_id );
    1280         if ( ! bp_activity_user_can_read( $activity_item, bp_loggedin_user_id() ) ) {
    1281                 return;
    1282         }
    1283 
    1284         if ( bp_activity_add_user_favorite( $_POST['id'] ) )
    1285                 _e( 'Remove Favorite', 'buddypress' );
    1286         else
    1287                 _e( 'Favorite', 'buddypress' );
     1280        if ( empty( $activity_item->id ) || ! bp_activity_user_can_read( $activity_item, bp_loggedin_user_id() ) ) {
     1281                return;
     1282        }
     1283
     1284        if ( bp_activity_add_user_favorite( $activity_id ) ) {
     1285                esc_html_e( 'Remove Favorite', 'buddypress' );
     1286        } else {
     1287                esc_html_e( 'Favorite', 'buddypress' );
     1288        }
    12881289
    12891290        exit;
     
    13121313        }
    13131314
    1314         if ( bp_activity_remove_user_favorite( $_POST['id'] ) )
    1315                 _e( 'Favorite', 'buddypress' );
    1316         else
    1317                 _e( 'Remove Favorite', 'buddypress' );
     1315        $activity_id = (int) $_POST['id'];
     1316
     1317        if ( bp_activity_remove_user_favorite( $activity_id ) ) {
     1318                esc_html_e( 'Favorite', 'buddypress' );
     1319        } else {
     1320                esc_html_e( 'Remove Favorite', 'buddypress' );
     1321        }
    13181322
    13191323        exit;
Note: See TracChangeset for help on using the changeset viewer.