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


Generated: Thu Sep 19 01:01:39 2019 Cross-referenced by PHPXref 0.7.1