[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-legacy/ -> buddypress-functions.php (source)

   1  <?php
   2  /**
   3   * Functions of BuddyPress's Legacy theme.
   4   *
   5   * @since 1.7.0
   6   *
   7   * @package BuddyPress
   8   * @subpackage BP_Theme_Compat
   9   * @version 3.1.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /** Theme Setup ***************************************************************/
  16  
  17  if ( !class_exists( 'BP_Legacy' ) ) :
  18  
  19  /**
  20   * Loads BuddyPress Legacy Theme functionality.
  21   *
  22   * This is not a real theme by WordPress standards, and is instead used as the
  23   * fallback for any WordPress theme that does not have BuddyPress templates in it.
  24   *
  25   * To make your custom theme BuddyPress compatible and customize the templates, you
  26   * can copy these files into your theme without needing to merge anything
  27   * together; BuddyPress should safely handle the rest.
  28   *
  29   * See @link BP_Theme_Compat() for more.
  30   *
  31   * @since 1.7.0
  32   *
  33   * @package BuddyPress
  34   * @subpackage BP_Theme_Compat
  35   */
  36  class BP_Legacy extends BP_Theme_Compat {
  37  
  38      /** Functions *************************************************************/
  39  
  40      /**
  41       * The main BuddyPress (Legacy) Loader.
  42       *
  43       * @since 1.7.0
  44       *
  45       */
  46  	public function __construct() {
  47          parent::start();
  48      }
  49  
  50      /**
  51       * Component global variables.
  52       *
  53       * You'll want to customize the values in here, so they match whatever your
  54       * needs are.
  55       *
  56       * @since 1.7.0
  57       */
  58  	protected function setup_globals() {
  59          $bp            = buddypress();
  60          $this->id      = 'legacy';
  61          $this->name    = __( 'BuddyPress Legacy', 'buddypress' );
  62          $this->version = bp_get_version();
  63          $this->dir     = trailingslashit( $bp->themes_dir . '/bp-legacy' );
  64          $this->url     = trailingslashit( $bp->themes_url . '/bp-legacy' );
  65      }
  66  
  67      /**
  68       * Setup the theme hooks.
  69       *
  70       * @since 1.7.0
  71       *
  72       */
  73  	protected function setup_actions() {
  74  
  75          // Template Output.
  76          add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'secondary_avatars' ), 10, 2 );
  77  
  78          // Filter BuddyPress template hierarchy and look for page templates.
  79          add_filter( 'bp_get_buddypress_template', array( $this, 'theme_compat_page_templates' ), 10, 1 );
  80  
  81          /** Scripts ***********************************************************/
  82  
  83          add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_styles'   ) ); // Enqueue theme CSS
  84          add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts'  ) ); // Enqueue theme JS
  85          add_filter( 'bp_enqueue_scripts', array( $this, 'localize_scripts' ) ); // Enqueue theme script localization
  86  
  87          /** Body no-js Class **************************************************/
  88  
  89          add_filter( 'body_class', array( $this, 'add_nojs_body_class' ), 20, 1 );
  90  
  91          /** Buttons ***********************************************************/
  92  
  93          if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
  94              // Register buttons for the relevant component templates
  95              // Friends button.
  96              if ( bp_is_active( 'friends' ) )
  97                  add_action( 'bp_member_header_actions',    'bp_add_friend_button',           5 );
  98  
  99              // Activity button.
 100              if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() )
 101                  add_action( 'bp_member_header_actions',    'bp_send_public_message_button',  20 );
 102  
 103              // Messages button.
 104              if ( bp_is_active( 'messages' ) )
 105                  add_action( 'bp_member_header_actions',    'bp_send_private_message_button', 20 );
 106  
 107              // Group buttons.
 108              if ( bp_is_active( 'groups' ) ) {
 109                  add_action( 'bp_group_header_actions',          'bp_group_join_button',               5           );
 110                  add_action( 'bp_directory_groups_actions',      'bp_group_join_button'                            );
 111                  add_action( 'bp_groups_directory_group_filter', 'bp_legacy_theme_group_create_nav', 999           );
 112                  add_action( 'bp_after_group_admin_content',     'bp_legacy_groups_admin_screen_hidden_input'      );
 113                  add_action( 'bp_before_group_admin_form',       'bp_legacy_theme_group_manage_members_add_search' );
 114              }
 115  
 116              // Blog button.
 117              if ( bp_is_active( 'blogs' ) ) {
 118                  add_action( 'bp_directory_blogs_actions',    'bp_blogs_visit_blog_button'           );
 119                  add_action( 'bp_blogs_directory_blog_types', 'bp_legacy_theme_blog_create_nav', 999 );
 120              }
 121          }
 122  
 123          /** Notices ***********************************************************/
 124  
 125          // Only hook the 'sitewide_notices' overlay if the Sitewide
 126          // Notices widget is not in use (to avoid duplicate content).
 127          if ( bp_is_active( 'messages' ) && ! is_active_widget( false, false, 'bp_messages_sitewide_notices_widget', true ) ) {
 128              add_action( 'wp_footer', array( $this, 'sitewide_notices' ), 9999 );
 129          }
 130  
 131          /** Ajax **************************************************************/
 132  
 133          $actions = array(
 134  
 135              // Directory filters.
 136              'blogs_filter'    => 'bp_legacy_theme_object_template_loader',
 137              'forums_filter'   => 'bp_legacy_theme_object_template_loader',
 138              'groups_filter'   => 'bp_legacy_theme_object_template_loader',
 139              'members_filter'  => 'bp_legacy_theme_object_template_loader',
 140              'messages_filter' => 'bp_legacy_theme_messages_template_loader',
 141              'invite_filter'   => 'bp_legacy_theme_invite_template_loader',
 142              'requests_filter' => 'bp_legacy_theme_requests_template_loader',
 143  
 144              // Friends.
 145              'accept_friendship' => 'bp_legacy_theme_ajax_accept_friendship',
 146              'addremove_friend'  => 'bp_legacy_theme_ajax_addremove_friend',
 147              'reject_friendship' => 'bp_legacy_theme_ajax_reject_friendship',
 148  
 149              // Activity.
 150              'activity_get_older_updates'  => 'bp_legacy_theme_activity_template_loader',
 151              'activity_mark_fav'           => 'bp_legacy_theme_mark_activity_favorite',
 152              'activity_mark_unfav'         => 'bp_legacy_theme_unmark_activity_favorite',
 153              'activity_widget_filter'      => 'bp_legacy_theme_activity_template_loader',
 154              'delete_activity'             => 'bp_legacy_theme_delete_activity',
 155              'delete_activity_comment'     => 'bp_legacy_theme_delete_activity_comment',
 156              'get_single_activity_content' => 'bp_legacy_theme_get_single_activity_content',
 157              'new_activity_comment'        => 'bp_legacy_theme_new_activity_comment',
 158              'post_update'                 => 'bp_legacy_theme_post_update',
 159              'bp_spam_activity'            => 'bp_legacy_theme_spam_activity',
 160              'bp_spam_activity_comment'    => 'bp_legacy_theme_spam_activity',
 161  
 162              // Groups.
 163              'groups_invite_user' => 'bp_legacy_theme_ajax_invite_user',
 164              'joinleave_group'    => 'bp_legacy_theme_ajax_joinleave_group',
 165  
 166              // Messages.
 167              'messages_autocomplete_results' => 'bp_legacy_theme_ajax_messages_autocomplete_results',
 168              'messages_close_notice'         => 'bp_legacy_theme_ajax_close_notice',
 169              'messages_delete'               => 'bp_legacy_theme_ajax_messages_delete',
 170              'messages_markread'             => 'bp_legacy_theme_ajax_message_markread',
 171              'messages_markunread'           => 'bp_legacy_theme_ajax_message_markunread',
 172              'messages_send_reply'           => 'bp_legacy_theme_ajax_messages_send_reply',
 173          );
 174  
 175          // Conditional actions.
 176          if ( bp_is_active( 'messages', 'star' ) ) {
 177              $actions['messages_star'] = 'bp_legacy_theme_ajax_messages_star_handler';
 178          }
 179  
 180          /**
 181           * Register all of these AJAX handlers.
 182           *
 183           * The "wp_ajax_" action is used for logged in users, and "wp_ajax_nopriv_"
 184           * executes for users that aren't logged in. This is for backpat with BP <1.6.
 185           */
 186          foreach( $actions as $name => $function ) {
 187              add_action( 'wp_ajax_'        . $name, $function );
 188              add_action( 'wp_ajax_nopriv_' . $name, $function );
 189          }
 190  
 191          add_filter( 'bp_ajax_querystring', 'bp_legacy_theme_ajax_querystring', 10, 2 );
 192  
 193          /** Override **********************************************************/
 194  
 195          /**
 196           * Fires after all of the BuddyPress theme compat actions have been added.
 197           *
 198           * @since 1.7.0
 199           *
 200           * @param BP_Legacy $this Current BP_Legacy instance.
 201           */
 202          do_action_ref_array( 'bp_theme_compat_actions', array( &$this ) );
 203      }
 204  
 205      /**
 206       * Load the theme CSS
 207       *
 208       * @since 1.7.0
 209       * @since 2.3.0 Support custom CSS file named after the current theme or parent theme.
 210       *
 211       */
 212  	public function enqueue_styles() {
 213          $min = bp_core_get_minified_asset_suffix();
 214  
 215          // Locate the BP stylesheet.
 216          $ltr = $this->locate_asset_in_stack( "buddypress{$min}.css",     'css' );
 217  
 218          // LTR.
 219          if ( ! is_rtl() && isset( $ltr['location'], $ltr['handle'] ) ) {
 220              wp_enqueue_style( $ltr['handle'], $ltr['location'], array(), $this->version, 'screen' );
 221  
 222              if ( $min ) {
 223                  wp_style_add_data( $ltr['handle'], 'suffix', $min );
 224              }
 225          }
 226  
 227          // RTL.
 228          if ( is_rtl() ) {
 229              $rtl = $this->locate_asset_in_stack( "buddypress-rtl{$min}.css", 'css' );
 230  
 231              if ( isset( $rtl['location'], $rtl['handle'] ) ) {
 232                  $rtl['handle'] = str_replace( '-css', '-css-rtl', $rtl['handle'] );  // Backwards compatibility.
 233                  wp_enqueue_style( $rtl['handle'], $rtl['location'], array(), $this->version, 'screen' );
 234  
 235                  if ( $min ) {
 236                      wp_style_add_data( $rtl['handle'], 'suffix', $min );
 237                  }
 238              }
 239          }
 240  
 241          // Compatibility stylesheets for specific themes.
 242          $theme = $this->locate_asset_in_stack( get_template() . "{$min}.css", 'css' );
 243          if ( ! is_rtl() && isset( $theme['location'] ) ) {
 244              // Use a unique handle.
 245              $theme['handle'] = 'bp-' . get_template();
 246              wp_enqueue_style( $theme['handle'], $theme['location'], array(), $this->version, 'screen' );
 247  
 248              if ( $min ) {
 249                  wp_style_add_data( $theme['handle'], 'suffix', $min );
 250              }
 251          }
 252  
 253          // Compatibility stylesheet for specific themes, RTL-version.
 254          if ( is_rtl() ) {
 255              $theme_rtl = $this->locate_asset_in_stack( get_template() . "-rtl{$min}.css", 'css' );
 256  
 257              if ( isset( $theme_rtl['location'] ) ) {
 258                  $theme_rtl['handle'] = $theme['handle'] . '-rtl';
 259                  wp_enqueue_style( $theme_rtl['handle'], $theme_rtl['location'], array(), $this->version, 'screen' );
 260  
 261                  if ( $min ) {
 262                      wp_style_add_data( $theme_rtl['handle'], 'suffix', $min );
 263                  }
 264              }
 265          }
 266      }
 267  
 268      /**
 269       * Enqueue the required JavaScript files
 270       *
 271       * @since 1.7.0
 272       */
 273  	public function enqueue_scripts() {
 274          $min = bp_core_get_minified_asset_suffix();
 275  
 276          // Locate the BP JS file.
 277          $asset = $this->locate_asset_in_stack( "buddypress{$min}.js", 'js' );
 278  
 279          // Enqueue the global JS, if found - AJAX will not work
 280          // without it.
 281          if ( isset( $asset['location'], $asset['handle'] ) ) {
 282              wp_enqueue_script( $asset['handle'], $asset['location'], bp_core_get_js_dependencies(), $this->version );
 283          }
 284  
 285          /**
 286           * Filters whether directory filter settings ('scope', etc) should be stored in a persistent cookie.
 287           *
 288           * @since 4.0.0
 289           *
 290           * @param bool $store_filter_settings Whether to store settings. Defaults to true for logged-in users.
 291           */
 292          $store_filter_settings = apply_filters( 'bp_legacy_store_filter_settings', is_user_logged_in() );
 293  
 294          /**
 295           * Filters core JavaScript strings for internationalization before AJAX usage.
 296           *
 297           * @since 2.0.0
 298           *
 299           * @param array $value Array of key/value pairs for AJAX usage.
 300           */
 301          $params = apply_filters( 'bp_core_get_js_strings', array(
 302              // Strings for display.
 303              'accepted'            => __( 'Accepted', 'buddypress' ),
 304              'close'               => __( 'Close', 'buddypress' ),
 305              'comments'            => __( 'comments', 'buddypress' ),
 306              'leave_group_confirm' => __( 'Are you sure you want to leave this group?', 'buddypress' ),
 307              'mark_as_fav'          => __( 'Favorite', 'buddypress' ),
 308              'my_favs'             => __( 'My Favorites', 'buddypress' ),
 309              'rejected'            => __( 'Rejected', 'buddypress' ),
 310              'remove_fav'          => __( 'Remove Favorite', 'buddypress' ),
 311              'show_all'            => __( 'Show all', 'buddypress' ),
 312              'show_all_comments'   => __( 'Show all comments for this thread', 'buddypress' ),
 313  
 314              /* translators: %s: number of activity comments */
 315              'show_x_comments'     => __( 'Show all comments (%d)', 'buddypress' ),
 316              'unsaved_changes'     => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ),
 317              'view'                => __( 'View', 'buddypress' ),
 318  
 319              // Settings.
 320              'store_filter_settings' => $store_filter_settings,
 321          ) );
 322          wp_localize_script( $asset['handle'], 'BP_DTheme', $params );
 323  
 324          // Maybe enqueue comment reply JS.
 325          if ( is_singular() && bp_is_blog_page() && get_option( 'thread_comments' ) ) {
 326              wp_enqueue_script( 'comment-reply' );
 327          }
 328  
 329          // Maybe enqueue password verify JS (register page or user settings page).
 330          if ( bp_is_register_page() || ( function_exists( 'bp_is_user_settings_general' ) && bp_is_user_settings_general() ) ) {
 331  
 332              // Locate the Register Page JS file.
 333              $asset = $this->locate_asset_in_stack( "password-verify{$min}.js", 'js', 'bp-legacy-password-verify' );
 334  
 335              $dependencies = array_merge( bp_core_get_js_dependencies(), array(
 336                  'password-strength-meter',
 337              ) );
 338  
 339              // Enqueue script.
 340              wp_enqueue_script( $asset['handle'] . '-password-verify', $asset['location'], $dependencies, $this->version);
 341          }
 342  
 343          // Star private messages.
 344          if ( bp_is_active( 'messages', 'star' ) && bp_is_user_messages() ) {
 345              wp_localize_script( $asset['handle'], 'BP_PM_Star', array(
 346                  'strings' => array(
 347                      'text_unstar'  => __( 'Unstar', 'buddypress' ),
 348                      'text_star'    => __( 'Star', 'buddypress' ),
 349                      'title_unstar' => __( 'Starred', 'buddypress' ),
 350                      'title_star'   => __( 'Not starred', 'buddypress' ),
 351                      'title_unstar_thread' => __( 'Remove all starred messages in this thread', 'buddypress' ),
 352                      'title_star_thread'   => __( 'Star the first message in this thread', 'buddypress' ),
 353                  ),
 354                  'is_single_thread' => (int) bp_is_messages_conversation(),
 355                  'star_counter'     => 0,
 356                  'unstar_counter'   => 0
 357              ) );
 358          }
 359      }
 360  
 361      /**
 362       * Get the URL and handle of a web-accessible CSS or JS asset
 363       *
 364       * We provide two levels of customizability with respect to where CSS
 365       * and JS files can be stored: (1) the child theme/parent theme/theme
 366       * compat hierarchy, and (2) the "template stack" of /buddypress/css/,
 367       * /community/css/, and /css/. In this way, CSS and JS assets can be
 368       * overloaded, and default versions provided, in exactly the same way
 369       * as corresponding PHP templates.
 370       *
 371       * We are duplicating some of the logic that is currently found in
 372       * bp_locate_template() and the _template_stack() functions. Those
 373       * functions were built with PHP templates in mind, and will require
 374       * refactoring in order to provide "stack" functionality for assets
 375       * that must be accessible both using file_exists() (the file path)
 376       * and at a public URI.
 377       *
 378       * This method is marked private, with the understanding that the
 379       * implementation is subject to change or removal in an upcoming
 380       * release, in favor of a unified _template_stack() system. Plugin
 381       * and theme authors should not attempt to use what follows.
 382       *
 383       * @since 1.8.0
 384       * @param string $file A filename like buddypress.css.
 385       * @param string $type Optional. Either "js" or "css" (the default).
 386       * @param string $script_handle Optional. If set, used as the script name in `wp_enqueue_script`.
 387       * @return array An array of data for the wp_enqueue_* function:
 388       *   'handle' (eg 'bp-child-css') and a 'location' (the URI of the
 389       *   asset)
 390       */
 391  	private function locate_asset_in_stack( $file, $type = 'css', $script_handle = '' ) {
 392          $locations = array();
 393  
 394          // Ensure the assets can be located when running from /src/.
 395          if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src' ) {
 396              $file = str_replace( '.min', '', $file );
 397          }
 398  
 399          // No need to check child if template == stylesheet.
 400          if ( is_child_theme() ) {
 401              $locations[] = array(
 402                  'type' => 'bp-child',
 403                  'dir'  => get_stylesheet_directory(),
 404                  'uri'  => get_stylesheet_directory_uri(),
 405                  'file' => $file,
 406              );
 407  
 408              $locations[] = array(
 409                  'type' => 'bp-child',
 410                  'dir'  => get_stylesheet_directory(),
 411                  'uri'  => get_stylesheet_directory_uri(),
 412                  'file' => str_replace( '.min', '', $file ),
 413              );
 414          }
 415  
 416          $locations[] = array(
 417              'type' => 'bp-parent',
 418              'dir'  => get_template_directory(),
 419              'uri'  => get_template_directory_uri(),
 420              'file' => str_replace( '.min', '', $file ),
 421          );
 422  
 423          $locations[] = array(
 424              'type' => 'bp-legacy',
 425              'dir'  => bp_get_theme_compat_dir(),
 426              'uri'  => bp_get_theme_compat_url(),
 427              'file' => $file,
 428          );
 429  
 430          // Subdirectories within the top-level $locations directories.
 431          $subdirs = array(
 432              'buddypress/' . $type,
 433              'community/' . $type,
 434              $type,
 435          );
 436  
 437          $retval = array();
 438  
 439          foreach ( $locations as $location ) {
 440              foreach ( $subdirs as $subdir ) {
 441                  if ( file_exists( trailingslashit( $location['dir'] ) . trailingslashit( $subdir ) . $location['file'] ) ) {
 442                      $retval['location'] = trailingslashit( $location['uri'] ) . trailingslashit( $subdir ) . $location['file'];
 443                      $retval['handle']   = ( $script_handle ) ? $script_handle : "{$location['type']}-{$type}";
 444  
 445                      break 2;
 446                  }
 447              }
 448          }
 449  
 450          return $retval;
 451      }
 452  
 453      /**
 454       * Adds the no-js class to the body tag.
 455       *
 456       * This function ensures that the <body> element will have the 'no-js' class by default. If you're
 457       * using JavaScript for some visual functionality in your theme, and you want to provide noscript
 458       * support, apply those styles to body.no-js.
 459       *
 460       * The no-js class is removed by the JavaScript created in buddypress.js.
 461       *
 462       * @since 1.7.0
 463       *
 464       * @param array $classes Array of classes to append to body tag.
 465       * @return array $classes
 466       */
 467  	public function add_nojs_body_class( $classes ) {
 468          if ( ! in_array( 'no-js', $classes ) )
 469              $classes[] = 'no-js';
 470  
 471          return array_unique( $classes );
 472      }
 473  
 474      /**
 475       * Load localizations for topic script.
 476       *
 477       * These localizations require information that may not be loaded even by init.
 478       *
 479       * @since 1.7.0
 480       */
 481  	public function localize_scripts() {
 482      }
 483  
 484      /**
 485       * Outputs sitewide notices markup in the footer.
 486       *
 487       * @since 1.7.0
 488       *
 489       * @see https://buddypress.trac.wordpress.org/ticket/4802
 490       */
 491  	public function sitewide_notices() {
 492          // Do not show notices if user is not logged in.
 493          if ( ! is_user_logged_in() )
 494              return;
 495  
 496          // Add a class to determine if the admin bar is on or not.
 497          $class = did_action( 'admin_bar_menu' ) ? 'admin-bar-on' : 'admin-bar-off';
 498  
 499          echo '<div id="sitewide-notice" class="' . $class . '">';
 500          bp_message_get_notices();
 501          echo '</div>';
 502      }
 503  
 504      /**
 505       * Add secondary avatar image to this activity stream's record, if supported.
 506       *
 507       * @since 1.7.0
 508       *
 509       * @param string               $action   The text of this activity.
 510       * @param BP_Activity_Activity $activity Activity object.
 511       * @return string
 512       */
 513  	function secondary_avatars( $action, $activity ) {
 514          switch ( $activity->component ) {
 515              case 'groups' :
 516              case 'friends' :
 517                  // Only insert avatar if one exists.
 518                  if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) {
 519                      $reverse_content = strrev( $action );
 520                      $position        = strpos( $reverse_content, 'a<' );
 521                      $action          = substr_replace( $action, $secondary_avatar, -$position - 2, 0 );
 522                  }
 523                  break;
 524          }
 525  
 526          return $action;
 527      }
 528  
 529      /**
 530       * Filter the default theme compatibility root template hierarchy, and prepend
 531       * a page template to the front if it's set.
 532       *
 533       * @see https://buddypress.trac.wordpress.org/ticket/6065
 534       *
 535       * @since 2.2.0
 536       *
 537       * @param  array $templates Array of templates.
 538       *                         to use the defined page template for component's directory and its single items
 539       * @return array
 540       */
 541  	public function theme_compat_page_templates( $templates = array() ) {
 542  
 543          /**
 544           * Filters whether or not we are looking at a directory to determine if to return early.
 545           *
 546           * @since 2.2.0
 547           *
 548           * @param bool $value Whether or not we are viewing a directory.
 549           */
 550          if ( true === (bool) apply_filters( 'bp_legacy_theme_compat_page_templates_directory_only', ! bp_is_directory() ) ) {
 551              return $templates;
 552          }
 553  
 554          // No page ID yet.
 555          $page_id = 0;
 556  
 557          // Get the WordPress Page ID for the current view.
 558          foreach ( (array) buddypress()->pages as $component => $bp_page ) {
 559  
 560              // Handles the majority of components.
 561              if ( bp_is_current_component( $component ) ) {
 562                  $page_id = (int) $bp_page->id;
 563              }
 564  
 565              // Stop if not on a user page.
 566              if ( ! bp_is_user() && ! empty( $page_id ) ) {
 567                  break;
 568              }
 569  
 570              // The Members component requires an explicit check due to overlapping components.
 571              if ( bp_is_user() && ( 'members' === $component ) ) {
 572                  $page_id = (int) $bp_page->id;
 573                  break;
 574              }
 575          }
 576  
 577          // Bail if no directory page set.
 578          if ( 0 === $page_id ) {
 579              return $templates;
 580          }
 581  
 582          // Check for page template.
 583          $page_template = get_page_template_slug( $page_id );
 584  
 585          // Add it to the beginning of the templates array so it takes precedence
 586          // over the default hierarchy.
 587          if ( ! empty( $page_template ) ) {
 588  
 589              /**
 590               * Check for existence of template before adding it to template
 591               * stack to avoid accidentally including an unintended file.
 592               *
 593               * @see: https://buddypress.trac.wordpress.org/ticket/6190
 594               */
 595              if ( '' !== locate_template( $page_template ) ) {
 596                  array_unshift( $templates, $page_template );
 597              }
 598          }
 599  
 600          return $templates;
 601      }
 602  }
 603  new BP_Legacy();
 604  endif;
 605  
 606  /**
 607   * Add the Create a Group button to the Groups directory title.
 608   *
 609   * The bp-legacy puts the Create a Group button into the page title, to mimic
 610   * the behavior of bp-default.
 611   *
 612   * @since 2.0.0
 613   * @todo Deprecate
 614   *
 615   * @param string $title Groups directory title.
 616   * @return string
 617   */
 618  function bp_legacy_theme_group_create_button( $title ) {
 619      return $title . ' ' . bp_get_group_create_button();
 620  }
 621  
 622  /**
 623   * Add the Create a Group nav to the Groups directory navigation.
 624   *
 625   * The bp-legacy puts the Create a Group nav at the last position of
 626   * the Groups directory navigation.
 627   *
 628   * @since 2.2.0
 629   *
 630   */
 631  function bp_legacy_theme_group_create_nav() {
 632      bp_group_create_nav_item();
 633  }
 634  
 635  /**
 636   * Renders the group ID hidden input on group admin screens.
 637   *
 638   * @since 2.7.0
 639   *
 640   * @return string|null html
 641   */
 642  function bp_legacy_groups_admin_screen_hidden_input() {
 643      ?>
 644       <input type="hidden" name="group-id" id="group-id" value="<?php bp_group_id(); ?>" />
 645      <?php
 646  }
 647  
 648  /**
 649   * Add the Create a Site button to the Sites directory title.
 650   *
 651   * The bp-legacy puts the Create a Site button into the page title, to mimic
 652   * the behavior of bp-default.
 653   *
 654   * @since 2.0.0
 655   * @todo Deprecate
 656   *
 657   * @param string $title Sites directory title.
 658   * @return string
 659   */
 660  function bp_legacy_theme_blog_create_button( $title ) {
 661      return $title . ' ' . bp_get_blog_create_button();
 662  }
 663  
 664  /**
 665   * Add the Create a Site nav to the Sites directory navigation.
 666   *
 667   * The bp-legacy puts the Create a Site nav at the last position of
 668   * the Sites directory navigation.
 669   *
 670   * @since 2.2.0
 671   *
 672   */
 673  function bp_legacy_theme_blog_create_nav() {
 674      bp_blog_create_nav_item();
 675  }
 676  
 677  /**
 678   * This function looks scarier than it actually is. :)
 679   * Each object loop (activity/members/groups/blogs/forums) contains default
 680   * parameters to show specific information based on the page we are currently
 681   * looking at.
 682   *
 683   * The following function will take into account any cookies set in the JS and
 684   * allow us to override the parameters sent. That way we can change the results
 685   * returned without reloading the page.
 686   *
 687   * By using cookies we can also make sure that user settings are retained
 688   * across page loads.
 689   *
 690   * @since 1.2.0
 691   *
 692   * @param string $query_string Query string for the current request.
 693   * @param string $object       Object for cookie.
 694   * @return string Query string for the component loops.
 695   */
 696  function bp_legacy_theme_ajax_querystring( $query_string, $object ) {
 697      if ( empty( $object ) )
 698          return '';
 699  
 700      // Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts.
 701      if ( ! empty( $_POST['cookie'] ) ) {
 702          $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) );
 703      } else {
 704          $_BP_COOKIE = &$_COOKIE;
 705      }
 706  
 707      $qs = array();
 708  
 709      /**
 710       * Check if any cookie values are set. If there are then override the
 711       * default params passed to the template loop.
 712       */
 713  
 714      // Activity stream filtering on action.
 715      if ( ! empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
 716          $qs[] = 'type=' . urlencode( $_BP_COOKIE['bp-' . $object . '-filter'] );
 717  
 718          if ( bp_is_active( 'activity' ) ) {
 719              $actions = bp_activity_get_actions_for_context();
 720  
 721              // Handle multiple actions (eg. 'friendship_accepted,friendship_created')
 722              $action_filter = explode( ',', $_BP_COOKIE['bp-' . $object . '-filter'] );
 723  
 724              // See if action filter matches registered actions. If so, add it to qs.
 725              if ( ! array_diff( $action_filter, wp_list_pluck( $actions, 'key' ) ) ) {
 726                  $qs[] = 'action=' . join( ',', $action_filter );
 727              }
 728          }
 729      }
 730  
 731      if ( ! empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {
 732          if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) {
 733              $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
 734              $qs[] = 'user_id=' . $user_id;
 735          }
 736  
 737          // Activity stream scope only on activity directory.
 738          if ( 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() )
 739              $qs[] = 'scope=' . urlencode( $_BP_COOKIE['bp-' . $object . '-scope'] );
 740      }
 741  
 742      // If page and search_terms have been passed via the AJAX post request, use those.
 743      if ( ! empty( $_POST['page'] ) && '-1' != $_POST['page'] )
 744          $qs[] = 'page=' . absint( $_POST['page'] );
 745  
 746      // Excludes activity just posted and avoids duplicate ids.
 747      if ( ! empty( $_POST['exclude_just_posted'] ) ) {
 748          $just_posted = wp_parse_id_list( $_POST['exclude_just_posted'] );
 749          $qs[] = 'exclude=' . implode( ',', $just_posted );
 750      }
 751  
 752      // To get newest activities.
 753      if ( ! empty( $_POST['offset'] ) ) {
 754          $qs[] = 'offset=' . intval( $_POST['offset'] );
 755      }
 756  
 757      $object_search_text = bp_get_search_default_text( $object );
 758      if ( ! empty( $_POST['search_terms'] ) && is_string( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
 759          $qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] );
 760  
 761      // Now pass the querystring to override default values.
 762      $query_string = empty( $qs ) ? '' : join( '&', (array) $qs );
 763  
 764      $object_filter = '';
 765      if ( isset( $_BP_COOKIE['bp-' . $object . '-filter'] ) )
 766          $object_filter = $_BP_COOKIE['bp-' . $object . '-filter'];
 767  
 768      $object_scope = '';
 769      if ( isset( $_BP_COOKIE['bp-' . $object . '-scope'] ) )
 770          $object_scope = $_BP_COOKIE['bp-' . $object . '-scope'];
 771  
 772      $object_page = '';
 773      if ( isset( $_BP_COOKIE['bp-' . $object . '-page'] ) )
 774          $object_page = $_BP_COOKIE['bp-' . $object . '-page'];
 775  
 776      $object_search_terms = '';
 777      if ( isset( $_BP_COOKIE['bp-' . $object . '-search-terms'] ) )
 778          $object_search_terms = $_BP_COOKIE['bp-' . $object . '-search-terms'];
 779  
 780      $object_extras = '';
 781      if ( isset( $_BP_COOKIE['bp-' . $object . '-extras'] ) )
 782          $object_extras = $_BP_COOKIE['bp-' . $object . '-extras'];
 783  
 784      /**
 785       * Filters the AJAX query string for the component loops.
 786       *
 787       * @since 1.7.0
 788       *
 789       * @param string $query_string        The query string we are working with.
 790       * @param string $object              The type of page we are on.
 791       * @param string $object_filter       The current object filter.
 792       * @param string $object_scope        The current object scope.
 793       * @param string $object_page         The current object page.
 794       * @param string $object_search_terms The current object search terms.
 795       * @param string $object_extras       The current object extras.
 796       */
 797      return apply_filters( 'bp_legacy_theme_ajax_querystring', $query_string, $object, $object_filter, $object_scope, $object_page, $object_search_terms, $object_extras );
 798  }
 799  
 800  /**
 801   * Load the template loop for the current object.
 802   *
 803   * @since 1.2.0
 804   *
 805   * @return string|null Prints template loop for the specified object
 806   */
 807  function bp_legacy_theme_object_template_loader() {
 808      if ( ! bp_is_post_request() ) {
 809          return;
 810      }
 811  
 812      // Bail if no object passed.
 813      if ( empty( $_POST['object'] ) ) {
 814          return;
 815      }
 816  
 817      // Sanitize the object.
 818      $object = sanitize_title( $_POST['object'] );
 819  
 820      // Bail if object is not an active component to prevent arbitrary file inclusion.
 821      if ( ! bp_is_active( $object ) ) {
 822          return;
 823      }
 824  
 825      /**
 826       * AJAX requests happen too early to be seen by bp_update_is_directory()
 827       * so we do it manually here to ensure templates load with the correct
 828       * context. Without this check, templates will load the 'single' version
 829       * of themselves rather than the directory version.
 830       */
 831      if ( ! bp_current_action() )
 832          bp_update_is_directory( true, bp_current_component() );
 833  
 834      // The template part can be overridden by the calling JS function.
 835      if ( ! empty( $_POST['template'] ) && 'groups/single/members' === $_POST['template'] ) {
 836          $template_part = 'groups/single/members.php';
 837      } else {
 838          $template_part = $object . '/' . $object . '-loop.php';
 839      }
 840  
 841      $template_path = bp_locate_template( array( $template_part ), false );
 842  
 843      $template_path = apply_filters( 'bp_legacy_object_template_path', $template_path );
 844  
 845      load_template( $template_path );
 846      exit();
 847  }
 848  
 849  /**
 850   * Load messages template loop when searched on the private message page
 851   *
 852   * @since 1.6.0
 853   *
 854   * @return string|null Prints template loop for the Messages component.
 855   */
 856  function bp_legacy_theme_messages_template_loader() {
 857      bp_get_template_part( 'members/single/messages/messages-loop' );
 858      exit();
 859  }
 860  
 861  /**
 862   * Load group invitations loop to handle pagination requests sent via AJAX.
 863   *
 864   * @since 2.0.0
 865   */
 866  function bp_legacy_theme_invite_template_loader() {
 867      bp_get_template_part( 'groups/single/invites-loop' );
 868      exit();
 869  }
 870  
 871  /**
 872   * Load group membership requests loop to handle pagination requests sent via AJAX.
 873   *
 874   * @since 2.0.0
 875   */
 876  function bp_legacy_theme_requests_template_loader() {
 877      bp_get_template_part( 'groups/single/requests-loop' );
 878      exit();
 879  }
 880  
 881  /**
 882   * Load the activity loop template when activity is requested via AJAX.
 883   *
 884   * @since 1.2.0
 885   *
 886   * @return string|null JSON object containing 'contents' (output of the template loop
 887   *                     for the Activity component) and 'feed_url' (URL to the relevant RSS feed).
 888   */
 889  function bp_legacy_theme_activity_template_loader() {
 890      if ( ! bp_is_post_request() ) {
 891          return;
 892      }
 893  
 894      $scope = '';
 895      if ( ! empty( $_POST['scope'] ) )
 896          $scope = $_POST['scope'];
 897  
 898      // We need to calculate and return the feed URL for each scope.
 899      switch ( $scope ) {
 900          case 'friends':
 901              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/friends/feed/';
 902              break;
 903          case 'groups':
 904              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/groups/feed/';
 905              break;
 906          case 'favorites':
 907              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
 908              break;
 909          case 'mentions':
 910              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
 911  
 912              if ( isset( $_POST['_wpnonce_activity_filter'] ) && wp_verify_nonce( wp_unslash( $_POST['_wpnonce_activity_filter'] ), 'activity_filter' ) ) {
 913                  bp_activity_clear_new_mentions( bp_loggedin_user_id() );
 914              }
 915  
 916              break;
 917          default:
 918              $feed_url = home_url( bp_get_activity_root_slug() . '/feed/' );
 919              break;
 920      }
 921  
 922      // Buffer the loop in the template to a var for JS to spit out.
 923      ob_start();
 924      bp_get_template_part( 'activity/activity-loop' );
 925      $result['contents'] = ob_get_contents();
 926  
 927      /**
 928       * Filters the feed URL for when activity is requested via AJAX.
 929       *
 930       * @since 1.7.0
 931       *
 932       * @param string $feed_url URL for the feed to be used.
 933       * @param string $scope    Scope for the activity request.
 934       */
 935      $result['feed_url'] = apply_filters( 'bp_legacy_theme_activity_feed_url', $feed_url, $scope );
 936      ob_end_clean();
 937  
 938      exit( json_encode( $result ) );
 939  }
 940  
 941  /**
 942   * Processes Activity updates received via a POST request.
 943   *
 944   * @since 1.2.0
 945   *
 946   * @return string|null HTML
 947   */
 948  function bp_legacy_theme_post_update() {
 949      $bp = buddypress();
 950  
 951      if ( ! bp_is_post_request() ) {
 952          return;
 953      }
 954  
 955      // Check the nonce.
 956      check_admin_referer( 'post_update', '_wpnonce_post_update' );
 957  
 958      if ( ! is_user_logged_in() )
 959          exit( '-1' );
 960  
 961      if ( empty( $_POST['content'] ) )
 962          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>' );
 963  
 964      $activity_id = 0;
 965      $item_id     = 0;
 966      $object      = '';
 967  
 968  
 969      // Try to get the item id from posted variables.
 970      if ( ! empty( $_POST['item_id'] ) ) {
 971          $item_id = (int) $_POST['item_id'];
 972      }
 973  
 974      // Try to get the object from posted variables.
 975      if ( ! empty( $_POST['object'] ) ) {
 976          $object  = sanitize_key( $_POST['object'] );
 977  
 978      // If the object is not set and we're in a group, set the item id and the object
 979      } elseif ( bp_is_group() ) {
 980          $item_id = bp_get_current_group_id();
 981          $object = 'groups';
 982      }
 983  
 984      if ( ! $object && bp_is_active( 'activity' ) ) {
 985          $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'], 'error_type' => 'wp_error' ) );
 986  
 987      } elseif ( 'groups' === $object ) {
 988          if ( $item_id && bp_is_active( 'groups' ) )
 989              $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id, 'error_type' => 'wp_error' ) );
 990  
 991      } else {
 992  
 993          /** This filter is documented in bp-activity/actions/post.php */
 994          $activity_id = apply_filters( 'bp_activity_custom_update', false, $object, $item_id, $_POST['content'] );
 995      }
 996  
 997      if ( false === $activity_id ) {
 998          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem posting your update. Please try again.', 'buddypress' ) . '</p></div>' );
 999      } elseif ( is_wp_error( $activity_id ) && $activity_id->get_error_code() ) {
1000          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . $activity_id->get_error_message() . '</p></div>' );
1001      }
1002  
1003      $last_recorded = ! empty( $_POST['since'] ) ? date( 'Y-m-d H:i:s', intval( $_POST['since'] ) ) : 0;
1004      if ( $last_recorded ) {
1005          $activity_args = array( 'since' => $last_recorded );
1006          $bp->activity->last_recorded = $last_recorded;
1007          add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
1008      } else {
1009          $activity_args = array( 'include' => $activity_id );
1010      }
1011  
1012      if ( bp_has_activities ( $activity_args ) ) {
1013          while ( bp_activities() ) {
1014              bp_the_activity();
1015              bp_get_template_part( 'activity/entry' );
1016          }
1017      }
1018  
1019      if ( ! empty( $last_recorded ) ) {
1020          remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10 );
1021      }
1022  
1023      exit;
1024  }
1025  
1026  /**
1027   * Posts new Activity comments received via a POST request.
1028   *
1029   * @since 1.2.0
1030   *
1031   * @global BP_Activity_Template $activities_template
1032   *
1033   * @return string|null HTML
1034   */
1035  function bp_legacy_theme_new_activity_comment() {
1036      global $activities_template;
1037  
1038      $bp = buddypress();
1039  
1040      if ( ! bp_is_post_request() ) {
1041          return;
1042      }
1043  
1044      // Check the nonce.
1045      check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
1046  
1047      if ( ! is_user_logged_in() ) {
1048          exit( '-1' );
1049      }
1050  
1051      $feedback = __( 'There was an error posting your reply. Please try again.', 'buddypress' );
1052  
1053      if ( empty( $_POST['content'] ) ) {
1054          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html__( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>' );
1055      }
1056  
1057      if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) ) {
1058          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $feedback ) . '</p></div>' );
1059      }
1060  
1061      $activity_id   = (int) $_POST['form_id'];
1062      $activity_item = new BP_Activity_Activity( $activity_id );
1063      if ( ! bp_activity_user_can_read( $activity_item ) ) {
1064          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $feedback ) . '</p></div>' );
1065      }
1066  
1067      $comment_id = bp_activity_new_comment( array(
1068          'activity_id' => $activity_id,
1069          'content'     => $_POST['content'],
1070          'parent_id'   => $_POST['comment_id'],
1071          'error_type'  => 'wp_error'
1072      ) );
1073  
1074      if ( is_wp_error( $comment_id ) ) {
1075          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $comment_id->get_error_message() ) . '</p></div>' );
1076      }
1077  
1078      // Load the new activity item into the $activities_template global.
1079      bp_has_activities( 'display_comments=stream&hide_spam=false&show_hidden=true&include=' . $comment_id );
1080  
1081      // Swap the current comment with the activity item we just loaded.
1082      if ( isset( $activities_template->activities[0] ) ) {
1083          $activities_template->activity = new stdClass();
1084          $activities_template->activity->id              = $activities_template->activities[0]->item_id;
1085          $activities_template->activity->current_comment = $activities_template->activities[0];
1086  
1087          // Because the whole tree has not been loaded, we manually
1088          // determine depth.
1089          $depth = 1;
1090          $parent_id = (int) $activities_template->activities[0]->secondary_item_id;
1091          while ( $parent_id !== (int) $activities_template->activities[0]->item_id ) {
1092              $depth++;
1093              $p_obj = new BP_Activity_Activity( $parent_id );
1094              $parent_id = (int) $p_obj->secondary_item_id;
1095          }
1096          $activities_template->activity->current_comment->depth = $depth;
1097      }
1098  
1099      // Get activity comment template part.
1100      bp_get_template_part( 'activity/comment' );
1101  
1102      unset( $activities_template );
1103      exit;
1104  }
1105  
1106  /**
1107   * Deletes an Activity item received via a POST request.
1108   *
1109   * @since 1.2.0
1110   *
1111   * @return mixed String on error, void on success.
1112   */
1113  function bp_legacy_theme_delete_activity() {
1114      if ( ! bp_is_post_request() ) {
1115          return;
1116      }
1117  
1118      // Check the nonce.
1119      check_admin_referer( 'bp_activity_delete_link' );
1120  
1121      if ( ! is_user_logged_in() )
1122          exit( '-1' );
1123  
1124      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
1125          exit( '-1' );
1126  
1127      $activity = new BP_Activity_Activity( (int) $_POST['id'] );
1128  
1129      // Check access.
1130      if ( ! bp_activity_user_can_delete( $activity ) )
1131          exit( '-1' );
1132  
1133      /** This action is documented in bp-activity/bp-activity-actions.php */
1134      do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id );
1135  
1136      if ( ! bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) )
1137          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
1138  
1139      /** This action is documented in bp-activity/bp-activity-actions.php */
1140      do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
1141      exit;
1142  }
1143  
1144  /**
1145   * Deletes an Activity comment received via a POST request.
1146   *
1147   * @since 1.2.0
1148   *
1149   * @return mixed String on error, void on success.
1150   */
1151  function bp_legacy_theme_delete_activity_comment() {
1152      if ( ! bp_is_post_request() ) {
1153          return;
1154      }
1155  
1156      // Check the nonce.
1157      check_admin_referer( 'bp_activity_delete_link' );
1158  
1159      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) ) {
1160          exit( '-1' );
1161      }
1162  
1163      if ( ! is_user_logged_in() ) {
1164          exit( '-1' );
1165      }
1166  
1167      $comment = new BP_Activity_Activity( $_POST['id'] );
1168  
1169      // Check access.
1170      if ( ! bp_current_user_can( 'bp_moderate' ) && $comment->user_id != bp_loggedin_user_id() )
1171          exit( '-1' );
1172  
1173      /** This action is documented in bp-activity/bp-activity-actions.php */
1174      do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $comment->user_id );
1175  
1176      if ( ! bp_activity_delete_comment( $comment->item_id, $comment->id ) )
1177          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
1178  
1179      /** This action is documented in bp-activity/bp-activity-actions.php */
1180      do_action( 'bp_activity_action_delete_activity', $_POST['id'], $comment->user_id );
1181      exit;
1182  }
1183  
1184  /**
1185   * AJAX spam an activity item or comment.
1186   *
1187   * @since 1.6.0
1188   *
1189   * @return mixed String on error, void on success.
1190   */
1191  function bp_legacy_theme_spam_activity() {
1192      $bp = buddypress();
1193  
1194      if ( ! bp_is_post_request() ) {
1195          return;
1196      }
1197  
1198      // Check that user is logged in, Activity Streams are enabled, and Akismet is present.
1199      if ( ! is_user_logged_in() || ! bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) )
1200          exit( '-1' );
1201  
1202      // Check an item ID was passed.
1203      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
1204          exit( '-1' );
1205  
1206      // Is the current user allowed to spam items?
1207      if ( ! bp_activity_user_can_mark_spam() )
1208          exit( '-1' );
1209  
1210      // Load up the activity item.
1211      $activity = new BP_Activity_Activity( (int) $_POST['id'] );
1212      if ( empty( $activity->component ) )
1213          exit( '-1' );
1214  
1215      // Check nonce.
1216      check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
1217  
1218      /** This action is documented in bp-activity/bp-activity-actions.php */
1219      do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
1220  
1221      // Mark as spam.
1222      bp_activity_mark_as_spam( $activity );
1223      $activity->save();
1224  
1225      /** This action is documented in bp-activity/bp-activity-actions.php */
1226      do_action( 'bp_activity_action_spam_activity', $activity->id, $activity->user_id );
1227      exit;
1228  }
1229  
1230  /**
1231   * Mark an activity as a favourite via a POST request.
1232   *
1233   * @since 1.2.0
1234   *
1235   * @return string|null HTML
1236   */
1237  function bp_legacy_theme_mark_activity_favorite() {
1238      // Bail if not a POST action.
1239      if ( ! bp_is_post_request() ) {
1240          return;
1241      }
1242  
1243      if ( ! isset( $_POST['nonce'] ) ) {
1244          return;
1245      }
1246  
1247      // Either the 'mark' or 'unmark' nonce is accepted, for backward compatibility.
1248      $nonce = wp_unslash( $_POST['nonce'] );
1249      if ( ! wp_verify_nonce( $nonce, 'mark_favorite' ) && ! wp_verify_nonce( $nonce, 'unmark_favorite' ) ) {
1250          return;
1251      }
1252  
1253      $activity_id   = (int) $_POST['id'];
1254      $activity_item = new BP_Activity_Activity( $activity_id );
1255      if ( ! bp_activity_user_can_read( $activity_item, bp_loggedin_user_id() ) ) {
1256          return;
1257      }
1258  
1259      if ( bp_activity_add_user_favorite( $_POST['id'] ) )
1260          _e( 'Remove Favorite', 'buddypress' );
1261      else
1262          _e( 'Favorite', 'buddypress' );
1263  
1264      exit;
1265  }
1266  
1267  /**
1268   * Un-favourite an activity via a POST request.
1269   *
1270   * @since 1.2.0
1271   *
1272   * @return string|null HTML
1273   */
1274  function bp_legacy_theme_unmark_activity_favorite() {
1275      if ( ! bp_is_post_request() ) {
1276          return;
1277      }
1278  
1279      if ( ! isset( $_POST['nonce'] ) ) {
1280          return;
1281      }
1282  
1283      // Either the 'mark' or 'unmark' nonce is accepted, for backward compatibility.
1284      $nonce = wp_unslash( $_POST['nonce'] );
1285      if ( ! wp_verify_nonce( $nonce, 'mark_favorite' ) && ! wp_verify_nonce( $nonce, 'unmark_favorite' ) ) {
1286          return;
1287      }
1288  
1289      if ( bp_activity_remove_user_favorite( $_POST['id'] ) )
1290          _e( 'Favorite', 'buddypress' );
1291      else
1292          _e( 'Remove Favorite', 'buddypress' );
1293  
1294      exit;
1295  }
1296  
1297  /**
1298   * Fetches an activity's full, non-excerpted content via a POST request.
1299   * Used for the 'Read More' link on long activity items.
1300   *
1301   * @since 1.5.0
1302   *
1303   * @return string|null HTML
1304   */
1305  function bp_legacy_theme_get_single_activity_content() {
1306      if ( ! bp_is_post_request() ) {
1307          return;
1308      }
1309  
1310      $activity_array = bp_activity_get_specific( array(
1311          'activity_ids'     => $_POST['activity_id'],
1312          'display_comments' => 'stream'
1313      ) );
1314  
1315      $activity = ! empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
1316  
1317      if ( empty( $activity ) )
1318          exit; // @todo: error?
1319  
1320      /**
1321       * Fires before the return of an activity's full, non-excerpted content via a POST request.
1322       *
1323       * @since 1.7.0
1324       *
1325       * @param string $activity Activity content. Passed by reference.
1326       */
1327      do_action_ref_array( 'bp_legacy_theme_get_single_activity_content', array( &$activity ) );
1328  
1329      // Activity content retrieved through AJAX should run through normal filters, but not be truncated.
1330      remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
1331  
1332      /** This filter is documented in bp-activity/bp-activity-template.php */
1333      $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $activity->content, &$activity ) );
1334  
1335      exit( $content );
1336  }
1337  
1338  /**
1339   * Invites a friend to join a group via a POST request.
1340   *
1341   * @since 1.2.0
1342   *
1343   * @todo Audit return types
1344   */
1345  function bp_legacy_theme_ajax_invite_user() {
1346      if ( ! bp_is_post_request() ) {
1347          return;
1348      }
1349  
1350      check_ajax_referer( 'groups_invite_uninvite_user' );
1351  
1352      if ( ! $_POST['friend_id'] || ! $_POST['friend_action'] || ! $_POST['group_id'] )
1353          return;
1354  
1355      if ( ! bp_groups_user_can_send_invites( $_POST['group_id'] ) )
1356          return;
1357  
1358      $group_id = (int) $_POST['group_id'];
1359      $friend_id = (int) $_POST['friend_id'];
1360  
1361      if ( 'invite' == $_POST['friend_action'] ) {
1362          if ( ! friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) ) {
1363              return;
1364          }
1365  
1366          $group = groups_get_group( $group_id );
1367  
1368          // Users who have previously requested membership do not need
1369          // another invitation created for them.
1370          if ( groups_check_for_membership_request( $friend_id, $group_id ) ) {
1371              $user_status = 'is_pending';
1372  
1373          // Create the user invitation.
1374          } elseif ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) {
1375              $user_status = 'is_invited';
1376  
1377          // Miscellaneous failure.
1378          } else {
1379              return;
1380          }
1381  
1382          $user = new BP_Core_User( $friend_id );
1383  
1384          $uninvite_url = bp_is_current_action( 'create' )
1385              ? bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $friend_id
1386              : bp_get_group_permalink( $group )    . 'send-invites/remove/' . $friend_id;
1387  
1388          echo '<li id="uid-' . esc_attr( $user->id ) . '">';
1389          echo $user->avatar_thumb;
1390          echo '<h4>' . $user->user_link . '</h4>';
1391          echo '<span class="activity">' . esc_attr( $user->last_active ) . '</span>';
1392          echo '<div class="action">
1393                  <a class="button remove" href="' . wp_nonce_url( $uninvite_url, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', 'buddypress' ) . '</a>
1394                </div>';
1395  
1396          if ( 'is_pending' == $user_status ) {
1397              /* translators: %s: user link */
1398              echo '<p class="description">' . sprintf( __( '%s has previously requested to join this group. Sending an invitation will automatically add the member to the group.', 'buddypress' ), $user->user_link ) . '</p>';
1399          }
1400  
1401          echo '</li>';
1402          exit;
1403  
1404      } elseif ( 'uninvite' == $_POST['friend_action'] ) {
1405          // Users who have previously requested membership should not
1406          // have their requests deleted on the "uninvite" action.
1407          if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
1408              return;
1409          }
1410  
1411          // Remove the unsent invitation.
1412          if ( ! groups_uninvite_user( $friend_id, $group_id ) ) {
1413              return;
1414          }
1415  
1416          exit;
1417  
1418      } else {
1419          return;
1420      }
1421  }
1422  
1423  /**
1424   * Friend/un-friend a user via a POST request.
1425   *
1426   * @since 1.2.0
1427   *
1428   * @return string|null HTML
1429   */
1430  function bp_legacy_theme_ajax_addremove_friend() {
1431      if ( ! bp_is_post_request() ) {
1432          return;
1433      }
1434  
1435      // Cast fid as an integer.
1436      $friend_id = (int) $_POST['fid'];
1437  
1438      $user = get_user_by( 'id', $friend_id );
1439      if ( ! $user ) {
1440          die( __( 'No member found by that ID.', 'buddypress' ) );
1441      }
1442  
1443      // Trying to cancel friendship.
1444      if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1445          check_ajax_referer( 'friends_remove_friend' );
1446  
1447          if ( ! friends_remove_friend( bp_loggedin_user_id(), $friend_id ) ) {
1448              echo __( 'Friendship could not be canceled.', 'buddypress' );
1449          } else {
1450              echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="friendship-button not_friends add" rel="add" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
1451          }
1452  
1453      // Trying to request friendship.
1454      } elseif ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1455          check_ajax_referer( 'friends_add_friend' );
1456  
1457          if ( ! friends_add_friend( bp_loggedin_user_id(), $friend_id ) ) {
1458              echo __(' Friendship could not be requested.', 'buddypress' );
1459          } else {
1460              echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="remove friendship-button pending_friend requested" rel="remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $friend_id . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
1461          }
1462  
1463      // Trying to cancel pending request.
1464      } elseif ( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1465          check_ajax_referer( 'friends_withdraw_friendship' );
1466  
1467          if ( friends_withdraw_friendship( bp_loggedin_user_id(), $friend_id ) ) {
1468              echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="friendship-button not_friends add" rel="add" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
1469          } else {
1470              echo __("Friendship request could not be cancelled.", 'buddypress');
1471          }
1472  
1473      // Request already pending.
1474      } else {
1475          echo __( 'Request Pending', 'buddypress' );
1476      }
1477  
1478      exit;
1479  }
1480  
1481  /**
1482   * Accept a user friendship request via a POST request.
1483   *
1484   * @since 1.2.0
1485   *
1486   * @return mixed String on error, void on success.
1487   */
1488  function bp_legacy_theme_ajax_accept_friendship() {
1489      if ( ! bp_is_post_request() ) {
1490          return;
1491      }
1492  
1493      check_admin_referer( 'friends_accept_friendship' );
1494  
1495      if ( ! friends_accept_friendship( (int) $_POST['id'] ) )
1496          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem accepting that request. Please try again.', 'buddypress' ) . '</p></div>';
1497  
1498      exit;
1499  }
1500  
1501  /**
1502   * Reject a user friendship request via a POST request.
1503   *
1504   * @since 1.2.0
1505   *
1506   * @return mixed String on error, void on success.
1507   */
1508  function bp_legacy_theme_ajax_reject_friendship() {
1509      if ( ! bp_is_post_request() ) {
1510          return;
1511      }
1512  
1513      check_admin_referer( 'friends_reject_friendship' );
1514  
1515      if ( ! friends_reject_friendship( (int) $_POST['id'] ) )
1516          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem rejecting that request. Please try again.', 'buddypress' ) . '</p></div>';
1517  
1518      exit;
1519  }
1520  
1521  /**
1522   * Join or leave a group when clicking the "join/leave" button via a POST request.
1523   *
1524   * @since 1.2.0
1525   *
1526   * @return string|null HTML
1527   */
1528  function bp_legacy_theme_ajax_joinleave_group() {
1529      if ( ! bp_is_post_request() ) {
1530          return;
1531      }
1532  
1533      // Cast gid as integer.
1534      $group_id = (int) $_POST['gid'];
1535  
1536      if ( groups_is_user_banned( bp_loggedin_user_id(), $group_id ) )
1537          return;
1538  
1539      if ( ! $group = groups_get_group( $group_id ) )
1540          return;
1541  
1542      // Client doesn't distinguish between different request types, so we infer from user status.
1543      if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
1544          $request_type = 'leave_group';
1545      } elseif ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) {
1546          $request_type = 'accept_invite';
1547      } elseif ( 'private' === $group->status ) {
1548          $request_type = 'request_membership';
1549      } else {
1550          $request_type = 'join_group';
1551      }
1552  
1553      switch ( $request_type ) {
1554          case 'join_group' :
1555              if ( ! bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) {
1556                  esc_html_e( 'Error joining group', 'buddypress' );
1557              }
1558  
1559              check_ajax_referer( 'groups_join_group' );
1560  
1561              if ( ! groups_join_group( $group->id ) ) {
1562                  _e( 'Error joining group', 'buddypress' );
1563              } else {
1564                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
1565              }
1566          break;
1567  
1568          case 'accept_invite' :
1569              if ( ! bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) {
1570                  esc_html_e( 'Error accepting invitation', 'buddypress' );
1571              }
1572  
1573              check_ajax_referer( 'groups_accept_invite' );
1574  
1575              if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) {
1576                  _e( 'Error requesting membership', 'buddypress' );
1577              } else {
1578                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
1579              }
1580          break;
1581  
1582          case 'request_membership' :
1583              check_ajax_referer( 'groups_request_membership' );
1584  
1585              if ( ! groups_send_membership_request( [ 'user_id' => bp_loggedin_user_id(), 'group_id' => $group->id ] ) ) {
1586                  _e( 'Error requesting membership', 'buddypress' );
1587              } else {
1588                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button disabled pending membership-requested" rel="membership-requested" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Request Sent', 'buddypress' ) . '</a>';
1589              }
1590          break;
1591  
1592          case 'leave_group' :
1593              check_ajax_referer( 'groups_leave_group' );
1594  
1595              if ( ! groups_leave_group( $group->id ) ) {
1596                  _e( 'Error leaving group', 'buddypress' );
1597              } elseif ( 'public' === $group->status ) {
1598                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button join-group" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>';
1599              } else {
1600                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button request-membership" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>';
1601              }
1602          break;
1603      }
1604  
1605      exit;
1606  }
1607  
1608  /**
1609   * Close and keep closed site wide notices from an admin in the sidebar, via a POST request.
1610   *
1611   * @since 1.2.0
1612   *
1613   * @return mixed String on error, void on success.
1614   */
1615  function bp_legacy_theme_ajax_close_notice() {
1616      if ( ! bp_is_post_request() ) {
1617          return;
1618      }
1619  
1620      $nonce_check = isset( $_POST['nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['nonce'] ), 'bp_messages_close_notice' );
1621  
1622      if ( ! $nonce_check || ! isset( $_POST['notice_id'] ) ) {
1623          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem closing the notice.', 'buddypress' ) . '</p></div>';
1624  
1625      } else {
1626          $user_id    = get_current_user_id();
1627          $notice_ids = bp_get_user_meta( $user_id, 'closed_notices', true );
1628          if ( ! is_array( $notice_ids ) ) {
1629              $notice_ids = array();
1630          }
1631  
1632          $notice_ids[] = (int) $_POST['notice_id'];
1633  
1634          bp_update_user_meta( $user_id, 'closed_notices', $notice_ids );
1635      }
1636  
1637      exit;
1638  }
1639  
1640  /**
1641   * Send a private message reply to a thread via a POST request.
1642   *
1643   * @since 1.2.0
1644   *
1645   * @return string|null HTML
1646   */
1647  function bp_legacy_theme_ajax_messages_send_reply() {
1648      if ( ! bp_is_post_request() ) {
1649          return;
1650      }
1651  
1652      check_ajax_referer( 'messages_send_message' );
1653  
1654      $thread_id = (int) $_POST['thread_id'];
1655  
1656      // Cannot respond to a thread you're not already a recipient on.
1657      if ( ! bp_current_user_can( 'bp_moderate' ) && ( ! messages_is_valid_thread( $thread_id ) || ! messages_check_thread_access( $thread_id ) ) ) {
1658          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>';
1659          die;
1660      }
1661  
1662      $result = messages_new_message( array( 'thread_id' => $thread_id, 'content' => $_REQUEST['content'] ) );
1663  
1664      if ( !empty( $result ) ) {
1665  
1666          // Pretend we're in the message loop.
1667          global $thread_template;
1668  
1669          bp_thread_has_messages( array( 'thread_id' => $thread_id ) );
1670  
1671          // Set the current message to the 2nd last.
1672          $thread_template->message = end( $thread_template->thread->messages );
1673          $thread_template->message = prev( $thread_template->thread->messages );
1674  
1675          // Set current message to current key.
1676          $thread_template->current_message = key( $thread_template->thread->messages );
1677  
1678          // Now manually iterate message like we're in the loop.
1679          bp_thread_the_message();
1680  
1681          // Manually call oEmbed
1682          // this is needed because we're not at the beginning of the loop.
1683          bp_messages_embed();
1684  
1685          // Add new-message css class.
1686          add_filter( 'bp_get_the_thread_message_css_class', function( $retval ) {
1687              $retval[] = 'new-message';
1688              return $retval;
1689          } );
1690  
1691          // Output single message template part.
1692          bp_get_template_part( 'members/single/messages/message' );
1693  
1694          // Clean up the loop.
1695          bp_thread_messages();
1696  
1697      } else {
1698          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>';
1699      }
1700  
1701      exit;
1702  }
1703  
1704  /**
1705   * Mark a private message as unread in your inbox via a POST request.
1706   *
1707   * No longer used.
1708   *
1709   * @since 1.2.0
1710   * @deprecated 2.2.0
1711   *
1712   * @return mixed String on error, void on success.
1713   */
1714  function bp_legacy_theme_ajax_message_markunread() {
1715      die( '-1' );
1716  }
1717  
1718  /**
1719   * Mark a private message as read in your inbox via a POST request.
1720   *
1721   * No longer used.
1722   *
1723   * @since 1.2.0
1724   * @deprecated 2.2.0
1725   *
1726   * @return mixed String on error, void on success.
1727   */
1728  function bp_legacy_theme_ajax_message_markread() {
1729      die( '-1' );
1730  }
1731  
1732  /**
1733   * Delete a private message(s) in your inbox via a POST request.
1734   *
1735   * No longer used.
1736   *
1737   * @since 1.2.0
1738   * @deprecated 2.2.0
1739   *
1740   * @return string|null HTML
1741   */
1742  function bp_legacy_theme_ajax_messages_delete() {
1743      die( '-1' );
1744  }
1745  
1746  /**
1747   * AJAX handler for autocomplete.
1748   *
1749   * Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.
1750   *
1751   * @since 1.2.0
1752   */
1753  function bp_legacy_theme_ajax_messages_autocomplete_results() {
1754  
1755      /**
1756       * Filters the max results default value for ajax messages autocomplete results.
1757       *
1758       * @since 1.5.0
1759       *
1760       * @param int $value Max results for autocomplete. Default 10.
1761       */
1762      $limit = isset( $_GET['limit'] ) ? absint( $_GET['limit'] )          : (int) apply_filters( 'bp_autocomplete_max_results', 10 );
1763      $term  = isset( $_GET['q'] )     ? sanitize_text_field( $_GET['q'] ) : '';
1764  
1765      // Include everyone in the autocomplete, or just friends?
1766      if ( bp_is_current_component( bp_get_messages_slug() ) ) {
1767          $only_friends = ( buddypress()->messages->autocomplete_all === false );
1768      } else {
1769          $only_friends = true;
1770      }
1771  
1772      $suggestions = bp_core_get_suggestions( array(
1773          'limit'        => $limit,
1774          'only_friends' => $only_friends,
1775          'term'         => $term,
1776          'type'         => 'members',
1777      ) );
1778  
1779      if ( $suggestions && ! is_wp_error( $suggestions ) ) {
1780          foreach ( $suggestions as $user ) {
1781  
1782              // Note that the final line break acts as a delimiter for the
1783              // autocomplete JavaScript and thus should not be removed.
1784              printf( '<span id="%s" href="#"></span><img src="%s" style="width: 15px"> &nbsp; %s (%s)' . "\n",
1785                  esc_attr( 'link-' . $user->ID ),
1786                  esc_url( $user->image ),
1787                  esc_html( $user->name ),
1788                  esc_html( $user->ID )
1789              );
1790          }
1791      }
1792  
1793      exit;
1794  }
1795  
1796  /**
1797   * AJAX callback to set a message's star status.
1798   *
1799   * @since 2.3.0
1800   */
1801  function bp_legacy_theme_ajax_messages_star_handler() {
1802      if ( false === bp_is_active( 'messages', 'star' ) || empty( $_POST['message_id'] ) ) {
1803          return;
1804      }
1805  
1806      // Check nonce.
1807      check_ajax_referer( 'bp-messages-star-' . (int) $_POST['message_id'], 'nonce' );
1808  
1809      // Check capability.
1810      if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) {
1811          return;
1812      }
1813  
1814      if ( true === bp_messages_star_set_action( array(
1815          'action'     => $_POST['star_status'],
1816          'message_id' => (int) $_POST['message_id'],
1817          'bulk'       => ! empty( $_POST['bulk'] ) ? true : false
1818       ) ) ) {
1819          echo '1';
1820          die();
1821      }
1822  
1823      echo '-1';
1824      die();
1825  }
1826  
1827  /**
1828   * BP Legacy's callback for the cover image feature.
1829   *
1830   * @since  2.4.0
1831   *
1832   * @param  array $params the current component's feature parameters.
1833   * @return null|string An array to inform about the css handle to attach the css rules to
1834   */
1835  function bp_legacy_theme_cover_image( $params = array() ) {
1836      if ( empty( $params ) ) {
1837          return;
1838      }
1839  
1840      // Avatar height - padding - 1/2 avatar height.
1841      $avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 );
1842  
1843      // Header content offset + spacing.
1844      $top_offset  = bp_core_avatar_full_height() - 10;
1845      $left_offset = bp_core_avatar_full_width() + 20;
1846  
1847      $cover_image = ( !empty( $params['cover_image'] ) ) ? 'background-image: url(' . $params['cover_image'] . ');' : '';
1848  
1849      $hide_avatar_style = '';
1850  
1851      // Adjust the cover image header, in case avatars are completely disabled.
1852      if ( ! buddypress()->avatar->show_avatars ) {
1853          $hide_avatar_style = '
1854              #buddypress #item-header-cover-image #item-header-avatar {
1855                  display:  none;
1856              }
1857          ';
1858  
1859          if ( bp_is_user() ) {
1860              $hide_avatar_style = '
1861                  #buddypress #item-header-cover-image #item-header-avatar a {
1862                      display: block;
1863                      height: ' . $top_offset . 'px;
1864                      margin: 0 15px 19px 0;
1865                  }
1866  
1867                  #buddypress div#item-header #item-header-cover-image #item-header-content {
1868                      margin-left: auto;
1869                  }
1870              ';
1871          }
1872      }
1873  
1874      return '
1875          /* Cover image */
1876          #buddypress #header-cover-image {
1877              height: ' . $params["height"] . 'px;
1878              ' . $cover_image . '
1879          }
1880  
1881          #buddypress #create-group-form #header-cover-image {
1882              margin: 1em 0;
1883              position: relative;
1884          }
1885  
1886          .bp-user #buddypress #item-header {
1887              padding-top: 0;
1888          }
1889  
1890          #buddypress #item-header-cover-image #item-header-avatar {
1891              margin-top: '. $avatar_offset .'px;
1892              float: left;
1893              overflow: visible;
1894              width: auto;
1895          }
1896  
1897          #buddypress div#item-header #item-header-cover-image #item-header-content {
1898              clear: both;
1899              float: left;
1900              margin-left: ' . $left_offset . 'px;
1901              margin-top: -' . $top_offset . 'px;
1902              width: auto;
1903          }
1904  
1905          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1906          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1907              clear: none;
1908              margin-top: ' . $params["height"] . 'px;
1909              margin-left: 0;
1910              max-width: 50%;
1911          }
1912  
1913          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1914              max-width: 20%;
1915              padding-top: 20px;
1916          }
1917  
1918          ' . $hide_avatar_style . '
1919  
1920          #buddypress div#item-header-cover-image .user-nicename a,
1921          #buddypress div#item-header-cover-image .user-nicename {
1922              font-size: 200%;
1923              color: #fff;
1924              margin: 0 0 0.6em;
1925              text-rendering: optimizelegibility;
1926              text-shadow: 0 0 3px rgba( 0, 0, 0, 0.8 );
1927          }
1928  
1929          #buddypress #item-header-cover-image #item-header-avatar img.avatar {
1930              background: rgba( 255, 255, 255, 0.8 );
1931              border: solid 2px #fff;
1932          }
1933  
1934          #buddypress #item-header-cover-image #item-header-avatar a {
1935              border: 0;
1936              text-decoration: none;
1937          }
1938  
1939          #buddypress #item-header-cover-image #item-buttons {
1940              margin: 0 0 10px;
1941              padding: 0 0 5px;
1942          }
1943  
1944          #buddypress #item-header-cover-image #item-buttons:after {
1945              clear: both;
1946              content: "";
1947              display: table;
1948          }
1949  
1950          @media screen and (max-width: 782px) {
1951              #buddypress #item-header-cover-image #item-header-avatar,
1952              .bp-user #buddypress #item-header #item-header-cover-image #item-header-avatar,
1953              #buddypress div#item-header #item-header-cover-image #item-header-content {
1954                  width: 100%;
1955                  text-align: center;
1956              }
1957  
1958              #buddypress #item-header-cover-image #item-header-avatar a {
1959                  display: inline-block;
1960              }
1961  
1962              #buddypress #item-header-cover-image #item-header-avatar img {
1963                  margin: 0;
1964              }
1965  
1966              #buddypress div#item-header #item-header-cover-image #item-header-content,
1967              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1968              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1969                  margin: 0;
1970              }
1971  
1972              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1973              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1974                  max-width: 100%;
1975              }
1976  
1977              #buddypress div#item-header-cover-image h2 a,
1978              #buddypress div#item-header-cover-image h2 {
1979                  color: inherit;
1980                  text-shadow: none;
1981                  margin: 25px 0 0;
1982                  font-size: 200%;
1983              }
1984  
1985              #buddypress #item-header-cover-image #item-buttons div {
1986                  float: none;
1987                  display: inline-block;
1988              }
1989  
1990              #buddypress #item-header-cover-image #item-buttons:before {
1991                  content: "";
1992              }
1993  
1994              #buddypress #item-header-cover-image #item-buttons {
1995                  margin: 5px 0;
1996              }
1997          }
1998      ';
1999  }
2000  
2001  /**
2002   * Add a search box to a single group's manage members screen.
2003   *
2004   * @since 2.7.0
2005   *
2006   * @return string|null HTML for the search form.
2007   */
2008  function bp_legacy_theme_group_manage_members_add_search() {
2009      if ( bp_is_action_variable( 'manage-members' ) ) :
2010          ?>
2011          <div id="members-dir-search" class="dir-search no-ajax" role="search">
2012              <?php bp_directory_members_search_form(); ?>
2013          </div>
2014          <?php
2015      endif;
2016  }


Generated: Thu Jul 2 01:01:34 2020 Cross-referenced by PHPXref 0.7.1