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


Generated: Thu Jul 9 01:01:31 2020 Cross-referenced by PHPXref 0.7.1