Skip to content

Commit

Permalink
Merge branch 'release/1.8.9' into issue/896-customer-db-class
Browse files Browse the repository at this point in the history
Resolved Conflicts: 	includes/class-give-html-elements.php
  • Loading branch information
DevinWalker committed Jun 1, 2017
2 parents 9002627 + 3559d46 commit 61103c9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 56 deletions.
4 changes: 2 additions & 2 deletions includes/admin/donors/donors.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function give_donor_view( $donor ) {

$data_atts = array(
'key' => 'user_login',
'exclude' => $user_id,
'search-type' => 'user'
);
$user_args = array(
'name' => 'customerinfo[user_id]',
Expand All @@ -254,7 +254,7 @@ function give_donor_view( $donor ) {

if ( ! empty( $user_id ) ) {
$userdata = get_userdata( $user_id );
$user_args['value'] = $userdata->user_login;
$user_args['selected'] = $user_id;
}

echo Give()->html->ajax_user_search( $user_args );
Expand Down
116 changes: 62 additions & 54 deletions includes/class-give-html-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ public function donations_dropdown( $args = array() ) {
'selected' => 0,
'chosen' => false,
'number' => 30,
'placeholder' => __( 'Select a donation', 'give' )
'placeholder' => __( 'Select a donation', 'give' ),
);

$args = wp_parse_args( $args, $defaults );

$payments = new Give_Payments_Query( array(
'number' => $args['number']
'number' => $args['number'],
) );

$payments = $payments->get_payments();

$options = array();

//Provide nice human readable options.
// Provide nice human readable options.
if ( $payments ) {
$options[0] = $args['placeholder'];
foreach ( $payments as $payment ) {
Expand All @@ -70,7 +70,6 @@ public function donations_dropdown( $args = array() ) {
$options[0] = __( 'No donations found.', 'give' );
}


$output = $this->select( array(
'name' => $args['name'],
'selected' => $args['selected'],
Expand All @@ -82,7 +81,7 @@ public function donations_dropdown( $args = array() ) {
'placeholder' => $args['placeholder'],
'select_atts' => $args['select_atts'],
'show_option_all' => false,
'show_option_none' => false
'show_option_none' => false,
) );

return $output;
Expand Down Expand Up @@ -111,7 +110,9 @@ public function forms_dropdown( $args = array() ) {
'chosen' => false,
'number' => 30,
'placeholder' => esc_attr__( 'Select a Donation Form', 'give' ),
'data' => array( 'search-type' => 'form' ),
'data' => array(
'search-type' => 'form',
),
);

$args = wp_parse_args( $args, $defaults );
Expand All @@ -120,7 +121,7 @@ public function forms_dropdown( $args = array() ) {
'post_type' => 'give_forms',
'orderby' => 'title',
'order' => 'ASC',
'posts_per_page' => $args['number']
'posts_per_page' => $args['number'],
) );

$options = array();
Expand All @@ -130,7 +131,6 @@ public function forms_dropdown( $args = array() ) {
$options[ $args['selected'] ] = get_the_title( $args['selected'] );
}


if ( $forms ) {
$options[0] = $args['placeholder'];
foreach ( $forms as $form ) {
Expand Down Expand Up @@ -181,7 +181,9 @@ public function donor_dropdown( $args = array() ) {
'chosen' => true,
'placeholder' => esc_attr__( 'Select a Donor', 'give' ),
'number' => 30,
'data' => array( 'search-type' => 'donor' )
'data' => array(
'search-type' => 'donor',
),
);

$args = wp_parse_args( $args, $defaults );
Expand All @@ -204,7 +206,6 @@ public function donor_dropdown( $args = array() ) {
if ( ! empty( $args['selected'] ) ) {

// If a selected customer has been specified, we need to ensure it's in the initial list of customers displayed.

if ( ! array_key_exists( $args['selected'], $options ) ) {

$donor = new Give_Donor( $args['selected'] );
Expand All @@ -214,9 +215,7 @@ public function donor_dropdown( $args = array() ) {
$options[ absint( $args['selected'] ) ] = esc_html( $donor->name . ' (' . $donor->email . ')' );

}

}

}

$output = $this->select( array(
Expand All @@ -243,9 +242,9 @@ public function donor_dropdown( $args = array() ) {
* @since 1.0
* @access public
*
* @param string $name Name attribute of the dropdown. Default is 'give_forms_categories'.
* @param int $selected Category to select automatically. Default is 0.
* @param array $args Select box options.
* @param string $name Name attribute of the dropdown. Default is 'give_forms_categories'.
* @param int $selected Category to select automatically. Default is 0.
* @param array $args Select box options.
*
* @return string Categories dropdown.
*/
Expand All @@ -257,16 +256,13 @@ public function category_dropdown( $name = 'give_forms_categories', $selected =
$options[ absint( $category->term_id ) ] = esc_html( $category->name );
}

$output = $this->select( wp_parse_args(
$args,
array(
'name' => $name,
'selected' => $selected,
'options' => $options,
'show_option_all' => esc_html__( 'All Categories', 'give' ),
'show_option_none' => false
)
) );
$output = $this->select( wp_parse_args( $args, array(
'name' => $name,
'selected' => $selected,
'options' => $options,
'show_option_all' => esc_html__( 'All Categories', 'give' ),
'show_option_none' => false,
) ) );

return $output;
}
Expand All @@ -279,9 +275,9 @@ public function category_dropdown( $name = 'give_forms_categories', $selected =
* @since 1.8
* @access public
*
* @param string $name Name attribute of the dropdown. Default is 'give_forms_tags'.
* @param int $selected Tag to select automatically. Default is 0.
* @param array $args Select box options.
* @param string $name Name attribute of the dropdown. Default is 'give_forms_tags'.
* @param int $selected Tag to select automatically. Default is 0.
* @param array $args Select box options.
*
* @return string Tags dropdown.
*/
Expand All @@ -293,16 +289,13 @@ public function tags_dropdown( $name = 'give_forms_tags', $selected = 0, $args =
$options[ absint( $tag->term_id ) ] = esc_html( $tag->name );
}

$output = $this->select( wp_parse_args(
$args,
array(
'name' => $name,
'selected' => $selected,
'options' => $options,
'show_option_all' => esc_html__( 'All Tags', 'give' ),
'show_option_none' => false,
)
) );
$output = $this->select( wp_parse_args( $args, array(
'name' => $name,
'selected' => $selected,
'options' => $options,
'show_option_all' => esc_html__( 'All Tags', 'give' ),
'show_option_none' => false,
) ) );

return $output;
}
Expand All @@ -315,10 +308,10 @@ public function tags_dropdown( $name = 'give_forms_tags', $selected = 0, $args =
* @since 1.0
* @access public
*
* @param string $name Name attribute of the dropdown. Default is 'year'.
* @param int $selected Year to select automatically. Default is 0.
* @param int $years_before Number of years before the current year the dropdown should start with. Default is 5.
* @param int $years_after Number of years after the current year the dropdown should finish at. Default is 0.
* @param string $name Name attribute of the dropdown. Default is 'year'.
* @param int $selected Year to select automatically. Default is 0.
* @param int $years_before Number of years before the current year the dropdown should start with. Default is 5.
* @param int $years_after Number of years after the current year the dropdown should finish at. Default is 0.
*
* @return string Years dropdown.
*/
Expand All @@ -339,7 +332,7 @@ public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5,
'selected' => $selected,
'options' => $options,
'show_option_all' => false,
'show_option_none' => false
'show_option_none' => false,
) );

return $output;
Expand All @@ -353,8 +346,8 @@ public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5,
* @since 1.0
* @access public
*
* @param string $name Name attribute of the dropdown. Default is 'month'.
* @param int $selected Month to select automatically. Default is 0.
* @param string $name Name attribute of the dropdown. Default is 'month'.
* @param int $selected Month to select automatically. Default is 0.
*
* @return string Months dropdown.
*/
Expand All @@ -373,7 +366,7 @@ public function month_dropdown( $name = 'month', $selected = 0 ) {
'selected' => $selected,
'options' => $options,
'show_option_all' => false,
'show_option_none' => false
'show_option_none' => false,
) );

return $output;
Expand Down Expand Up @@ -432,7 +425,6 @@ public function select( $args = array() ) {
$placeholder = '';
}


$output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ) . '" class="give-select ' . esc_attr( $args['class'] ) . '"' . $multiple . ' ' . $args['select_atts'] . ' data-placeholder="' . $placeholder . '"' . $data_elements . '>';

if ( $args['show_option_all'] ) {
Expand Down Expand Up @@ -491,8 +483,8 @@ public function checkbox( $args = array() ) {
'class' => 'give-checkbox',
'options' => array(
'disabled' => false,
'readonly' => false
)
'readonly' => false,
),
);

$args = wp_parse_args( $args, $defaults );
Expand Down Expand Up @@ -541,7 +533,7 @@ public function text( $args = array() ) {
'class' => 'regular-text',
'disabled' => false,
'autocomplete' => '',
'data' => false
'data' => false,
);

$args = wp_parse_args( $args, $defaults );
Expand Down Expand Up @@ -615,7 +607,7 @@ public function textarea( $args = array() ) {
'label' => null,
'desc' => null,
'class' => 'large-text',
'disabled' => false
'disabled' => false,
);

$args = wp_parse_args( $args, $defaults );
Expand Down Expand Up @@ -664,17 +656,33 @@ public function ajax_user_search( $args = array() ) {
'number' => 30,
'select_atts' => '',
'placeholder' => __( 'Select a user', 'give' ),
'data' => array( 'search-type' => 'user' ),
'data' => array(
'search-type' => 'user',
),
);


$args = wp_parse_args( $args, $defaults );

// Set initial args.
$get_users_args = array(
'number' => $args['number'],
);

// Ensure selected user is not included in initial query.
// This is because sites with many users, it's not a guarantee the selected user will be returned.
if ( ! empty( $args['selected'] ) ) {
$get_users_args['exclude'] = $args['selected'];
}

// Initial users array.
$users = apply_filters( 'give_ajax_user_search_initial_results', get_users( $get_users_args ), $args );

// Now add the selected user to the $users array if the arg is present.
if ( ! empty( $args['selected'] ) ) {
$selected_user = apply_filters( 'give_ajax_user_search_selected_results', get_users( "include={$args['selected']}" ), $args );;
$users = array_merge( $users, $selected_user );
}

$options = array();

if ( $users ) {
Expand All @@ -683,7 +691,7 @@ public function ajax_user_search( $args = array() ) {
$options[ absint( $user->ID ) ] = esc_html( $user->user_login . ' (' . $user->user_email . ')' );
}
} else {
$options[0] = esc_html__( 'No users found.', 'give' );
$options[0] = __( 'No users found.', 'give' );
}

$output = $this->select( array(
Expand Down

0 comments on commit 61103c9

Please sign in to comment.