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


Generated: Sun Oct 24 01:00:54 2021 Cross-referenced by PHPXref 0.7.1