[ 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  
  22      if ( ! isset( $_POST['comment_form_id'] ) ) {
  23          return false;
  24      }
  25  
  26      $activity_id = absint( wp_unslash( $_POST['comment_form_id'] ) );
  27  
  28      if ( ! isset( $activity_id ) ) {
  29          return false;
  30      }
  31  
  32      // Check the nonce.
  33      check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment_' . $activity_id );
  34  
  35      /**
  36       * Filters the activity ID a comment will be in reply to.
  37       *
  38       * @since 1.2.0
  39       *
  40       * @param string $activity_id ID of the activity being replied to.
  41       */
  42      $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $activity_id );
  43  
  44      /**
  45       * Filters the comment content for a comment reply.
  46       *
  47       * @since 1.2.0
  48       *
  49       * @param string $value Comment content being posted.
  50       */
  51      $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
  52  
  53      if ( empty( $content ) ) {
  54          bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
  55          bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
  56      }
  57  
  58      $activity_item = new BP_Activity_Activity( $activity_id );
  59      if ( ! bp_activity_user_can_read( $activity_item ) ) {
  60          bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' );
  61          bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
  62      }
  63  
  64      $comment_id = bp_activity_new_comment(
  65          array(
  66              'content'     => $content,
  67              'activity_id' => $activity_id,
  68              'parent_id'   => false
  69          )
  70      );
  71  
  72      if ( ! empty( $comment_id ) ) {
  73          bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
  74      } else {
  75          bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' );
  76      }
  77  
  78      bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
  79  }
  80  add_action( 'bp_actions', 'bp_activity_action_post_comment' );


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1