[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Activity: Reply action
   4   *
   5   * @package BuddyPress
   6   * @subpackage ActivityActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Post new activity comment.
  12   *
  13   * @since 1.2.0
  14   *
  15   * @return bool False on failure.
  16   */
  17  function bp_activity_action_post_comment() {
  18      if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'reply' ) )
  19          return false;
  20  
  21      // Check the nonce.
  22      check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
  23  
  24      /**
  25       * Filters the activity ID a comment will be in reply to.
  26       *
  27       * @since 1.2.0
  28       *
  29       * @param string $value ID of the activity being replied to.
  30       */
  31      $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
  32  
  33      /**
  34       * Filters the comment content for a comment reply.
  35       *
  36       * @since 1.2.0
  37       *
  38       * @param string $value Comment content being posted.
  39       */
  40      $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
  41  
  42      if ( empty( $content ) ) {
  43          bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
  44          bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
  45      }
  46  
  47      $activity_item = new BP_Activity_Activity( $activity_id );
  48      if ( ! bp_activity_user_can_read( $activity_item ) ) {
  49          bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' );
  50          bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
  51      }
  52  
  53      $comment_id = bp_activity_new_comment( array(
  54          'content'     => $content,
  55          'activity_id' => $activity_id,
  56          'parent_id'   => false
  57      ));
  58  
  59      if ( !empty( $comment_id ) )
  60          bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
  61      else
  62          bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' );
  63  
  64      bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
  65  }
  66  add_action( 'bp_actions', 'bp_activity_action_post_comment' );


Generated: Sun Dec 8 01:01:37 2019 Cross-referenced by PHPXref 0.7.1