Skip to content

Commit

Permalink
Merge branch 'master' into core-code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgibbs committed Jun 21, 2017
2 parents cefcbbd + 3a58503 commit 7779605
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 343 deletions.
14 changes: 8 additions & 6 deletions bp-templates/bp-nouveau/buddypress-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ private function includes() {
}, 0 );
}

// Customizer.
add_action( 'bp_customize_register', function() {
// @todo Cap check might need to change.
if ( bp_is_root_blog() && current_user_can( 'customize' ) ) {
require $this->includes_dir . 'customizer.php';
}
}, 0 );

foreach ( bp_core_get_packaged_component_ids() as $component ) {
$component_loader = trailingslashit( $this->includes_dir ) . $component . '/loader.php';

Expand Down Expand Up @@ -205,12 +213,6 @@ protected function setup_actions() {
// Register directory nav items
add_action( 'bp_screens', array( $this, 'setup_directory_nav' ), 15 );

// BP Nouveau Customizer panel.
add_action( 'bp_customize_register', 'bp_nouveau_customize_register', 10, 1 );

// Enqueue scripts for the BP Nouveau customizer panel.
add_action( 'customize_controls_enqueue_scripts', 'bp_nouveau_customizer_enqueue_scripts' );

// Register the Default front pages Dynamic Sidebars
add_action( 'widgets_init', 'bp_nouveau_register_sidebars', 11 );

Expand Down
347 changes: 347 additions & 0 deletions bp-templates/bp-nouveau/includes/customizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,347 @@
<?php
/**
* Code to hook into the WP Customizer
*
* @since 1.0.0
*
* @package BP Nouveau
*/

/**
* Add a specific panel for the BP Nouveau Template Pack.
*
* @since 1.0.0
*
* @param WP_Customize_Manager $wp_customize WordPress customizer.
*/
function bp_nouveau_customize_register( WP_Customize_Manager $wp_customize ) {
if ( ! bp_is_root_blog() ) {
return;
}

// include the Customizer control.
require_once( trailingslashit( bp_nouveau()->includes_dir ) . 'customizer-controls.php' );

// Add it to control types
$wp_customize->register_control_type( 'BP_Nouveau_Nav_Customize_Control' );

$bp_nouveau_options = bp_nouveau_get_appearance_settings();

$wp_customize->add_panel( 'bp_nouveau_panel', array(
'description' => __( 'Customize the appearance of your BuddyPress Template pack.', 'bp-nouveau' ),
'title' => _x( 'BuddyPress Template Pack', 'Customizer Panel', 'bp-nouveau' ),
'priority' => 200,
) );

$sections = apply_filters( 'bp_nouveau_customizer_sections', array(
'bp_nouveau_general_settings' => array(
'title' => __( 'General BP Settings', 'bp-nouveau' ),
'panel' => 'bp_nouveau_panel',
'priority' => 10,
'description' => __( 'Set general BuddyPress styles', 'bp-nouveau' ),
),
'bp_nouveau_user_front_page' => array(
'title' => __( 'User\'s front page', 'bp-nouveau' ),
'panel' => 'bp_nouveau_panel',
'priority' => 30,
'description' => __( 'Set your preferences about the members default front page.', 'bp-nouveau' ),
),
'bp_nouveau_user_primary_nav' => array(
'title' => __( 'User\'s navigation', 'bp-nouveau' ),
'panel' => 'bp_nouveau_panel',
'priority' => 50,
'description' => __( 'Customize the members primary navigations. Navigate to any random member\'s profile to live preview your changes.', 'bp-nouveau' ),
),
'bp_nouveau_loops_layout' => array(
'title' => __( 'Loops layouts', 'bp-nouveau' ),
'panel' => 'bp_nouveau_panel',
'priority' => 70,
'description' => __( 'Set the number of columns to use for the BuddyPress loops.', 'bp-nouveau' ),
),
'bp_nouveau_dir_layout' => array(
'title' => __( 'Directory layouts', 'bp-nouveau' ),
'panel' => 'bp_nouveau_panel',
'priority' => 80,
'description' => __( 'Select the layout style for directory content &amp; navigation.', 'bp-nouveau' ),
),
) );

// Add the sections to the customizer
foreach ( $sections as $id_section => $section_args ) {
$wp_customize->add_section( $id_section, $section_args );
}

$settings = apply_filters( 'bp_nouveau_customizer_settings', array(
'bp_nouveau_appearance[avatar_style]' => array(
'index' => 'avatar_style',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[user_front_page]' => array(
'index' => 'user_front_page',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[user_front_bio]' => array(
'index' => 'user_front_bio',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[user_nav_display]' => array(
'index' => 'user_nav_display',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[user_nav_tabs]' => array(
'index' => 'user_nav_tabs',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[user_nav_order]' => array(
'index' => 'user_nav_order',
'capability' => 'bp_moderate',
'sanitize_callback' => 'bp_nouveau_sanitize_nav_order',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[members_layout]' => array(
'index' => 'members_layout',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[members_group_layout]' => array(
'index' => 'members_group_layout',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[members_friends_layout]' => array(
'index' => 'members_friends_layout',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[activity_dir_layout]' => array(
'index' => 'activity_dir_layout',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[activity_dir_tabs]' => array(
'index' => 'activity_dir_tabs',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[members_dir_layout]' => array(
'index' => 'members_dir_layout',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[members_dir_tabs]' => array(
'index' => 'members_dir_tabs',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[groups_dir_layout]' => array(
'index' => 'groups_dir_layout',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[groups_dir_tabs]' => array(
'index' => 'groups_dir_tabs',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[sites_dir_layout]' => array(
'index' => 'sites_dir_layout',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
'bp_nouveau_appearance[sites_dir_tabs]' => array(
'index' => 'sites_dir_tabs',
'capability' => 'bp_moderate',
'sanitize_callback' => 'absint',
'transport' => 'refresh',
'type' => 'option',
),
) );

// Add the settings
foreach ( $settings as $id_setting => $setting_args ) {
$args = array();

if ( empty( $setting_args['index'] ) || ! isset( $bp_nouveau_options[ $setting_args['index'] ] ) ) {
continue;
}

$args = array_merge( $setting_args, array( 'default' => $bp_nouveau_options[ $setting_args['index'] ] ) );

$wp_customize->add_setting( $id_setting, $args );
}

$controls = apply_filters( 'bp_nouveau_customizer_controls', array(
'bp_site_avatars' => array(
'label' => __( 'Set BP User, Group avatars to rounded style.', 'bp-nouveau' ),
'section' => 'bp_nouveau_general_settings',
'settings' => 'bp_nouveau_appearance[avatar_style]',
'type' => 'checkbox',
),
'user_front_page' => array(
'label' => __( 'Enable default front page for user profiles.', 'bp-nouveau' ),
'section' => 'bp_nouveau_user_front_page',
'settings' => 'bp_nouveau_appearance[user_front_page]',
'type' => 'checkbox',
),
'user_front_bio' => array(
'label' => __( 'Display the WordPress Biographical Info of the user.', 'bp-nouveau' ),
'section' => 'bp_nouveau_user_front_page',
'settings' => 'bp_nouveau_appearance[user_front_bio]',
'type' => 'checkbox',
),
'user_nav_display' => array(
'label' => __( 'Display the User\'s primary nav vertically.', 'bp-nouveau' ),
'section' => 'bp_nouveau_user_primary_nav',
'settings' => 'bp_nouveau_appearance[user_nav_display]',
'type' => 'checkbox',
),
'user_nav_tabs' => array(
'label' => __( 'Set User nav to tab style:', 'bp-nouveau' ),
'section' => 'bp_nouveau_user_primary_nav',
'settings' => 'bp_nouveau_appearance[user_nav_tabs]',
'type' => 'checkbox',
),
'user_nav_order' => array(
'class' => 'BP_Nouveau_Nav_Customize_Control',
'label' => __( 'Reorder the Members single items primary navigation.', 'bp-nouveau' ),
'section' => 'bp_nouveau_user_primary_nav',
'settings' => 'bp_nouveau_appearance[user_nav_order]',
'type' => 'user',
),
'members_layout' => array(
'label' => __( 'Members loop:', 'bp-nouveau' ),
'section' => 'bp_nouveau_loops_layout',
'settings' => 'bp_nouveau_appearance[members_layout]',
'type' => 'select',
'choices' => bp_nouveau_customizer_grid_choices(),
),
'members_group_layout' => array(
'label' => __( 'Members loop - Single Groups:', 'bp-nouveau' ),
'section' => 'bp_nouveau_loops_layout',
'settings' => 'bp_nouveau_appearance[members_group_layout]',
'type' => 'select',
'choices' => bp_nouveau_customizer_grid_choices(),
),
'members_friends_layout' => array(
'label' => __( 'Members Friends - User Account:', 'bp-nouveau' ),
'section' => 'bp_nouveau_loops_layout',
'settings' => 'bp_nouveau_appearance[members_friends_layout]',
'type' => 'select',
'choices' => bp_nouveau_customizer_grid_choices(),
),
'act_dir_layout' => array(
'label' => __( 'Set Activity dir nav to column.', 'bp-nouveau' ),
'section' => 'bp_nouveau_dir_layout',
'settings' => 'bp_nouveau_appearance[activity_dir_layout]',
'type' => 'checkbox',
),
'act_dir_tabs' => array(
'label' => __( 'Set Activity nav to tab style.', 'bp-nouveau' ),
'section' => 'bp_nouveau_dir_layout',
'settings' => 'bp_nouveau_appearance[activity_dir_tabs]',
'type' => 'checkbox',
),
'members_dir_layout' => array(
'label' => __( 'Set Members dir nav to column.', 'bp-nouveau' ),
'section' => 'bp_nouveau_dir_layout',
'settings' => 'bp_nouveau_appearance[members_dir_layout]',
'type' => 'checkbox',
),
'members_dir_tabs' => array(
'label' => __( 'Set Members nav to tab style.', 'bp-nouveau' ),
'section' => 'bp_nouveau_dir_layout',
'settings' => 'bp_nouveau_appearance[members_dir_tabs]',
'type' => 'checkbox',
),
'group_dir_layout' => array(
'label' => __( 'Set Groups dir nav to column.', 'bp-nouveau' ),
'section' => 'bp_nouveau_dir_layout',
'settings' => 'bp_nouveau_appearance[groups_dir_layout]',
'type' => 'checkbox',
),
'group_dir_tabs' => array(
'label' => __( 'Set Groups nav to tab style.', 'bp-nouveau' ),
'section' => 'bp_nouveau_dir_layout',
'settings' => 'bp_nouveau_appearance[groups_dir_tabs]',
'type' => 'checkbox',
),
'sites_dir_layout' => array(
'label' => __( 'Set Sites dir nav to column:', 'bp-nouveau' ),
'section' => 'bp_nouveau_dir_layout',
'settings' => 'bp_nouveau_appearance[sites_dir_layout]',
'type' => 'checkbox',
),
'sites_dir_tabs' => array(
'label' => __( 'Set Sites nav to tab style:', 'bp-nouveau' ),
'section' => 'bp_nouveau_dir_layout',
'settings' => 'bp_nouveau_appearance[sites_dir_tabs]',
'type' => 'checkbox',
),
) );

// Add the controls to the customizer's section
foreach ( $controls as $id_control => $control_args ) {
if ( empty( $control_args['class'] ) ) {
$wp_customize->add_control( $id_control, $control_args );
} else {
$wp_customize->add_control( new $control_args['class']( $wp_customize, $id_control, $control_args ) );
}
}
}
add_action( 'bp_customize_register', 'bp_nouveau_customize_register', 10, 1 );

/**
* Enqueue needed JS for our customizer Settings & Controls
*
* @since 1.0.0
*/
function bp_nouveau_customizer_enqueue_scripts() {
$min = bp_core_get_minified_asset_suffix();

wp_enqueue_script(
'bp-nouveau-customizer',
trailingslashit( bp_get_theme_compat_url() ) . "js/customizer{$min}.js",
array( 'jquery', 'jquery-ui-sortable', 'customize-controls', 'iris', 'underscore', 'wp-util' ),
bp_nouveau()->version,
true
);

do_action( 'bp_nouveau_customizer_enqueue_scripts' );
}
add_action( 'customize_controls_enqueue_scripts', 'bp_nouveau_customizer_enqueue_scripts' );
Loading

0 comments on commit 7779605

Please sign in to comment.