[ 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          'user_front_page'    => 1,
 629          'user_front_bio'     => 0,
 630          'user_nav_display'   => 0, // O is default (horizontally). 1 is vertically.
 631          'user_nav_tabs'      => 0,
 632          'user_subnav_tabs'   => 0,
 633          'user_nav_order'     => array(),
 634          'members_layout'     => 1,
 635          'members_dir_tabs'   => 0,
 636          'members_dir_layout' => 0,
 637      );
 638  
 639      if ( bp_is_active( 'friends' ) ) {
 640          $default_args['members_friends_layout'] = 1;
 641      }
 642  
 643      if ( bp_is_active( 'activity' ) ) {
 644          $default_args['activity_dir_layout'] = 0;
 645          $default_args['activity_dir_tabs']   = 0; // default = no tabs
 646      }
 647  
 648      if ( bp_is_active( 'groups' ) ) {
 649          $default_args = array_merge( $default_args, array(
 650              'group_front_page'        => 1,
 651              'group_front_boxes'       => 1,
 652              'group_front_description' => 0,
 653              'group_nav_display'       => 0,       // O is default (horizontally). 1 is vertically.
 654              'group_nav_order'         => array(),
 655              'group_nav_tabs'          => 0,
 656              'group_subnav_tabs'       => 0,
 657              'groups_create_tabs'      => 1,
 658              'groups_layout'           => 1,
 659              'members_group_layout'    => 1,
 660              'groups_dir_layout'       => 0,
 661              'groups_dir_tabs'         => 0,
 662          ) );
 663      }
 664  
 665      if ( is_multisite() && bp_is_active( 'blogs' ) ) {
 666          $default_args = array_merge( $default_args, array(
 667              'sites_dir_layout' => 0,
 668              'sites_dir_tabs'   => 0,
 669          ) );
 670      }
 671  
 672      $settings = bp_parse_args(
 673          bp_get_option( 'bp_nouveau_appearance', array() ),
 674          $default_args,
 675          'nouveau_appearance_settings'
 676      );
 677  
 678      if ( ! empty( $option ) ) {
 679          if ( isset( $settings[ $option ] ) ) {
 680              return $settings[ $option ];
 681          } else {
 682              return false;
 683          }
 684      }
 685  
 686      return $settings;
 687  }
 688  
 689  /**
 690   * Returns the choices for the Layout option of the customizer
 691   * or the list of corresponding css classes.
 692   *
 693   * @since 3.0.0
 694   *
 695   * @param string $type 'option' to get the labels, 'classes' to get the classes
 696   *
 697   * @return array The list of labels or classes preserving keys.
 698   */
 699  function bp_nouveau_customizer_grid_choices( $type = 'option' ) {
 700      $columns = array(
 701          array( 'key' => '1', 'label' => __( 'One column', 'buddypress'    ), 'class' => ''      ),
 702          array( 'key' => '2', 'label' => __( 'Two columns', 'buddypress'   ), 'class' => 'two'   ),
 703          array( 'key' => '3', 'label' => __( 'Three columns', 'buddypress' ), 'class' => 'three' ),
 704          array( 'key' => '4', 'label' => __( 'Four columns', 'buddypress'  ), 'class' => 'four'  ),
 705      );
 706  
 707      if ( 'option' === $type ) {
 708          return wp_list_pluck( $columns, 'label', 'key' );
 709      }
 710  
 711      return wp_list_pluck( $columns, 'class', 'key' );
 712  }
 713  
 714  /**
 715   * Sanitize a list of slugs to save it as an array
 716   *
 717   * @since 3.0.0
 718   *
 719   * @param  string $option A comma separated list of nav items slugs.
 720   *
 721   * @return array An array of nav items slugs.
 722   */
 723  function bp_nouveau_sanitize_nav_order( $option = '' ) {
 724      $option = explode( ',', $option );
 725      return array_map( 'sanitize_key', $option );
 726  }
 727  
 728  /**
 729   * BP Nouveau's callback for the cover image feature.
 730   *
 731   * @since 3.0.0
 732   *
 733   * @param array $params Optional. The current component's feature parameters.
 734   *
 735   * @return string
 736   */
 737  function bp_nouveau_theme_cover_image( $params = array() ) {
 738      if ( empty( $params ) ) {
 739          return '';
 740      }
 741  
 742      // Avatar height - padding - 1/2 avatar height.
 743      $avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 );
 744  
 745      // Header content offset + spacing.
 746      $top_offset  = bp_core_avatar_full_height() - 10;
 747      $left_offset = bp_core_avatar_full_width() + 20;
 748  
 749      $cover_image = isset( $params['cover_image'] ) ? 'background-image: url( ' . $params['cover_image'] . ' );' : '';
 750      $hide_avatar_style = '';
 751  
 752      // Adjust the cover image header, in case avatars are completely disabled.
 753      if ( ! buddypress()->avatar->show_avatars ) {
 754          $hide_avatar_style = '
 755              #buddypress #item-header-cover-image #item-header-avatar {
 756                  display:  none;
 757              }
 758          ';
 759  
 760          if ( bp_is_user() ) {
 761              $hide_avatar_style = '
 762                  #buddypress #item-header-cover-image #item-header-avatar a {
 763                      display: block;
 764                      height: ' . $top_offset . 'px;
 765                      margin: 0 15px 19px 0;
 766                  }
 767  
 768                  #buddypress div#item-header #item-header-cover-image #item-header-content {
 769                      margin-left:auto;
 770                  }
 771              ';
 772          }
 773      }
 774  
 775      return '
 776          /* Cover image */
 777          #buddypress #item-header-cover-image {
 778              min-height: ' . $params['height'] . 'px;
 779              margin-bottom: 1em;
 780          }
 781  
 782          #buddypress #item-header-cover-image:after {
 783              clear: both;
 784              content: "";
 785              display: table;
 786          }
 787  
 788          #buddypress #header-cover-image {
 789              height: ' . $params['height'] . 'px;
 790              ' . $cover_image . '
 791          }
 792  
 793          #buddypress #create-group-form #header-cover-image {
 794              position: relative;
 795              margin: 1em 0;
 796          }
 797  
 798          .bp-user #buddypress #item-header {
 799              padding-top: 0;
 800          }
 801  
 802          #buddypress #item-header-cover-image #item-header-avatar {
 803              margin-top: ' . $avatar_offset . 'px;
 804              float: left;
 805              overflow: visible;
 806              width:auto;
 807          }
 808  
 809          #buddypress div#item-header #item-header-cover-image #item-header-content {
 810              clear: both;
 811              float: left;
 812              margin-left: ' . $left_offset . 'px;
 813              margin-top: -' . $top_offset . 'px;
 814              width:auto;
 815          }
 816  
 817          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
 818          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
 819              margin-top: ' . $params['height'] . 'px;
 820              margin-left: 0;
 821              clear: none;
 822              max-width: 50%;
 823          }
 824  
 825          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
 826              padding-top: 20px;
 827              max-width: 20%;
 828          }
 829  
 830          ' . $hide_avatar_style . '
 831  
 832          #buddypress div#item-header-cover-image h2 a,
 833          #buddypress div#item-header-cover-image h2 {
 834              color: #FFF;
 835              text-rendering: optimizelegibility;
 836              text-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.8 );
 837              margin: 0 0 .6em;
 838              font-size:200%;
 839          }
 840  
 841          #buddypress #item-header-cover-image #item-header-avatar img.avatar {
 842              border: solid 2px #FFF;
 843              background: rgba( 255, 255, 255, 0.8 );
 844          }
 845  
 846          #buddypress #item-header-cover-image #item-header-avatar a {
 847              border: none;
 848              text-decoration: none;
 849          }
 850  
 851          #buddypress #item-header-cover-image #item-buttons {
 852              margin: 0 0 10px;
 853              padding: 0 0 5px;
 854          }
 855  
 856          #buddypress #item-header-cover-image #item-buttons:after {
 857              clear: both;
 858              content: "";
 859              display: table;
 860          }
 861  
 862          @media screen and (max-width: 782px) {
 863              #buddypress #item-header-cover-image #item-header-avatar,
 864              .bp-user #buddypress #item-header #item-header-cover-image #item-header-avatar,
 865              #buddypress div#item-header #item-header-cover-image #item-header-content {
 866                  width:100%;
 867                  text-align:center;
 868              }
 869  
 870              #buddypress #item-header-cover-image #item-header-avatar a {
 871                  display:inline-block;
 872              }
 873  
 874              #buddypress #item-header-cover-image #item-header-avatar img {
 875                  margin:0;
 876              }
 877  
 878              #buddypress div#item-header #item-header-cover-image #item-header-content,
 879              body.single-item.groups #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-actions {
 881                  margin:0;
 882              }
 883  
 884              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
 885              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
 886                  max-width: 100%;
 887              }
 888  
 889              #buddypress div#item-header-cover-image h2 a,
 890              #buddypress div#item-header-cover-image h2 {
 891                  color: inherit;
 892                  text-shadow: none;
 893                  margin:25px 0 0;
 894                  font-size:200%;
 895              }
 896  
 897              #buddypress #item-header-cover-image #item-buttons div {
 898                  float:none;
 899                  display:inline-block;
 900              }
 901  
 902              #buddypress #item-header-cover-image #item-buttons:before {
 903                  content:"";
 904              }
 905  
 906              #buddypress #item-header-cover-image #item-buttons {
 907                  margin: 5px 0;
 908              }
 909          }
 910      ';
 911  }
 912  
 913  /**
 914   * All user feedback messages are available here
 915   *
 916   * @since 3.0.0
 917   *
 918   * @param string $feedback_id The ID of the message.
 919   *
 920   * @return string|false The list of parameters for the message
 921   */
 922  function bp_nouveau_get_user_feedback( $feedback_id = '' ) {
 923      /**
 924       * Filters the BuddyPress Nouveau feedback messages.
 925       *
 926       * Use this filter to add your custom feedback messages.
 927       *
 928       * @since 3.0.0
 929       *
 930       * @param array $value The list of feedback messages.
 931       */
 932      $feedback_messages = apply_filters( 'bp_nouveau_feedback_messages', array(
 933          'registration-disabled' => array(
 934              'type'    => 'info',
 935              'message' => __( 'Member registration is currently not allowed.', 'buddypress' ),
 936              'before'  => 'bp_before_registration_disabled',
 937              'after'   => 'bp_after_registration_disabled'
 938          ),
 939          'request-details' => array(
 940              'type'    => 'info',
 941              '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' ),
 942              'before'  => false,
 943              'after'   => false,
 944          ),
 945          'completed-confirmation' => array(
 946              'type'    => 'info',
 947              'message' => __( 'You have successfully created your account! Please log in using the username and password you have just created.', 'buddypress' ),
 948              'before'  => 'bp_before_registration_confirmed',
 949              'after'   => 'bp_after_registration_confirmed',
 950          ),
 951          'directory-activity-loading' => array(
 952              'type'    => 'loading',
 953              'message' => __( 'Loading the community updates. Please wait.', 'buddypress' ),
 954          ),
 955          'single-activity-loading' => array(
 956              'type'    => 'loading',
 957              'message' => __( 'Loading the update. Please wait.', 'buddypress' ),
 958          ),
 959          'activity-loop-none' => array(
 960              'type'    => 'info',
 961              'message' => __( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ),
 962          ),
 963          'blogs-loop-none' => array(
 964              'type'    => 'info',
 965              'message' => __( 'Sorry, there were no sites found.', 'buddypress' ),
 966          ),
 967          'blogs-no-signup' => array(
 968              'type'    => 'info',
 969              'message' => __( 'Site registration is currently disabled.', 'buddypress' ),
 970          ),
 971          'directory-blogs-loading' => array(
 972              'type'    => 'loading',
 973              'message' => __( 'Loading the sites of the network. Please wait.', 'buddypress' ),
 974          ),
 975          'directory-groups-loading' => array(
 976              'type'    => 'loading',
 977              'message' => __( 'Loading the groups of the community. Please wait.', 'buddypress' ),
 978          ),
 979          'groups-loop-none' => array(
 980              'type'    => 'info',
 981              'message' => __( 'Sorry, there were no groups found.', 'buddypress' ),
 982          ),
 983          'group-activity-loading' => array(
 984              'type'    => 'loading',
 985              'message' => __( 'Loading the group updates. Please wait.', 'buddypress' ),
 986          ),
 987          'group-members-loading' => array(
 988              'type'    => 'loading',
 989              'message' => __( 'Requesting the group members. Please wait.', 'buddypress' ),
 990          ),
 991          'group-members-none' => array(
 992              'type'    => 'info',
 993              'message' => __( 'Sorry, there were no group members found.', 'buddypress' ),
 994          ),
 995          'group-members-search-none' => array(
 996              'type'    => 'info',
 997              'message' => __( 'Sorry, there was no member of that name found in this group.', 'buddypress' ),
 998          ),
 999          'group-manage-members-none' => array(
1000              'type'    => 'info',
1001              'message' => __( 'This group has no members.', 'buddypress' ),
1002          ),
1003          'group-requests-none' => array(
1004              'type'    => 'info',
1005              'message' => __( 'There are no pending membership requests.', 'buddypress' ),
1006          ),
1007          'group-requests-loading' => array(
1008              'type'    => 'loading',
1009              'message' => __( 'Loading the members who requested to join the group. Please wait.', 'buddypress' ),
1010          ),
1011          'group-delete-warning' => array(
1012              'type'    => 'warning',
1013              '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' ),
1014          ),
1015          'group-avatar-delete-info' => array(
1016              'type'    => 'info',
1017              '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' ),
1018          ),
1019          'directory-members-loading' => array(
1020              'type'    => 'loading',
1021              'message' => __( 'Loading the members of your community. Please wait.', 'buddypress' ),
1022          ),
1023          'members-loop-none' => array(
1024              'type'    => 'info',
1025              'message' => __( 'Sorry, no members were found.', 'buddypress' ),
1026          ),
1027          'member-requests-none' => array(
1028              'type'    => 'info',
1029              'message' => __( 'You have no pending friendship requests.', 'buddypress' ),
1030          ),
1031          'member-invites-none' => array(
1032              'type'    => 'info',
1033              'message' => __( 'You have no outstanding group invites.', 'buddypress' ),
1034          ),
1035          'member-notifications-none' => array(
1036              'type'    => 'info',
1037              'message' => __( 'This member has no notifications.', 'buddypress' ),
1038          ),
1039          'member-wp-profile-none' => array(
1040              'type'    => 'info',
1041              'message' => __( '%s did not save any profile information yet.', 'buddypress' ),
1042          ),
1043          'member-delete-account' => array(
1044              'type'    => 'warning',
1045              'message' => __( 'Deleting this account will delete all of the content it has created. It will be completely unrecoverable.', 'buddypress' ),
1046          ),
1047          'member-activity-loading' => array(
1048              'type'    => 'loading',
1049              'message' => __( 'Loading the member\'s updates. Please wait.', 'buddypress' ),
1050          ),
1051          'member-blogs-loading' => array(
1052              'type'    => 'loading',
1053              'message' => __( 'Loading the member\'s blogs. Please wait.', 'buddypress' ),
1054          ),
1055          'member-friends-loading' => array(
1056              'type'    => 'loading',
1057              'message' => __( 'Loading the member\'s friends. Please wait.', 'buddypress' ),
1058          ),
1059          'member-groups-loading' => array(
1060              'type'    => 'loading',
1061              'message' => __( 'Loading the member\'s groups. Please wait.', 'buddypress' ),
1062          ),
1063          'member-notifications-loading' => array(
1064              'type'    => 'loading',
1065              'message' => __( 'Loading notifications. Please wait.', 'buddypress' ),
1066          ),
1067          'member-group-invites-all' => array(
1068              'type'    => 'info',
1069              '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' ),
1070          ),
1071          'member-group-invites-friends-only' => array(
1072              'type'    => 'info',
1073              'message' => __( 'Currently only your friends can invite you to groups. Uncheck the box to allow any member to send invites.', 'buddypress' ),
1074          ),
1075      ) );
1076  
1077      if ( ! isset( $feedback_messages[ $feedback_id ] ) ) {
1078          return false;
1079      }
1080  
1081      /*
1082       * Adjust some messages to the context.
1083       */
1084      if ( 'completed-confirmation' === $feedback_id && bp_registration_needs_activation() ) {
1085          $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' );
1086      } elseif ( 'member-notifications-none' === $feedback_id ) {
1087          $is_myprofile = bp_is_my_profile();
1088  
1089          if ( bp_is_current_action( 'unread' ) ) {
1090              $feedback_messages['member-notifications-none']['message'] = __( 'This member has no unread notifications.', 'buddypress' );
1091  
1092              if ( $is_myprofile ) {
1093                  $feedback_messages['member-notifications-none']['message'] = __( 'You have no unread notifications.', 'buddypress' );
1094              }
1095          } elseif ( $is_myprofile ) {
1096              $feedback_messages['member-notifications-none']['message'] = __( 'You have no notifications.', 'buddypress' );
1097          }
1098      } elseif ( 'member-wp-profile-none' === $feedback_id && bp_is_user_profile() ) {
1099          $feedback_messages['member-wp-profile-none']['message'] = sprintf( $feedback_messages['member-wp-profile-none']['message'], bp_get_displayed_user_fullname() );
1100      } elseif ( 'member-delete-account' === $feedback_id && bp_is_my_profile() ) {
1101          $feedback_messages['member-delete-account']['message'] = __( 'Deleting your account will delete all of the content you have created. It will be completely irrecoverable.', 'buddypress' );
1102      } elseif ( 'member-activity-loading' === $feedback_id && bp_is_my_profile() ) {
1103          $feedback_messages['member-activity-loading']['message'] = __( 'Loading your updates. Please wait.', 'buddypress' );
1104      } elseif ( 'member-blogs-loading' === $feedback_id && bp_is_my_profile() ) {
1105          $feedback_messages['member-blogs-loading']['message'] = __( 'Loading your blogs. Please wait.', 'buddypress' );
1106      } elseif ( 'member-friends-loading' === $feedback_id && bp_is_my_profile() ) {
1107          $feedback_messages['member-friends-loading']['message'] = __( 'Loading your friends. Please wait.', 'buddypress' );
1108      } elseif ( 'member-groups-loading' === $feedback_id && bp_is_my_profile() ) {
1109          $feedback_messages['member-groups-loading']['message'] = __( 'Loading your groups. Please wait.', 'buddypress' );
1110      }
1111  
1112      /**
1113       * Filter here if you wish to edit the message just before being displayed
1114       *
1115       * @since 3.0.0
1116       *
1117       * @param array $feedback_messages
1118       */
1119      return apply_filters( 'bp_nouveau_get_user_feedback', $feedback_messages[ $feedback_id ] );
1120  }
1121  
1122  /**
1123   * Get the signup fields for the requested section
1124   *
1125   * @since 3.0.0
1126   *
1127   * @param string $section Optional. The section of fields to get 'account_details' or 'blog_details'.
1128   *
1129   * @return array|false The list of signup fields for the requested section. False if not found.
1130   */
1131  function bp_nouveau_get_signup_fields( $section = '' ) {
1132      if ( empty( $section ) ) {
1133          return false;
1134      }
1135  
1136      /**
1137       * Filter to add your specific 'text' or 'password' inputs
1138       *
1139       * If you need to use other types of field, please use the
1140       * do_action( 'bp_account_details_fields' ) or do_action( 'blog_details' ) hooks instead.
1141       *
1142       * @since 3.0.0
1143       *
1144       * @param array $value The list of fields organized into sections.
1145       */
1146      $fields = apply_filters( 'bp_nouveau_get_signup_fields', array(
1147          'account_details' => array(
1148              'signup_username' => array(
1149                  'label'          => __( 'Username', 'buddypress' ),
1150                  'required'       => true,
1151                  'value'          => 'bp_get_signup_username_value',
1152                  'attribute_type' => 'username',
1153                  'type'           => 'text',
1154                  'class'          => '',
1155              ),
1156              'signup_email' => array(
1157                  'label'          => __( 'Email Address', 'buddypress' ),
1158                  'required'       => true,
1159                  'value'          => 'bp_get_signup_email_value',
1160                  'attribute_type' => 'email',
1161                  'type'           => 'email',
1162                  'class'          => '',
1163              ),
1164              'signup_password' => array(),
1165              'signup_password_confirm' => array(),
1166          ),
1167          'blog_details' => array(
1168              'signup_blog_url' => array(
1169                  'label'          => __( 'Site URL', 'buddypress' ),
1170                  'required'       => true,
1171                  'value'          => 'bp_get_signup_blog_url_value',
1172                  'attribute_type' => 'slug',
1173                  'type'           => 'text',
1174                  'class'          => '',
1175              ),
1176              'signup_blog_title' => array(
1177                  'label'          => __( 'Site Title', 'buddypress' ),
1178                  'required'       => true,
1179                  'value'          => 'bp_get_signup_blog_title_value',
1180                  'attribute_type' => 'title',
1181                  'type'           => 'text',
1182                  'class'          => '',
1183              ),
1184              'signup_blog_privacy_public' => array(
1185                  'label'          => __( 'Yes', 'buddypress' ),
1186                  'required'       => false,
1187                  'value'          => 'public',
1188                  'attribute_type' => '',
1189                  'type'           => 'radio',
1190                  'class'          => '',
1191              ),
1192              'signup_blog_privacy_private' => array(
1193                  'label'          => __( 'No', 'buddypress' ),
1194                  'required'       => false,
1195                  'value'          => 'private',
1196                  'attribute_type' => '',
1197                  'type'           => 'radio',
1198                  'class'          => '',
1199              ),
1200          ),
1201      ) );
1202  
1203      if ( ! bp_get_blog_signup_allowed() ) {
1204          unset( $fields['blog_details'] );
1205      }
1206  
1207      if ( isset( $fields[ $section ] ) ) {
1208          return $fields[ $section ];
1209      }
1210  
1211      return false;
1212  }
1213  
1214  /**
1215   * Get Some submit buttons data.
1216   *
1217   * @since 3.0.0
1218   *
1219   * @param string $action The action requested.
1220   *
1221   * @return array|false The list of the submit button parameters for the requested action
1222   *                     False if no actions were found.
1223   */
1224  function bp_nouveau_get_submit_button( $action = '' ) {
1225      if ( empty( $action ) ) {
1226          return false;
1227      }
1228  
1229      /**
1230       * Filter the Submit buttons to add your own.
1231       *
1232       * @since 3.0.0
1233       *
1234       * @param array $value The list of submit buttons.
1235       *
1236       * @return array|false
1237       */
1238      $actions = apply_filters( 'bp_nouveau_get_submit_button', array(
1239          'register' => array(
1240              'before'     => 'bp_before_registration_submit_buttons',
1241              'after'      => 'bp_after_registration_submit_buttons',
1242              'nonce'      => 'bp_new_signup',
1243              'attributes' => array(
1244                  'name'  => 'signup_submit',
1245                  'id'    => 'submit',
1246                  'value' => __( 'Complete Sign Up', 'buddypress' ),
1247              ),
1248          ),
1249          'member-profile-edit' => array(
1250              'before' => '',
1251              'after'  => '',
1252              'nonce'  => 'bp_xprofile_edit',
1253              'attributes' => array(
1254                  'name'  => 'profile-group-edit-submit',
1255                  'id'    => 'profile-group-edit-submit',
1256                  'value' => __( 'Save Changes', 'buddypress' ),
1257              ),
1258          ),
1259          'member-capabilities' => array(
1260              'before' => 'bp_members_capabilities_account_before_submit',
1261              'after'  => 'bp_members_capabilities_account_after_submit',
1262              'nonce'  => 'capabilities',
1263              'attributes' => array(
1264                  'name'  => 'capabilities-submit',
1265                  'id'    => 'capabilities-submit',
1266                  'value' => __( 'Save', 'buddypress' ),
1267              ),
1268          ),
1269          'member-delete-account' => array(
1270              'before' => 'bp_members_delete_account_before_submit',
1271              'after'  => 'bp_members_delete_account_after_submit',
1272              'nonce'  => 'delete-account',
1273              'attributes' => array(
1274                  'disabled' => 'disabled',
1275                  'name'     => 'delete-account-button',
1276                  'id'       => 'delete-account-button',
1277                  'value'    => __( 'Delete Account', 'buddypress' ),
1278              ),
1279          ),
1280          'members-general-settings' => array(
1281              'before' => 'bp_core_general_settings_before_submit',
1282              'after'  => 'bp_core_general_settings_after_submit',
1283              'nonce'  => 'bp_settings_general',
1284              'attributes' => array(
1285                  'name'  => 'submit',
1286                  'id'    => 'submit',
1287                  'value' => __( 'Save Changes', 'buddypress' ),
1288                  'class' => 'auto',
1289              ),
1290          ),
1291          'member-notifications-settings' => array(
1292              'before' => 'bp_members_notification_settings_before_submit',
1293              'after'  => 'bp_members_notification_settings_after_submit',
1294              'nonce'  => 'bp_settings_notifications',
1295              'attributes' => array(
1296                  'name'  => 'submit',
1297                  'id'    => 'submit',
1298                  'value' => __( 'Save Changes', 'buddypress' ),
1299                  'class' => 'auto',
1300              ),
1301          ),
1302          'members-profile-settings' => array(
1303              'before' => 'bp_core_xprofile_settings_before_submit',
1304              'after'  => 'bp_core_xprofile_settings_after_submit',
1305              'nonce'  => 'bp_xprofile_settings',
1306              'attributes' => array(
1307                  'name'  => 'xprofile-settings-submit',
1308                  'id'    => 'submit',
1309                  'value' => __( 'Save Changes', 'buddypress' ),
1310                  'class' => 'auto',
1311              ),
1312          ),
1313          'member-group-invites' => array(
1314              'nonce'  => 'bp_nouveau_group_invites_settings',
1315              'attributes' => array(
1316                  'name'  => 'member-group-invites-submit',
1317                  'id'    => 'submit',
1318                  'value' => __( 'Save', 'buddypress' ),
1319                  'class' => 'auto',
1320              ),
1321          ),
1322          'activity-new-comment' => array(
1323              'after'     => 'bp_activity_entry_comments',
1324              'nonce'     => 'new_activity_comment',
1325              'nonce_key' => '_wpnonce_new_activity_comment',
1326              'wrapper'   => false,
1327              'attributes' => array(
1328                  'name'  => 'ac_form_submit',
1329                  'value' => _x( 'Post', 'button', 'buddypress' ),
1330              ),
1331          ),
1332      ) );
1333  
1334      if ( isset( $actions[ $action ] ) ) {
1335          return $actions[ $action ];
1336      }
1337  
1338      return false;
1339  }
1340  
1341  /**
1342   * Reorder a BuddyPress item nav according to a given list of nav item slugs
1343   *
1344   * @since 3.0.0
1345   *
1346   * @param object $nav         The BuddyPress Item Nav object to reorder
1347   * @param array  $order       A list of slugs ordered (eg: array( 'profile', 'activity', etc..) )
1348   * @param string $parent_slug A parent slug if it's a secondary nav we are reordering (case of the Groups single item)
1349   *
1350   * @return bool True on success. False otherwise.
1351   */
1352  function bp_nouveau_set_nav_item_order( $nav = null, $order = array(), $parent_slug = '' ) {
1353      if ( ! is_object( $nav ) || empty( $order ) || ! is_array( $order ) ) {
1354          return false;
1355      }
1356  
1357      $position = 0;
1358  
1359      foreach ( $order as $slug ) {
1360          $position += 10;
1361  
1362          $key = $slug;
1363          if ( ! empty( $parent_slug ) ) {
1364              $key = $parent_slug . '/' . $key;
1365          }
1366  
1367          $item_nav = $nav->get( $key );
1368  
1369          if ( ! $item_nav ) {
1370              continue;
1371          }
1372  
1373          if ( (int) $item_nav->position !== (int) $position ) {
1374              $nav->edit_nav( array( 'position' => $position ), $slug, $parent_slug );
1375          }
1376      }
1377  
1378      return true;
1379  }


Generated: Thu Sep 19 01:01:39 2019 Cross-referenced by PHPXref 0.7.1