Skip to content

Commit

Permalink
Merge pull request #1712 from spencerfinnell/feature/split-metaboxess
Browse files Browse the repository at this point in the history
Split Metaboxes
  • Loading branch information
pippinsplugins committed Nov 17, 2013
2 parents f284d03 + 714d1bd commit d6c2cc8
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 53 deletions.
6 changes: 6 additions & 0 deletions assets/css/edd-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ textarea#edd_product_notes { width: 100%; height: 4em; margin: 0; }
#edd-order-data .data span { color: #666; font-weight: 600; }
#edd-purchased-files .inside { margin: 0; padding: 0; }

.edd-price-field { width: 80px; }

/** Stats */
#edd_product_stats .label { width: 70px; display: inline-block; }
#edd_product_stats hr { border-style: solid; border-width: 1px; border-color: #ccc #fff #fff #ccc; }

/* Dashboard Widget Styles
-------------------------------------------------------------- */
.edd_dashboard_widget .table { margin: 20px 0 0 0; padding: 0; position: relative; border-top: 1px solid #ececec; }
Expand Down
157 changes: 110 additions & 47 deletions includes/admin/downloads/metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function edd_add_download_meta_box() {
foreach ( $post_types as $post_type ) {

/** Product Prices **/
add_meta_box( 'edd_product_prices', sprintf( __( '%1$s Configuration', 'edd' ), edd_get_label_singular(), edd_get_label_plural() ), 'edd_render_download_meta_box', $post_type, 'normal', 'high' );
add_meta_box( 'edd_product_prices', sprintf( __( '%1$s Prices', 'edd' ), edd_get_label_singular(), edd_get_label_plural() ), 'edd_render_download_meta_box', $post_type, 'normal', 'high' );

/** Product Files (and bundled products) **/
add_meta_box( 'edd_product_files', sprintf( __( '%1$s Files', 'edd' ), edd_get_label_singular(), edd_get_label_plural() ), 'edd_render_files_meta_box', $post_type, 'normal', 'high' );
Expand Down Expand Up @@ -306,10 +306,20 @@ function edd_render_price_field( $post_id ) {
</p>

<div id="edd_regular_price_field" class="edd_pricing_fields" <?php echo $price_display; ?>>
<?php
$price_args = array(
'name' => 'edd_price',
'value' => isset( $price ) ? esc_attr( edd_format_amount( $price ) ) : '',
'class' => 'edd-price-field'
);
?>

<?php if ( ! isset( $edd_options['currency_position'] ) || $edd_options['currency_position'] == 'before' ) : ?>
<?php echo edd_currency_filter( '' ); ?><input type="text" name="edd_price" id="edd_price" value="<?php echo isset( $price ) ? esc_attr( edd_format_amount( $price ) ) : ''; ?>" size="30" style="width: 80px;" placeholder="9.99"/>
<?php echo edd_currency_filter( '' ); ?>
<?php echo EDD()->html->text( $price_args ); ?>
<?php else : ?>
<input type="text" name="edd_price" id="edd_price" value="<?php echo isset( $price ) ? esc_attr( edd_format_amount( $price ) ) : ''; ?>" size="30" style="width: 80px;" placeholder="9.99"/><?php echo edd_currency_filter( '' ); ?>
<?php echo EDD()->html->text( $price_args ); ?>
<?php echo edd_currency_filter( '' ); ?>
<?php endif; ?>

<?php do_action( 'edd_price_field', $post_id ); ?>
Expand All @@ -320,8 +330,8 @@ function edd_render_price_field( $post_id ) {
<div id="edd_variable_price_fields" class="edd_pricing_fields" <?php echo $variable_display; ?>>
<input type="hidden" id="edd_variable_prices" class="edd_variable_prices_name_field" value=""/>
<p>
<input type="checkbox" name="_edd_price_options_mode" id="edd_price_options_mode"<?php checked( 1, $single_option_mode ); ?> />
<label for="edd_price_options_mode"><?php apply_filters( 'edd_multi_option_purchase_text', _e( 'Enable multi option purchase mode. Leave unchecked to only permit a single price option to be purchased', 'edd' ) ); ?></label>
<?php echo EDD()->html->checkbox( array( 'name' => '_edd_price_options_mode', 'current' => $single_option_mode ) ); ?>
<label for="_edd_price_options_mode"><?php apply_filters( 'edd_multi_option_purchase_text', _e( 'Enable multi option purchase mode. Leave unchecked to only permit a single price option to be purchased', 'edd' ) ); ?></label>
</p>
<div id="edd_price_fields" class="edd_meta_table_wrap">
<table class="widefat edd_repeatable_table" width="100%" cellpadding="0" cellspacing="0">
Expand All @@ -331,7 +341,7 @@ function edd_render_price_field( $post_id ) {
<th style="width: 20px"></th>
-->
<th><?php _e( 'Option Name', 'edd' ); ?></th>
<th style="width: 90px"><?php _e( 'Price', 'edd' ); ?></th>
<th style="width: 100px"><?php _e( 'Price', 'edd' ); ?></th>
<?php do_action( 'edd_download_price_table_head', $post_id ); ?>
<th style="width: 2%"></th>
</tr>
Expand Down Expand Up @@ -401,14 +411,28 @@ function edd_render_price_row( $key, $args = array(), $post_id ) {
-->

<td>
<input type="text" class="edd_variable_prices_name" placeholder="<?php _e( 'Option Name', 'edd' ); ?>" name="edd_variable_prices[<?php echo $key; ?>][name]" id="edd_variable_prices[<?php echo $key; ?>][name]" value="<?php echo esc_attr( $name ); ?>" size="20" style="width:100%" />
<?php echo EDD()->html->text( array(
'name' => 'edd_variable_prices[' . $key . '][name]',
'value' => esc_attr( $name ),
'class' => 'large-text'
) ); ?>
</td>

<td>
<?php
$price_args = array(
'name' => 'edd_variable_prices[' . $key . '][amount]',
'value' => $amount,
'class' => 'edd-price-field'
);
?>

<?php if( ! isset( $edd_options['currency_position'] ) || $edd_options['currency_position'] == 'before' ) : ?>
<span><?php echo edd_currency_filter( '' ); ?></span> <input type="text" class="edd_variable_prices_amount text" value="<?php echo $amount; ?>" placeholder="9.99" name="edd_variable_prices[<?php echo $key; ?>][amount]" id="edd_variable_prices[<?php echo $key; ?>][amount]" size="30" style="width:80px;" />
<span><?php echo edd_currency_filter( '' ); ?></span>
<?php echo EDD()->html->text( $price_args ); ?>
<?php else : ?>
<input type="text" class="edd_variable_prices_amount text" value="<?php echo $amount; ?>" placeholder="9.99" name="edd_variable_prices[<?php echo $key; ?>][amount]" id="edd_variable_prices[<?php echo $key; ?>][amount]" size="30" style="width:80px;" /><?php echo edd_currency_filter( '' ); ?>
<?php echo EDD()->html->text( $price_args ); ?>
<?php echo edd_currency_filter( '' ); ?>
<?php endif; ?>
</td>

Expand Down Expand Up @@ -437,7 +461,13 @@ function edd_render_product_type_field( $post_id = 0 ) {
<strong><?php apply_filters( 'edd_product_type_options_heading', _e( 'Product Type Options:', 'edd' ) ); ?></strong>
</p>
<p>
<?php echo EDD()->html->select( array( 'options' => $types, 'name' => '_edd_product_type', 'selected' => $type, 'show_option_all' => false, 'show_option_none' => false ) ); ?>
<?php echo EDD()->html->select( array(
'options' => $types,
'name' => '_edd_product_type',
'selected' => $type,
'show_option_all' => false,
'show_option_none' => false
) ); ?>
<label for="edd_product_type"><?php _e( 'Select a product type', 'edd' ); ?></label>
</p>
<?php
Expand Down Expand Up @@ -632,12 +662,20 @@ function edd_render_file_row( $key = '', $args = array(), $post_id ) {
</td>
-->
<td>
<input type="text" class="edd_repeatable_name_field" name="edd_download_files[<?php echo $key; ?>][name]" id="edd_download_files[<?php echo $key; ?>][name]" value="<?php echo $name; ?>" placeholder="<?php _e( 'File Name', 'edd' ); ?>" style="width:100%" />
<?php echo EDD()->html->text( array(
'name' => 'edd_download_files[' . $key . '][name]',
'value' => $name,
'class' => 'large-text'
) ); ?>
</td>

<td>
<div class="edd_repeatable_upload_field_container">
<input type="text" class="edd_repeatable_upload_field edd_upload_field" name="edd_download_files[<?php echo $key; ?>][file]" id="edd_download_files[<?php echo $key; ?>][file]" value="<?php echo $file; ?>" placeholder="<?php _e( 'http://', 'edd' ); ?>" style="width:100%" />
<?php echo EDD()->html->text( array(
'name' => 'edd_download_files[' . $key . '][file]',
'value' => $name,
'class' => 'edd_repeatable_upload_field edd_upload_field large-text'
) ); ?>

<span class="edd_upload_file">
<a href="#" data-uploader_title="" data-uploader_button_text="<?php _e( 'Insert', 'edd' ); ?>" class="edd_upload_image_button" onclick="return false;"><?php _e( 'Upload a File', 'edd' ); ?></a>
Expand All @@ -646,12 +684,22 @@ function edd_render_file_row( $key = '', $args = array(), $post_id ) {
</td>

<td class="pricing"<?php echo $variable_display; ?>>
<select class="edd_repeatable_condition_field" name="edd_download_files[<?php echo $key; ?>][condition]" id="edd_download_files[<?php echo $key; ?>][condition]" <?php echo $variable_display; ?>>
<option value="all"><?php _e( 'All Prices', 'edd' ); ?></option>
<?php if ( $prices ) : foreach ( $prices as $price_key => $price ) : ?>
<option value="<?php echo $price_key; ?>" <?php selected( $price_key, $condition ); ?>><?php echo $prices[ $price_key ]['name']; ?></option>
<?php endforeach; endif; ?>
</select>
<?php
$options = array();

if ( $prices ) {
foreach ( $prices as $price_key => $price ) {
$options[ $price_key ] = $prices[ $price_key ][ 'name' ];
}
}

echo EDD()->html->select( array(
'name' => 'edd_download_files[' . $key . '][condition]',
'class' => 'edd_repeatable_condition_field',
'options' => $options,
'selected' => $condition
) );
?>
</td>

<?php do_action( 'edd_download_file_table_row', $post_id, $key, $args ); ?>
Expand Down Expand Up @@ -684,7 +732,11 @@ function edd_render_download_limit_row( $post_id ) {
?>
<p><strong><?php _e( 'File Download Limit:', 'edd' ); ?></strong></p>
<label for="edd_download_limit">
<input type="text" name="_edd_download_limit" id="edd_download_limit" value="<?php echo esc_attr( $edd_download_limit ); ?>" size="30" style="width: 80px;" placeholder="0"/>
<?php echo EDD()->html->text( array(
'name' => '_edd_download_limit',
'value' => $edd_download_limit,
'class' => 'small-text'
) ); ?>
<?php _e( 'The maximum number of times a buyer can download each file. Leave blank or set to 0 for unlimited', 'edd' ); ?>
</label>
<?php
Expand All @@ -711,7 +763,11 @@ function edd_render_accounting_options( $post_id ) {
<p><strong><?php _e( 'Accounting Options:', 'edd' ); ?></strong></p>
<p>
<label for="edd_sku">
<input type="text" name="edd_sku" id="edd_sku" value="<?php echo esc_attr( $edd_sku ); ?>" size="30" style="width: 80px;"/>
<?php echo EDD()->html->text( array(
'name' => 'edd_sku',
'value' => $edd_sku,
'class' => 'small-text'
) ); ?>
<?php echo sprintf( __( 'Enter an SKU for this %s.', 'edd' ), strtolower( edd_get_label_singular() ) ); ?>
</label>
</p>
Expand All @@ -728,24 +784,33 @@ function edd_render_accounting_options( $post_id ) {
* @return void
*/
function edd_render_disable_button( $post_id ) {
$hide_button = get_post_meta( $post_id, '_edd_hide_purchase_link', true ) ? true : false;
$hide_button = get_post_meta( $post_id, '_edd_hide_purchase_link', true ) ? 1 : 0;
$behavior = get_post_meta( $post_id, '_edd_button_behavior', true );
?>
<p><strong><?php _e( 'Button Options:', 'edd' ); ?></strong></p>
<p>
<label for="_edd_hide_purchase_link">
<input type="checkbox" name="_edd_hide_purchase_link" id="_edd_hide_purchase_link" value="1" <?php checked( true, $hide_button ); ?> />
<?php echo EDD()->html->checkbox( array(
'name' => '_edd_hide_purchase_link',
'current' => $hide_button
) ); ?>
<?php _e( 'Disable the automatic output of the purchase button', 'edd' ); ?>
</label>
</p>
<?php if( edd_shop_supports_buy_now() ) : ?>
<p>
<label for="_edd_button_behavior">
<select name="_edd_button_behavior" id="_edd_button_behavior" >
<option value="add_to_cart"<?php selected( $behavior, 'add_to_cart' ); ?>><?php _e( 'Add to Cart', 'edd' ); ?></option>
<option value="direct"<?php selected( $behavior, 'direct' ); ?>><?php _e( 'Buy Now', 'edd' ); ?></option>
</select>
<?php _e( 'Select the purchase button behavior', 'edd' ); ?>
<?php echo EDD()->html->select( array(
'name' => '_edd_button_behavior',
'options' => array(
'add_to_cart' => __( 'Add to Cart', 'edd' ),
'direct' => __( 'Buy Now', 'edd' )
),
'show_option_all' => null,
'show_option_none' => null,
'selected' => $behavior
) ); ?>
<?php _e( 'Purchase button behavior', 'edd' ); ?>
</label>
</p>
<?php
Expand Down Expand Up @@ -805,25 +870,23 @@ function edd_render_stats_meta_box() {

$earnings = edd_get_download_earnings_stats( $post->ID );
$sales = edd_get_download_sales_stats( $post->ID );
?>

echo '<table class="form-table">';
echo '<tr>';
echo '<th style="width: 20%">' . __( 'Sales:', 'edd' ) . '</th>';
echo '<td class="edd_download_stats">';
echo $sales . '&nbsp;&ndash;&nbsp;<a href="' . admin_url( '/edit.php?page=edd-reports&view=sales&post_type=download&tab=logs&download=' . $post->ID ) . '">' . __( 'View Sales Log', 'edd' ) . '</a>';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<th style="width: 30%">' . __( 'Earnings:', 'edd' ) . '</th>';
echo '<td class="edd_download_stats">';
echo edd_currency_filter( edd_format_amount( $earnings ) );
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2" class="edd_download_stats">';
echo '<a href="' . admin_url( '/edit.php?page=edd-reports&view=file_downloads&post_type=download&tab=logs&download=' . $post->ID ) . '">' . __( 'View File Download Log', 'edd' ) . '</a>';
echo '</td>';
echo '</tr>';
do_action('edd_stats_meta_box');
echo '</table>';
<p>
<strong class="label"><?php _e( 'Sales:', 'edd' ); ?></strong>
<span><?php echo $sales; ?> &mdash; <a href="<?php echo admin_url( '/edit.php?page=edd-reports&view=sales&post_type=download&tab=logs&download=' . $post->ID ); ?>"><?php _e( 'View Sales Log', 'edd' ); ?></a></span>
</p>

<p>
<strong class="label"><?php _e( 'Earnings:', 'edd' ); ?></strong>
<span><?php echo edd_currency_filter( edd_format_amount( $earnings ) ); ?></span>
</p>

<hr />

<p>
<span><a href="<?php echo admin_url( '/edit.php?page=edd-reports&view=file_downloads&post_type=download&tab=logs&download=' . $post->ID ); ?>"><?php _e( 'View File Download Log', 'edd' ); ?></a></span>
</p>
<?php
do_action('edd_stats_meta_box');
}
60 changes: 54 additions & 6 deletions includes/class-edd-html-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,29 @@ public function select( $args = array() ) {
return $output;
}

/**
* Renders an HTML Checkbox
*
* @since 1.9
*
* @param array $args
*
* @return string
*/
public function checkbox( $args = array() ) {
$defaults = array(
'name' => null,
'current' => null,
'class' => 'edd-select'
);

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

$output = '<input type="checkbox" name="' . esc_attr( $args[ 'name' ] ) . '" id="' . esc_attr( $args[ 'name' ] ) . '" class="edd-select ' . esc_attr( $args[ 'name'] ) . '" ' . checked( 1, $args[ 'current' ], false ) . '" class="' . $args[ 'class' ] .'" />';

return $output;
}

/**
* Renders an HTML Text field
*
Expand All @@ -231,12 +254,37 @@ public function select( $args = array() ) {
* @param string $desc
* @return string Text field
*/
public function text( $name = 'text', $value = '', $label = '', $desc = '' ) {
$output = '<span id="edd-' . sanitize_key( $name ) . '-wrap">';
$output .= '<label class="edd-label" for="edd-' . sanitize_key( $name ) . '">' . esc_html( $label ) . '</label>';
if ( ! empty( $desc ) )
$output .= '<span class="edd-description">' . esc_html( $desc ) . '</span>';
$output = '<input type="text" name="' . esc_attr( $name ) . '" id="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '"/>';
public function text( $args = array() ) {
// Backwards compatabliity
if ( func_num_args() > 1 ) {
$args = func_get_args();

$name = $args[0];
$value = isset( $args[1] ) ? $args[1] : '';
$label = isset( $args[2] ) ? $args[2] : '';
$desc = isset( $args[3] ) ? $args[3] : '';
}

$defaults = array(
'name' => isset( $name ) ? $name : 'text',
'value' => isset( $value ) ? $value : null,
'label' => isset( $label ) ? $label : null,
'desc' => isset( $desc ) ? $desc : null,
'class' => 'regular-text'
);

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

$output = '<span id="edd-' . sanitize_key( $args[ 'name' ] ) . '-wrap">';

$output .= '<label class="edd-label" for="edd-' . sanitize_key( $args[ 'name' ] ) . '">' . esc_html( $args[ 'label' ] ) . '</label>';

if ( ! empty( $args[ 'desc' ] ) ) {
$output .= '<span class="edd-description">' . esc_html( $args[ 'desc' ] ) . '</span>';
}

$output = '<input type="text" name="' . esc_attr( $args[ 'name' ] ) . '" id="' . esc_attr( $args[ 'name' ] ) . '" value="' . esc_attr( $args[ 'value' ] ) . '" class="' . $args[ 'class' ] . '"/>';

$output .= '</span>';

return $output;
Expand Down

0 comments on commit d6c2cc8

Please sign in to comment.