[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-nouveau/includes/ -> functions.php (source)

   1  <?php
   2  /**
   3   * Common functions
   4   *
   5   * @since 3.0.0
   6   * @version 3.1.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * This function looks scarier than it actually is. :)
  14   * Each object loop (activity/members/groups/blogs/forums) contains default
  15   * parameters to show specific information based on the page we are currently
  16   * looking at.
  17   *
  18   * The following function will take into account any cookies set in the JS and
  19   * allow us to override the parameters sent. That way we can change the results
  20   * returned without reloading the page.
  21   *
  22   * By using cookies we can also make sure that user settings are retained
  23   * across page loads.
  24   *
  25   * @since 3.0.0
  26   *
  27   * @param string $query_string Query string for the current request.
  28   * @param string $object       Object for cookie.
  29   *
  30   * @return string Query string for the component loops
  31   */
  32  function bp_nouveau_ajax_querystring( $query_string, $object ) {
  33      if ( empty( $object ) ) {
  34          return '';
  35      }
  36  
  37      // Default query
  38      $post_query = array(
  39          'filter'       => '',
  40          'scope'        => 'all',
  41          'page'         => 1,
  42          'search_terms' => '',
  43          'extras'       => '',
  44      );
  45  
  46      if ( ! empty( $_POST ) ) {
  47          $post_query = bp_parse_args(
  48              $_POST,
  49              $post_query,
  50              'nouveau_ajax_querystring'
  51          );
  52  
  53          // Make sure to transport the scope, filter etc.. in HeartBeat Requests
  54          if ( ! empty( $post_query['data']['bp_heartbeat'] ) ) {
  55              $bp_heartbeat = $post_query['data']['bp_heartbeat'];
  56  
  57              // Remove heartbeat specific vars
  58              $post_query = array_diff_key(
  59                  bp_parse_args(
  60                      $bp_heartbeat,
  61                      $post_query,
  62                      'nouveau_ajax_querystring_heartbeat'
  63                  ),
  64                  array(
  65                      'data'      => false,
  66                      'interval'  => false,
  67                      '_nonce'    => false,
  68                      'action'    => false,
  69                      'screen_id' => false,
  70                      'has_focus' => false,
  71                  )
  72              );
  73          }
  74      }
  75  
  76      // Init the query string
  77      $qs = array();
  78  
  79      // Activity stream filtering on action.
  80      if ( ! empty( $post_query['filter'] ) && '-1' !== $post_query['filter'] ) {
  81          if ( 'notifications' === $object ) {
  82              $qs[] = 'component_action=' . $post_query['filter'];
  83          } else {
  84              $qs[] = 'type=' . $post_query['filter'];
  85              $qs[] = 'action=' . $post_query['filter'];
  86          }
  87      }
  88  
  89      // Sort the notifications if needed
  90      if ( ! empty( $post_query['extras'] ) && 'notifications' === $object ) {
  91          $qs[] = 'sort_order=' . $post_query['extras'];
  92      }
  93  
  94      if ( 'personal' === $post_query['scope'] ) {
  95          $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
  96          $qs[]    = 'user_id=' . $user_id;
  97      }
  98  
  99      // Activity stream scope only on activity directory.
 100      if ( 'all' !== $post_query['scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() ) {
 101          $qs[] = 'scope=' . $post_query['scope'];
 102      }
 103  
 104      // If page have been passed via the AJAX post request, use those.
 105      if ( '-1' != $post_query['page'] ) {
 106          $qs[] = 'page=' . absint( $post_query['page'] );
 107      }
 108  
 109      // Excludes activity just posted and avoids duplicate ids.
 110      if ( ! empty( $post_query['exclude_just_posted'] ) ) {
 111          $just_posted = wp_parse_id_list( $post_query['exclude_just_posted'] );
 112          $qs[]        = 'exclude=' . implode( ',', $just_posted );
 113      }
 114  
 115      // To get newest activities.
 116      if ( ! empty( $post_query['offset'] ) ) {
 117          $qs[] = 'offset=' . intval( $post_query['offset'] );
 118      }
 119  
 120      $object_search_text = bp_get_search_default_text( $object );
 121      if ( ! empty( $post_query['search_terms'] ) && $object_search_text != $post_query['search_terms'] && 'false' != $post_query['search_terms'] && 'undefined' != $post_query['search_terms'] ) {
 122          $qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] );
 123      }
 124  
 125      // Specific to messages
 126      if ( 'messages' === $object ) {
 127          if ( ! empty( $post_query['box'] ) ) {
 128              $qs[] = 'box=' . $post_query['box'];
 129          }
 130      }
 131  
 132      // Single activity.
 133      if ( bp_is_single_activity() ) {
 134          $qs = array(
 135              'display_comments=threaded',
 136              'show_hidden=true',
 137              'include=' . bp_current_action(),
 138          );
 139      }
 140  
 141      // Now pass the querystring to override default values.
 142      $query_string = empty( $qs ) ? '' : join( '&', (array) $qs );
 143  
 144      // List the variables for the filter
 145      list( $filter, $scope, $page, $search_terms, $extras ) = array_values( $post_query );
 146  
 147      /**
 148       * Filters the AJAX query string for the component loops.
 149       *
 150       * @since 3.0.0
 151       *
 152       * @param string $query_string The query string we are working with.
 153       * @param string $object       The type of page we are on.
 154       * @param string $filter       The current object filter.
 155       * @param string $scope        The current object scope.
 156       * @param string $page         The current object page.
 157       * @param string $search_terms The current object search terms.
 158       * @param string $extras       The current object extras.
 159       */
 160      return apply_filters( 'bp_nouveau_ajax_querystring', $query_string, $object, $filter, $scope, $page, $search_terms, $extras );
 161  }
 162  
 163  /**
 164   * @since 3.0.0
 165   *
 166   * @return string
 167   */
 168  function bp_nouveau_ajax_button( $output = '', $button = null, $before = '', $after = '', $r = array() ) {
 169      if ( empty( $button->component ) ) {
 170          return $output;
 171      }
 172  
 173      // Custom data attribute.
 174      $r['button_attr']['data-bp-btn-action'] = $button->id;
 175  
 176      $reset_ids = array(
 177          'member_friendship' => true,
 178          'group_membership'  => true,
 179      );
 180  
 181      if ( ! empty( $reset_ids[ $button->id ] ) )  {
 182          $parse_class = array_map( 'sanitize_html_class', explode( ' ', $r['button_attr']['class'] ) );
 183          if ( false === $parse_class ) {
 184              return $output;
 185          }
 186  
 187          $find_id = array_intersect( $parse_class, array(
 188              'pending_friend',
 189              'is_friend',
 190              'not_friends',
 191              'leave-group',
 192              'join-group',
 193              'accept-invite',
 194              'membership-requested',
 195              'request-membership',
 196          ) );
 197  
 198          if ( 1 !== count( $find_id ) ) {
 199              return $output;
 200          }
 201  
 202          $data_attribute = reset( $find_id );
 203          if ( 'pending_friend' === $data_attribute ) {
 204              $data_attribute = str_replace( '_friend', '', $data_attribute );
 205          } elseif ( 'group_membership' === $button->id ) {
 206              $data_attribute = str_replace( '-', '_', $data_attribute );
 207          }
 208  
 209          $r['button_attr']['data-bp-btn-action'] = $data_attribute;
 210      }
 211  
 212      // Re-render the button with our custom data attribute.
 213      $output = new BP_Core_HTML_Element( array(
 214          'element'    => $r['button_element'],
 215          'attr'       => $r['button_attr'],
 216          'inner_html' => ! empty( $r['link_text'] ) ? $r['link_text'] : ''
 217      ) );
 218      $output = $output->contents();
 219  
 220      // Add span bp-screen-reader-text class
 221      return $before . $output . $after;
 222  }
 223  
 224  /**
 225   * Output HTML content into a wrapper.
 226   *
 227   * @since 3.0.0
 228   *
 229   * @param array $args {
 230   *     Optional arguments.
 231   *
 232   *     @type string $container         String HTML container type that should wrap
 233   *                                     the items as a group: 'div', 'ul', or 'p'. Required.
 234   *     @type string $container_id      The group wrapping container element ID
 235   *     @type string $container_classes The group wrapping container elements class
 236   *     @type string $output            The HTML to output. Required.
 237   * }
 238   */
 239  function bp_nouveau_wrapper( $args = array() ) {
 240   /**
 241      * Classes need to be determined & set by component to a certain degree
 242      *
 243      * Check the component to find a default container_class to add
 244      */
 245      $current_component_class = bp_current_component() . '-meta';
 246  
 247      if ( bp_is_group_activity() ) {
 248          $generic_class = ' activity-meta ';
 249      } else {
 250          $generic_class = '';
 251      }
 252  
 253      $r = bp_parse_args(
 254          $args,
 255          array(
 256              'container'         => 'div',
 257              'container_id'      => '',
 258              'container_classes' => array( $generic_class, $current_component_class   ),
 259              'output'            => '',
 260          ),
 261          'nouveau_wrapper'
 262      );
 263  
 264      $valid_containers = array(
 265          'div'  => true,
 266          'ul'   => true,
 267          'ol'   => true,
 268          'span' => true,
 269          'p'    => true,
 270      );
 271  
 272      // Actually merge some classes defaults and $args
 273      // @todo This is temp, we need certain classes but maybe improve this approach.
 274      $default_classes        = array( 'action' );
 275      $r['container_classes'] = array_merge( $r['container_classes'], $default_classes );
 276  
 277      if ( empty( $r['container'] ) || ! isset( $valid_containers[ $r['container'] ] ) || empty( $r['output'] ) ) {
 278          return;
 279      }
 280  
 281      $container         = $r['container'];
 282      $container_id      = '';
 283      $container_classes = '';
 284      $output            = $r['output'];
 285  
 286      if ( ! empty( $r['container_id'] ) ) {
 287          $container_id = ' id="' . esc_attr( $r['container_id'] ) . '"';
 288      }
 289  
 290      if ( ! empty( $r['container_classes'] ) && is_array( $r['container_classes'] ) ) {
 291          $container_classes = ' class="' . join( ' ', array_map( 'sanitize_html_class', $r['container_classes'] ) ) . '"';
 292      }
 293  
 294      // Print the wrapper and its content.
 295      printf( '<%1$s%2$s%3$s>%4$s</%1$s>', $container, $container_id, $container_classes, $output );
 296  }
 297  
 298  /**
 299   * Register the 2 sidebars for the Group & User default front page
 300   *
 301   * @since 3.0.0
 302   */
 303  function bp_nouveau_register_sidebars() {
 304      $default_fronts      = bp_nouveau_get_appearance_settings();
 305      $default_user_front  = 0;
 306      $default_group_front = 0;
 307      $is_active_groups    = bp_is_active( 'groups' );
 308  
 309      if ( isset( $default_fronts['user_front_page'] ) ) {
 310          $default_user_front = $default_fronts['user_front_page'];
 311      }
 312  
 313      if ( $is_active_groups ) {
 314          if ( isset( $default_fronts['group_front_page'] ) ) {
 315              $default_group_front = $default_fronts['group_front_page'];
 316          }
 317      }
 318  
 319      // Setting the front template happens too early, so we need this!
 320      if ( is_customize_preview() ) {
 321          $default_user_front = bp_nouveau_get_temporary_setting( 'user_front_page', $default_user_front );
 322  
 323          if ( $is_active_groups ) {
 324              $default_group_front = bp_nouveau_get_temporary_setting( 'group_front_page', $default_group_front );
 325          }
 326      }
 327  
 328      $sidebars = array();
 329      if ( $default_user_front ) {
 330          $sidebars[] = array(
 331              'name'          => __( 'BuddyPress Member\'s Home', 'buddypress' ),
 332              'id'            => 'sidebar-buddypress-members',
 333              'description'   => __( 'Add widgets here to appear in the front page of each member of your community.', 'buddypress' ),
 334              'before_widget' => '<div id="%1$s" class="widget %2$s">',
 335              'after_widget'  => '</div>',
 336              'before_title'  => '<h2 class="widget-title">',
 337              'after_title'   => '</h2>',
 338          );
 339      }
 340  
 341      if ( $default_group_front ) {
 342          $sidebars[] = array(
 343              'name'          => __( 'BuddyPress Group\'s Home', 'buddypress' ),
 344              'id'            => 'sidebar-buddypress-groups',
 345              'description'   => __( 'Add widgets here to appear in the front page of each group of your community.', 'buddypress' ),
 346              'before_widget' => '<div id="%1$s" class="widget %2$s">',
 347              'after_widget'  => '</div>',
 348              'before_title'  => '<h2 class="widget-title">',
 349              'after_title'   => '</h2>',
 350          );
 351      }
 352  
 353      if ( empty( $sidebars ) ) {
 354          return;
 355      }
 356  
 357      // Register the sidebars if needed.
 358      foreach ( $sidebars as $sidebar ) {
 359          register_sidebar( $sidebar );
 360      }
 361  }
 362  
 363  /**
 364   * @since 3.0.0
 365   *
 366   * @return bool
 367   */
 368  function bp_nouveau_is_object_nav_in_sidebar() {
 369      return is_active_widget( false, false, 'bp_nouveau_sidebar_object_nav_widget', true );
 370  }
 371  
 372  /**
 373   * @since 3.0.0
 374   *
 375   * @return bool
 376   */
 377  function bp_nouveau_current_user_can( $capability = '' ) {
 378      /**
 379       * Filters whether or not the current user can perform an action for BuddyPress Nouveau.
 380       *
 381       * @since 3.0.0
 382       *
 383       * @param bool   $value      Whether or not the user is logged in.
 384       * @param string $capability Current capability being checked.
 385       * @param int    $value      Current logged in user ID.
 386       */
 387      return apply_filters( 'bp_nouveau_current_user_can', is_user_logged_in(), $capability, bp_loggedin_user_id() );
 388  }
 389  
 390  /**
 391   * Parse an html output to a list of component's directory nav item.
 392   *
 393   * @since 3.0.0
 394   *
 395   * @param string $hook      The hook to fire.
 396   * @param string $component The component nav belongs to.
 397   * @param int    $position  The position of the nav item.
 398   *
 399   * @return array A list of component's dir nav items
 400   */
 401  function bp_nouveau_parse_hooked_dir_nav( $hook = '', $component = '', $position = 99 ) {
 402      $extra_nav_items = array();
 403  
 404      if ( empty( $hook ) || empty( $component ) || ! has_action( $hook ) ) {
 405          return $extra_nav_items;
 406      }
 407  
 408      // Get the hook output.
 409      ob_start();
 410  
 411      /**
 412       * Fires at the start of the output for `bp_nouveau_parse_hooked_dir_nav()`.
 413       *
 414       * This hook is variable and depends on the hook parameter passed in.
 415       *
 416       * @since 3.0.0
 417       */
 418      do_action( $hook );
 419      $output = ob_get_clean();
 420  
 421      if ( empty( $output ) ) {
 422          return $extra_nav_items;
 423      }
 424  
 425      preg_match_all( "/<li\sid=\"{$component}\-(.*)\"[^>]*>/siU", $output, $lis );
 426      if ( empty( $lis[1] ) ) {
 427          return $extra_nav_items;
 428      }
 429  
 430      $extra_nav_items = array_fill_keys( $lis[1], array( 'component' => $component, 'position' => $position ) );
 431      preg_match_all( '/<a\s[^>]*>(.*)<\/a>/siU', $output, $as );
 432  
 433      if ( ! empty( $as[0] ) ) {
 434          foreach ( $as[0] as $ka => $a ) {
 435              $extra_nav_items[ $lis[1][ $ka ] ]['slug'] = $lis[1][ $ka ];
 436              $extra_nav_items[ $lis[1][ $ka ] ]['text'] = $as[1][ $ka ];
 437              preg_match_all( '/([\w\-]+)=([^"\'> ]+|([\'"]?)(?:[^\3]|\3+)+?\3)/', $a, $attrs );
 438  
 439              if ( ! empty( $attrs[1] ) ) {
 440                  foreach ( $attrs[1] as $katt => $att ) {
 441                      if ( 'href' === $att ) {
 442                          $extra_nav_items[ $lis[1][ $ka ] ]['link'] = trim( $attrs[2][ $katt ], '"' );
 443                      } else {
 444                          $extra_nav_items[ $lis[1][ $ka ] ][ $att ] = trim( $attrs[2][ $katt ], '"' );
 445                      }
 446                  }
 447              }
 448          }
 449      }
 450  
 451      if ( ! empty( $as[1] ) ) {
 452          foreach ( $as[1] as $ks => $s ) {
 453              preg_match_all( '/<span>(.*)<\/span>/siU', $s, $spans );
 454  
 455              if ( empty( $spans[0] ) ) {
 456                  $extra_nav_items[ $lis[1][ $ks ] ]['count'] = false;
 457              } elseif ( ! empty( $spans[1][0] ) ) {
 458                  $extra_nav_items[ $lis[1][ $ks ] ]['count'] = (int) $spans[1][0];
 459              } else {
 460                  $extra_nav_items[ $lis[1][ $ks ] ]['count'] = '';
 461              }
 462          }
 463      }
 464  
 465      return $extra_nav_items;
 466  }
 467  
 468  /**
 469   * Run specific "select filter" hooks to catch the options and build an array out of them
 470   *
 471   * @since 3.0.0
 472   *
 473   * @param string $hook
 474   * @param array  $filters
 475   *
 476   * @return array
 477   */
 478  function bp_nouveau_parse_hooked_options( $hook = '', $filters = array() ) {
 479      if ( empty( $hook ) ) {
 480          return $filters;
 481      }
 482  
 483      ob_start();
 484  
 485      /**
 486       * Fires at the start of the output for `bp_nouveau_parse_hooked_options()`.
 487       *
 488       * This hook is variable and depends on the hook parameter passed in.
 489       *
 490       * @since 3.0.0
 491       */
 492      do_action( $hook );
 493  
 494      $output = ob_get_clean();
 495  
 496      preg_match_all( '/<option value="(.*?)"\s*>(.*?)<\/option>/', $output, $matches );
 497  
 498      if ( ! empty( $matches[1] ) && ! empty( $matches[2] ) ) {
 499          foreach ( $matches[1] as $ik => $key_action ) {
 500              if ( ! empty( $matches[2][ $ik ] ) && ! isset( $filters[ $key_action ] ) ) {
 501                  $filters[ $key_action ] = $matches[2][ $ik ];
 502              }
 503          }
 504      }
 505  
 506      return $filters;
 507  }
 508  
 509  /**
 510   * Get Dropdawn filters for the current component of the one passed in params
 511   *
 512   * @since 3.0.0
 513   *
 514   * @param string $context   'directory', 'user' or 'group'
 515   * @param string $component The BuddyPress component ID
 516   *
 517   * @return array the dropdown filters
 518   */
 519  function bp_nouveau_get_component_filters( $context = '', $component = '' ) {
 520      $filters = array();
 521  
 522      if ( empty( $context ) ) {
 523          if ( bp_is_user() ) {
 524              $context = 'user';
 525          } elseif ( bp_is_group() ) {
 526              $context = 'group';
 527  
 528          // Defaults to directory
 529          } else {
 530              $context = 'directory';
 531          }
 532      }
 533  
 534      if ( empty( $component ) ) {
 535          if ( 'directory' === $context || 'user' === $context ) {
 536              $component = bp_current_component();
 537  
 538              if ( 'friends' === $component ) {
 539                  $context   = 'friends';
 540                  $component = 'members';
 541              }
 542          } elseif ( 'group' === $context && bp_is_group_activity() ) {
 543              $component = 'activity';
 544          } elseif ( 'group' === $context && bp_is_group_members() ) {
 545              $component = 'members';
 546          }
 547      }
 548  
 549      if ( ! bp_is_active( $component ) ) {
 550          return $filters;
 551      }
 552  
 553      if ( 'members' === $component ) {
 554          $filters = bp_nouveau_get_members_filters( $context );
 555      } elseif ( 'activity' === $component ) {
 556          $filters = bp_nouveau_get_activity_filters();
 557  
 558          // Specific case for the activity dropdown
 559          $filters = array_merge( array( '-1' => __( '&mdash; Everything &mdash;', 'buddypress' ) ), $filters );
 560      } elseif ( 'groups' === $component ) {
 561          $filters = bp_nouveau_get_groups_filters( $context );
 562      } elseif ( 'blogs' === $component ) {
 563          $filters = bp_nouveau_get_blogs_filters( $context );
 564      }
 565  
 566      return $filters;
 567  }
 568  
 569  /**
 570   * When previewing make sure to get the temporary setting of the customizer.
 571   * This is necessary when we need to get these very early.
 572   *
 573   * @since 3.0.0
 574   *
 575   * @param string $option the index of the setting to get.
 576   * @param mixed  $retval the value to use as default.
 577   *
 578   * @return mixed The value for the requested option.
 579   */
 580  function bp_nouveau_get_temporary_setting( $option = '', $retval = false ) {
 581      if ( empty( $option ) || ! isset( $_POST['customized'] ) ) {
 582          return $retval;
 583      }
 584  
 585      $temporary_setting = wp_unslash( $_POST['customized'] );
 586      if ( ! is_array( $temporary_setting ) ) {
 587          $temporary_setting = json_decode( $temporary_setting, true );
 588      }
 589  
 590      // This is used to transport the customizer settings into Ajax requests.
 591      if ( 'any' === $option ) {
 592          $retval = array();
 593  
 594          foreach ( $temporary_setting as $key => $setting ) {
 595              if ( 0 !== strpos( $key, 'bp_nouveau_appearance' ) ) {
 596                  continue;
 597              }
 598  
 599              $k            = str_replace( array( '[', ']' ), array( '_', '' ), $key );
 600              $retval[ $k ] = $setting;
 601          }
 602  
 603      // Used when it's an early regular request
 604      } elseif ( isset( $temporary_setting[ 'bp_nouveau_appearance[' . $option . ']' ] ) ) {
 605          $retval = $temporary_setting[ 'bp_nouveau_appearance[' . $option . ']' ];
 606  
 607      // Used when it's an ajax request
 608      } elseif ( isset( $_POST['customized'][ 'bp_nouveau_appearance_' . $option ] ) ) {
 609          $retval = $_POST['customized'][ 'bp_nouveau_appearance_' . $option ];
 610      }
 611  
 612      return $retval;
 613  }
 614  
 615  /**
 616   * Get the BP Nouveau Appearance settings.
 617   *
 618   * @since 3.0.0
 619   *
 620   * @param string $option Leave empty to get all settings, specify a value for a specific one.
 621   * @param mixed          An array of settings, the value of the requested setting.
 622   *
 623   * @return array|false|mixed
 624   */
 625  function bp_nouveau_get_appearance_settings( $option = '' ) {
 626      $default_args = array(
 627          'avatar_style'       => 0,
 628          'global_alignment'   => 'alignwide',
 629          'user_front_page'    => 1,
 630          'user_front_bio'     => 0,
 631          'user_nav_display'   => 0, // O is default (horizontally). 1 is vertically.
 632          'user_nav_tabs'      => 0,
 633          'user_subnav_tabs'   => 0,
 634          'user_nav_order'     => array(),
 635          'members_layout'     => 1,
 636          'members_dir_tabs'   => 0,
 637          'members_dir_layout' => 0,
 638      );
 639  
 640      if ( bp_is_active( 'friends' ) ) {
 641          $default_args['members_friends_layout'] = 1;
 642      }
 643  
 644      if ( bp_is_active( 'activity' ) ) {
 645          $default_args['activity_dir_layout'] = 0;
 646          $default_args['activity_dir_tabs']   = 0; // default = no tabs
 647      }
 648  
 649      if ( bp_is_active( 'groups' ) ) {
 650          $default_args = array_merge( $default_args, array(
 651              'group_front_page'        => 1,
 652              'group_front_boxes'       => 1,
 653              'group_front_description' => 0,
 654              'group_nav_display'       => 0,       // O is default (horizontally). 1 is vertically.
 655              'group_nav_order'         => array(),
 656              'group_nav_tabs'          => 0,
 657              'group_subnav_tabs'       => 0,
 658              'groups_create_tabs'      => 1,
 659              'groups_layout'           => 1,
 660              'members_group_layout'    => 1,
 661              'groups_dir_layout'       => 0,
 662              'groups_dir_tabs'         => 0,
 663          ) );
 664      }
 665  
 666      if ( is_multisite() && bp_is_active( 'blogs' ) ) {
 667          $default_args = array_merge( $default_args, array(
 668              'sites_dir_layout' => 0,
 669              'sites_dir_tabs'   => 0,
 670          ) );
 671      }
 672  
 673      $settings = bp_parse_args(
 674          bp_get_option( 'bp_nouveau_appearance', array() ),
 675          $default_args,
 676          'nouveau_appearance_settings'
 677      );
 678  
 679      if ( ! empty( $option ) ) {
 680          if ( isset( $settings[ $option ] ) ) {
 681              return $settings[ $option ];
 682          } else {
 683              return false;
 684          }
 685      }
 686  
 687      return $settings;
 688  }
 689  
 690  /**
 691   * Returns the choices for the Layout option of the customizer
 692   * or the list of corresponding css classes.
 693   *
 694   * @since 3.0.0
 695   *
 696   * @param string $type 'option' to get the labels, 'classes' to get the classes
 697   *
 698   * @return array The list of labels or classes preserving keys.
 699   */
 700  function bp_nouveau_customizer_grid_choices( $type = 'option' ) {
 701      $columns = array(
 702          array( 'key' => '1', 'label' => __( 'One column', 'buddypress'    ), 'class' => ''      ),
 703          array( 'key' => '2', 'label' => __( 'Two columns', 'buddypress'   ), 'class' => 'two'   ),
 704          array( 'key' => '3', 'label' => __( 'Three columns', 'buddypress' ), 'class' => 'three' ),
 705          array( 'key' => '4', 'label' => __( 'Four columns', 'buddypress'  ), 'class' => 'four'  ),
 706      );
 707  
 708      if ( 'option' === $type ) {
 709          return wp_list_pluck( $columns, 'label', 'key' );
 710      }
 711  
 712      return wp_list_pluck( $columns, 'class', 'key' );
 713  }
 714  
 715  /**
 716   * Sanitize a list of slugs to save it as an array
 717   *
 718   * @since 3.0.0
 719   *
 720   * @param  string $option A comma separated list of nav items slugs.
 721   *
 722   * @return array An array of nav items slugs.
 723   */
 724  function bp_nouveau_sanitize_nav_order( $option = '' ) {
 725      $option = explode( ',', $option );
 726      return array_map( 'sanitize_key', $option );
 727  }
 728  
 729  /**
 730   * BP Nouveau's callback for the cover image feature.
 731   *
 732   * @since 3.0.0
 733   *
 734   * @param array $params Optional. The current component's feature parameters.
 735   *
 736   * @return string
 737   */
 738  function bp_nouveau_theme_cover_image( $params = array() ) {
 739      if ( empty( $params ) ) {
 740          return '';
 741      }
 742  
 743      // Avatar height - padding - 1/2 avatar height.
 744      $avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 );
 745  
 746      // Header content offset + spacing.
 747      $top_offset  = bp_core_avatar_full_height() - 10;
 748      $left_offset = bp_core_avatar_full_width() + 20;
 749  
 750      $cover_image = isset( $params['cover_image'] ) ? 'background-image: url( ' . $params['cover_image'] . ' );' : '';
 751      $hide_avatar_style = '';
 752  
 753      // Adjust the cover image header, in case avatars are completely disabled.
 754      if ( ! buddypress()->avatar->show_avatars ) {
 755          $hide_avatar_style = '
 756              #buddypress #item-header-cover-image #item-header-avatar {
 757                  display:  none;
 758              }
 759          ';
 760  
 761          if ( bp_is_user() ) {
 762              $hide_avatar_style = '
 763                  #buddypress #item-header-cover-image #item-header-avatar a {
 764                      display: block;
 765                      height: ' . $top_offset . 'px;
 766                      margin: 0 15px 19px 0;
 767                  }
 768  
 769                  #buddypress div#item-header #item-header-cover-image #item-header-content {
 770                      margin-left:auto;
 771                  }
 772              ';
 773          }
 774      }
 775  
 776      return '
 777          /* Cover image */
 778          #buddypress #item-header-cover-image {
 779              min-height: ' . $params['height'] . 'px;
 780              margin-bottom: 1em;
 781          }
 782  
 783          #buddypress #item-header-cover-image:after {
 784              clear: both;
 785              content: "";
 786              display: table;
 787          }
 788  
 789          #buddypress #header-cover-image {
 790              height: ' . $params['height'] . 'px;
 791              ' . $cover_image . '
 792          }
 793  
 794          #buddypress #create-group-form #header-cover-image {
 795              position: relative;
 796              margin: 1em 0;
 797          }
 798  
 799          .bp-user #buddypress #item-header {
 800              padding-top: 0;
 801          }
 802  
 803          #buddypress #item-header-cover-image #item-header-avatar {
 804              margin-top: ' . $avatar_offset . 'px;
 805              float: left;
 806              overflow: visible;
 807              width:auto;
 808          }
 809  
 810          #buddypress div#item-header #item-header-cover-image #item-header-content {
 811              clear: both;
 812              float: left;
 813              margin-left: ' . $left_offset . 'px;
 814              margin-top: -' . $top_offset . 'px;
 815              width:auto;
 816          }
 817  
 818          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
 819          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
 820              margin-top: ' . $params['height'] . 'px;
 821              margin-left: 0;
 822              clear: none;
 823              max-width: 50%;
 824          }
 825  
 826          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
 827              padding-top: 20px;
 828              max-width: 20%;
 829          }
 830  
 831          ' . $hide_avatar_style . '
 832  
 833          #buddypress div#item-header-cover-image h2 a,
 834          #buddypress div#item-header-cover-image h2 {
 835              color: #FFF;
 836              text-rendering: optimizelegibility;
 837              text-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.8 );
 838              margin: 0 0 .6em;
 839              font-size:200%;
 840          }
 841  
 842          #buddypress #item-header-cover-image #item-header-avatar img.avatar {
 843              border: solid 2px #FFF;
 844              background: rgba( 255, 255, 255, 0.8 );
 845          }
 846  
 847          #buddypress #item-header-cover-image #item-header-avatar a {
 848              border: none;
 849              text-decoration: none;
 850          }
 851  
 852          #buddypress #item-header-cover-image #item-buttons {
 853              margin: 0 0 10px;
 854              padding: 0 0 5px;
 855          }
 856  
 857          #buddypress #item-header-cover-image #item-buttons:after {
 858              clear: both;
 859              content: "";
 860              display: table;
 861          }
 862  
 863          @media screen and (max-width: 782px) {
 864              #buddypress #item-header-cover-image #item-header-avatar,
 865              .bp-user #buddypress #item-header #item-header-cover-image #item-header-avatar,
 866              #buddypress div#item-header #item-header-cover-image #item-header-content {
 867                  width:100%;
 868                  text-align:center;
 869              }
 870  
 871              #buddypress #item-header-cover-image #item-header-avatar a {
 872                  display:inline-block;
 873              }
 874  
 875              #buddypress #item-header-cover-image #item-header-avatar img {
 876                  margin:0;
 877              }
 878  
 879              #buddypress div#item-header #item-header-cover-image #item-header-content,
 880              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
 881              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
 882                  margin:0;
 883              }
 884  
 885              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
 886              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
 887                  max-width: 100%;
 888              }
 889  
 890              #buddypress div#item-header-cover-image h2 a,
 891              #buddypress div#item-header-cover-image h2 {
 892                  color: inherit;
 893                  text-shadow: none;
 894                  margin:25px 0 0;
 895                  font-size:200%;
 896              }
 897  
 898              #buddypress #item-header-cover-image #item-buttons div {
 899                  float:none;
 900                  display:inline-block;
 901              }
 902  
 903              #buddypress #item-header-cover-image #item-buttons:before {
 904                  content:"";
 905              }
 906  
 907              #buddypress #item-header-cover-image #item-buttons {
 908                  margin: 5px 0;
 909              }
 910          }
 911      ';
 912  }
 913  
 914  /**
 915   * All user feedback messages are available here
 916   *
 917   * @since 3.0.0
 918   *
 919   * @param string $feedback_id The ID of the message.
 920   *
 921   * @return string|false The list of parameters for the message
 922   */
 923  function bp_nouveau_get_user_feedback( $feedback_id = '' ) {
 924      /**
 925       * Filters the BuddyPress Nouveau feedback messages.
 926       *
 927       * Use this filter to add your custom feedback messages.
 928       *
 929       * @since 3.0.0
 930       *
 931       * @param array $value The list of feedback messages.
 932       */
 933      $feedback_messages = apply_filters( 'bp_nouveau_feedback_messages', array(
 934          'registration-disabled' => array(
 935              'type'    => 'info',
 936              'message' => __( 'Member registration is currently not allowed.', 'buddypress' ),
 937              'before'  => 'bp_before_registration_disabled',
 938              'after'   => 'bp_after_registration_disabled'
 939          ),
 940          'request-details' => array(
 941              'type'    => 'info',
 942              'message' => __( 'Registering for this site is easy. Just fill in the fields below, and we\'ll get a new account set up for you in no time.', 'buddypress' ),
 943              'before'  => false,
 944              'after'   => false,
 945          ),
 946          'completed-confirmation' => array(
 947              'type'    => 'info',
 948              'message' => __( 'You have successfully created your account! Please log in using the username and password you have just created.', 'buddypress' ),
 949              'before'  => 'bp_before_registration_confirmed',
 950              'after'   => 'bp_after_registration_confirmed',
 951          ),
 952          'directory-activity-loading' => array(
 953              'type'    => 'loading',
 954              'message' => __( 'Loading the community updates. Please wait.', 'buddypress' ),
 955          ),
 956          'single-activity-loading' => array(
 957              'type'    => 'loading',
 958              'message' => __( 'Loading the update. Please wait.', 'buddypress' ),
 959          ),
 960          'activity-loop-none' => array(
 961              'type'    => 'info',
 962              'message' => __( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ),
 963          ),
 964          'blogs-loop-none' => array(
 965              'type'    => 'info',
 966              'message' => __( 'Sorry, there were no sites found.', 'buddypress' ),
 967          ),
 968          'blogs-no-signup' => array(
 969              'type'    => 'info',
 970              'message' => __( 'Site registration is currently disabled.', 'buddypress' ),
 971          ),
 972          'directory-blogs-loading' => array(
 973              'type'    => 'loading',
 974              'message' => __( 'Loading the sites of the network. Please wait.', 'buddypress' ),
 975          ),
 976          'directory-groups-loading' => array(
 977              'type'    => 'loading',
 978              'message' => __( 'Loading the groups of the community. Please wait.', 'buddypress' ),
 979          ),
 980          'groups-loop-none' => array(
 981              'type'    => 'info',
 982              'message' => __( 'Sorry, there were no groups found.', 'buddypress' ),
 983          ),
 984          'group-activity-loading' => array(
 985              'type'    => 'loading',
 986              'message' => __( 'Loading the group updates. Please wait.', 'buddypress' ),
 987          ),
 988          'group-members-loading' => array(
 989              'type'    => 'loading',
 990              'message' => __( 'Requesting the group members. Please wait.', 'buddypress' ),
 991          ),
 992          'group-members-none' => array(
 993              'type'    => 'info',
 994              'message' => __( 'Sorry, there were no group members found.', 'buddypress' ),
 995          ),
 996          'group-members-search-none' => array(
 997              'type'    => 'info',
 998              'message' => __( 'Sorry, there was no member of that name found in this group.', 'buddypress' ),
 999          ),
1000          'group-manage-members-none' => array(
1001              'type'    => 'info',
1002              'message' => __( 'This group has no members.', 'buddypress' ),
1003          ),
1004          'group-requests-none' => array(
1005              'type'    => 'info',
1006              'message' => __( 'There are no pending membership requests.', 'buddypress' ),
1007          ),
1008          'group-requests-loading' => array(
1009              'type'    => 'loading',
1010              'message' => __( 'Loading the members who requested to join the group. Please wait.', 'buddypress' ),
1011          ),
1012          'group-delete-warning' => array(
1013              'type'    => 'warning',
1014              'message' => __( 'WARNING: Deleting this group will completely remove ALL content associated with it. There is no way back. Please be careful with this option.', 'buddypress' ),
1015          ),
1016          'group-avatar-delete-info' => array(
1017              'type'    => 'info',
1018              'message' => __( 'If you\'d like to remove the existing group profile photo but not upload a new one, please use the delete group profile photo button.', 'buddypress' ),
1019          ),
1020          'directory-members-loading' => array(
1021              'type'    => 'loading',
1022              'message' => __( 'Loading the members of your community. Please wait.', 'buddypress' ),
1023          ),
1024          'members-loop-none' => array(
1025              'type'    => 'info',
1026              'message' => __( 'Sorry, no members were found.', 'buddypress' ),
1027          ),
1028          'member-requests-none' => array(
1029              'type'    => 'info',
1030              'message' => __( 'You have no pending friendship requests.', 'buddypress' ),
1031          ),
1032          'member-invites-none' => array(
1033              'type'    => 'info',
1034              'message' => __( 'You have no outstanding group invites.', 'buddypress' ),
1035          ),
1036          'member-notifications-none' => array(
1037              'type'    => 'info',
1038              'message' => __( 'This member has no notifications.', 'buddypress' ),
1039          ),
1040          'member-wp-profile-none' => array(
1041              'type'    => 'info',
1042              'message' => __( '%s did not save any profile information yet.', 'buddypress' ),
1043          ),
1044          'member-delete-account' => array(
1045              'type'    => 'warning',
1046              'message' => __( 'Deleting this account will delete all of the content it has created. It will be completely unrecoverable.', 'buddypress' ),
1047          ),
1048          'member-activity-loading' => array(
1049              'type'    => 'loading',
1050              'message' => __( 'Loading the member\'s updates. Please wait.', 'buddypress' ),
1051          ),
1052          'member-blogs-loading' => array(
1053              'type'    => 'loading',
1054              'message' => __( 'Loading the member\'s blogs. Please wait.', 'buddypress' ),
1055          ),
1056          'member-friends-loading' => array(
1057              'type'    => 'loading',
1058              'message' => __( 'Loading the member\'s friends. Please wait.', 'buddypress' ),
1059          ),
1060          'member-groups-loading' => array(
1061              'type'    => 'loading',
1062              'message' => __( 'Loading the member\'s groups. Please wait.', 'buddypress' ),
1063          ),
1064          'member-notifications-loading' => array(
1065              'type'    => 'loading',
1066              'message' => __( 'Loading notifications. Please wait.', 'buddypress' ),
1067          ),
1068          'member-group-invites-all' => array(
1069              'type'    => 'info',
1070              'message' => __( 'Currently every member of the community can invite you to join their groups. If you are not comfortable with it, you can always restrict group invites to your friends only.', 'buddypress' ),
1071          ),
1072          'member-group-invites-friends-only' => array(
1073              'type'    => 'info',
1074              'message' => __( 'Currently only your friends can invite you to groups. Uncheck the box to allow any member to send invites.', 'buddypress' ),
1075          ),
1076      ) );
1077  
1078      if ( ! isset( $feedback_messages[ $feedback_id ] ) ) {
1079          return false;
1080      }
1081  
1082      /*
1083       * Adjust some messages to the context.
1084       */
1085      if ( 'completed-confirmation' === $feedback_id && bp_registration_needs_activation() ) {
1086          $feedback_messages['completed-confirmation']['message'] = __( 'You have successfully created your account! To begin using this site you will need to activate your account via the email we have just sent to your address.', 'buddypress' );
1087      } elseif ( 'member-notifications-none' === $feedback_id ) {
1088          $is_myprofile = bp_is_my_profile();
1089  
1090          if ( bp_is_current_action( 'unread' ) ) {
1091              $feedback_messages['member-notifications-none']['message'] = __( 'This member has no unread notifications.', 'buddypress' );
1092  
1093              if ( $is_myprofile ) {
1094                  $feedback_messages['member-notifications-none']['message'] = __( 'You have no unread notifications.', 'buddypress' );
1095              }
1096          } elseif ( $is_myprofile ) {
1097              $feedback_messages['member-notifications-none']['message'] = __( 'You have no notifications.', 'buddypress' );
1098          }
1099      } elseif ( 'member-wp-profile-none' === $feedback_id && bp_is_user_profile() ) {
1100          $feedback_messages['member-wp-profile-none']['message'] = sprintf( $feedback_messages['member-wp-profile-none']['message'], bp_get_displayed_user_fullname() );
1101      } elseif ( 'member-delete-account' === $feedback_id && bp_is_my_profile() ) {
1102          $feedback_messages['member-delete-account']['message'] = __( 'Deleting your account will delete all of the content you have created. It will be completely irrecoverable.', 'buddypress' );
1103      } elseif ( 'member-activity-loading' === $feedback_id && bp_is_my_profile() ) {
1104          $feedback_messages['member-activity-loading']['message'] = __( 'Loading your updates. Please wait.', 'buddypress' );
1105      } elseif ( 'member-blogs-loading' === $feedback_id && bp_is_my_profile() ) {
1106          $feedback_messages['member-blogs-loading']['message'] = __( 'Loading your blogs. Please wait.', 'buddypress' );
1107      } elseif ( 'member-friends-loading' === $feedback_id && bp_is_my_profile() ) {
1108          $feedback_messages['member-friends-loading']['message'] = __( 'Loading your friends. Please wait.', 'buddypress' );
1109      } elseif ( 'member-groups-loading' === $feedback_id && bp_is_my_profile() ) {
1110          $feedback_messages['member-groups-loading']['message'] = __( 'Loading your groups. Please wait.', 'buddypress' );
1111      }
1112  
1113      /**
1114       * Filter here if you wish to edit the message just before being displayed
1115       *
1116       * @since 3.0.0
1117       *
1118       * @param array $feedback_messages
1119       */
1120      return apply_filters( 'bp_nouveau_get_user_feedback', $feedback_messages[ $feedback_id ] );
1121  }
1122  
1123  /**
1124   * Get the signup fields for the requested section
1125   *
1126   * @since 3.0.0
1127   *
1128   * @param string $section Optional. The section of fields to get 'account_details' or 'blog_details'.
1129   *
1130   * @return array|false The list of signup fields for the requested section. False if not found.
1131   */
1132  function bp_nouveau_get_signup_fields( $section = '' ) {
1133      if ( empty( $section ) ) {
1134          return false;
1135      }
1136  
1137      /**
1138       * Filter to add your specific 'text' or 'password' inputs
1139       *
1140       * If you need to use other types of field, please use the
1141       * do_action( 'bp_account_details_fields' ) or do_action( 'blog_details' ) hooks instead.
1142       *
1143       * @since 3.0.0
1144       *
1145       * @param array $value The list of fields organized into sections.
1146       */
1147      $fields = apply_filters( 'bp_nouveau_get_signup_fields', array(
1148          'account_details' => array(
1149              'signup_username' => array(
1150                  'label'          => __( 'Username', 'buddypress' ),
1151                  'required'       => true,
1152                  'value'          => 'bp_get_signup_username_value',
1153                  'attribute_type' => 'username',
1154                  'type'           => 'text',
1155                  'class'          => '',
1156              ),
1157              'signup_email' => array(
1158                  'label'          => __( 'Email Address', 'buddypress' ),
1159                  'required'       => true,
1160                  'value'          => 'bp_get_signup_email_value',
1161                  'attribute_type' => 'email',
1162                  'type'           => 'email',
1163                  'class'          => '',
1164              ),
1165              'signup_password' => array(),
1166              'signup_password_confirm' => array(),
1167          ),
1168          'blog_details' => array(
1169              'signup_blog_url' => array(
1170                  'label'          => __( 'Site URL', 'buddypress' ),
1171                  'required'       => true,
1172                  'value'          => 'bp_get_signup_blog_url_value',
1173                  'attribute_type' => 'slug',
1174                  'type'           => 'text',
1175                  'class'          => '',
1176              ),
1177              'signup_blog_title' => array(
1178                  'label'          => __( 'Site Title', 'buddypress' ),
1179                  'required'       => true,
1180                  'value'          => 'bp_get_signup_blog_title_value',
1181                  'attribute_type' => 'title',
1182                  'type'           => 'text',
1183                  'class'          => '',
1184              ),
1185              'signup_blog_privacy_public' => array(
1186                  'label'          => __( 'Yes', 'buddypress' ),
1187                  'required'       => false,
1188                  'value'          => 'public',
1189                  'attribute_type' => '',
1190                  'type'           => 'radio',
1191                  'class'          => '',
1192              ),
1193              'signup_blog_privacy_private' => array(
1194                  'label'          => __( 'No', 'buddypress' ),
1195                  'required'       => false,
1196                  'value'          => 'private',
1197                  'attribute_type' => '',
1198                  'type'           => 'radio',
1199                  'class'          => '',
1200              ),
1201          ),
1202      ) );
1203  
1204      if ( ! bp_get_blog_signup_allowed() ) {
1205          unset( $fields['blog_details'] );
1206      }
1207  
1208      if ( isset( $fields[ $section ] ) ) {
1209          return $fields[ $section ];
1210      }
1211  
1212      return false;
1213  }
1214  
1215  /**
1216   * Get Some submit buttons data.
1217   *
1218   * @since 3.0.0
1219   *
1220   * @param string $action The action requested.
1221   *
1222   * @return array|false The list of the submit button parameters for the requested action
1223   *                     False if no actions were found.
1224   */
1225  function bp_nouveau_get_submit_button( $action = '' ) {
1226      if ( empty( $action ) ) {
1227          return false;
1228      }
1229  
1230      /**
1231       * Filter the Submit buttons to add your own.
1232       *
1233       * @since 3.0.0
1234       *
1235       * @param array $value The list of submit buttons.
1236       *
1237       * @return array|false
1238       */
1239      $actions = apply_filters( 'bp_nouveau_get_submit_button', array(
1240          'register' => array(
1241              'before'     => 'bp_before_registration_submit_buttons',
1242              'after'      => 'bp_after_registration_submit_buttons',
1243              'nonce'      => 'bp_new_signup',
1244              'attributes' => array(
1245                  'name'  => 'signup_submit',
1246                  'id'    => 'submit',
1247                  'value' => __( 'Complete Sign Up', 'buddypress' ),
1248              ),
1249          ),
1250          'member-profile-edit' => array(
1251              'before' => '',
1252              'after'  => '',
1253              'nonce'  => 'bp_xprofile_edit',
1254              'attributes' => array(
1255                  'name'  => 'profile-group-edit-submit',
1256                  'id'    => 'profile-group-edit-submit',
1257                  'value' => __( 'Save Changes', 'buddypress' ),
1258              ),
1259          ),
1260          'member-capabilities' => array(
1261              'before' => 'bp_members_capabilities_account_before_submit',
1262              'after'  => 'bp_members_capabilities_account_after_submit',
1263              'nonce'  => 'capabilities',
1264              'attributes' => array(
1265                  'name'  => 'capabilities-submit',
1266                  'id'    => 'capabilities-submit',
1267                  'value' => __( 'Save', 'buddypress' ),
1268              ),
1269          ),
1270          'member-delete-account' => array(
1271              'before' => 'bp_members_delete_account_before_submit',
1272              'after'  => 'bp_members_delete_account_after_submit',
1273              'nonce'  => 'delete-account',
1274              'attributes' => array(
1275                  'disabled' => 'disabled',
1276                  'name'     => 'delete-account-button',
1277                  'id'       => 'delete-account-button',
1278                  'value'    => __( 'Delete Account', 'buddypress' ),
1279              ),
1280          ),
1281          'members-general-settings' => array(
1282              'before' => 'bp_core_general_settings_before_submit',
1283              'after'  => 'bp_core_general_settings_after_submit',
1284              'nonce'  => 'bp_settings_general',
1285              'attributes' => array(
1286                  'name'  => 'submit',
1287                  'id'    => 'submit',
1288                  'value' => __( 'Save Changes', 'buddypress' ),
1289                  'class' => 'auto',
1290              ),
1291          ),
1292          'member-notifications-settings' => array(
1293              'before' => 'bp_members_notification_settings_before_submit',
1294              'after'  => 'bp_members_notification_settings_after_submit',
1295              'nonce'  => 'bp_settings_notifications',
1296              'attributes' => array(
1297                  'name'  => 'submit',
1298                  'id'    => 'submit',
1299                  'value' => __( 'Save Changes', 'buddypress' ),
1300                  'class' => 'auto',
1301              ),
1302          ),
1303          'members-profile-settings' => array(
1304              'before' => 'bp_core_xprofile_settings_before_submit',
1305              'after'  => 'bp_core_xprofile_settings_after_submit',
1306              'nonce'  => 'bp_xprofile_settings',
1307              'attributes' => array(
1308                  'name'  => 'xprofile-settings-submit',
1309                  'id'    => 'submit',
1310                  'value' => __( 'Save Changes', 'buddypress' ),
1311                  'class' => 'auto',
1312              ),
1313          ),
1314          'member-group-invites' => array(
1315              'nonce'  => 'bp_nouveau_group_invites_settings',
1316              'attributes' => array(
1317                  'name'  => 'member-group-invites-submit',
1318                  'id'    => 'submit',
1319                  'value' => __( 'Save', 'buddypress' ),
1320                  'class' => 'auto',
1321              ),
1322          ),
1323          'activity-new-comment' => array(
1324              'after'     => 'bp_activity_entry_comments',
1325              'nonce'     => 'new_activity_comment',
1326              'nonce_key' => '_wpnonce_new_activity_comment',
1327              'wrapper'   => false,
1328              'attributes' => array(
1329                  'name'  => 'ac_form_submit',
1330                  'value' => _x( 'Post', 'button', 'buddypress' ),
1331              ),
1332          ),
1333      ) );
1334  
1335      if ( isset( $actions[ $action ] ) ) {
1336          return $actions[ $action ];
1337      }
1338  
1339      return false;
1340  }
1341  
1342  /**
1343   * Reorder a BuddyPress item nav according to a given list of nav item slugs
1344   *
1345   * @since 3.0.0
1346   *
1347   * @param object $nav         The BuddyPress Item Nav object to reorder
1348   * @param array  $order       A list of slugs ordered (eg: array( 'profile', 'activity', etc..) )
1349   * @param string $parent_slug A parent slug if it's a secondary nav we are reordering (case of the Groups single item)
1350   *
1351   * @return bool True on success. False otherwise.
1352   */
1353  function bp_nouveau_set_nav_item_order( $nav = null, $order = array(), $parent_slug = '' ) {
1354      if ( ! is_object( $nav ) || empty( $order ) || ! is_array( $order ) ) {
1355          return false;
1356      }
1357  
1358      $position = 0;
1359  
1360      foreach ( $order as $slug ) {
1361          $position += 10;
1362  
1363          $key = $slug;
1364          if ( ! empty( $parent_slug ) ) {
1365              $key = $parent_slug . '/' . $key;
1366          }
1367  
1368          $item_nav = $nav->get( $key );
1369  
1370          if ( ! $item_nav ) {
1371              continue;
1372          }
1373  
1374          if ( (int) $item_nav->position !== (int) $position ) {
1375              $nav->edit_nav( array( 'position' => $position ), $slug, $parent_slug );
1376          }
1377      }
1378  
1379      return true;
1380  }


Generated: Tue Jan 28 01:01:42 2020 Cross-referenced by PHPXref 0.7.1