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


Generated: Fri Oct 18 01:01:36 2019 Cross-referenced by PHPXref 0.7.1