[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/actions/ -> post.php (source)

   1  <?php
   2  /**
   3   * Activity: Post action
   4   *
   5   * @package BuddyPress
   6   * @subpackage ActivityActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Post user/group activity update.
  12   *
  13   * @since 1.2.0
  14   *
  15   * @return bool False on failure.
  16   */
  17  function bp_activity_action_post_update() {
  18      // Do not proceed if user is not logged in, not viewing activity, or not posting.
  19      if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) )
  20          return false;
  21  
  22      // Check the nonce.
  23      check_admin_referer( 'post_update', '_wpnonce_post_update' );
  24  
  25      /**
  26       * Filters the content provided in the activity input field.
  27       *
  28       * @since 1.2.0
  29       *
  30       * @param string $value Activity message being posted.
  31       */
  32      $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
  33  
  34      if ( ! empty( $_POST['whats-new-post-object'] ) ) {
  35  
  36          /**
  37           * Filters the item type that the activity update should be associated with.
  38           *
  39           * @since 1.2.0
  40           *
  41           * @param string $value Item type to associate with.
  42           */
  43          $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
  44      }
  45  
  46      if ( ! empty( $_POST['whats-new-post-in'] ) ) {
  47  
  48          /**
  49           * Filters what component the activity is being to.
  50           *
  51           * @since 1.2.0
  52           *
  53           * @param string $value Chosen component to post activity to.
  54           */
  55          $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
  56      }
  57  
  58      // No activity content so provide feedback and redirect.
  59      if ( empty( $content ) ) {
  60          bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
  61          bp_core_redirect( wp_get_referer() );
  62      }
  63  
  64      // No existing item_id.
  65      if ( empty( $item_id ) ) {
  66          $activity_id = bp_activity_post_update( array( 'content' => $content ) );
  67  
  68      // Post to groups object.
  69      } elseif ( 'groups' == $object && bp_is_active( 'groups' ) ) {
  70          if ( (int) $item_id ) {
  71              $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
  72          }
  73  
  74      } else {
  75  
  76          /**
  77           * Filters activity object for BuddyPress core and plugin authors before posting activity update.
  78           *
  79           * @since 1.2.0
  80           * @since 5.0.0 Fixed filter signature to match other instances of filter,
  81           *              with $activity_id as the first param.
  82           *
  83           * @param int    $activity_id ID of the activity item.
  84           * @param string $object      Activity item being associated to.
  85           * @param string $item_id     Component ID being posted to.
  86           * @param string $content     Activity content being posted.
  87           */
  88          $activity_id = apply_filters( 'bp_activity_custom_update', 0, $object, $item_id, $content );
  89      }
  90  
  91      // Provide user feedback.
  92      if ( !empty( $activity_id ) )
  93          bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
  94      else
  95          bp_core_add_message( __( 'There was an error when posting your update. Please try again.', 'buddypress' ), 'error' );
  96  
  97      // Redirect.
  98      bp_core_redirect( wp_get_referer() );
  99  }
 100  add_action( 'bp_actions', 'bp_activity_action_post_update' );


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1