[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-nouveau/includes/groups/ -> functions.php (source)

   1  <?php
   2  /**
   3   * Groups functions
   4   *
   5   * @since 3.0.0
   6   * @version 5.0.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Provide a convenience function to add markup wrapper for message strings
  14   *
  15   * @param string $message The message text string
  16   * @param string $type    The message type - 'error, 'info', 'warning', success'
  17   *
  18   * @return string
  19   *
  20   * @since 3.0
  21   */
  22  function bp_nouveau_message_markup_wrapper( $message, $type ) {
  23      if ( ! $message ) {
  24          return false;
  25      }
  26  
  27      $message = '<div class=" ' . esc_attr( "bp-feedback {$type}" ) . '"><span class="bp-icon" aria-hidden="true"></span><p>' . esc_html( $message ) . '</p></div>';
  28  
  29      return $message;
  30  }
  31  
  32  /**
  33   * Register Scripts for the Groups component
  34   *
  35   * @since 3.0.0
  36   *
  37   * @param array $scripts Optional. The array of scripts to register.
  38   *
  39   * @return array The same array with the specific groups scripts.
  40   */
  41  function bp_nouveau_groups_register_scripts( $scripts = array() ) {
  42      if ( ! isset( $scripts['bp-nouveau'] ) ) {
  43          return $scripts;
  44      }
  45  
  46      return array_merge( $scripts, array(
  47          'bp-nouveau-group-invites' => array(
  48              'file'         => 'js/buddypress-group-invites%s.js',
  49              'dependencies' => array( 'bp-nouveau', 'json2', 'wp-backbone' ),
  50              'footer'       => true,
  51          ),
  52      ) );
  53  }
  54  
  55  /**
  56   * Enqueue the groups scripts
  57   *
  58   * @since 3.0.0
  59   */
  60  function bp_nouveau_groups_enqueue_scripts() {
  61      // Neutralize Ajax when using BuddyPress Groups & member widgets on default front page
  62      if ( bp_is_group_home() && bp_nouveau_get_appearance_settings( 'group_front_page' ) ) {
  63          wp_add_inline_style( 'bp-nouveau', '
  64              #group-front-widgets #groups-list-options,
  65              #group-front-widgets #members-list-options {
  66                  display: none;
  67              }
  68          ' );
  69      }
  70  
  71      if ( bp_is_group_invites() || ( bp_is_group_create() && bp_is_group_creation_step( 'group-invites' ) ) ) {
  72          wp_enqueue_script( 'bp-nouveau-group-invites' );
  73      }
  74  
  75      if ( bp_rest_api_is_available() && bp_is_group_admin_page() && bp_is_group_admin_screen( 'manage-members' ) ) {
  76          wp_enqueue_script( 'bp-group-manage-members' );
  77          wp_localize_script(
  78              'bp-group-manage-members',
  79              'bpGroupManageMembersSettings',
  80              bp_groups_get_group_manage_members_script_data( bp_get_current_group_id() )
  81          );
  82      }
  83  }
  84  
  85  /**
  86   * Can all members be invited to join any group?
  87   *
  88   * @since 3.0.0
  89   *
  90   * @param bool $default False to allow. True to disallow.
  91   *
  92   * @return bool
  93   */
  94  function bp_nouveau_groups_disallow_all_members_invites( $default = false ) {
  95      /**
  96       * Filter to remove the All members nav, returning true
  97       *
  98       * @since 3.0.0
  99       *
 100       * @param bool $default True to disable the nav. False otherwise.
 101       */
 102      return apply_filters( 'bp_nouveau_groups_disallow_all_members_invites', $default );
 103  }
 104  
 105  /**
 106   * Localize the strings needed for the Group's Invite UI
 107   *
 108   * @since 3.0.0
 109   *
 110   * @param array $params Associative array containing the JS Strings needed by scripts
 111   *
 112   * @return array The same array with specific strings for the Group's Invite UI if needed.
 113   */
 114  function bp_nouveau_groups_localize_scripts( $params = array() ) {
 115      if ( ! bp_is_group_invites() && ! ( bp_is_group_create() && bp_is_group_creation_step( 'group-invites' ) ) ) {
 116          return $params;
 117      }
 118  
 119      $show_pending = bp_group_has_invites( array( 'user_id' => 'any' ) ) && ! bp_is_group_create();
 120  
 121      // Init the Group invites nav
 122      $invites_nav = array(
 123          'members' => array(
 124              'id'      => 'members',
 125              'caption' => __( 'All Members', 'buddypress' ),
 126              'order'   => 5,
 127          ),
 128          'invited' => array(
 129              'id'      => 'invited',
 130              'caption' => __( 'Pending Invites', 'buddypress' ),
 131              'order'   => 90,
 132              'hide'    => (int) ! $show_pending,
 133          ),
 134          'invites' => array(
 135              'id'      => 'invites',
 136              'caption' => __( 'Send Invites', 'buddypress' ),
 137              'order'   => 100,
 138              'hide'    => 1,
 139              'href'    => '#send-invites-editor',
 140          ),
 141      );
 142  
 143      if ( bp_is_active( 'friends' ) ) {
 144          $invites_nav['friends'] = array(
 145              'id'      => 'friends',
 146              'caption' => __( 'My Friends', 'buddypress' ),
 147              'order'   => 0,
 148          );
 149  
 150          if ( true === bp_nouveau_groups_disallow_all_members_invites() ) {
 151              unset( $invites_nav['members'] );
 152          }
 153      }
 154  
 155      $params['group_invites'] = array(
 156          'nav'                => bp_sort_by_key( $invites_nav, 'order', 'num' ),
 157          'loading'            => __( 'Loading members. Please wait.', 'buddypress' ),
 158          'invites_form'       => __( 'Use the "Send" button to send your invite or the "Cancel" button to abort.', 'buddypress' ),
 159          'invites_form_reset' => __( 'Group invitations cleared. Please use one of the available tabs to select members to invite.', 'buddypress' ),
 160          'invites_sending'    => __( 'Sending group invitations. Please wait.', 'buddypress' ),
 161  
 162          /* translators: %s: member name */
 163          'removeUserInvite'   => __( 'Cancel invitation %s', 'buddypress' ),
 164          'group_id'           => ! bp_get_current_group_id() ? bp_get_new_group_id() : bp_get_current_group_id(),
 165          'is_group_create'    => bp_is_group_create(),
 166          'nonces'             => array(
 167              'uninvite'     => wp_create_nonce( 'groups_invite_uninvite_user' ),
 168              'send_invites' => wp_create_nonce( 'groups_send_invites' )
 169          ),
 170      );
 171  
 172      return $params;
 173  }
 174  
 175  /**
 176   * @since 3.0.0
 177   */
 178  function bp_nouveau_groups_get_inviter_ids( $user_id, $group_id ) {
 179      if ( empty( $user_id ) || empty( $group_id ) ) {
 180          return false;
 181      }
 182  
 183      return BP_Nouveau_Group_Invite_Query::get_inviter_ids( $user_id, $group_id );
 184  }
 185  
 186  /**
 187   * @since 3.0.0
 188   */
 189  function bp_nouveau_prepare_group_potential_invites_for_js( $user ) {
 190      $bp = buddypress();
 191  
 192      $response = array(
 193          'id'           => intval( $user->ID ),
 194          'name'         => $user->display_name,
 195          'avatar'       => htmlspecialchars_decode( bp_core_fetch_avatar( array(
 196              'item_id' => $user->ID,
 197              'object'  => 'user',
 198              'type'    => 'thumb',
 199              'width'   => 50,
 200              'height'  => 50,
 201              'html'    => false )
 202          ) ),
 203      );
 204  
 205      // Do extra queries only if needed
 206      if ( ! empty( $bp->groups->invites_scope ) && 'invited' === $bp->groups->invites_scope ) {
 207          $response['is_sent']  = (bool) groups_check_user_has_invite( $user->ID, bp_get_current_group_id() );
 208  
 209          $inviter_ids = bp_nouveau_groups_get_inviter_ids( $user->ID, bp_get_current_group_id() );
 210  
 211          foreach ( $inviter_ids as $inviter_id ) {
 212              $class = false;
 213  
 214              if ( bp_loggedin_user_id() === (int) $inviter_id ) {
 215                  $class = 'group-self-inviter';
 216              }
 217  
 218              $response['invited_by'][] = array(
 219                  'avatar' => htmlspecialchars_decode( bp_core_fetch_avatar( array(
 220                      'item_id' => $inviter_id,
 221                      'object'  => 'user',
 222                      'type'    => 'thumb',
 223                      'width'   => 50,
 224                      'height'  => 50,
 225                      'html'    => false,
 226                      'class'   => $class,
 227                  ) ) ),
 228                  'user_link' => bp_core_get_userlink( $inviter_id, false, true ),
 229                  'user_name' => bp_core_get_username( $inviter_id ),
 230              );
 231          }
 232  
 233          if ( bp_is_item_admin() ) {
 234              $response['can_edit'] = true;
 235          } else {
 236              $response['can_edit'] = in_array( bp_loggedin_user_id(), $inviter_ids, true );
 237          }
 238      }
 239  
 240      /**
 241       * Filters the response value for potential group invite data for use with javascript.
 242       *
 243       * @since 3.0.0
 244       *
 245       * @param array   $response Array of invite data.
 246       * @param WP_User $user User object.
 247       */
 248      return apply_filters( 'bp_nouveau_prepare_group_potential_invites_for_js', $response, $user );
 249  }
 250  
 251  /**
 252   * @since 3.0.0
 253   */
 254  function bp_nouveau_get_group_potential_invites( $args = array() ) {
 255      $r = bp_parse_args( $args, array(
 256          'group_id'     => bp_get_current_group_id(),
 257          'type'         => 'alphabetical',
 258          'per_page'     => 20,
 259          'page'         => 1,
 260          'search_terms' => false,
 261          'member_type'  => false,
 262          'user_id'      => 0,
 263          'is_confirmed' => true,
 264      ) );
 265  
 266      if ( empty( $r['group_id'] ) ) {
 267          return false;
 268      }
 269  
 270      // Check the current user's access to the group.
 271      if ( ! bp_groups_user_can_send_invites( $r['group_id'] ) ) {
 272          return false;
 273      }
 274  
 275      /*
 276       * If it's not a friend request and users can restrict invites to friends,
 277       * make sure they are not displayed in results.
 278       */
 279      if ( ! $r['user_id'] && bp_is_active( 'friends' ) && bp_is_active( 'settings' ) && ! bp_nouveau_groups_disallow_all_members_invites() ) {
 280          $r['meta_query'] = array(
 281              array(
 282                  'key'     => '_bp_nouveau_restrict_invites_to_friends',
 283                  'compare' => 'NOT EXISTS',
 284              ),
 285          );
 286      }
 287  
 288      $query = new BP_Nouveau_Group_Invite_Query( $r );
 289  
 290      $response = new stdClass();
 291  
 292      $response->meta = array( 'total_page' => 0, 'current_page' => 0 );
 293      $response->users = array();
 294  
 295      if ( ! empty( $query->results ) ) {
 296          $response->users = $query->results;
 297  
 298          if ( ! empty( $r['per_page'] ) ) {
 299              $response->meta = array(
 300                  'total_page' => ceil( (int) $query->total_users / (int) $r['per_page'] ),
 301                  'page'       => (int) $r['page'],
 302              );
 303          }
 304      }
 305  
 306      return $response;
 307  }
 308  
 309  /**
 310   * @since 3.0.0
 311   */
 312  function bp_nouveau_group_invites_create_steps( $steps = array() ) {
 313      if ( bp_is_active( 'friends' ) && isset( $steps['group-invites'] ) ) {
 314          // Simply change the name
 315          $steps['group-invites']['name'] = _x( 'Invite', 'Group invitations menu title', 'buddypress' );
 316          return $steps;
 317      }
 318  
 319      // Add the create step if friends component is not active
 320      $steps['group-invites'] = array(
 321          'name'     => _x( 'Invite', 'Group invitations menu title', 'buddypress' ),
 322          'position' => 30,
 323      );
 324  
 325      return $steps;
 326  }
 327  
 328  /**
 329   * @since 3.0.0
 330   */
 331  function bp_nouveau_group_setup_nav() {
 332      if ( ! bp_is_group() || ! bp_groups_user_can_send_invites() ) {
 333          return;
 334      }
 335  
 336      // Simply change the name
 337      if ( bp_is_active( 'friends' ) ) {
 338          $bp = buddypress();
 339  
 340          $bp->groups->nav->edit_nav(
 341              array( 'name' => _x( 'Invite', 'Group invitations menu title', 'buddypress' ) ),
 342              'send-invites',
 343              bp_get_current_group_slug()
 344          );
 345  
 346      // Create the Subnav item for the group
 347      } else {
 348          $current_group = groups_get_current_group();
 349          $group_link    = bp_get_group_permalink( $current_group );
 350  
 351          bp_core_new_subnav_item( array(
 352              'name'            => _x( 'Invite', 'Group invitations menu title', 'buddypress' ),
 353              'slug'            => 'send-invites',
 354              'parent_url'      => $group_link,
 355              'parent_slug'     => $current_group->slug,
 356              'screen_function' => 'groups_screen_group_invite',
 357              'item_css_id'     => 'invite',
 358              'position'        => 70,
 359              'user_has_access' => $current_group->user_has_access,
 360              'no_access_url'   => $group_link,
 361          ) );
 362      }
 363  }
 364  
 365  /**
 366   * @since 3.0.0
 367   */
 368  function bp_nouveau_groups_invites_custom_message( $message = '' ) {
 369      if ( empty( $message ) ) {
 370          return $message;
 371      }
 372  
 373      $bp = buddypress();
 374  
 375      if ( empty( $bp->groups->invites_message ) ) {
 376          return $message;
 377      }
 378  
 379      $message = str_replace( '---------------------', "
 380  ---------------------\n
 381  " . $bp->groups->invites_message . "\n
 382  ---------------------
 383      ", $message );
 384  
 385      return $message;
 386  }
 387  
 388  /**
 389   * Format a Group for a json reply
 390   *
 391   * @since 3.0.0
 392   */
 393  function bp_nouveau_prepare_group_for_js( $item ) {
 394      if ( empty( $item->id ) ) {
 395          return array();
 396      }
 397  
 398      $item_avatar_url = bp_core_fetch_avatar( array(
 399          'item_id'    => $item->id,
 400          'object'     => 'group',
 401          'type'       => 'thumb',
 402          'html'       => false
 403      ) );
 404  
 405      return array(
 406          'id'          => $item->id,
 407          'name'        => $item->name,
 408          'avatar_url'  => $item_avatar_url,
 409          'object_type' => 'group',
 410          'is_public'   => ( 'public' === $item->status ),
 411      );
 412  }
 413  
 414  /**
 415   * Group invites restriction settings navigation.
 416   *
 417   * @since 3.0.0
 418   */
 419  function bp_nouveau_groups_invites_restriction_nav() {
 420      $slug        = bp_get_settings_slug();
 421      $user_domain = bp_loggedin_user_domain();
 422  
 423      if ( bp_displayed_user_domain() ) {
 424          $user_domain = bp_displayed_user_domain();
 425      }
 426  
 427      bp_core_new_subnav_item( array(
 428          'name'            => _x( 'Group Invites', 'Group invitations main menu title', 'buddypress' ),
 429          'slug'            => 'invites',
 430          'parent_url'      => trailingslashit( $user_domain . $slug ),
 431          'parent_slug'     => $slug,
 432          'screen_function' => 'bp_nouveau_groups_screen_invites_restriction',
 433          'item_css_id'     => 'invites',
 434          'position'        => 70,
 435          'user_has_access' => bp_core_can_edit_settings(),
 436      ), 'members' );
 437  }
 438  
 439  /**
 440   * Group invites restriction settings Admin Bar navigation.
 441   *
 442   * @since 3.0.0
 443   *
 444   * @param array $wp_admin_nav The list of settings admin subnav items.
 445   *
 446   * @return array The list of settings admin subnav items.
 447   */
 448  function bp_nouveau_groups_invites_restriction_admin_nav( $wp_admin_nav ) {
 449      // Setup the logged in user variables.
 450      $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
 451  
 452      // Add the "Group Invites" subnav item.
 453      $wp_admin_nav[] = array(
 454          'parent' => 'my-account-' . buddypress()->settings->id,
 455          'id'     => 'my-account-' . buddypress()->settings->id . '-invites',
 456          'title'  => _x( 'Group Invites', 'Group invitations main menu title', 'buddypress' ),
 457          'href'   => trailingslashit( $settings_link . 'invites/' ),
 458      );
 459  
 460      return $wp_admin_nav;
 461  }
 462  
 463  /**
 464   * Group invites restriction screen.
 465   *
 466   * @since 3.0.0
 467   */
 468  function bp_nouveau_groups_screen_invites_restriction() {
 469      // Redirect if no invites restriction settings page is accessible.
 470      if ( 'invites' !== bp_current_action() || ! bp_is_active( 'friends' ) ) {
 471          bp_do_404();
 472          return;
 473      }
 474  
 475      if ( isset( $_POST['member-group-invites-submit'] ) ) {
 476          // Nonce check.
 477          check_admin_referer( 'bp_nouveau_group_invites_settings' );
 478  
 479          if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) ) {
 480              if ( empty( $_POST['account-group-invites-preferences'] ) ) {
 481                  bp_delete_user_meta( bp_displayed_user_id(), '_bp_nouveau_restrict_invites_to_friends' );
 482              } else {
 483                  bp_update_user_meta( bp_displayed_user_id(), '_bp_nouveau_restrict_invites_to_friends', (int) $_POST['account-group-invites-preferences'] );
 484              }
 485  
 486              bp_core_add_message( __( 'Group invites preferences saved.', 'buddypress' ) );
 487          } else {
 488              bp_core_add_message( __( 'You are not allowed to perform this action.', 'buddypress' ), 'error' );
 489          }
 490  
 491          bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_settings_slug() ) . 'invites/' );
 492      }
 493  
 494      /**
 495       * Filters the template to load for the Group Invites settings screen.
 496       *
 497       * @since 3.0.0
 498       *
 499       * @param string $template Path to the Group Invites settings screen template to load.
 500       */
 501      bp_core_load_template( apply_filters( 'bp_nouveau_groups_screen_invites_restriction', 'members/single/settings/group-invites' ) );
 502  }
 503  
 504  /**
 505   * @since 3.0.0
 506   */
 507  function bp_nouveau_get_groups_directory_nav_items() {
 508      $nav_items = array();
 509  
 510      $nav_items['all'] = array(
 511          'component' => 'groups',
 512          'slug'      => 'all', // slug is used because BP_Core_Nav requires it, but it's the scope
 513          'li_class'  => array( 'selected' ),
 514          'link'      => bp_get_groups_directory_permalink(),
 515          'text'      => __( 'All Groups', 'buddypress' ),
 516          'count'     => bp_get_total_group_count(),
 517          'position'  => 5,
 518      );
 519  
 520      if ( is_user_logged_in() ) {
 521  
 522          $my_groups_count = bp_get_total_group_count_for_user( bp_loggedin_user_id() );
 523  
 524          // If the user has groups create a nav item
 525          if ( $my_groups_count ) {
 526              $nav_items['personal'] = array(
 527                  'component' => 'groups',
 528                  'slug'      => 'personal', // slug is used because BP_Core_Nav requires it, but it's the scope
 529                  'li_class'  => array(),
 530                  'link'      => bp_loggedin_user_domain() . bp_get_groups_slug() . '/my-groups/',
 531                  'text'      => __( 'My Groups', 'buddypress' ),
 532                  'count'     => $my_groups_count,
 533                  'position'  => 15,
 534              );
 535          }
 536  
 537          // If the user can create groups, add the create nav
 538          if ( bp_user_can_create_groups() ) {
 539              $nav_items['create'] = array(
 540                  'component' => 'groups',
 541                  'slug'      => 'create', // slug is used because BP_Core_Nav requires it, but it's the scope
 542                  'li_class'  => array( 'no-ajax', 'group-create', 'create-button' ),
 543                  'link'      => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),
 544                  'text'      => __( 'Create a Group', 'buddypress' ),
 545                  'count'     => false,
 546                  'position'  => 999,
 547              );
 548          }
 549      }
 550  
 551      // Check for the deprecated hook :
 552      $extra_nav_items = bp_nouveau_parse_hooked_dir_nav( 'bp_groups_directory_group_filter', 'groups', 20 );
 553  
 554      if ( ! empty( $extra_nav_items ) ) {
 555          $nav_items = array_merge( $nav_items, $extra_nav_items );
 556      }
 557  
 558      /**
 559       * Use this filter to introduce your custom nav items for the groups directory.
 560       *
 561       * @since 3.0.0
 562       *
 563       * @param  array $nav_items The list of the groups directory nav items.
 564       */
 565      return apply_filters( 'bp_nouveau_get_groups_directory_nav_items', $nav_items );
 566  }
 567  
 568  /**
 569   * Get Dropdown filters for the groups component
 570   *
 571   * @since 3.0.0
 572   *
 573   * @param string $context 'directory' or 'user'
 574   *
 575   * @return array the filters
 576   */
 577  function bp_nouveau_get_groups_filters( $context = '' ) {
 578      if ( empty( $context ) ) {
 579          return array();
 580      }
 581  
 582      $action = '';
 583      if ( 'user' === $context ) {
 584          $action = 'bp_member_group_order_options';
 585      } elseif ( 'directory' === $context ) {
 586          $action = 'bp_groups_directory_order_options';
 587      }
 588  
 589      /**
 590       * Recommended, filter here instead of adding an action to 'bp_member_group_order_options'
 591       * or 'bp_groups_directory_order_options'
 592       *
 593       * @since 3.0.0
 594       *
 595       * @param array  the members filters.
 596       * @param string the context.
 597       */
 598      $filters = apply_filters( 'bp_nouveau_get_groups_filters', array(
 599          'active'       => __( 'Last Active', 'buddypress' ),
 600          'popular'      => __( 'Most Members', 'buddypress' ),
 601          'newest'       => __( 'Newly Created', 'buddypress' ),
 602          'alphabetical' => __( 'Alphabetical', 'buddypress' ),
 603      ), $context );
 604  
 605      if ( $action ) {
 606          return bp_nouveau_parse_hooked_options( $action, $filters );
 607      }
 608  
 609      return $filters;
 610  }
 611  
 612  /**
 613   * Catch the arguments for buttons
 614   *
 615   * @since 3.0.0
 616   *
 617   * @param array $button The arguments of the button that BuddyPress is about to create.
 618   *
 619   * @return array An empty array to stop the button creation process.
 620   */
 621  function bp_nouveau_groups_catch_button_args( $button = array() ) {
 622      /**
 623       * Globalize the arguments so that we can use it
 624       * in bp_nouveau_get_groups_buttons().
 625       */
 626      bp_nouveau()->groups->button_args = $button;
 627  
 628      // return an empty array to stop the button creation process
 629      return array();
 630  }
 631  
 632  /**
 633   * Catch the content hooked to the 'bp_group_header_meta' action
 634   *
 635   * @since 3.0.0
 636   *
 637   * @return string|bool HTML Output if hooked. False otherwise.
 638   */
 639  function bp_nouveau_get_hooked_group_meta() {
 640      ob_start();
 641  
 642      /**
 643       * Fires after inside the group header item meta section.
 644       *
 645       * @since 1.2.0
 646       */
 647      do_action( 'bp_group_header_meta' );
 648  
 649      $output = ob_get_clean();
 650  
 651      if ( ! empty( $output ) ) {
 652          return $output;
 653      }
 654  
 655      return false;
 656  }
 657  
 658  /**
 659   * Display the Widgets of Group extensions into the default front page?
 660   *
 661   * @since 3.0.0
 662   *
 663   * @return bool True to display. False otherwise.
 664   */
 665  function bp_nouveau_groups_do_group_boxes() {
 666      $group_settings = bp_nouveau_get_appearance_settings();
 667  
 668      return ! empty( $group_settings['group_front_page'] ) && ! empty( $group_settings['group_front_boxes'] );
 669  }
 670  
 671  /**
 672   * Display description of the Group into the default front page?
 673   *
 674   * @since 3.0.0
 675   *
 676   * @return bool True to display. False otherwise.
 677   */
 678  function bp_nouveau_groups_front_page_description() {
 679      $group_settings = bp_nouveau_get_appearance_settings();
 680  
 681      // This check is a problem it needs to be used in templates but returns true even if not on the front page
 682      // return false on this if we are not displaying the front page 'bp_is_group_home()'
 683      // This may well be a bad approach to re-think ~hnla.
 684      // @todo
 685      return ! empty( $group_settings['group_front_page'] ) && ! empty( $group_settings['group_front_description'] ) && bp_is_group_home();
 686  }
 687  
 688  /**
 689   * Add sections to the customizer for the groups component.
 690   *
 691   * @since 3.0.0
 692   *
 693   * @param array $sections the Customizer sections to add.
 694   *
 695   * @return array the Customizer sections to add.
 696   */
 697  function bp_nouveau_groups_customizer_sections( $sections = array() ) {
 698      return array_merge( $sections, array(
 699          'bp_nouveau_group_front_page' => array(
 700              'title'       => __( 'Group front page', 'buddypress' ),
 701              'panel'       => 'bp_nouveau_panel',
 702              'priority'    => 20,
 703              'description' => __( 'Configure the default front page for groups.', 'buddypress' ),
 704          ),
 705          'bp_nouveau_group_primary_nav' => array(
 706              'title'       => __( 'Group navigation', 'buddypress' ),
 707              'panel'       => 'bp_nouveau_panel',
 708              'priority'    => 40,
 709              'description' => __( 'Customize the navigation menu for groups. See your changes by navigating to a group in the live-preview window.', 'buddypress' ),
 710          ),
 711      ) );
 712  }
 713  
 714  /**
 715   * Add settings to the customizer for the groups component.
 716   *
 717   * @since 3.0.0
 718   *
 719   * @param array $settings Optional. The settings to add.
 720   *
 721   * @return array the settings to add.
 722   */
 723  function bp_nouveau_groups_customizer_settings( $settings = array() ) {
 724      return array_merge( $settings, array(
 725          'bp_nouveau_appearance[group_front_page]' => array(
 726              'index'             => 'group_front_page',
 727              'capability'        => 'bp_moderate',
 728              'sanitize_callback' => 'absint',
 729              'transport'         => 'refresh',
 730              'type'              => 'option',
 731          ),
 732          'bp_nouveau_appearance[group_front_boxes]' => array(
 733              'index'             => 'group_front_boxes',
 734              'capability'        => 'bp_moderate',
 735              'sanitize_callback' => 'absint',
 736              'transport'         => 'refresh',
 737              'type'              => 'option',
 738          ),
 739          'bp_nouveau_appearance[group_front_description]' => array(
 740              'index'             => 'group_front_description',
 741              'capability'        => 'bp_moderate',
 742              'sanitize_callback' => 'absint',
 743              'transport'         => 'refresh',
 744              'type'              => 'option',
 745          ),
 746          'bp_nouveau_appearance[group_nav_display]' => array(
 747              'index'             => 'group_nav_display',
 748              'capability'        => 'bp_moderate',
 749              'sanitize_callback' => 'absint',
 750              'transport'         => 'refresh',
 751              'type'              => 'option',
 752          ),
 753          'bp_nouveau_appearance[group_nav_tabs]' => array(
 754              'index'             => 'group_nav_tabs',
 755              'capability'        => 'bp_moderate',
 756              'sanitize_callback' => 'absint',
 757              'transport'         => 'refresh',
 758              'type'              => 'option',
 759          ),
 760          'bp_nouveau_appearance[group_subnav_tabs]' => array(
 761              'index'             => 'group_subnav_tabs',
 762              'capability'        => 'bp_moderate',
 763              'sanitize_callback' => 'absint',
 764              'transport'         => 'refresh',
 765              'type'              => 'option',
 766          ),
 767          'bp_nouveau_appearance[groups_create_tabs]' => array(
 768              'index'             => 'groups_create_tabs',
 769              'capability'        => 'bp_moderate',
 770              'sanitize_callback' => 'absint',
 771              'transport'         => 'refresh',
 772              'type'              => 'option',
 773          ),
 774          'bp_nouveau_appearance[group_nav_order]' => array(
 775              'index'             => 'group_nav_order',
 776              'capability'        => 'bp_moderate',
 777              'sanitize_callback' => 'bp_nouveau_sanitize_nav_order',
 778              'transport'         => 'refresh',
 779              'type'              => 'option',
 780          ),
 781          'bp_nouveau_appearance[groups_layout]' => array(
 782              'index'             => 'groups_layout',
 783              'capability'        => 'bp_moderate',
 784              'sanitize_callback' => 'absint',
 785              'transport'         => 'refresh',
 786              'type'              => 'option',
 787          ),
 788          'bp_nouveau_appearance[groups_dir_tabs]' => array(
 789              'index'             => 'groups_dir_tabs',
 790              'capability'        => 'bp_moderate',
 791              'sanitize_callback' => 'absint',
 792              'transport'         => 'refresh',
 793              'type'              => 'option',
 794          ),
 795      ) );
 796  }
 797  
 798  /**
 799   * Add controls for the settings of the customizer for the groups component.
 800   *
 801   * @since 3.0.0
 802   *
 803   * @param array $controls Optional. The controls to add.
 804   *
 805   * @return array the controls to add.
 806   */
 807  function bp_nouveau_groups_customizer_controls( $controls = array() ) {
 808      return array_merge( $controls, array(
 809          'group_front_page' => array(
 810              'label'      => __( 'Enable custom front pages for groups.', 'buddypress' ),
 811              'section'    => 'bp_nouveau_group_front_page',
 812              'settings'   => 'bp_nouveau_appearance[group_front_page]',
 813              'type'       => 'checkbox',
 814          ),
 815          'group_front_boxes' => array(
 816              'label'      => __( 'Enable widget region for group homepages. When enabled, the site admin can add widgets to group pages via the Widgets panel.', 'buddypress' ),
 817              'section'    => 'bp_nouveau_group_front_page',
 818              'settings'   => 'bp_nouveau_appearance[group_front_boxes]',
 819              'type'       => 'checkbox',
 820          ),
 821          'group_front_description' => array(
 822              'label'      => __( "Display the group description in the body of the group's front page.", 'buddypress' ),
 823              'section'    => 'bp_nouveau_group_front_page',
 824              'settings'   => 'bp_nouveau_appearance[group_front_description]',
 825              'type'       => 'checkbox',
 826          ),
 827          'group_nav_display' => array(
 828              'label'      => __( 'Display the group navigation vertically.', 'buddypress' ),
 829              'section'    => 'bp_nouveau_group_primary_nav',
 830              'settings'   => 'bp_nouveau_appearance[group_nav_display]',
 831              'type'       => 'checkbox',
 832          ),
 833          'group_nav_tabs' => array(
 834              'label'      => __( 'Use tab styling for primary navigation.', 'buddypress' ),
 835              'section'    => 'bp_nouveau_group_primary_nav',
 836              'settings'   => 'bp_nouveau_appearance[group_nav_tabs]',
 837              'type'       => 'checkbox',
 838          ),
 839          'group_subnav_tabs' => array(
 840              'label'      => __( 'Use tab styling for secondary navigation.', 'buddypress' ),
 841              'section'    => 'bp_nouveau_group_primary_nav',
 842              'settings'   => 'bp_nouveau_appearance[group_subnav_tabs]',
 843              'type'       => 'checkbox',
 844          ),
 845          'groups_create_tabs' => array(
 846              'label'      => __( 'Use tab styling for the group creation process.', 'buddypress' ),
 847              'section'    => 'bp_nouveau_group_primary_nav',
 848              'settings'   => 'bp_nouveau_appearance[groups_create_tabs]',
 849              'type'       => 'checkbox',
 850          ),
 851          'group_nav_order' => array(
 852              'class'       => 'BP_Nouveau_Nav_Customize_Control',
 853              'label'      => __( 'Reorder the primary navigation for a group.', 'buddypress' ),
 854              'section'    => 'bp_nouveau_group_primary_nav',
 855              'settings'   => 'bp_nouveau_appearance[group_nav_order]',
 856              'type'       => 'group',
 857          ),
 858          'groups_layout' => array(
 859              'label'      => _x( 'Groups', 'Customizer control label', 'buddypress' ),
 860              'section'    => 'bp_nouveau_loops_layout',
 861              'settings'   => 'bp_nouveau_appearance[groups_layout]',
 862              'type'       => 'select',
 863              'choices'    => bp_nouveau_customizer_grid_choices(),
 864          ),
 865          'members_group_layout' => array(
 866              'label'      => __( 'Group > Members', 'buddypress' ),
 867              'section'    => 'bp_nouveau_loops_layout',
 868              'settings'   => 'bp_nouveau_appearance[members_group_layout]',
 869              'type'       => 'select',
 870              'choices'    => bp_nouveau_customizer_grid_choices(),
 871          ),
 872          'group_dir_layout' => array(
 873              'label'      => __( 'Use column navigation for the Groups directory.', 'buddypress' ),
 874              'section'    => 'bp_nouveau_dir_layout',
 875              'settings'   => 'bp_nouveau_appearance[groups_dir_layout]',
 876              'type'       => 'checkbox',
 877          ),
 878          'group_dir_tabs' => array(
 879              'label'      => __( 'Use tab styling for Groups directory navigation.', 'buddypress' ),
 880              'section'    => 'bp_nouveau_dir_layout',
 881              'settings'   => 'bp_nouveau_appearance[groups_dir_tabs]',
 882              'type'       => 'checkbox',
 883          ),
 884      ) );
 885  }
 886  
 887  /**
 888   * Add the default group front template to the front template hierarchy.
 889   *
 890   * @since 3.0.0
 891   *
 892   * @param array           $templates Optional. The list of templates for the front.php template part.
 893   * @param BP_Groups_Group $group Optional. The group object.
 894   *
 895   * @return array The same list with the default front template if needed.
 896   */
 897  function bp_nouveau_group_reset_front_template( $templates = array(), $group = null ) {
 898      if ( empty( $group->id ) ) {
 899          return $templates;
 900      }
 901  
 902      $use_default_front = bp_nouveau_get_appearance_settings( 'group_front_page' );
 903  
 904      // Setting the front template happens too early, so we need this!
 905      if ( is_customize_preview() ) {
 906          $use_default_front = bp_nouveau_get_temporary_setting( 'group_front_page', $use_default_front );
 907      }
 908  
 909      if ( ! empty( $use_default_front ) ) {
 910          array_push( $templates, 'groups/single/default-front.php' );
 911      }
 912  
 913      /**
 914       * Filters the BuddyPress Nouveau template hierarchy after resetting front template for groups.
 915       *
 916       * @since 3.0.0
 917       *
 918       * @param array $templates Array of templates.
 919       */
 920      return apply_filters( '_bp_nouveau_group_reset_front_template', $templates );
 921  }
 922  
 923  /**
 924   * Locate a single group template into a specific hierarchy.
 925   *
 926   * @since 3.0.0
 927   *
 928   * @param string $template Optional. The template part to get (eg: activity, members...).
 929   *
 930   * @return string The located template.
 931   */
 932  function bp_nouveau_group_locate_template_part( $template = '' ) {
 933      $current_group = groups_get_current_group();
 934      $bp_nouveau    = bp_nouveau();
 935  
 936      if ( ! $template || empty( $current_group->id ) ) {
 937          return '';
 938      }
 939  
 940      // Use a global to avoid requesting the hierarchy for each template
 941      if ( ! isset( $bp_nouveau->groups->current_group_hierarchy ) ) {
 942          $bp_nouveau->groups->current_group_hierarchy = array(
 943              'groups/single/%s-id-' . (int) $current_group->id                     . '.php',
 944              'groups/single/%s-slug-' . sanitize_file_name( $current_group->slug ) . '.php',
 945          );
 946  
 947          /**
 948           * Check for group types and add it to the hierarchy
 949           */
 950          if ( bp_groups_get_group_types() ) {
 951              $current_group_type = bp_groups_get_group_type( $current_group->id );
 952              if ( ! $current_group_type ) {
 953                  $current_group_type = 'none';
 954              }
 955  
 956              $bp_nouveau->groups->current_group_hierarchy[] = 'groups/single/%s-group-type-' . sanitize_file_name( $current_group_type ) . '.php';
 957          }
 958  
 959          $bp_nouveau->groups->current_group_hierarchy = array_merge( $bp_nouveau->groups->current_group_hierarchy, array(
 960              'groups/single/%s-status-' . sanitize_file_name( $current_group->status ) . '.php',
 961              'groups/single/%s.php'
 962          ) );
 963      }
 964  
 965      // Init the templates
 966      $templates = array();
 967  
 968      // Loop in the hierarchy to fill it for the requested template part
 969      foreach ( $bp_nouveau->groups->current_group_hierarchy as $part ) {
 970          $templates[] = sprintf( $part, sanitize_file_name( $template ) );
 971      }
 972  
 973      /**
 974       * Filters the found template parts for the group template part locating functionality.
 975       *
 976       * @since 3.0.0
 977       *
 978       * @param array $templates Array of found templates.
 979       */
 980      return bp_locate_template( apply_filters( 'bp_nouveau_group_locate_template_part', $templates ), false, true );
 981  }
 982  
 983  /**
 984   * Load a single group template part
 985   *
 986   * @since 3.0.0
 987   *
 988   * @param string $template Optional. The template part to get (eg: activity, members...).
 989   *
 990   * @return string HTML output.
 991   */
 992  function bp_nouveau_group_get_template_part( $template = '' ) {
 993      $located = bp_nouveau_group_locate_template_part( $template );
 994  
 995      if ( false !== $located ) {
 996          $slug = str_replace( '.php', '', $located );
 997          $name = null;
 998  
 999          /**
1000           * Let plugins adding an action to bp_get_template_part get it from here.
1001           *
1002           * This is a variable hook that is dependent on the template part slug.
1003           *
1004           * @since 3.0.0
1005           *
1006           * @param string $slug Template part slug requested.
1007           * @param string $name Template part name requested.
1008           */
1009          do_action( 'get_template_part_' . $slug, $slug, $name );
1010  
1011          load_template( $located, true );
1012      }
1013  
1014      return $located;
1015  }
1016  
1017  /**
1018   * Are we inside the Current group's default front page sidebar?
1019   *
1020   * @since 3.0.0
1021   *
1022   * @return bool True if in the group's home sidebar. False otherwise.
1023   */
1024  function bp_nouveau_group_is_home_widgets() {
1025      return ( true === bp_nouveau()->groups->is_group_home_sidebar );
1026  }
1027  
1028  /**
1029   * Filter the Latest activities Widget to only keep the one of the group displayed
1030   *
1031   * @since 3.0.0
1032   *
1033   * @param array $args Optional. The Activities Template arguments.
1034   *
1035   * @return array The Activities Template arguments.
1036   */
1037  function bp_nouveau_group_activity_widget_overrides( $args = array() ) {
1038      return array_merge( $args, array(
1039          'object'     => 'groups',
1040          'primary_id' => bp_get_current_group_id(),
1041      ) );
1042  }
1043  
1044  /**
1045   * Filter the Groups widget to only keep the displayed group.
1046   *
1047   * @since 3.0.0
1048   *
1049   * @param array $args Optional. The Groups Template arguments.
1050   *
1051   * @return array The Groups Template arguments.
1052   */
1053  function bp_nouveau_group_groups_widget_overrides( $args = array() ) {
1054      return array_merge( $args, array(
1055          'include' => bp_get_current_group_id(),
1056      ) );
1057  }
1058  
1059  /**
1060   * Filter the Members widgets to only keep members of the displayed group.
1061   *
1062   * @since 3.0.0
1063   *
1064   * @param array $args Optional. The Members Template arguments.
1065   *
1066   * @return array The Members Template arguments.
1067   */
1068  function bp_nouveau_group_members_widget_overrides( $args = array() ) {
1069      $group_members = groups_get_group_members( array( 'exclude_admins_mods' => false ) );
1070  
1071      if ( empty( $group_members['members'] ) ) {
1072          return $args;
1073      }
1074  
1075      return array_merge( $args, array(
1076          'include' => wp_list_pluck( $group_members['members'], 'ID' ),
1077      ) );
1078  }
1079  
1080  /**
1081   * Init the Group's default front page filters as we're in the sidebar
1082   *
1083   * @since 3.0.0
1084   */
1085  function bp_nouveau_groups_add_home_widget_filters() {
1086      add_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_group_activity_widget_overrides', 10, 1 );
1087      add_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_group_groups_widget_overrides', 10, 1 );
1088      add_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_group_members_widget_overrides', 10, 1 );
1089  
1090      /**
1091       * Fires after BuddyPress Nouveau groups have added their home widget filters.
1092       *
1093       * @since 3.0.0
1094       */
1095      do_action( 'bp_nouveau_groups_add_home_widget_filters' );
1096  }
1097  
1098  /**
1099   * Remove the Group's default front page filters as we're no more in the sidebar
1100   *
1101   * @since 3.0.0
1102   */
1103  function bp_nouveau_groups_remove_home_widget_filters() {
1104      remove_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_group_activity_widget_overrides', 10, 1 );
1105      remove_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_group_groups_widget_overrides', 10, 1 );
1106      remove_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_group_members_widget_overrides', 10, 1 );
1107  
1108      /**
1109       * Fires after BuddyPress Nouveau groups have removed their home widget filters.
1110       *
1111       * @since 3.0.0
1112       */
1113      do_action( 'bp_nouveau_groups_remove_home_widget_filters' );
1114  }
1115  
1116  /**
1117   * Get the hook, nonce, and eventually a specific template for Core Group's create screens.
1118   *
1119   * @since 3.0.0
1120   *
1121   * @param string $id Optional. The screen id
1122   *
1123   * @return mixed An array containing the hook dynamic part, the nonce, and eventually a specific template.
1124   *               False if it's not a core create screen.
1125   */
1126  function bp_nouveau_group_get_core_create_screens( $id = '' ) {
1127      // screen id => dynamic part of the hooks, nonce & specific template to use.
1128      $screens = array(
1129          'group-details' => array(
1130              'hook'     => 'group_details_creation_step',
1131              'nonce'    => 'groups_create_save_group-details',
1132              'template' => 'groups/single/admin/edit-details',
1133          ),
1134          'group-settings' => array(
1135              'hook'  => 'group_settings_creation_step',
1136              'nonce' => 'groups_create_save_group-settings',
1137          ),
1138          'group-avatar' => array(
1139              'hook'  => 'group_avatar_creation_step',
1140              'nonce' => 'groups_create_save_group-avatar',
1141          ),
1142          'group-cover-image' => array(
1143              'hook'  => 'group_cover_image_creation_step',
1144              'nonce' => 'groups_create_save_group-cover-image',
1145          ),
1146          'group-invites' => array(
1147              'hook'     => 'group_invites_creation_step',
1148              'nonce'    => 'groups_create_save_group-invites',
1149              'template' => 'common/js-templates/invites/index',
1150          ),
1151      );
1152  
1153      if ( isset( $screens[ $id ] ) ) {
1154          return $screens[ $id ];
1155      }
1156  
1157      return false;
1158  }
1159  
1160  /**
1161   * Get the hook and nonce for Core Group's manage screens.
1162   *
1163   * @since 3.0.0
1164   *
1165   * @param string $id Optional. The screen id
1166   *
1167   * @return mixed An array containing the hook dynamic part and the nonce.
1168   *               False if it's not a core manage screen.
1169   */
1170  function bp_nouveau_group_get_core_manage_screens( $id = '' ) {
1171      // screen id => dynamic part of the hooks & nonce.
1172      $screens = array(
1173          'edit-details'        => array( 'hook' => 'group_details_admin',             'nonce' => 'groups_edit_group_details'  ),
1174          'group-settings'      => array( 'hook' => 'group_settings_admin',            'nonce' => 'groups_edit_group_settings' ),
1175          'group-avatar'        => array(),
1176          'group-cover-image'   => array( 'hook' => 'group_settings_cover_image',      'nonce' => ''                           ),
1177          'manage-members'      => array( 'hook' => 'group_manage_members_admin',      'nonce' => ''                           ),
1178          'membership-requests' => array( 'hook' => 'group_membership_requests_admin', 'nonce' => ''                           ),
1179          'delete-group'        => array( 'hook' => 'group_delete_admin',              'nonce' => 'groups_delete_group'        ),
1180      );
1181  
1182      if ( isset( $screens[ $id ] ) ) {
1183          return $screens[ $id ];
1184      }
1185  
1186      return false;
1187  }
1188  
1189  /**
1190   * Register notifications filters for the groups component.
1191   *
1192   * @since 3.0.0
1193   */
1194  function bp_nouveau_groups_notification_filters() {
1195      $notifications = array(
1196          array(
1197              'id'       => 'new_membership_request',
1198              'label'    => __( 'Pending Group membership requests', 'buddypress' ),
1199              'position' => 55,
1200          ),
1201          array(
1202              'id'       => 'membership_request_accepted',
1203              'label'    => __( 'Accepted Group membership requests', 'buddypress' ),
1204              'position' => 65,
1205          ),
1206          array(
1207              'id'       => 'membership_request_rejected',
1208              'label'    => __( 'Rejected Group membership requests', 'buddypress' ),
1209              'position' => 75,
1210          ),
1211          array(
1212              'id'       => 'member_promoted_to_admin',
1213              'label'    => __( 'Group Administrator promotions', 'buddypress' ),
1214              'position' => 85,
1215          ),
1216          array(
1217              'id'       => 'member_promoted_to_mod',
1218              'label'    => __( 'Group Moderator promotions', 'buddypress' ),
1219              'position' => 95,
1220          ),
1221          array(
1222              'id'       => 'group_invite',
1223              'label'    => __( 'Group invitations', 'buddypress' ),
1224              'position' => 105,
1225          ),
1226      );
1227  
1228      foreach ( $notifications as $notification ) {
1229          bp_nouveau_notifications_register_filter( $notification );
1230      }
1231  }


Generated: Mon May 25 01:01:32 2020 Cross-referenced by PHPXref 0.7.1