[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-messages/ -> bp-messages-filters.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Messages Filters.
   4   *
   5   * Apply WordPress defined filters to private messages.
   6   *
   7   * @package BuddyPress
   8   * @subpackage MessagesFilters
   9   * @since 1.0.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  add_filter( 'bp_get_message_notice_subject',        'wp_filter_kses', 1 );
  16  add_filter( 'bp_get_message_notice_text',           'wp_filter_kses', 1 );
  17  add_filter( 'bp_get_message_thread_subject',        'wp_filter_kses', 1 );
  18  add_filter( 'bp_get_message_thread_excerpt',        'wp_filter_kses', 1 );
  19  add_filter( 'bp_get_messages_subject_value',        'wp_filter_kses', 1 );
  20  add_filter( 'bp_get_messages_content_value',        'wp_filter_kses', 1 );
  21  add_filter( 'messages_message_subject_before_save', 'wp_filter_kses', 1 );
  22  add_filter( 'messages_notice_subject_before_save',  'wp_filter_kses', 1 );
  23  add_filter( 'bp_get_the_thread_subject',            'wp_filter_kses', 1 );
  24  
  25  add_filter( 'bp_get_the_thread_message_content',    'bp_messages_filter_kses', 1 );
  26  add_filter( 'messages_message_content_before_save', 'bp_messages_filter_kses', 1 );
  27  add_filter( 'messages_notice_message_before_save',  'bp_messages_filter_kses', 1 );
  28  add_filter( 'bp_get_message_thread_content',        'bp_messages_filter_kses', 1 );
  29  
  30  add_filter( 'messages_message_content_before_save', 'force_balance_tags' );
  31  add_filter( 'messages_message_subject_before_save', 'force_balance_tags' );
  32  add_filter( 'messages_notice_message_before_save',  'force_balance_tags' );
  33  add_filter( 'messages_notice_subject_before_save',  'force_balance_tags' );
  34  
  35  add_filter( 'messages_message_subject_before_save', 'wp_encode_emoji' );
  36  add_filter( 'messages_message_content_before_save', 'wp_encode_emoji' );
  37  add_filter( 'messages_notice_message_before_save',  'wp_encode_emoji' );
  38  add_filter( 'messages_notice_subject_before_save',  'wp_encode_emoji' );
  39  
  40  add_filter( 'bp_get_message_notice_subject',     'wptexturize' );
  41  add_filter( 'bp_get_message_notice_text',        'wptexturize' );
  42  add_filter( 'bp_get_message_thread_subject',     'wptexturize' );
  43  add_filter( 'bp_get_message_thread_excerpt',     'wptexturize' );
  44  add_filter( 'bp_get_the_thread_message_content', 'wptexturize' );
  45  add_filter( 'bp_get_message_thread_content',     'wptexturize' );
  46  
  47  add_filter( 'bp_get_message_notice_subject',     'convert_smilies', 2 );
  48  add_filter( 'bp_get_message_notice_text',        'convert_smilies', 2 );
  49  add_filter( 'bp_get_message_thread_subject',     'convert_smilies', 2 );
  50  add_filter( 'bp_get_message_thread_excerpt',     'convert_smilies', 2 );
  51  add_filter( 'bp_get_the_thread_message_content', 'convert_smilies', 2 );
  52  add_filter( 'bp_get_message_thread_content',     'convert_smilies', 2 );
  53  
  54  add_filter( 'bp_get_message_notice_subject',     'convert_chars' );
  55  add_filter( 'bp_get_message_notice_text',        'convert_chars' );
  56  add_filter( 'bp_get_message_thread_subject',     'convert_chars' );
  57  add_filter( 'bp_get_message_thread_excerpt',     'convert_chars' );
  58  add_filter( 'bp_get_the_thread_message_content', 'convert_chars' );
  59  add_filter( 'bp_get_message_thread_content',     'convert_chars' );
  60  
  61  add_filter( 'bp_get_message_notice_text',        'make_clickable', 9 );
  62  add_filter( 'bp_get_the_thread_message_content', 'make_clickable', 9 );
  63  add_filter( 'bp_get_message_thread_content',     'make_clickable', 9 );
  64  
  65  add_filter( 'bp_get_message_notice_text',        'wpautop' );
  66  add_filter( 'bp_get_the_thread_message_content', 'wpautop' );
  67  add_filter( 'bp_get_message_thread_content',     'wpautop' );
  68  
  69  add_filter( 'bp_get_message_notice_subject',          'stripslashes_deep'    );
  70  add_filter( 'bp_get_message_notice_text',             'stripslashes_deep'    );
  71  add_filter( 'bp_get_message_thread_subject',          'stripslashes_deep'    );
  72  add_filter( 'bp_get_message_thread_excerpt',          'stripslashes_deep'    );
  73  add_filter( 'bp_get_message_get_recipient_usernames', 'stripslashes_deep'    );
  74  add_filter( 'bp_get_messages_subject_value',          'stripslashes_deep'    );
  75  add_filter( 'bp_get_messages_content_value',          'stripslashes_deep'    );
  76  add_filter( 'bp_get_the_thread_message_content',      'stripslashes_deep'    );
  77  add_filter( 'bp_get_the_thread_subject',              'stripslashes_deep'    );
  78  add_filter( 'bp_get_message_thread_content',          'stripslashes_deep', 1 );
  79  
  80  add_filter( 'bp_get_the_thread_message_content', 'bp_core_add_loading_lazy_attribute' );
  81  
  82  // Personal data export.
  83  add_filter( 'wp_privacy_personal_data_exporters', 'bp_messages_register_personal_data_exporter' );
  84  
  85  /**
  86   * Enforce limitations on viewing private message contents
  87   *
  88   * @since 2.3.2
  89   *
  90   * @see bp_has_message_threads() for description of parameters
  91   *
  92   * @param array|string $args See {@link bp_has_message_threads()}.
  93   * @return array|string
  94   */
  95  function bp_messages_enforce_current_user( $args = array() ) {
  96  
  97      // Non-community moderators can only ever see their own messages.
  98      if ( is_user_logged_in() && ! bp_current_user_can( 'bp_moderate' ) ) {
  99          $_user_id = (int) bp_loggedin_user_id();
 100          if ( $_user_id !== (int) $args['user_id'] ) {
 101              $args['user_id'] = $_user_id;
 102          }
 103      }
 104  
 105      // Return possibly modified $args array.
 106      return $args;
 107  }
 108  add_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_enforce_current_user', 5 );
 109  
 110  /**
 111   * Custom kses filtering for message content.
 112   *
 113   * @since 3.0.0
 114   *
 115   * @param string $content The message content.
 116   * @return string         The filtered message content.
 117   */
 118  function bp_messages_filter_kses( $content ) {
 119      $messages_allowedtags      = bp_get_allowedtags();
 120      $messages_allowedtags['p'] = array();
 121  
 122      /**
 123       * Filters the allowed HTML tags for BuddyPress Messages content.
 124       *
 125       * @since 3.0.0
 126       *
 127       * @param array $value Array of allowed HTML tags and attributes.
 128       */
 129      $messages_allowedtags = apply_filters( 'bp_messages_allowed_tags', $messages_allowedtags );
 130      return wp_kses( $content, $messages_allowedtags );
 131  }
 132  
 133  /**
 134   * Register Messages personal data exporter.
 135   *
 136   * @since 4.0.0
 137   * @since 5.0.0 adds an `exporter_bp_friendly_name` param to exporters.
 138   *
 139   * @param array $exporters  An array of personal data exporters.
 140   * @return array An array of personal data exporters.
 141   */
 142  function bp_messages_register_personal_data_exporter( $exporters ) {
 143      $exporters['buddypress-messages'] = array(
 144          'exporter_friendly_name'    => __( 'BuddyPress Messages', 'buddypress' ),
 145          'callback'                  => 'bp_messages_personal_data_exporter',
 146          'exporter_bp_friendly_name' => _x( 'Private Messages', 'BuddyPress Messages data exporter friendly name', 'buddypress' ),
 147      );
 148  
 149      return $exporters;
 150  }


Generated: Thu Dec 26 01:01:04 2024 Cross-referenced by PHPXref 0.7.1