[ 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' ) && ! bp_is_widget_block_active( 'bp/sitewide-notices', '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() || is_admin() ) {
 494              return;
 495          }
 496  
 497          // Add a class to determine if the admin bar is on or not.
 498          $class = did_action( 'admin_bar_menu' ) ? 'admin-bar-on' : 'admin-bar-off';
 499  
 500          echo '<div id="sitewide-notice" class="' . $class . '">';
 501          bp_message_get_notices();
 502          echo '</div>';
 503      }
 504  
 505      /**
 506       * Add secondary avatar image to this activity stream's record, if supported.
 507       *
 508       * @since 1.7.0
 509       *
 510       * @param string               $action   The text of this activity.
 511       * @param BP_Activity_Activity $activity Activity object.
 512       * @return string
 513       */
 514  	function secondary_avatars( $action, $activity ) {
 515          switch ( $activity->component ) {
 516              case 'groups' :
 517              case 'friends' :
 518                  // Only insert avatar if one exists.
 519                  if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) {
 520                      $reverse_content = strrev( $action );
 521                      $position        = strpos( $reverse_content, 'a<' );
 522                      $action          = substr_replace( $action, $secondary_avatar, -$position - 2, 0 );
 523                  }
 524                  break;
 525          }
 526  
 527          return $action;
 528      }
 529  
 530      /**
 531       * Filter the default theme compatibility root template hierarchy, and prepend
 532       * a page template to the front if it's set.
 533       *
 534       * @see https://buddypress.trac.wordpress.org/ticket/6065
 535       *
 536       * @since 2.2.0
 537       *
 538       * @param  array $templates Array of templates.
 539       *                         to use the defined page template for component's directory and its single items
 540       * @return array
 541       */
 542  	public function theme_compat_page_templates( $templates = array() ) {
 543  
 544          /**
 545           * Filters whether or not we are looking at a directory to determine if to return early.
 546           *
 547           * @since 2.2.0
 548           *
 549           * @param bool $value Whether or not we are viewing a directory.
 550           */
 551          if ( true === (bool) apply_filters( 'bp_legacy_theme_compat_page_templates_directory_only', ! bp_is_directory() ) ) {
 552              return $templates;
 553          }
 554  
 555          // No page ID yet.
 556          $page_id = 0;
 557  
 558          // Get the WordPress Page ID for the current view.
 559          foreach ( (array) buddypress()->pages as $component => $bp_page ) {
 560  
 561              // Handles the majority of components.
 562              if ( bp_is_current_component( $component ) ) {
 563                  $page_id = (int) $bp_page->id;
 564              }
 565  
 566              // Stop if not on a user page.
 567              if ( ! bp_is_user() && ! empty( $page_id ) ) {
 568                  break;
 569              }
 570  
 571              // The Members component requires an explicit check due to overlapping components.
 572              if ( bp_is_user() && ( 'members' === $component ) ) {
 573                  $page_id = (int) $bp_page->id;
 574                  break;
 575              }
 576          }
 577  
 578          // Bail if no directory page set.
 579          if ( 0 === $page_id ) {
 580              return $templates;
 581          }
 582  
 583          // Check for page template.
 584          $page_template = get_page_template_slug( $page_id );
 585  
 586          // Add it to the beginning of the templates array so it takes precedence
 587          // over the default hierarchy.
 588          if ( ! empty( $page_template ) ) {
 589  
 590              /**
 591               * Check for existence of template before adding it to template
 592               * stack to avoid accidentally including an unintended file.
 593               *
 594               * @see: https://buddypress.trac.wordpress.org/ticket/6190
 595               */
 596              if ( '' !== locate_template( $page_template ) ) {
 597                  array_unshift( $templates, $page_template );
 598              }
 599          }
 600  
 601          return $templates;
 602      }
 603  }
 604  new BP_Legacy();
 605  endif;
 606  
 607  /**
 608   * Add the Create a Group button to the Groups directory title.
 609   *
 610   * The bp-legacy puts the Create a Group button into the page title, to mimic
 611   * the behavior of bp-default.
 612   *
 613   * @since 2.0.0
 614   * @todo Deprecate
 615   *
 616   * @param string $title Groups directory title.
 617   * @return string
 618   */
 619  function bp_legacy_theme_group_create_button( $title ) {
 620      return $title . ' ' . bp_get_group_create_button();
 621  }
 622  
 623  /**
 624   * Add the Create a Group nav to the Groups directory navigation.
 625   *
 626   * The bp-legacy puts the Create a Group nav at the last position of
 627   * the Groups directory navigation.
 628   *
 629   * @since 2.2.0
 630   *
 631   */
 632  function bp_legacy_theme_group_create_nav() {
 633      bp_group_create_nav_item();
 634  }
 635  
 636  /**
 637   * Renders the group ID hidden input on group admin screens.
 638   *
 639   * @since 2.7.0
 640   *
 641   * @return string|null html
 642   */
 643  function bp_legacy_groups_admin_screen_hidden_input() {
 644      ?>
 645       <input type="hidden" name="group-id" id="group-id" value="<?php bp_group_id(); ?>" />
 646      <?php
 647  }
 648  
 649  /**
 650   * Add the Create a Site button to the Sites directory title.
 651   *
 652   * The bp-legacy puts the Create a Site button into the page title, to mimic
 653   * the behavior of bp-default.
 654   *
 655   * @since 2.0.0
 656   * @todo Deprecate
 657   *
 658   * @param string $title Sites directory title.
 659   * @return string
 660   */
 661  function bp_legacy_theme_blog_create_button( $title ) {
 662      return $title . ' ' . bp_get_blog_create_button();
 663  }
 664  
 665  /**
 666   * Add the Create a Site nav to the Sites directory navigation.
 667   *
 668   * The bp-legacy puts the Create a Site nav at the last position of
 669   * the Sites directory navigation.
 670   *
 671   * @since 2.2.0
 672   *
 673   */
 674  function bp_legacy_theme_blog_create_nav() {
 675      bp_blog_create_nav_item();
 676  }
 677  
 678  /**
 679   * This function looks scarier than it actually is. :)
 680   * Each object loop (activity/members/groups/blogs/forums) contains default
 681   * parameters to show specific information based on the page we are currently
 682   * looking at.
 683   *
 684   * The following function will take into account any cookies set in the JS and
 685   * allow us to override the parameters sent. That way we can change the results
 686   * returned without reloading the page.
 687   *
 688   * By using cookies we can also make sure that user settings are retained
 689   * across page loads.
 690   *
 691   * @since 1.2.0
 692   *
 693   * @param string $query_string Query string for the current request.
 694   * @param string $object       Object for cookie.
 695   * @return string Query string for the component loops.
 696   */
 697  function bp_legacy_theme_ajax_querystring( $query_string, $object ) {
 698      if ( empty( $object ) )
 699          return '';
 700  
 701      // Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts.
 702      if ( ! empty( $_POST['cookie'] ) ) {
 703          $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) );
 704      } else {
 705          $_BP_COOKIE = &$_COOKIE;
 706      }
 707  
 708      $qs = array();
 709  
 710      /**
 711       * Check if any cookie values are set. If there are then override the
 712       * default params passed to the template loop.
 713       */
 714  
 715      // Activity stream filtering on action.
 716      if ( ! empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
 717          $qs[] = 'type=' . urlencode( $_BP_COOKIE['bp-' . $object . '-filter'] );
 718  
 719          if ( bp_is_active( 'activity' ) ) {
 720              $actions = bp_activity_get_actions_for_context();
 721  
 722              // Handle multiple actions (eg. 'friendship_accepted,friendship_created')
 723              $action_filter = explode( ',', $_BP_COOKIE['bp-' . $object . '-filter'] );
 724  
 725              // See if action filter matches registered actions. If so, add it to qs.
 726              if ( ! array_diff( $action_filter, wp_list_pluck( $actions, 'key' ) ) ) {
 727                  $qs[] = 'action=' . join( ',', $action_filter );
 728              }
 729          }
 730      }
 731  
 732      if ( ! empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {
 733          if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) {
 734              $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
 735              $qs[] = 'user_id=' . $user_id;
 736          }
 737  
 738          // Activity stream scope only on activity directory.
 739          if ( 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() )
 740              $qs[] = 'scope=' . urlencode( $_BP_COOKIE['bp-' . $object . '-scope'] );
 741      }
 742  
 743      // If page and search_terms have been passed via the AJAX post request, use those.
 744      if ( ! empty( $_POST['page'] ) && '-1' != $_POST['page'] )
 745          $qs[] = 'page=' . absint( $_POST['page'] );
 746  
 747      // Excludes activity just posted and avoids duplicate ids.
 748      if ( ! empty( $_POST['exclude_just_posted'] ) ) {
 749          $just_posted = wp_parse_id_list( $_POST['exclude_just_posted'] );
 750          $qs[] = 'exclude=' . implode( ',', $just_posted );
 751      }
 752  
 753      // To get newest activities.
 754      if ( ! empty( $_POST['offset'] ) ) {
 755          $qs[] = 'offset=' . intval( $_POST['offset'] );
 756      }
 757  
 758      $object_search_text = bp_get_search_default_text( $object );
 759      if ( ! empty( $_POST['search_terms'] ) && is_string( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
 760          $qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] );
 761  
 762      // Now pass the querystring to override default values.
 763      $query_string = empty( $qs ) ? '' : join( '&', (array) $qs );
 764  
 765      $object_filter = '';
 766      if ( isset( $_BP_COOKIE['bp-' . $object . '-filter'] ) )
 767          $object_filter = $_BP_COOKIE['bp-' . $object . '-filter'];
 768  
 769      $object_scope = '';
 770      if ( isset( $_BP_COOKIE['bp-' . $object . '-scope'] ) )
 771          $object_scope = $_BP_COOKIE['bp-' . $object . '-scope'];
 772  
 773      $object_page = '';
 774      if ( isset( $_BP_COOKIE['bp-' . $object . '-page'] ) )
 775          $object_page = $_BP_COOKIE['bp-' . $object . '-page'];
 776  
 777      $object_search_terms = '';
 778      if ( isset( $_BP_COOKIE['bp-' . $object . '-search-terms'] ) )
 779          $object_search_terms = $_BP_COOKIE['bp-' . $object . '-search-terms'];
 780  
 781      $object_extras = '';
 782      if ( isset( $_BP_COOKIE['bp-' . $object . '-extras'] ) )
 783          $object_extras = $_BP_COOKIE['bp-' . $object . '-extras'];
 784  
 785      /**
 786       * Filters the AJAX query string for the component loops.
 787       *
 788       * @since 1.7.0
 789       *
 790       * @param string $query_string        The query string we are working with.
 791       * @param string $object              The type of page we are on.
 792       * @param string $object_filter       The current object filter.
 793       * @param string $object_scope        The current object scope.
 794       * @param string $object_page         The current object page.
 795       * @param string $object_search_terms The current object search terms.
 796       * @param string $object_extras       The current object extras.
 797       */
 798      return apply_filters( 'bp_legacy_theme_ajax_querystring', $query_string, $object, $object_filter, $object_scope, $object_page, $object_search_terms, $object_extras );
 799  }
 800  
 801  /**
 802   * Load the template loop for the current object.
 803   *
 804   * @since 1.2.0
 805   *
 806   * @return string|null Prints template loop for the specified object
 807   */
 808  function bp_legacy_theme_object_template_loader() {
 809      if ( ! bp_is_post_request() ) {
 810          return;
 811      }
 812  
 813      // Bail if no object passed.
 814      if ( empty( $_POST['object'] ) ) {
 815          return;
 816      }
 817  
 818      // Sanitize the object.
 819      $object = sanitize_title( $_POST['object'] );
 820  
 821      // Bail if object is not an active component to prevent arbitrary file inclusion.
 822      if ( ! bp_is_active( $object ) ) {
 823          return;
 824      }
 825  
 826      /**
 827       * AJAX requests happen too early to be seen by bp_update_is_directory()
 828       * so we do it manually here to ensure templates load with the correct
 829       * context. Without this check, templates will load the 'single' version
 830       * of themselves rather than the directory version.
 831       */
 832      if ( ! bp_current_action() )
 833          bp_update_is_directory( true, bp_current_component() );
 834  
 835      // The template part can be overridden by the calling JS function.
 836      if ( ! empty( $_POST['template'] ) && 'groups/single/members' === $_POST['template'] ) {
 837          $template_part = 'groups/single/members.php';
 838      } else {
 839          $template_part = $object . '/' . $object . '-loop.php';
 840      }
 841  
 842      $template_path = bp_locate_template( array( $template_part ), false );
 843  
 844      $template_path = apply_filters( 'bp_legacy_object_template_path', $template_path );
 845  
 846      load_template( $template_path );
 847      exit();
 848  }
 849  
 850  /**
 851   * Load messages template loop when searched on the private message page
 852   *
 853   * @since 1.6.0
 854   *
 855   * @return string|null Prints template loop for the Messages component.
 856   */
 857  function bp_legacy_theme_messages_template_loader() {
 858      bp_get_template_part( 'members/single/messages/messages-loop' );
 859      exit();
 860  }
 861  
 862  /**
 863   * Load group invitations loop to handle pagination requests sent via AJAX.
 864   *
 865   * @since 2.0.0
 866   */
 867  function bp_legacy_theme_invite_template_loader() {
 868      bp_get_template_part( 'groups/single/invites-loop' );
 869      exit();
 870  }
 871  
 872  /**
 873   * Load group membership requests loop to handle pagination requests sent via AJAX.
 874   *
 875   * @since 2.0.0
 876   */
 877  function bp_legacy_theme_requests_template_loader() {
 878      bp_get_template_part( 'groups/single/requests-loop' );
 879      exit();
 880  }
 881  
 882  /**
 883   * Load the activity loop template when activity is requested via AJAX.
 884   *
 885   * @since 1.2.0
 886   *
 887   * @return string|null JSON object containing 'contents' (output of the template loop
 888   *                     for the Activity component) and 'feed_url' (URL to the relevant RSS feed).
 889   */
 890  function bp_legacy_theme_activity_template_loader() {
 891      if ( ! bp_is_post_request() ) {
 892          return;
 893      }
 894  
 895      $scope = '';
 896      if ( ! empty( $_POST['scope'] ) )
 897          $scope = $_POST['scope'];
 898  
 899      // We need to calculate and return the feed URL for each scope.
 900      switch ( $scope ) {
 901          case 'friends':
 902              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/friends/feed/';
 903              break;
 904          case 'groups':
 905              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/groups/feed/';
 906              break;
 907          case 'favorites':
 908              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
 909              break;
 910          case 'mentions':
 911              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
 912  
 913              if ( isset( $_POST['_wpnonce_activity_filter'] ) && wp_verify_nonce( wp_unslash( $_POST['_wpnonce_activity_filter'] ), 'activity_filter' ) ) {
 914                  bp_activity_clear_new_mentions( bp_loggedin_user_id() );
 915              }
 916  
 917              break;
 918          default:
 919              $feed_url = home_url( bp_get_activity_root_slug() . '/feed/' );
 920              break;
 921      }
 922  
 923      // Buffer the loop in the template to a var for JS to spit out.
 924      ob_start();
 925      bp_get_template_part( 'activity/activity-loop' );
 926      $result['contents'] = ob_get_contents();
 927  
 928      /**
 929       * Filters the feed URL for when activity is requested via AJAX.
 930       *
 931       * @since 1.7.0
 932       *
 933       * @param string $feed_url URL for the feed to be used.
 934       * @param string $scope    Scope for the activity request.
 935       */
 936      $result['feed_url'] = apply_filters( 'bp_legacy_theme_activity_feed_url', $feed_url, $scope );
 937      ob_end_clean();
 938  
 939      exit( json_encode( $result ) );
 940  }
 941  
 942  /**
 943   * Processes Activity updates received via a POST request.
 944   *
 945   * @since 1.2.0
 946   *
 947   * @return string|null HTML
 948   */
 949  function bp_legacy_theme_post_update() {
 950      $bp = buddypress();
 951  
 952      if ( ! bp_is_post_request() ) {
 953          return;
 954      }
 955  
 956      // Check the nonce.
 957      check_admin_referer( 'post_update', '_wpnonce_post_update' );
 958  
 959      if ( ! is_user_logged_in() )
 960          exit( '-1' );
 961  
 962      if ( empty( $_POST['content'] ) )
 963          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>' );
 964  
 965      $activity_id = 0;
 966      $item_id     = 0;
 967      $object      = '';
 968  
 969  
 970      // Try to get the item id from posted variables.
 971      if ( ! empty( $_POST['item_id'] ) ) {
 972          $item_id = (int) $_POST['item_id'];
 973      }
 974  
 975      // Try to get the object from posted variables.
 976      if ( ! empty( $_POST['object'] ) ) {
 977          $object  = sanitize_key( $_POST['object'] );
 978  
 979      // If the object is not set and we're in a group, set the item id and the object
 980      } elseif ( bp_is_group() ) {
 981          $item_id = bp_get_current_group_id();
 982          $object = 'groups';
 983      }
 984  
 985      if ( ! $object && bp_is_active( 'activity' ) ) {
 986          $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'], 'error_type' => 'wp_error' ) );
 987  
 988      } elseif ( 'groups' === $object ) {
 989          if ( $item_id && bp_is_active( 'groups' ) )
 990              $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id, 'error_type' => 'wp_error' ) );
 991  
 992      } else {
 993  
 994          /** This filter is documented in bp-activity/actions/post.php */
 995          $activity_id = apply_filters( 'bp_activity_custom_update', false, $object, $item_id, $_POST['content'] );
 996      }
 997  
 998      if ( false === $activity_id ) {
 999          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem posting your update. Please try again.', 'buddypress' ) . '</p></div>' );
1000      } elseif ( is_wp_error( $activity_id ) && $activity_id->get_error_code() ) {
1001          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . $activity_id->get_error_message() . '</p></div>' );
1002      }
1003  
1004      $last_recorded = ! empty( $_POST['since'] ) ? date( 'Y-m-d H:i:s', intval( $_POST['since'] ) ) : 0;
1005      if ( $last_recorded ) {
1006          $activity_args = array( 'since' => $last_recorded );
1007          $bp->activity->last_recorded = $last_recorded;
1008          add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
1009      } else {
1010          $activity_args = array( 'include' => $activity_id );
1011      }
1012  
1013      if ( bp_has_activities ( $activity_args ) ) {
1014          while ( bp_activities() ) {
1015              bp_the_activity();
1016              bp_get_template_part( 'activity/entry' );
1017          }
1018      }
1019  
1020      if ( ! empty( $last_recorded ) ) {
1021          remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10 );
1022      }
1023  
1024      exit;
1025  }
1026  
1027  /**
1028   * Posts new Activity comments received via a POST request.
1029   *
1030   * @since 1.2.0
1031   *
1032   * @global BP_Activity_Template $activities_template
1033   *
1034   * @return string|null HTML
1035   */
1036  function bp_legacy_theme_new_activity_comment() {
1037      global $activities_template;
1038  
1039      $bp = buddypress();
1040  
1041      if ( ! bp_is_post_request() ) {
1042          return;
1043      }
1044  
1045      // Check the nonce.
1046      check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
1047  
1048      if ( ! is_user_logged_in() ) {
1049          exit( '-1' );
1050      }
1051  
1052      $feedback = __( 'There was an error posting your reply. Please try again.', 'buddypress' );
1053  
1054      if ( empty( $_POST['content'] ) ) {
1055          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html__( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>' );
1056      }
1057  
1058      if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) ) {
1059          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $feedback ) . '</p></div>' );
1060      }
1061  
1062      $activity_id   = (int) $_POST['form_id'];
1063      $activity_item = new BP_Activity_Activity( $activity_id );
1064      if ( ! bp_activity_user_can_read( $activity_item ) ) {
1065          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $feedback ) . '</p></div>' );
1066      }
1067  
1068      $comment_id = bp_activity_new_comment( array(
1069          'activity_id' => $activity_id,
1070          'content'     => $_POST['content'],
1071          'parent_id'   => $_POST['comment_id'],
1072          'error_type'  => 'wp_error'
1073      ) );
1074  
1075      if ( is_wp_error( $comment_id ) ) {
1076          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $comment_id->get_error_message() ) . '</p></div>' );
1077      }
1078  
1079      // Load the new activity item into the $activities_template global.
1080      bp_has_activities( 'display_comments=stream&hide_spam=false&show_hidden=true&include=' . $comment_id );
1081  
1082      // Swap the current comment with the activity item we just loaded.
1083      if ( isset( $activities_template->activities[0] ) ) {
1084          $activities_template->activity = new stdClass();
1085          $activities_template->activity->id              = $activities_template->activities[0]->item_id;
1086          $activities_template->activity->current_comment = $activities_template->activities[0];
1087  
1088          // Because the whole tree has not been loaded, we manually
1089          // determine depth.
1090          $depth = 1;
1091          $parent_id = (int) $activities_template->activities[0]->secondary_item_id;
1092          while ( $parent_id !== (int) $activities_template->activities[0]->item_id ) {
1093              $depth++;
1094              $p_obj = new BP_Activity_Activity( $parent_id );
1095              $parent_id = (int) $p_obj->secondary_item_id;
1096          }
1097          $activities_template->activity->current_comment->depth = $depth;
1098      }
1099  
1100      // Get activity comment template part.
1101      bp_get_template_part( 'activity/comment' );
1102  
1103      unset( $activities_template );
1104      exit;
1105  }
1106  
1107  /**
1108   * Deletes an Activity item received via a POST request.
1109   *
1110   * @since 1.2.0
1111   *
1112   * @return mixed String on error, void on success.
1113   */
1114  function bp_legacy_theme_delete_activity() {
1115      if ( ! bp_is_post_request() ) {
1116          return;
1117      }
1118  
1119      // Check the nonce.
1120      check_admin_referer( 'bp_activity_delete_link' );
1121  
1122      if ( ! is_user_logged_in() )
1123          exit( '-1' );
1124  
1125      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
1126          exit( '-1' );
1127  
1128      $activity = new BP_Activity_Activity( (int) $_POST['id'] );
1129  
1130      // Check access.
1131      if ( ! bp_activity_user_can_delete( $activity ) )
1132          exit( '-1' );
1133  
1134      /** This action is documented in bp-activity/bp-activity-actions.php */
1135      do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id );
1136  
1137      if ( ! bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) )
1138          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
1139  
1140      /** This action is documented in bp-activity/bp-activity-actions.php */
1141      do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
1142      exit;
1143  }
1144  
1145  /**
1146   * Deletes an Activity comment received via a POST request.
1147   *
1148   * @since 1.2.0
1149   *
1150   * @return mixed String on error, void on success.
1151   */
1152  function bp_legacy_theme_delete_activity_comment() {
1153      if ( ! bp_is_post_request() ) {
1154          return;
1155      }
1156  
1157      // Check the nonce.
1158      check_admin_referer( 'bp_activity_delete_link' );
1159  
1160      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) ) {
1161          exit( '-1' );
1162      }
1163  
1164      if ( ! is_user_logged_in() ) {
1165          exit( '-1' );
1166      }
1167  
1168      $comment = new BP_Activity_Activity( $_POST['id'] );
1169  
1170      // Check access.
1171      if ( ! bp_current_user_can( 'bp_moderate' ) && $comment->user_id != bp_loggedin_user_id() )
1172          exit( '-1' );
1173  
1174      /** This action is documented in bp-activity/bp-activity-actions.php */
1175      do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $comment->user_id );
1176  
1177      if ( ! bp_activity_delete_comment( $comment->item_id, $comment->id ) )
1178          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
1179  
1180      /** This action is documented in bp-activity/bp-activity-actions.php */
1181      do_action( 'bp_activity_action_delete_activity', $_POST['id'], $comment->user_id );
1182      exit;
1183  }
1184  
1185  /**
1186   * AJAX spam an activity item or comment.
1187   *
1188   * @since 1.6.0
1189   *
1190   * @return mixed String on error, void on success.
1191   */
1192  function bp_legacy_theme_spam_activity() {
1193      $bp = buddypress();
1194  
1195      if ( ! bp_is_post_request() ) {
1196          return;
1197      }
1198  
1199      // Check that user is logged in, Activity Streams are enabled, and Akismet is present.
1200      if ( ! is_user_logged_in() || ! bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) )
1201          exit( '-1' );
1202  
1203      // Check an item ID was passed.
1204      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
1205          exit( '-1' );
1206  
1207      // Is the current user allowed to spam items?
1208      if ( ! bp_activity_user_can_mark_spam() )
1209          exit( '-1' );
1210  
1211      // Load up the activity item.
1212      $activity = new BP_Activity_Activity( (int) $_POST['id'] );
1213      if ( empty( $activity->component ) )
1214          exit( '-1' );
1215  
1216      // Check nonce.
1217      check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
1218  
1219      /** This action is documented in bp-activity/bp-activity-actions.php */
1220      do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
1221  
1222      // Mark as spam.
1223      bp_activity_mark_as_spam( $activity );
1224      $activity->save();
1225  
1226      /** This action is documented in bp-activity/bp-activity-actions.php */
1227      do_action( 'bp_activity_action_spam_activity', $activity->id, $activity->user_id );
1228      exit;
1229  }
1230  
1231  /**
1232   * Mark an activity as a favourite via a POST request.
1233   *
1234   * @since 1.2.0
1235   *
1236   * @return string|null HTML
1237   */
1238  function bp_legacy_theme_mark_activity_favorite() {
1239      // Bail if not a POST action.
1240      if ( ! bp_is_post_request() ) {
1241          return;
1242      }
1243  
1244      if ( ! isset( $_POST['nonce'] ) ) {
1245          return;
1246      }
1247  
1248      // Either the 'mark' or 'unmark' nonce is accepted, for backward compatibility.
1249      $nonce = wp_unslash( $_POST['nonce'] );
1250      if ( ! wp_verify_nonce( $nonce, 'mark_favorite' ) && ! wp_verify_nonce( $nonce, 'unmark_favorite' ) ) {
1251          return;
1252      }
1253  
1254      $activity_id   = (int) $_POST['id'];
1255      $activity_item = new BP_Activity_Activity( $activity_id );
1256      if ( ! bp_activity_user_can_read( $activity_item, bp_loggedin_user_id() ) ) {
1257          return;
1258      }
1259  
1260      if ( bp_activity_add_user_favorite( $_POST['id'] ) )
1261          _e( 'Remove Favorite', 'buddypress' );
1262      else
1263          _e( 'Favorite', 'buddypress' );
1264  
1265      exit;
1266  }
1267  
1268  /**
1269   * Un-favourite an activity via a POST request.
1270   *
1271   * @since 1.2.0
1272   *
1273   * @return string|null HTML
1274   */
1275  function bp_legacy_theme_unmark_activity_favorite() {
1276      if ( ! bp_is_post_request() ) {
1277          return;
1278      }
1279  
1280      if ( ! isset( $_POST['nonce'] ) ) {
1281          return;
1282      }
1283  
1284      // Either the 'mark' or 'unmark' nonce is accepted, for backward compatibility.
1285      $nonce = wp_unslash( $_POST['nonce'] );
1286      if ( ! wp_verify_nonce( $nonce, 'mark_favorite' ) && ! wp_verify_nonce( $nonce, 'unmark_favorite' ) ) {
1287          return;
1288      }
1289  
1290      if ( bp_activity_remove_user_favorite( $_POST['id'] ) )
1291          _e( 'Favorite', 'buddypress' );
1292      else
1293          _e( 'Remove Favorite', 'buddypress' );
1294  
1295      exit;
1296  }
1297  
1298  /**
1299   * Fetches an activity's full, non-excerpted content via a POST request.
1300   * Used for the 'Read More' link on long activity items.
1301   *
1302   * @since 1.5.0
1303   *
1304   * @return string|null HTML
1305   */
1306  function bp_legacy_theme_get_single_activity_content() {
1307      if ( ! bp_is_post_request() ) {
1308          return;
1309      }
1310  
1311      $activity_array = bp_activity_get_specific( array(
1312          'activity_ids'     => $_POST['activity_id'],
1313          'display_comments' => 'stream'
1314      ) );
1315  
1316      $activity = ! empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
1317  
1318      if ( empty( $activity ) )
1319          exit; // @todo: error?
1320  
1321      /**
1322       * Fires before the return of an activity's full, non-excerpted content via a POST request.
1323       *
1324       * @since 1.7.0
1325       *
1326       * @param string $activity Activity content. Passed by reference.
1327       */
1328      do_action_ref_array( 'bp_legacy_theme_get_single_activity_content', array( &$activity ) );
1329  
1330      // Activity content retrieved through AJAX should run through normal filters, but not be truncated.
1331      remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
1332  
1333      /** This filter is documented in bp-activity/bp-activity-template.php */
1334      $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $activity->content, &$activity ) );
1335  
1336      exit( $content );
1337  }
1338  
1339  /**
1340   * Invites a friend to join a group via a POST request.
1341   *
1342   * @since 1.2.0
1343   *
1344   * @todo Audit return types
1345   */
1346  function bp_legacy_theme_ajax_invite_user() {
1347      if ( ! bp_is_post_request() ) {
1348          return;
1349      }
1350  
1351      check_ajax_referer( 'groups_invite_uninvite_user' );
1352  
1353      if ( ! $_POST['friend_id'] || ! $_POST['friend_action'] || ! $_POST['group_id'] )
1354          return;
1355  
1356      if ( ! bp_groups_user_can_send_invites( $_POST['group_id'] ) )
1357          return;
1358  
1359      $group_id = (int) $_POST['group_id'];
1360      $friend_id = (int) $_POST['friend_id'];
1361  
1362      if ( 'invite' == $_POST['friend_action'] ) {
1363          if ( ! friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) ) {
1364              return;
1365          }
1366  
1367          $group = groups_get_group( $group_id );
1368  
1369          // Users who have previously requested membership do not need
1370          // another invitation created for them.
1371          if ( groups_check_for_membership_request( $friend_id, $group_id ) ) {
1372              $user_status = 'is_pending';
1373  
1374          // Create the user invitation.
1375          } elseif ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) {
1376              $user_status = 'is_invited';
1377  
1378          // Miscellaneous failure.
1379          } else {
1380              return;
1381          }
1382  
1383          $user = new BP_Core_User( $friend_id );
1384  
1385          $uninvite_url = bp_is_current_action( 'create' )
1386              ? bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $friend_id
1387              : bp_get_group_permalink( $group )    . 'send-invites/remove/' . $friend_id;
1388  
1389          echo '<li id="uid-' . esc_attr( $user->id ) . '">';
1390          echo $user->avatar_thumb;
1391          echo '<h4>' . $user->user_link . '</h4>';
1392          echo '<span class="activity">' . esc_attr( $user->last_active ) . '</span>';
1393          echo '<div class="action">
1394                  <a class="button remove" href="' . wp_nonce_url( $uninvite_url, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', 'buddypress' ) . '</a>
1395                </div>';
1396  
1397          if ( 'is_pending' == $user_status ) {
1398              /* translators: %s: user link */
1399              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>';
1400          }
1401  
1402          echo '</li>';
1403          exit;
1404  
1405      } elseif ( 'uninvite' == $_POST['friend_action'] ) {
1406          // Users who have previously requested membership should not
1407          // have their requests deleted on the "uninvite" action.
1408          if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
1409              return;
1410          }
1411  
1412          // Remove the unsent invitation.
1413          if ( ! groups_uninvite_user( $friend_id, $group_id ) ) {
1414              return;
1415          }
1416  
1417          exit;
1418  
1419      } else {
1420          return;
1421      }
1422  }
1423  
1424  /**
1425   * Friend/un-friend a user via a POST request.
1426   *
1427   * @since 1.2.0
1428   *
1429   * @return string|null HTML
1430   */
1431  function bp_legacy_theme_ajax_addremove_friend() {
1432      if ( ! bp_is_post_request() ) {
1433          return;
1434      }
1435  
1436      // Cast fid as an integer.
1437      $friend_id = (int) $_POST['fid'];
1438  
1439      $user = get_user_by( 'id', $friend_id );
1440      if ( ! $user ) {
1441          die( __( 'No member found by that ID.', 'buddypress' ) );
1442      }
1443  
1444      // Trying to cancel friendship.
1445      if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1446          check_ajax_referer( 'friends_remove_friend' );
1447  
1448          if ( ! friends_remove_friend( bp_loggedin_user_id(), $friend_id ) ) {
1449              echo __( 'Friendship could not be canceled.', 'buddypress' );
1450          } else {
1451              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>';
1452          }
1453  
1454      // Trying to request friendship.
1455      } elseif ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1456          check_ajax_referer( 'friends_add_friend' );
1457  
1458          if ( ! friends_add_friend( bp_loggedin_user_id(), $friend_id ) ) {
1459              echo __(' Friendship could not be requested.', 'buddypress' );
1460          } else {
1461              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>';
1462          }
1463  
1464      // Trying to cancel pending request.
1465      } elseif ( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1466          check_ajax_referer( 'friends_withdraw_friendship' );
1467  
1468          if ( friends_withdraw_friendship( bp_loggedin_user_id(), $friend_id ) ) {
1469              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>';
1470          } else {
1471              echo __("Friendship request could not be cancelled.", 'buddypress');
1472          }
1473  
1474      // Request already pending.
1475      } else {
1476          echo __( 'Request Pending', 'buddypress' );
1477      }
1478  
1479      exit;
1480  }
1481  
1482  /**
1483   * Accept a user friendship request via a POST request.
1484   *
1485   * @since 1.2.0
1486   *
1487   * @return mixed String on error, void on success.
1488   */
1489  function bp_legacy_theme_ajax_accept_friendship() {
1490      if ( ! bp_is_post_request() ) {
1491          return;
1492      }
1493  
1494      check_admin_referer( 'friends_accept_friendship' );
1495  
1496      if ( ! friends_accept_friendship( (int) $_POST['id'] ) )
1497          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem accepting that request. Please try again.', 'buddypress' ) . '</p></div>';
1498  
1499      exit;
1500  }
1501  
1502  /**
1503   * Reject a user friendship request via a POST request.
1504   *
1505   * @since 1.2.0
1506   *
1507   * @return mixed String on error, void on success.
1508   */
1509  function bp_legacy_theme_ajax_reject_friendship() {
1510      if ( ! bp_is_post_request() ) {
1511          return;
1512      }
1513  
1514      check_admin_referer( 'friends_reject_friendship' );
1515  
1516      if ( ! friends_reject_friendship( (int) $_POST['id'] ) )
1517          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem rejecting that request. Please try again.', 'buddypress' ) . '</p></div>';
1518  
1519      exit;
1520  }
1521  
1522  /**
1523   * Join or leave a group when clicking the "join/leave" button via a POST request.
1524   *
1525   * @since 1.2.0
1526   *
1527   * @return string|null HTML
1528   */
1529  function bp_legacy_theme_ajax_joinleave_group() {
1530      if ( ! bp_is_post_request() ) {
1531          return;
1532      }
1533  
1534      // Cast gid as integer.
1535      $group_id = (int) $_POST['gid'];
1536  
1537      if ( groups_is_user_banned( bp_loggedin_user_id(), $group_id ) )
1538          return;
1539  
1540      if ( ! $group = groups_get_group( $group_id ) )
1541          return;
1542  
1543      // Client doesn't distinguish between different request types, so we infer from user status.
1544      if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
1545          $request_type = 'leave_group';
1546      } elseif ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) {
1547          $request_type = 'accept_invite';
1548      } elseif ( 'private' === $group->status ) {
1549          $request_type = 'request_membership';
1550      } else {
1551          $request_type = 'join_group';
1552      }
1553  
1554      switch ( $request_type ) {
1555          case 'join_group' :
1556              if ( ! bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) {
1557                  esc_html_e( 'Error joining group', 'buddypress' );
1558              }
1559  
1560              check_ajax_referer( 'groups_join_group' );
1561  
1562              if ( ! groups_join_group( $group->id ) ) {
1563                  _e( 'Error joining group', 'buddypress' );
1564              } else {
1565                  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>';
1566              }
1567          break;
1568  
1569          case 'accept_invite' :
1570              if ( ! bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) {
1571                  esc_html_e( 'Error accepting invitation', 'buddypress' );
1572              }
1573  
1574              check_ajax_referer( 'groups_accept_invite' );
1575  
1576              if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) {
1577                  _e( 'Error requesting membership', 'buddypress' );
1578              } else {
1579                  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>';
1580              }
1581          break;
1582  
1583          case 'request_membership' :
1584              check_ajax_referer( 'groups_request_membership' );
1585  
1586              if ( ! groups_send_membership_request( [ 'user_id' => bp_loggedin_user_id(), 'group_id' => $group->id ] ) ) {
1587                  _e( 'Error requesting membership', 'buddypress' );
1588              } else {
1589                  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>';
1590              }
1591          break;
1592  
1593          case 'leave_group' :
1594              check_ajax_referer( 'groups_leave_group' );
1595  
1596              if ( ! groups_leave_group( $group->id ) ) {
1597                  _e( 'Error leaving group', 'buddypress' );
1598              } elseif ( 'public' === $group->status ) {
1599                  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>';
1600              } else {
1601                  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>';
1602              }
1603          break;
1604      }
1605  
1606      exit;
1607  }
1608  
1609  /**
1610   * Close and keep closed site wide notices from an admin in the sidebar, via a POST request.
1611   *
1612   * @since 1.2.0
1613   *
1614   * @return mixed String on error, void on success.
1615   */
1616  function bp_legacy_theme_ajax_close_notice() {
1617      if ( ! bp_is_post_request() ) {
1618          return;
1619      }
1620  
1621      $nonce_check = isset( $_POST['nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['nonce'] ), 'bp_messages_close_notice' );
1622  
1623      if ( ! $nonce_check || ! isset( $_POST['notice_id'] ) ) {
1624          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem closing the notice.', 'buddypress' ) . '</p></div>';
1625  
1626      } else {
1627          bp_messages_dismiss_sitewide_notice( bp_loggedin_user_id(), (int) $_POST['notice_id'] );
1628      }
1629  
1630      exit;
1631  }
1632  
1633  /**
1634   * Send a private message reply to a thread via a POST request.
1635   *
1636   * @since 1.2.0
1637   *
1638   * @return string|null HTML
1639   */
1640  function bp_legacy_theme_ajax_messages_send_reply() {
1641      if ( ! bp_is_post_request() ) {
1642          return;
1643      }
1644  
1645      check_ajax_referer( 'messages_send_message' );
1646  
1647      $thread_id = (int) $_POST['thread_id'];
1648  
1649      // Cannot respond to a thread you're not already a recipient on.
1650      if ( ! bp_current_user_can( 'bp_moderate' ) && ( ! messages_is_valid_thread( $thread_id ) || ! messages_check_thread_access( $thread_id ) ) ) {
1651          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>';
1652          die;
1653      }
1654  
1655      $result = messages_new_message( array( 'thread_id' => $thread_id, 'content' => $_REQUEST['content'] ) );
1656  
1657      if ( !empty( $result ) ) {
1658  
1659          // Pretend we're in the message loop.
1660          global $thread_template;
1661  
1662          bp_thread_has_messages( array( 'thread_id' => $thread_id ) );
1663  
1664          // Set the current message to the 2nd last.
1665          $thread_template->message = end( $thread_template->thread->messages );
1666          $thread_template->message = prev( $thread_template->thread->messages );
1667  
1668          // Set current message to current key.
1669          $thread_template->current_message = key( $thread_template->thread->messages );
1670  
1671          // Now manually iterate message like we're in the loop.
1672          bp_thread_the_message();
1673  
1674          // Manually call oEmbed
1675          // this is needed because we're not at the beginning of the loop.
1676          bp_messages_embed();
1677  
1678          // Add new-message css class.
1679          add_filter( 'bp_get_the_thread_message_css_class', function( $retval ) {
1680              $retval[] = 'new-message';
1681              return $retval;
1682          } );
1683  
1684          // Output single message template part.
1685          bp_get_template_part( 'members/single/messages/message' );
1686  
1687          // Clean up the loop.
1688          bp_thread_messages();
1689  
1690      } else {
1691          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>';
1692      }
1693  
1694      exit;
1695  }
1696  
1697  /**
1698   * Mark a private message as unread in your inbox via a POST request.
1699   *
1700   * No longer used.
1701   *
1702   * @since 1.2.0
1703   * @deprecated 2.2.0
1704   *
1705   * @return mixed String on error, void on success.
1706   */
1707  function bp_legacy_theme_ajax_message_markunread() {
1708      die( '-1' );
1709  }
1710  
1711  /**
1712   * Mark a private message as read in your inbox via a POST request.
1713   *
1714   * No longer used.
1715   *
1716   * @since 1.2.0
1717   * @deprecated 2.2.0
1718   *
1719   * @return mixed String on error, void on success.
1720   */
1721  function bp_legacy_theme_ajax_message_markread() {
1722      die( '-1' );
1723  }
1724  
1725  /**
1726   * Delete a private message(s) in your inbox via a POST request.
1727   *
1728   * No longer used.
1729   *
1730   * @since 1.2.0
1731   * @deprecated 2.2.0
1732   *
1733   * @return string|null HTML
1734   */
1735  function bp_legacy_theme_ajax_messages_delete() {
1736      die( '-1' );
1737  }
1738  
1739  /**
1740   * AJAX handler for autocomplete.
1741   *
1742   * Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.
1743   *
1744   * @since 1.2.0
1745   */
1746  function bp_legacy_theme_ajax_messages_autocomplete_results() {
1747  
1748      /**
1749       * Filters the max results default value for ajax messages autocomplete results.
1750       *
1751       * @since 1.5.0
1752       *
1753       * @param int $value Max results for autocomplete. Default 10.
1754       */
1755      $limit = isset( $_GET['limit'] ) ? absint( $_GET['limit'] )          : (int) apply_filters( 'bp_autocomplete_max_results', 10 );
1756      $term  = isset( $_GET['q'] )     ? sanitize_text_field( $_GET['q'] ) : '';
1757  
1758      // Include everyone in the autocomplete, or just friends?
1759      if ( bp_is_current_component( bp_get_messages_slug() ) ) {
1760          $only_friends = ( buddypress()->messages->autocomplete_all === false );
1761      } else {
1762          $only_friends = true;
1763      }
1764  
1765      $suggestions = bp_core_get_suggestions( array(
1766          'limit'        => $limit,
1767          'only_friends' => $only_friends,
1768          'term'         => $term,
1769          'type'         => 'members',
1770      ) );
1771  
1772      if ( $suggestions && ! is_wp_error( $suggestions ) ) {
1773          foreach ( $suggestions as $user ) {
1774  
1775              // Note that the final line break acts as a delimiter for the
1776              // autocomplete JavaScript and thus should not be removed.
1777              printf( '<span id="%s" href="#"></span><img src="%s" style="width: 15px"> &nbsp; %s (%s)' . "\n",
1778                  esc_attr( 'link-' . $user->ID ),
1779                  esc_url( $user->image ),
1780                  esc_html( $user->name ),
1781                  esc_html( $user->ID )
1782              );
1783          }
1784      }
1785  
1786      exit;
1787  }
1788  
1789  /**
1790   * AJAX callback to set a message's star status.
1791   *
1792   * @since 2.3.0
1793   */
1794  function bp_legacy_theme_ajax_messages_star_handler() {
1795      if ( false === bp_is_active( 'messages', 'star' ) || empty( $_POST['message_id'] ) ) {
1796          return;
1797      }
1798  
1799      // Check nonce.
1800      check_ajax_referer( 'bp-messages-star-' . (int) $_POST['message_id'], 'nonce' );
1801  
1802      // Check capability.
1803      if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) {
1804          return;
1805      }
1806  
1807      if ( true === bp_messages_star_set_action( array(
1808          'action'     => $_POST['star_status'],
1809          'message_id' => (int) $_POST['message_id'],
1810          'bulk'       => ! empty( $_POST['bulk'] ) ? true : false
1811       ) ) ) {
1812          echo '1';
1813          die();
1814      }
1815  
1816      echo '-1';
1817      die();
1818  }
1819  
1820  /**
1821   * BP Legacy's callback for the cover image feature.
1822   *
1823   * @since  2.4.0
1824   *
1825   * @param  array $params the current component's feature parameters.
1826   * @return null|string An array to inform about the css handle to attach the css rules to
1827   */
1828  function bp_legacy_theme_cover_image( $params = array() ) {
1829      if ( empty( $params ) ) {
1830          return;
1831      }
1832  
1833      // Avatar height - padding - 1/2 avatar height.
1834      $avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 );
1835  
1836      // Header content offset + spacing.
1837      $top_offset  = bp_core_avatar_full_height() - 10;
1838      $left_offset = bp_core_avatar_full_width() + 20;
1839  
1840      $cover_image = ( !empty( $params['cover_image'] ) ) ? 'background-image: url(' . $params['cover_image'] . ');' : '';
1841  
1842      $hide_avatar_style = '';
1843  
1844      // Adjust the cover image header, in case avatars are completely disabled.
1845      if ( ! buddypress()->avatar->show_avatars ) {
1846          $hide_avatar_style = '
1847              #buddypress #item-header-cover-image #item-header-avatar {
1848                  display:  none;
1849              }
1850          ';
1851  
1852          if ( bp_is_user() ) {
1853              $hide_avatar_style = '
1854                  #buddypress #item-header-cover-image #item-header-avatar a {
1855                      display: block;
1856                      height: ' . $top_offset . 'px;
1857                      margin: 0 15px 19px 0;
1858                  }
1859  
1860                  #buddypress div#item-header #item-header-cover-image #item-header-content {
1861                      margin-left: auto;
1862                  }
1863              ';
1864          }
1865      }
1866  
1867      return '
1868          /* Cover image */
1869          #buddypress #header-cover-image {
1870              height: ' . $params["height"] . 'px;
1871              ' . $cover_image . '
1872          }
1873  
1874          #buddypress #create-group-form #header-cover-image {
1875              margin: 1em 0;
1876              position: relative;
1877          }
1878  
1879          .bp-user #buddypress #item-header {
1880              padding-top: 0;
1881          }
1882  
1883          #buddypress #item-header-cover-image #item-header-avatar {
1884              margin-top: '. $avatar_offset .'px;
1885              float: left;
1886              overflow: visible;
1887              width: auto;
1888          }
1889  
1890          #buddypress div#item-header #item-header-cover-image #item-header-content {
1891              clear: both;
1892              float: left;
1893              margin-left: ' . $left_offset . 'px;
1894              margin-top: -' . $top_offset . 'px;
1895              width: auto;
1896          }
1897  
1898          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1899          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1900              clear: none;
1901              margin-top: ' . $params["height"] . 'px;
1902              margin-left: 0;
1903              max-width: 50%;
1904          }
1905  
1906          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1907              max-width: 20%;
1908              padding-top: 20px;
1909          }
1910  
1911          ' . $hide_avatar_style . '
1912  
1913          #buddypress div#item-header-cover-image .user-nicename a,
1914          #buddypress div#item-header-cover-image .user-nicename {
1915              font-size: 200%;
1916              color: #fff;
1917              margin: 0 0 0.6em;
1918              text-rendering: optimizelegibility;
1919              text-shadow: 0 0 3px rgba( 0, 0, 0, 0.8 );
1920          }
1921  
1922          #buddypress #item-header-cover-image #item-header-avatar img.avatar {
1923              background: rgba( 255, 255, 255, 0.8 );
1924              border: solid 2px #fff;
1925          }
1926  
1927          #buddypress #item-header-cover-image #item-header-avatar a {
1928              border: 0;
1929              text-decoration: none;
1930          }
1931  
1932          #buddypress #item-header-cover-image #item-buttons {
1933              margin: 0 0 10px;
1934              padding: 0 0 5px;
1935          }
1936  
1937          #buddypress #item-header-cover-image #item-buttons:after {
1938              clear: both;
1939              content: "";
1940              display: table;
1941          }
1942  
1943          @media screen and (max-width: 782px) {
1944              #buddypress #item-header-cover-image #item-header-avatar,
1945              .bp-user #buddypress #item-header #item-header-cover-image #item-header-avatar,
1946              #buddypress div#item-header #item-header-cover-image #item-header-content {
1947                  width: 100%;
1948                  text-align: center;
1949              }
1950  
1951              #buddypress #item-header-cover-image #item-header-avatar a {
1952                  display: inline-block;
1953              }
1954  
1955              #buddypress #item-header-cover-image #item-header-avatar img {
1956                  margin: 0;
1957              }
1958  
1959              #buddypress div#item-header #item-header-cover-image #item-header-content,
1960              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1961              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1962                  margin: 0;
1963              }
1964  
1965              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1966              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1967                  max-width: 100%;
1968              }
1969  
1970              #buddypress div#item-header-cover-image h2 a,
1971              #buddypress div#item-header-cover-image h2 {
1972                  color: inherit;
1973                  text-shadow: none;
1974                  margin: 25px 0 0;
1975                  font-size: 200%;
1976              }
1977  
1978              #buddypress #item-header-cover-image #item-buttons div {
1979                  float: none;
1980                  display: inline-block;
1981              }
1982  
1983              #buddypress #item-header-cover-image #item-buttons:before {
1984                  content: "";
1985              }
1986  
1987              #buddypress #item-header-cover-image #item-buttons {
1988                  margin: 5px 0;
1989              }
1990          }
1991      ';
1992  }
1993  
1994  /**
1995   * Add a search box to a single group's manage members screen.
1996   *
1997   * @since 2.7.0
1998   *
1999   * @return string|null HTML for the search form.
2000   */
2001  function bp_legacy_theme_group_manage_members_add_search() {
2002      if ( bp_is_action_variable( 'manage-members' ) ) :
2003          ?>
2004          <div id="members-dir-search" class="dir-search no-ajax" role="search">
2005              <?php bp_directory_members_search_form(); ?>
2006          </div>
2007          <?php
2008      endif;
2009  }
2010  
2011  /**
2012   * Modify welcome message in Legacy template pack when
2013   * community invitations are enabled.
2014   *
2015   * @since 8.0.0
2016   */
2017  function bp_members_invitations_add_legacy_welcome_message() {
2018      $message = bp_members_invitations_get_registration_welcome_message();
2019  
2020      if ( $message ) {
2021          // Surround the message with `<p>` tags.
2022          echo wpautop( $message );
2023      }
2024  }
2025  add_action( 'bp_before_register_page', 'bp_members_invitations_add_legacy_welcome_message' );
2026  
2027  
2028  /**
2029   * Modify "registration disabled" message in Legacy template pack when
2030   * community invitations are enabled.
2031   *
2032   * @since 8.0.0
2033   */
2034  function bp_members_invitations_add_legacy_registration_disabled_message() {
2035      $message = bp_members_invitations_get_modified_registration_disabled_message();
2036  
2037      if ( $message ) {
2038          // Surround the message with `<p>` tags.
2039          echo wpautop( $message );
2040      }
2041  }
2042  add_action( 'bp_after_registration_disabled', 'bp_members_invitations_add_legacy_registration_disabled_message' );


Generated: Mon Jul 26 01:01:36 2021 Cross-referenced by PHPXref 0.7.1