[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Groups Template tags
   4   *
   5   * @since 3.0.0
   6   * @version 3.2.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Template tag to wrap all Legacy actions that was used
  14   * before the groups directory content
  15   *
  16   * @since 3.0.0
  17   */
  18  function bp_nouveau_before_groups_directory_content() {
  19      /**
  20       * Fires at the begining of the templates BP injected content.
  21       *
  22       * @since 2.3.0
  23       */
  24      do_action( 'bp_before_directory_groups_page' );
  25  
  26      /**
  27       * Fires before the display of the groups.
  28       *
  29       * @since 1.1.0
  30       */
  31      do_action( 'bp_before_directory_groups' );
  32  
  33      /**
  34       * Fires before the display of the groups content.
  35       *
  36       * @since 1.1.0
  37       */
  38      do_action( 'bp_before_directory_groups_content' );
  39  }
  40  
  41  /**
  42   * Template tag to wrap all Legacy actions that was used
  43   * after the groups directory content
  44   *
  45   * @since 3.0.0
  46   */
  47  function bp_nouveau_after_groups_directory_content() {
  48      /**
  49       * Fires and displays the group content.
  50       *
  51       * @since 1.1.0
  52       */
  53      do_action( 'bp_directory_groups_content' );
  54  
  55      /**
  56       * Fires after the display of the groups content.
  57       *
  58       * @since 1.1.0
  59       */
  60      do_action( 'bp_after_directory_groups_content' );
  61  
  62      /**
  63       * Fires after the display of the groups.
  64       *
  65       * @since 1.1.0
  66       */
  67      do_action( 'bp_after_directory_groups' );
  68  
  69      /**
  70       * Fires at the bottom of the groups directory template file.
  71       *
  72       * @since 1.5.0
  73       */
  74      do_action( 'bp_after_directory_groups_page' );
  75  }
  76  
  77  /**
  78   * Fire specific hooks into the groups create template.
  79   *
  80   * @since 3.0.0
  81   *
  82   * @param string $when   Optional. Either 'before' or 'after'.
  83   * @param string $suffix Optional. Use it to add terms at the end of the hook name.
  84   */
  85  function bp_nouveau_groups_create_hook( $when = '', $suffix = '' ) {
  86      $hook = array( 'bp' );
  87  
  88      if ( $when ) {
  89          $hook[] = $when;
  90      }
  91  
  92      // It's a create group hook
  93      $hook[] = 'create_group';
  94  
  95      if ( $suffix ) {
  96          $hook[] = $suffix;
  97      }
  98  
  99      bp_nouveau_hook( $hook );
 100  }
 101  
 102  /**
 103   * Fire specific hooks into the single groups templates.
 104   *
 105   * @since 3.0.0
 106   *
 107   * @param string $when   Optional. Either 'before' or 'after'.
 108   * @param string $suffix Optional. Use it to add terms at the end of the hook name.
 109   */
 110  function bp_nouveau_group_hook( $when = '', $suffix = '' ) {
 111      $hook = array( 'bp' );
 112  
 113      if ( $when ) {
 114          $hook[] = $when;
 115      }
 116  
 117      // It's a group hook
 118      $hook[] = 'group';
 119  
 120      if ( $suffix ) {
 121          $hook[] = $suffix;
 122      }
 123  
 124      bp_nouveau_hook( $hook );
 125  }
 126  
 127  /**
 128   * Fire an isolated hook inside the groups loop
 129   *
 130   * @since 3.0.0
 131   */
 132  function bp_nouveau_groups_loop_item() {
 133      /**
 134       * Fires inside the listing of an individual group listing item.
 135       *
 136       * @since 1.1.0
 137       */
 138      do_action( 'bp_directory_groups_item' );
 139  }
 140  
 141  /**
 142   * Display the current group activity post form if needed
 143   *
 144   * @since 3.0.0
 145   */
 146  function bp_nouveau_groups_activity_post_form() {
 147      /**
 148       * Fires before the display of the group activity post form.
 149       *
 150       * @since 1.2.0
 151       */
 152      do_action( 'bp_before_group_activity_post_form' );
 153  
 154      if ( is_user_logged_in() && bp_group_is_member() ) {
 155          bp_get_template_part( 'activity/post-form' );
 156      }
 157  
 158      /**
 159       * Fires after the display of the group activity post form.
 160       *
 161       * @since 1.2.0
 162       */
 163      do_action( 'bp_after_group_activity_post_form' );
 164  }
 165  
 166  /**
 167   * Load the Group Invites UI.
 168   *
 169   * @since 3.0.0
 170   *
 171   * @return string HTML Output.
 172   */
 173  function bp_nouveau_group_invites_interface() {
 174      /**
 175       * Fires before the send invites content.
 176       *
 177       * @since 1.1.0
 178       */
 179      do_action( 'bp_before_group_send_invites_content' );
 180  
 181      bp_get_template_part( 'common/js-templates/invites/index' );
 182  
 183      /**
 184       * Fires after the send invites content.
 185       *
 186       * @since 1.2.0
 187       */
 188      do_action( 'bp_after_group_send_invites_content' );
 189  }
 190  
 191  /**
 192   * Gets the displayed user group invites preferences
 193   *
 194   * @since 3.0.0
 195   *
 196   * @return int Returns 1 if user chose to restrict to friends, 0 otherwise.
 197   */
 198  function bp_nouveau_groups_get_group_invites_setting() {
 199      return (int) bp_get_user_meta( bp_displayed_user_id(), '_bp_nouveau_restrict_invites_to_friends' );
 200  }
 201  
 202  /**
 203   * Outputs the group creation numbered steps navbar
 204   *
 205   * @since 3.0.0
 206   *
 207   * @todo This output isn't localised correctly.
 208   */
 209  function bp_nouveau_group_creation_tabs() {
 210      $bp = buddypress();
 211  
 212      if ( ! is_array( $bp->groups->group_creation_steps ) ) {
 213          return;
 214      }
 215  
 216      if ( ! bp_get_groups_current_create_step() ) {
 217          $keys                            = array_keys( $bp->groups->group_creation_steps );
 218          $bp->groups->current_create_step = array_shift( $keys );
 219      }
 220  
 221      $counter = 1;
 222  
 223      foreach ( (array) $bp->groups->group_creation_steps as $slug => $step ) {
 224          $is_enabled = bp_are_previous_group_creation_steps_complete( $slug ); ?>
 225  
 226          <li<?php if ( bp_get_groups_current_create_step() === $slug ) : ?> class="current"<?php endif; ?>>
 227              <?php if ( $is_enabled ) : ?>
 228                  <a href="<?php echo esc_url( bp_groups_directory_permalink() . 'create/step/' . $slug . '/' ); ?>">
 229                      <?php echo (int) $counter; ?> <?php echo esc_html( $step['name'] ); ?>
 230                  </a>
 231              <?php else : ?>
 232                  <?php echo (int) $counter; ?>. <?php echo esc_html( $step['name'] ); ?>
 233              <?php endif ?>
 234          </li>
 235              <?php
 236          $counter++;
 237      }
 238  
 239      unset( $is_enabled );
 240  
 241      /**
 242       * Fires at the end of the creation of the group tabs.
 243       *
 244       * @since 1.0.0
 245       */
 246      do_action( 'groups_creation_tabs' );
 247  }
 248  
 249  /**
 250   * Load the requested Create Screen for the new group.
 251   *
 252   * @since 3.0.0
 253   */
 254  function bp_nouveau_group_creation_screen() {
 255      return bp_nouveau_group_manage_screen();
 256  }
 257  
 258  /**
 259   * Load the requested Manage Screen for the current group.
 260   *
 261   * @since 3.0.0
 262   */
 263  
 264  function bp_nouveau_group_manage_screen() {
 265      $action          = bp_action_variable( 0 );
 266      $is_group_create = bp_is_group_create();
 267      $output          = '';
 268  
 269      if ( $is_group_create ) {
 270          $action = bp_action_variable( 1 );
 271      }
 272  
 273      $screen_id = sanitize_file_name( $action );
 274      if ( ! bp_is_group_admin_screen( $screen_id ) && ! bp_is_group_creation_step( $screen_id ) ) {
 275          return;
 276      }
 277  
 278      if ( ! $is_group_create ) {
 279          /**
 280           * Fires inside the group admin form and before the content.
 281           *
 282           * @since 1.1.0
 283           */
 284          do_action( 'bp_before_group_admin_content' );
 285  
 286          $core_screen = bp_nouveau_group_get_core_manage_screens( $screen_id );
 287  
 288      // It's a group step, get the creation screens.
 289      } else {
 290          $core_screen = bp_nouveau_group_get_core_create_screens( $screen_id );
 291      }
 292  
 293      if ( ! $core_screen ) {
 294          if ( ! $is_group_create ) {
 295              /**
 296               * Fires inside the group admin template.
 297               *
 298               * Allows plugins to add custom group edit screens.
 299               *
 300               * @since 1.1.0
 301               */
 302              do_action( 'groups_custom_edit_steps' );
 303  
 304          // Else use the group create hook
 305          } else {
 306              /**
 307               * Fires inside the group admin template.
 308               *
 309               * Allows plugins to add custom group creation steps.
 310               *
 311               * @since 1.1.0
 312               */
 313              do_action( 'groups_custom_create_steps' );
 314          }
 315  
 316      // Else we load the core screen.
 317      } else {
 318          if ( ! empty( $core_screen['hook'] ) ) {
 319              /**
 320               * Fires before the display of group delete admin.
 321               *
 322               * @since 1.1.0 For most hooks.
 323               * @since 2.4.0 For the cover image hook.
 324               */
 325              do_action( 'bp_before_' . $core_screen['hook'] );
 326          }
 327  
 328          $template = 'groups/single/admin/' . $screen_id;
 329  
 330          if ( ! empty( $core_screen['template'] ) ) {
 331              $template = $core_screen['template'];
 332          }
 333  
 334          bp_get_template_part( $template );
 335  
 336          if ( ! empty( $core_screen['hook'] ) ) {
 337  
 338              // Group's "Manage > Details" page.
 339              if ( 'group_details_admin' === $core_screen['hook'] ) {
 340                  /**
 341                   * Fires after the group description admin details.
 342                   *
 343                   * @since 1.0.0
 344                   */
 345                  do_action( 'groups_custom_group_fields_editable' );
 346              }
 347  
 348              /**
 349               * Fires before the display of group delete admin.
 350               *
 351               * @since 1.1.0 For most hooks.
 352               * @since 2.4.0 For the cover image hook.
 353               */
 354              do_action( 'bp_after_' . $core_screen['hook'] );
 355          }
 356  
 357          if ( ! empty( $core_screen['nonce'] ) ) {
 358              if ( ! $is_group_create ) {
 359                  $output = sprintf( '<p><input type="submit" value="%s" id="save" name="save" /></p>', esc_attr__( 'Save Changes', 'buddypress' ) );
 360  
 361                  // Specific case for the delete group screen
 362                  if ( 'delete-group' === $screen_id ) {
 363                      $output = sprintf(
 364                          '<div class="submit">
 365                              <input type="submit" disabled="disabled" value="%s" id="delete-group-button" name="delete-group-button" />
 366                          </div>',
 367                          esc_attr__( 'Delete Group', 'buddypress' )
 368                      );
 369                  }
 370              }
 371          }
 372      }
 373  
 374      if ( $is_group_create ) {
 375          /**
 376           * Fires before the display of the group creation step buttons.
 377           *
 378           * @since 1.1.0
 379           */
 380          do_action( 'bp_before_group_creation_step_buttons' );
 381  
 382          if ( 'crop-image' !== bp_get_avatar_admin_step() ) {
 383              $creation_step_buttons = '';
 384  
 385              if ( ! bp_is_first_group_creation_step() ) {
 386                  $creation_step_buttons .= sprintf(
 387                      '<input type="button" value="%1$s" id="group-creation-previous" name="previous" onclick="%2$s" />',
 388                      esc_attr__( 'Back to Previous Step', 'buddypress' ),
 389                      "location.href='" . esc_js( esc_url_raw( bp_get_group_creation_previous_link() ) ) . "'"
 390                  );
 391              }
 392  
 393              if ( ! bp_is_last_group_creation_step() && ! bp_is_first_group_creation_step() ) {
 394                  $creation_step_buttons .= sprintf(
 395                      '<input type="submit" value="%s" id="group-creation-next" name="save" />',
 396                      esc_attr__( 'Next Step', 'buddypress' )
 397                  );
 398              }
 399  
 400              if ( bp_is_first_group_creation_step() ) {
 401                  $creation_step_buttons .= sprintf(
 402                      '<input type="submit" value="%s" id="group-creation-create" name="save" />',
 403                      esc_attr__( 'Create Group and Continue', 'buddypress' )
 404                  );
 405              }
 406  
 407              if ( bp_is_last_group_creation_step() ) {
 408                  $creation_step_buttons .= sprintf(
 409                      '<input type="submit" value="%s" id="group-creation-finish" name="save" />',
 410                      esc_attr__( 'Finish', 'buddypress' )
 411                  );
 412              }
 413  
 414              // Set the output for the buttons
 415              $output = sprintf( '<div class="submit" id="previous-next">%s</div>', $creation_step_buttons );
 416          }
 417  
 418          /**
 419           * Fires after the display of the group creation step buttons.
 420           *
 421           * @since 1.1.0
 422           */
 423          do_action( 'bp_after_group_creation_step_buttons' );
 424      }
 425  
 426      /**
 427       * Avoid nested forms with the Backbone views for the group invites step.
 428       */
 429      if ( 'group-invites' === bp_get_groups_current_create_step() ) {
 430          printf(
 431              '<form action="%s" method="post" enctype="multipart/form-data">',
 432              bp_get_group_creation_form_action()
 433          );
 434      }
 435  
 436      if ( ! empty( $core_screen['nonce'] ) ) {
 437          wp_nonce_field( $core_screen['nonce'] );
 438      }
 439  
 440      printf(
 441          '<input type="hidden" name="group-id" id="group-id" value="%s" />',
 442          $is_group_create ? esc_attr( bp_get_new_group_id() ) : esc_attr( bp_get_group_id() )
 443      );
 444  
 445      // The submit actions
 446      echo $output;
 447  
 448      if ( ! $is_group_create ) {
 449          /**
 450           * Fires inside the group admin form and after the content.
 451           *
 452           * @since 1.1.0
 453           */
 454          do_action( 'bp_after_group_admin_content' );
 455  
 456      } else {
 457          /**
 458           * Fires and displays the groups directory content.
 459           *
 460           * @since 1.1.0
 461           */
 462          do_action( 'bp_directory_groups_content' );
 463      }
 464  
 465      /**
 466       * Avoid nested forms with the Backbone views for the group invites step.
 467       */
 468      if ( 'group-invites' === bp_get_groups_current_create_step() ) {
 469          echo '</form>';
 470      }
 471  }
 472  
 473  /**
 474   * Output the action buttons for the displayed group
 475   *
 476   * @since 3.0.0
 477   *
 478   * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 479   */
 480  function bp_nouveau_group_header_buttons( $args = array() ) {
 481      $bp_nouveau = bp_nouveau();
 482  
 483      $output = join( ' ', bp_nouveau_get_groups_buttons( $args ) );
 484  
 485      // On the group's header we need to reset the group button's global.
 486      if ( ! empty( $bp_nouveau->groups->group_buttons ) ) {
 487          unset( $bp_nouveau->groups->group_buttons );
 488      }
 489  
 490      ob_start();
 491      /**
 492       * Fires in the group header actions section.
 493       *
 494       * @since 1.2.6
 495       */
 496      do_action( 'bp_group_header_actions' );
 497      $output .= ob_get_clean();
 498  
 499      if ( ! $output ) {
 500          return;
 501      }
 502  
 503      if ( ! $args ) {
 504          $args = array( 'classes' => array( 'item-buttons' ) );
 505      }
 506  
 507      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 508  }
 509  
 510  /**
 511   * Output the action buttons inside the groups loop.
 512   *
 513   * @since 3.0.0
 514   *
 515   * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 516   */
 517  function bp_nouveau_groups_loop_buttons( $args = array() ) {
 518      if ( empty( $GLOBALS['groups_template'] ) ) {
 519          return;
 520      }
 521  
 522      $args['type'] = 'loop';
 523  
 524      $output = join( ' ', bp_nouveau_get_groups_buttons( $args ) );
 525  
 526      ob_start();
 527      /**
 528       * Fires inside the action section of an individual group listing item.
 529       *
 530       * @since 1.1.0
 531       */
 532      do_action( 'bp_directory_groups_actions' );
 533      $output .= ob_get_clean();
 534  
 535      if ( ! $output ) {
 536          return;
 537      }
 538  
 539      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 540  }
 541  
 542  /**
 543   * Output the action buttons inside the invites loop of the displayed user.
 544   *
 545   * @since 3.0.0
 546   *
 547   * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 548   */
 549  function bp_nouveau_groups_invite_buttons( $args = array() ) {
 550      if ( empty( $GLOBALS['groups_template'] ) ) {
 551          return;
 552      }
 553  
 554      $args['type'] = 'invite';
 555  
 556      $output = join( ' ', bp_nouveau_get_groups_buttons( $args ) );
 557  
 558      ob_start();
 559      /**
 560       * Fires inside the member group item action markup.
 561       *
 562       * @since 1.1.0
 563       */
 564      do_action( 'bp_group_invites_item_action' );
 565      $output .= ob_get_clean();
 566  
 567      if ( ! $output ) {
 568          return;
 569      }
 570  
 571      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 572  }
 573  
 574  /**
 575   * Output the action buttons inside the requests loop of the group's manage screen.
 576   *
 577   * @since 3.0.0
 578   *
 579   * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 580   */
 581  function bp_nouveau_groups_request_buttons( $args = array() ) {
 582      if ( empty( $GLOBALS['requests_template'] ) ) {
 583          return;
 584      }
 585  
 586      $args['type'] = 'request';
 587  
 588      $output = join( ' ', bp_nouveau_get_groups_buttons( $args ) );
 589  
 590      ob_start();
 591      /**
 592       * Fires inside the list of membership request actions.
 593       *
 594       * @since 1.1.0
 595       */
 596      do_action( 'bp_group_membership_requests_admin_item_action' );
 597      $output .= ob_get_clean();
 598  
 599      if ( ! $output ) {
 600          return;
 601      }
 602  
 603      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 604  }
 605  
 606  /**
 607   * Output the action buttons inside the manage members loop of the group's manage screen.
 608   *
 609   * @since 3.0.0
 610   *
 611   * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 612   */
 613  function bp_nouveau_groups_manage_members_buttons( $args = array() ) {
 614      if ( empty( $GLOBALS['members_template'] ) ) {
 615          return;
 616      }
 617  
 618      $args['type'] = 'manage_members';
 619  
 620      $output = join( ' ', bp_nouveau_get_groups_buttons( $args ) );
 621  
 622      ob_start();
 623      /**
 624       * Fires inside the display of a member admin item in group management area.
 625       *
 626       * @since 1.1.0
 627       */
 628      do_action( 'bp_group_manage_members_admin_item' );
 629      $output .= ob_get_clean();
 630  
 631      if ( ! $output ) {
 632          return;
 633      }
 634  
 635      if ( ! $args ) {
 636          $args = array(
 637              'wrapper' => 'span',
 638              'classes' => array( 'small' ),
 639          );
 640      }
 641  
 642      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 643  }
 644  
 645      /**
 646       * Get the action buttons for the current group in the loop,
 647       * or the current displayed group.
 648       *
 649       * @since 3.0.0
 650       *
 651       * @param array $args Optional. See bp_nouveau_wrapper() for the description of parameters.
 652       */
 653  	function bp_nouveau_get_groups_buttons( $args = array() ) {
 654          $type = ( ! empty( $args['type'] ) ) ? $args['type'] : 'group';
 655  
 656          // @todo Not really sure why BP Legacy needed to do this...
 657          if ( 'group' === $type && is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
 658              return;
 659          }
 660  
 661          $buttons = array();
 662  
 663          if ( ( 'loop' === $type || 'invite' === $type ) && isset( $GLOBALS['groups_template']->group ) ) {
 664              $group = $GLOBALS['groups_template']->group;
 665          } else {
 666              $group = groups_get_current_group();
 667          }
 668  
 669          if ( empty( $group->id ) ) {
 670              return $buttons;
 671          }
 672  
 673          /*
 674           * If the 'container' is set to 'ul' set $parent_element to li,
 675           * otherwise simply pass any value found in $args or set var false.
 676           */
 677          if ( ! empty( $args['container'] ) && 'ul' === $args['container']  ) {
 678              $parent_element = 'li';
 679          } elseif ( ! empty( $args['parent_element'] ) ) {
 680              $parent_element = $args['parent_element'];
 681          } else {
 682              $parent_element = false;
 683          }
 684  
 685          /*
 686           * If we have a arg value for $button_element passed through
 687           * use it to default all the $buttons['button_element'] values
 688           * otherwise default to 'a' (anchor) o override & hardcode the
 689           * 'element' string on $buttons array.
 690           *
 691           * Icons sets a class for icon display if not using the button element
 692           */
 693          $icons = '';
 694          if ( ! empty( $args['button_element'] ) ) {
 695              $button_element = $args['button_element'] ;
 696          } else {
 697              $button_element = 'a';
 698              $icons = ' icons';
 699          }
 700  
 701          // If we pass through parent classes add them to $button array
 702          $parent_class = '';
 703          if ( ! empty( $args['parent_attr']['class'] ) ) {
 704              $parent_class = $args['parent_attr']['class'];
 705          }
 706  
 707          // Invite buttons on member's invites screen
 708          if ( 'invite' === $type ) {
 709              // Don't show button if not logged in or previously banned
 710              if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) || empty( $group->status ) ) {
 711                  return $buttons;
 712              }
 713  
 714              // Setup Accept button attributes
 715              $buttons['accept_invite'] =  array(
 716                  'id'                => 'accept_invite',
 717                  'position'          => 5,
 718                  'component'         => 'groups',
 719                  'must_be_logged_in' => true,
 720                  'parent_element'    => $parent_element,
 721                  'link_text'         => esc_html__( 'Accept', 'buddypress' ),
 722                  'button_element'    => $button_element,
 723                  'parent_attr'       => array(
 724                      'id'    => '',
 725                      'class' => $parent_class . ' ' . 'accept',
 726                  ),
 727                  'button_attr'       => array(
 728                      'id'    => '',
 729                      'class' => 'button accept group-button accept-invite',
 730                      'rel'   => '',
 731                  ),
 732              );
 733  
 734              // If button element set add nonce link to data-attr attr
 735              if ( 'button' === $button_element ) {
 736                  $buttons['accept_invite']['button_attr']['data-bp-nonce'] = esc_url( bp_get_group_accept_invite_link() );
 737              } else {
 738                  $buttons['accept_invite']['button_attr']['href'] = esc_url( bp_get_group_accept_invite_link() );
 739              }
 740  
 741              // Setup Reject button attributes
 742              $buttons['reject_invite'] = array(
 743                  'id'                => 'reject_invite',
 744                  'position'          => 15,
 745                  'component'         => 'groups',
 746                  'must_be_logged_in' => true,
 747                  'parent_element'    => $parent_element,
 748                  'link_text'         => __( 'Reject', 'buddypress' ),
 749                  'parent_attr'       => array(
 750                      'id'    => '',
 751                      'class' => $parent_class . ' ' . 'reject',
 752                  ),
 753                  'button_element'    => $button_element,
 754                  'button_attr'       => array(
 755                      'id'    => '',
 756                      'class' => 'button reject group-button reject-invite',
 757                      'rel'   => '',
 758                  ),
 759              );
 760  
 761              // If button element set add nonce link to formaction attr
 762              if ( 'button' === $button_element ) {
 763                  $buttons['reject_invite']['button_attr']['data-bp-nonce'] = esc_url( bp_get_group_reject_invite_link() );
 764              } else {
 765                  $buttons['reject_invite']['button_attr']['href'] = esc_url( bp_get_group_reject_invite_link() );
 766              }
 767  
 768          // Request button for the group's manage screen
 769          } elseif ( 'request' === $type ) {
 770              // Setup Accept button attributes
 771              $buttons['group_membership_accept'] =  array(
 772                  'id'                => 'group_membership_accept',
 773                  'position'          => 5,
 774                  'component'         => 'groups',
 775                  'must_be_logged_in' => true,
 776                  'parent_element'    => $parent_element,
 777                  'link_text'         => esc_html__( 'Accept', 'buddypress' ),
 778                  'button_element'    => $button_element,
 779                  'parent_attr'       => array(
 780                      'id'    => '',
 781                      'class' => $parent_class,
 782                  ),
 783                  'button_attr'       => array(
 784                      'id'    => '',
 785                      'class' => 'button accept',
 786                      'rel'   => '',
 787                  ),
 788              );
 789  
 790              // If button element set add nonce link to data-attr attr
 791              if ( 'button' === $button_element ) {
 792                  $buttons['group_membership_accept']['button_attr']['data-bp-nonce'] = esc_url( bp_get_group_request_accept_link() );
 793              } else {
 794                  $buttons['group_membership_accept']['button_attr']['href'] = esc_url( bp_get_group_request_accept_link() );
 795              }
 796  
 797              $buttons['group_membership_reject'] = array(
 798                  'id'                => 'group_membership_reject',
 799                  'position'          => 15,
 800                  'component'         => 'groups',
 801                  'must_be_logged_in' => true,
 802                  'parent_element'    => $parent_element,
 803                  'button_element'    => $button_element,
 804                  'link_text'         => __( 'Reject', 'buddypress' ),
 805                  'parent_attr'       => array(
 806                      'id'    => '',
 807                      'class' => $parent_class,
 808                  ),
 809                  'button_attr'       => array(
 810                      'id'    => '',
 811                      'class' => 'button reject',
 812                      'rel'   => '',
 813                  ),
 814              );
 815  
 816              // If button element set add nonce link to data-attr attr
 817              if ( 'button' === $button_element ) {
 818                  $buttons['group_membership_reject']['button_attr']['data-bp-nonce'] = esc_url( bp_get_group_request_reject_link() );
 819              } else {
 820                  $buttons['group_membership_reject']['button_attr']['href'] = esc_url( bp_get_group_request_reject_link() );
 821              }
 822  
 823          /*
 824           * Manage group members for the group's manage screen.
 825           * The 'button_attr' keys 'href' & 'formaction' are set at the end of this array block
 826           */
 827          } elseif ( 'manage_members' === $type && isset( $GLOBALS['members_template']->member->user_id ) ) {
 828              $user_id = $GLOBALS['members_template']->member->user_id;
 829  
 830              $buttons = array(
 831                  'unban_member' => array(
 832                      'id'                => 'unban_member',
 833                      'position'          => 5,
 834                      'component'         => 'groups',
 835                      'must_be_logged_in' => true,
 836                      'parent_element'    => $parent_element,
 837                      'button_element'    => $button_element,
 838                      'link_text'         => __( 'Remove Ban', 'buddypress' ),
 839                      'parent_attr'       => array(
 840                          'id'    => '',
 841                          'class' => $parent_class,
 842                      ),
 843                      'button_attr'       => array(
 844                          'id'    => '',
 845                          'class' => 'button confirm member-unban',
 846                          'rel'   => '',
 847                          'title' => '',
 848                      ),
 849                  ),
 850                  'ban_member' => array(
 851                      'id'                => 'ban_member',
 852                      'position'          => 15,
 853                      'component'         => 'groups',
 854                      'must_be_logged_in' => true,
 855                      'parent_element'    => $parent_element,
 856                      'button_element'    => $button_element,
 857                      'link_text'         => __( 'Kick &amp; Ban', 'buddypress' ),
 858                      'parent_attr'       => array(
 859                          'id'    => '',
 860                          'class' => $parent_class,
 861                      ),
 862                      'button_attr'       => array(
 863                          'id'    => '',
 864                          'class' => 'button confirm member-ban',
 865                          'rel'   => '',
 866                          'title' => '',
 867                      ),
 868                  ),
 869                  'promote_mod' => array(
 870                      'id'                => 'promote_mod',
 871                      'position'          => 25,
 872                      'component'         => 'groups',
 873                      'must_be_logged_in' => true,
 874                      'parent_element'    => $parent_element,
 875                      'parent_attr'       => array(
 876                          'id'    => '',
 877                          'class' => $parent_class,
 878                      ),
 879                      'button_element'    => $button_element,
 880                      'button_attr'       => array(
 881                          'id'               => '',
 882                          'class'            => 'button confirm member-promote-to-mod',
 883                          'rel'              => '',
 884                          'title'            => '',
 885                      ),
 886                      'link_text'         => __( 'Promote to Mod', 'buddypress' ),
 887                  ),
 888                  'promote_admin' => array(
 889                      'id'                => 'promote_admin',
 890                      'position'          => 35,
 891                      'component'         => 'groups',
 892                      'must_be_logged_in' => true,
 893                      'parent_element'    => $parent_element,
 894                      'button_element'    => $button_element,
 895                      'link_text'         => __( 'Promote to Admin', 'buddypress' ),
 896                      'parent_attr'       => array(
 897                          'id'    => '',
 898                          'class' => $parent_class,
 899                      ),
 900                      'button_attr'       => array(
 901                          'href'  => esc_url( bp_get_group_member_promote_admin_link() ),
 902                          'id'    => '',
 903                          'class' => 'button confirm member-promote-to-admin',
 904                          'rel'   => '',
 905                          'title' => '',
 906                      ),
 907                  ),
 908                  'remove_member' => array(
 909                      'id'                => 'remove_member',
 910                      'position'          => 45,
 911                      'component'         => 'groups',
 912                      'must_be_logged_in' => true,
 913                      'parent_element'    => $parent_element,
 914                      'button_element'    => $button_element,
 915                      'link_text'         => __( 'Remove from group', 'buddypress' ),
 916                      'parent_attr'       => array(
 917                          'id'    => '',
 918                          'class' => $parent_class,
 919                      ),
 920                      'button_attr'       => array(
 921                          'id'    => '',
 922                          'class' => 'button confirm',
 923                          'rel'   => '',
 924                          'title' => '',
 925                      ),
 926                  ),
 927              );
 928  
 929              // If 'button' element is set add the nonce link to data-attr attr, else add it to the href.
 930              if ( 'button' === $button_element ) {
 931                  $buttons['unban_member']['button_attr']['data-bp-nonce'] = bp_get_group_member_unban_link( $user_id );
 932                  $buttons['ban_member']['button_attr']['data-bp-nonce'] = bp_get_group_member_ban_link( $user_id );
 933                  $buttons['promote_mod']['button_attr']['data-bp-nonce'] = bp_get_group_member_promote_mod_link();
 934                  $buttons['promote_admin']['button_attr']['data-bp-nonce'] = bp_get_group_member_promote_admin_link();
 935                  $buttons['remove_member']['button_attr']['data-bp-nonce'] = bp_get_group_member_remove_link( $user_id );
 936              } else {
 937                  $buttons['unban_member']['button_attr']['href'] = bp_get_group_member_unban_link( $user_id );
 938                  $buttons['ban_member']['button_attr']['href'] = bp_get_group_member_ban_link( $user_id );
 939                  $buttons['promote_mod']['button_attr']['href'] = bp_get_group_member_promote_mod_link();
 940                  $buttons['promote_admin']['button_attr']['href'] = bp_get_group_member_promote_admin_link();
 941                  $buttons['remove_member']['button_attr']['href'] = bp_get_group_member_remove_link( $user_id );
 942              }
 943  
 944          // Membership button on groups loop or single group's header
 945          } else {
 946              /*
 947               * This filter workaround is waiting for a core adaptation
 948               * so that we can directly get the groups button arguments
 949               * instead of the button.
 950               *
 951               * See https://buddypress.trac.wordpress.org/ticket/7126
 952               */
 953              add_filter( 'bp_get_group_join_button', 'bp_nouveau_groups_catch_button_args', 100, 1 );
 954  
 955              bp_get_group_join_button( $group );
 956  
 957              remove_filter( 'bp_get_group_join_button', 'bp_nouveau_groups_catch_button_args', 100, 1 );
 958  
 959              if ( isset( bp_nouveau()->groups->button_args ) && bp_nouveau()->groups->button_args ) {
 960                  $button_args = bp_nouveau()->groups->button_args;
 961  
 962                  // If we pass through parent classes merge those into the existing ones
 963                  if ( $parent_class ) {
 964                      $parent_class .= ' ' . $button_args['wrapper_class'];
 965                  }
 966  
 967                  // The join or leave group header button should default to 'button'
 968                  // Reverse the earler button var to set default as 'button' not 'a'
 969                  if ( empty( $args['button_element'] ) ) {
 970                      $button_element = 'button';
 971                  }
 972  
 973                  $buttons['group_membership'] = array(
 974                      'id'                => 'group_membership',
 975                      'position'          => 5,
 976                      'component'         => $button_args['component'],
 977                      'must_be_logged_in' => $button_args['must_be_logged_in'],
 978                      'block_self'        => $button_args['block_self'],
 979                      'parent_element'    => $parent_element,
 980                      'button_element'    => $button_element,
 981                      'link_text'         => $button_args['link_text'],
 982                      'parent_attr'       => array(
 983                              'id'    => $button_args['wrapper_id'],
 984                              'class' => $parent_class,
 985                      ),
 986                      'button_attr'       => array(
 987                          'id'    => ! empty( $button_args['link_id'] ) ? $button_args['link_id'] : '',
 988                          'class' => $button_args['link_class'] . ' button',
 989                          'rel'   => ! empty( $button_args['link_rel'] ) ? $button_args['link_rel'] : '',
 990                          'title' => '',
 991                      ),
 992                  );
 993  
 994              // If button element set add nonce 'href' link to data-attr attr.
 995              if ( 'button' === $button_element ) {
 996                  $buttons['group_membership']['button_attr']['data-bp-nonce'] = $button_args['link_href'];
 997              } else {
 998              // Else this is an anchor so use an 'href' attr.
 999                  $buttons['group_membership']['button_attr']['href'] = $button_args['link_href'];
1000              }
1001  
1002                  unset( bp_nouveau()->groups->button_args );
1003              }
1004          }
1005  
1006          /**
1007           * Filter to add your buttons, use the position argument to choose where to insert it.
1008           *
1009           * @since 3.0.0
1010           *
1011           * @param array  $buttons The list of buttons.
1012           * @param int    $group   The current group object.
1013           * @param string $type    Whether we're displaying a groups loop or a groups single item.
1014           */
1015          $buttons_group = apply_filters( 'bp_nouveau_get_groups_buttons', $buttons, $group, $type );
1016  
1017          if ( ! $buttons_group ) {
1018              return $buttons;
1019          }
1020  
1021          // It's the first entry of the loop, so build the Group and sort it
1022          if ( ! isset( bp_nouveau()->groups->group_buttons ) || ! is_a( bp_nouveau()->groups->group_buttons, 'BP_Buttons_Group' ) ) {
1023              $sort = true;
1024              bp_nouveau()->groups->group_buttons = new BP_Buttons_Group( $buttons_group );
1025  
1026          // It's not the first entry, the order is set, we simply need to update the Buttons Group
1027          } else {
1028              $sort = false;
1029              bp_nouveau()->groups->group_buttons->update( $buttons_group );
1030          }
1031  
1032          $return = bp_nouveau()->groups->group_buttons->get( $sort );
1033  
1034          if ( ! $return ) {
1035              return array();
1036          }
1037  
1038          // Remove buttons according to the user's membership type.
1039          if ( 'manage_members' === $type && isset( $GLOBALS['members_template'] ) ) {
1040              if ( bp_get_group_member_is_banned() ) {
1041                  unset( $return['ban_member'], $return['promote_mod'], $return['promote_admin'] );
1042              } else {
1043                  unset( $return['unban_member'] );
1044              }
1045          }
1046  
1047          /**
1048           * Leave a chance to adjust the $return
1049           *
1050           * @since 3.0.0
1051           *
1052           * @param array  $return  The list of buttons.
1053           * @param int    $group   The current group object.
1054           * @parem string $type    Whether we're displaying a groups loop or a groups single item.
1055           */
1056          do_action_ref_array( 'bp_nouveau_return_groups_buttons', array( &$return, $group, $type ) );
1057  
1058          return $return;
1059      }
1060  
1061  /**
1062   * Does the group has metas or a specific meta value.
1063   *
1064   * @since 3.0.0
1065   * @since 3.2.0 Adds the $meta_key argument.
1066   *
1067   * @param  string $meta_key The key of the meta to check the value for.
1068   * @return bool             True if the group has meta. False otherwise.
1069   */
1070  function bp_nouveau_group_has_meta( $meta_key = '' ) {
1071      $group_meta = bp_nouveau_get_group_meta();
1072  
1073      if ( ! $meta_key ) {
1074          return (bool) $group_meta;
1075      }
1076  
1077      return ! empty( $group_meta[ $meta_key ] );
1078  }
1079  
1080  /**
1081   * Does the group have extra meta?
1082   *
1083   * @since 3.0.0
1084   *
1085   * @return bool True if the group has meta. False otherwise.
1086   */
1087  function bp_nouveau_group_has_meta_extra() {
1088      return (bool) bp_nouveau_get_hooked_group_meta();
1089  }
1090  
1091  /**
1092   * Display the group meta.
1093   *
1094   * @since 3.0.0
1095   *
1096   * @return string HTML Output.
1097   */
1098  function bp_nouveau_group_meta() {
1099      $meta = bp_nouveau_get_group_meta();
1100  
1101      if ( ! bp_is_group() ) {
1102          echo join( ' / ', array_map( 'esc_html', (array) $meta ) );
1103      } else {
1104  
1105          /*
1106           * Lets return an object not echo an array here for the single groups,
1107           * more flexible for the template!!?? ~hnla
1108           *
1109           * @todo Paul says that a function that prints and/or returns a value,
1110           * depending on global state, is madness. This needs changing.
1111           */
1112          return (object) bp_nouveau_get_group_meta();
1113      }
1114  }
1115  
1116      /**
1117       * Get the group meta.
1118       *
1119       * @since 3.0.0
1120       *
1121       * @return array The group meta.
1122       */
1123  	function bp_nouveau_get_group_meta() {
1124          /*
1125           * @todo For brevity required approapriate markup is added here as strings
1126           * this needs to be either filterable or the function needs to be able to accept
1127           * & parse args!
1128           */
1129          $meta     = array();
1130          $is_group = bp_is_group();
1131  
1132          if ( ! empty( $GLOBALS['groups_template']->group ) ) {
1133              $group = $GLOBALS['groups_template']->group;
1134          }
1135  
1136          if ( empty( $group->id ) ) {
1137              return $meta;
1138          }
1139  
1140          if ( empty( $group->template_meta ) ) {
1141              // It's a single group
1142              if ( $is_group ) {
1143                      $meta = array(
1144                          'status'          =>  bp_get_group_type(),
1145                          'group_type_list' =>  bp_get_group_type_list(),
1146                          'description'     =>  bp_get_group_description(),
1147                      );
1148  
1149                  // Make sure to include hooked meta.
1150                  $extra_meta = bp_nouveau_get_hooked_group_meta();
1151  
1152                  if ( $extra_meta ) {
1153                      $meta['extra'] = $extra_meta;
1154                  }
1155  
1156              // We're in the groups loop
1157              } else {
1158                  $meta = array(
1159                      'status' => bp_get_group_type(),
1160                      'count'  => bp_get_group_member_count(),
1161                  );
1162              }
1163  
1164              /**
1165               * Filter to add/remove Group meta.
1166               *
1167               * @since 3.0.0
1168               *
1169               * @param array  $meta     The list of meta to output.
1170               * @param object $group    The current Group of the loop object.
1171               * @param bool   $is_group True if a single group is displayed. False otherwise.
1172               */
1173              $group->template_meta = apply_filters( 'bp_nouveau_get_group_meta', $meta, $group, $is_group );
1174          }
1175  
1176          return $group->template_meta;
1177      }
1178  
1179  /**
1180   * Load the appropriate content for the single group pages
1181   *
1182   * @since 3.0.0
1183   */
1184  function bp_nouveau_group_template_part() {
1185      /**
1186       * Fires before the display of the group home body.
1187       *
1188       * @since 1.2.0
1189       */
1190      do_action( 'bp_before_group_body' );
1191  
1192      $bp_is_group_home = bp_is_group_home();
1193  
1194      if ( $bp_is_group_home && ! bp_current_user_can( 'groups_access_group' ) ) {
1195          /**
1196           * Fires before the display of the group status message.
1197           *
1198           * @since 1.1.0
1199           */
1200          do_action( 'bp_before_group_status_message' );
1201          ?>
1202  
1203          <div id="message" class="info">
1204              <p><?php bp_group_status_message(); ?></p>
1205          </div>
1206  
1207          <?php
1208  
1209          /**
1210           * Fires after the display of the group status message.
1211           *
1212           * @since 1.1.0
1213           */
1214          do_action( 'bp_after_group_status_message' );
1215  
1216      // We have a front template, Use BuddyPress function to load it.
1217      } elseif ( $bp_is_group_home && false !== bp_groups_get_front_template() ) {
1218          bp_groups_front_template_part();
1219  
1220      // Otherwise use BP_Nouveau template hierarchy
1221      } else {
1222          $template = 'plugins';
1223  
1224          // the home page
1225          if ( $bp_is_group_home ) {
1226              if ( bp_is_active( 'activity' ) ) {
1227                  $template = 'activity';
1228              } else {
1229                  $template = 'members';
1230              }
1231  
1232          // Not the home page
1233          } elseif ( bp_is_group_admin_page() ) {
1234              $template = 'admin';
1235          } elseif ( bp_is_group_activity() ) {
1236              $template = 'activity';
1237          } elseif ( bp_is_group_members() ) {
1238              $template = 'members';
1239          } elseif ( bp_is_group_invites() ) {
1240              $template = 'send-invites';
1241          } elseif ( bp_is_group_membership_request() ) {
1242              $template = 'request-membership';
1243          }
1244  
1245          bp_nouveau_group_get_template_part( $template );
1246      }
1247  
1248      /**
1249       * Fires after the display of the group home body.
1250       *
1251       * @since 1.2.0
1252       */
1253      do_action( 'bp_after_group_body' );
1254  }
1255  
1256  /**
1257   * Use the appropriate Group header and enjoy a template hierarchy
1258   *
1259   * @since 3.0.0
1260   */
1261  function bp_nouveau_group_header_template_part() {
1262      $template = 'group-header';
1263  
1264      if ( bp_group_use_cover_image_header() ) {
1265          $template = 'cover-image-header';
1266      }
1267  
1268      /**
1269       * Fires before the display of a group's header.
1270       *
1271       * @since 1.2.0
1272       */
1273      do_action( 'bp_before_group_header' );
1274  
1275      // Get the template part for the header
1276      bp_nouveau_group_get_template_part( $template );
1277  
1278      /**
1279       * Fires after the display of a group's header.
1280       *
1281       * @since 1.2.0
1282       */
1283      do_action( 'bp_after_group_header' );
1284  
1285      bp_nouveau_template_notices();
1286  }
1287  
1288  /**
1289   * Get a link to set the Group's default front page and directly
1290   * reach the Customizer section where it's possible to do it.
1291   *
1292   * @since 3.0.0
1293   *
1294   * @return string HTML Output
1295   */
1296  function bp_nouveau_groups_get_customizer_option_link() {
1297      return bp_nouveau_get_customizer_link(
1298          array(
1299              'object'    => 'group',
1300              'autofocus' => 'bp_nouveau_group_front_page',
1301              'text'      => __( 'Groups default front page', 'buddypress' ),
1302          )
1303      );
1304  }
1305  
1306  /**
1307   * Get a link to set the Group's front page widgets and directly
1308   * reach the Customizer section where it's possible to do it.
1309   *
1310   * @since 3.0.0
1311   *
1312   * @return string HTML Output
1313   */
1314  function bp_nouveau_groups_get_customizer_widgets_link() {
1315      return bp_nouveau_get_customizer_link(
1316          array(
1317              'object'    => 'group',
1318              'autofocus' => 'sidebar-widgets-sidebar-buddypress-groups',
1319              'text'      => __( '(BuddyPress) Widgets', 'buddypress' ),
1320          )
1321      );
1322  }
1323  
1324  /**
1325   * Output the group description excerpt
1326   *
1327   * @since 3.0.0
1328   *
1329   * @param object $group Optional. The group being referenced.
1330   *                      Defaults to the group currently being iterated on in the groups loop.
1331   * @param int $length   Optional. Length of returned string, including ellipsis. Default: 100.
1332   *
1333   * @return string Excerpt.
1334   */
1335  function bp_nouveau_group_description_excerpt( $group = null, $length = null ) {
1336      echo bp_nouveau_get_group_description_excerpt( $group, $length );
1337  }
1338  
1339  /**
1340   * Filters the excerpt of a group description.
1341   *
1342   * Checks if the group loop is set as a 'Grid' layout and returns a reduced excerpt.
1343   *
1344   * @since 3.0.0
1345   *
1346   * @param object $group Optional. The group being referenced. Defaults to the group currently being
1347   *                      iterated on in the groups loop.
1348   * @param int $length   Optional. Length of returned string, including ellipsis. Default: 100.
1349   *
1350   * @return string Excerpt.
1351   */
1352  function bp_nouveau_get_group_description_excerpt( $group = null, $length = null ) {
1353      global $groups_template;
1354  
1355      if ( ! $group ) {
1356          $group =& $groups_template->group;
1357      }
1358  
1359      /**
1360       * If this is a grid layout but no length is passed in set a shorter
1361       * default value otherwise use the passed in value.
1362       * If not a grid then the BP core default is used or passed in value.
1363       */
1364      if ( bp_nouveau_loop_is_grid() && 'groups' === bp_current_component() ) {
1365          if ( ! $length ) {
1366              $length = 100;
1367          } else {
1368              $length = $length;
1369          }
1370      }
1371  
1372      /**
1373       * Filters the excerpt of a group description.
1374       *
1375       * @since 3.0.0
1376       *
1377       * @param string $value Excerpt of a group description.
1378       * @param object $group Object for group whose description is made into an excerpt.
1379       */
1380      return apply_filters( 'bp_nouveau_get_group_description_excerpt', bp_create_excerpt( $group->description, $length ), $group );
1381  }
1382  
1383  /**
1384   * Output "checked" attribute to determine if the group type should be checked.
1385   *
1386   * @since 3.2.0
1387   *
1388   * @param object $type Group type object. See bp_groups_get_group_type_object().
1389   */
1390  function bp_nouveau_group_type_checked( $type = null ) {
1391      if ( ! is_object( $type ) ) {
1392          return;
1393      }
1394  
1395      // Group creation screen requires a different check.
1396      if ( bp_is_group_create() ) {
1397          checked( true, ! empty( $type->create_screen_checked ) );
1398      } elseif ( bp_is_group() ) {
1399          checked( bp_groups_has_group_type( bp_get_current_group_id(), $type->name ) );
1400      }
1401  }
1402  
1403  /**
1404   * Adds the "Notify group members of these changes" checkbox to the Manage > Details panel.
1405   *
1406   * See #7837 for background on why this technique is required.
1407   *
1408   * @since 4.0.0
1409   */
1410  function bp_nouveau_add_notify_group_members_checkbox() {
1411      printf( '<p class="bp-controls-wrap">
1412          <label for="group-notify-members" class="bp-label-text">
1413              <input type="checkbox" name="group-notify-members" id="group-notify-members" value="1" /> %s
1414          </label>
1415      </p>', esc_html__( 'Notify group members of these changes via email', 'buddypress' ) );
1416  }
1417  add_action( 'groups_custom_group_fields_editable', 'bp_nouveau_add_notify_group_members_checkbox', 20 );


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