BP_REST_Notifications_Endpoint::prepare_item_for_database( WP_REST_Request $request )
Prepare a notification for create or update.
Description
Parameters
- $request
-
(Required) Request object.
Return
(stdClass)
Source
File: bp-notifications/classes/class-bp-rest-notifications-endpoint.php
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 | protected function prepare_item_for_database( $request ) { $prepared_notification = new stdClass(); $schema = $this ->get_item_schema(); $notification = $this ->get_notification_object( $request ); if ( ! empty ( $schema [ 'properties' ][ 'id' ] ) && ! empty ( $notification ->id ) ) { $prepared_notification ->id = $notification ->id; } if ( ! empty ( $schema [ 'properties' ][ 'user_id' ] ) && isset( $request [ 'user_id' ] ) ) { $prepared_notification ->user_id = (int) $request [ 'user_id' ]; } elseif ( isset( $notification ->user_id ) ) { $prepared_notification ->user_id = $notification ->user_id; } else { $prepared_notification ->user_id = bp_loggedin_user_id(); } if ( ! empty ( $schema [ 'properties' ][ 'item_id' ] ) && isset( $request [ 'item_id' ] ) ) { $prepared_notification ->item_id = $request [ 'item_id' ]; } elseif ( isset( $notification ->item_id ) ) { $prepared_notification ->item_id = $notification ->item_id; } if ( ! empty ( $schema [ 'properties' ][ 'secondary_item_id' ] ) && isset( $request [ 'secondary_item_id' ] ) ) { $prepared_notification ->secondary_item_id = $request [ 'secondary_item_id' ]; } elseif ( isset( $notification ->secondary_item_id ) ) { $prepared_notification ->secondary_item_id = $notification ->secondary_item_id; } if ( ! empty ( $schema [ 'properties' ][ 'component' ] ) && isset( $request [ 'component' ] ) ) { $prepared_notification ->component_name = $request [ 'component' ]; } elseif ( isset( $notification ->component_name ) ) { $prepared_notification ->component_name = $notification ->component_name; } if ( ! empty ( $schema [ 'properties' ][ 'action' ] ) && isset( $request [ 'action' ] ) ) { $prepared_notification ->component_action = $request [ 'action' ]; } elseif ( isset( $notification ->component_action ) ) { $prepared_notification ->component_action = $notification ->component_action; } if ( ! empty ( $schema [ 'properties' ][ 'is_new' ] ) && isset( $request [ 'is_new' ] ) ) { $prepared_notification ->is_new = $request [ 'is_new' ]; } elseif ( isset( $notification ->is_new ) ) { $prepared_notification ->is_new = $notification ->is_new; } if ( ! empty ( $schema [ 'properties' ][ 'date' ] ) && isset( $request [ 'date' ] ) ) { $prepared_notification ->date_notified = $request [ 'date' ]; } elseif ( isset( $notification ->date_notified ) ) { $prepared_notification ->date_notified = $notification ->date_notified; } /** * Filters a notification before it is inserted or updated via the REST API. * * @param stdClass $prepared_notification An object prepared for inserting or updating the database. * @param WP_REST_Request $request Request object. * * @since 0.1.0 */ return apply_filters( 'bp_rest_notifications_pre_insert_value' , $prepared_notification , $request ); } |
Changelog
Version | Description |
---|---|
0.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.