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


Generated: Tue Jul 16 01:01:43 2019 Cross-referenced by PHPXref 0.7.1