Skip to content

Commit

Permalink
Add the ability to use different labels for submit button and action
Browse files Browse the repository at this point in the history
  • Loading branch information
sudar committed Sep 24, 2020
1 parent 2ad3a79 commit 123cb89
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
15 changes: 13 additions & 2 deletions assets/js/src/bulk-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,21 @@ jQuery(document).ready(function () {
jQuery( "input:radio.schedule-deletion" ).change( function () {
var submitButton = jQuery( this ).parents( 'fieldset' ).next().find( 'button[name="bd_action"]' );

var scheduledLable = 'Schedule Bulk Delete »';
var label = 'Bulk Delete »';

if ( submitButton.data( 'label' ) ) {
label = submitButton.data( 'label' );
}

if ( submitButton.data( 'schedule-label' ) ) {
scheduledLable = submitButton.data( 'schedule-label' );
}

if ( "true" === jQuery( this ).val() ) {
submitButton.html( 'Schedule Bulk Delete »' );
submitButton.html( scheduledLable );
} else {
submitButton.html( 'Bulk Delete »' );
submitButton.html( label );
}
} );

Expand Down
20 changes: 16 additions & 4 deletions include/Core/Base/Mixin/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,16 @@ protected function render_limit_settings( $item_type = '' ) {

/**
* Render cron settings based on whether scheduler is present or not.
*
* @since 6.1.0 Added $now_label param.
*
* @param string $now_label Now button label. Default is empty. If empty then `Delete now` will be used.
*/
protected function render_cron_settings() {
protected function render_cron_settings( $now_label = '' ) {
if ( empty( $now_label ) ) {
$now_label = __( 'Delete now', 'bulk-delete' );
}

$pro_class = '';

$disabled_attr = 'disabled';
Expand All @@ -680,7 +688,7 @@ protected function render_cron_settings() {
<label>
<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="false" type="radio"
checked="checked" class="schedule-deletion">
<?php _e( 'Delete now', 'bulk-delete' ); ?>
<?php echo esc_html( $now_label ); ?>
</label>

<label>
Expand Down Expand Up @@ -762,8 +770,12 @@ class="<?php echo sanitize_html_class( $pro_class ); ?>" style="display: none;"

/**
* Render submit button.
*
* @since 6.1.0 Added $label param.
*
* @param string $label The label for the button. Default empty.
*/
protected function render_submit_button() {
bd_render_submit_button( $this->action );
protected function render_submit_button( $label = '' ) {
bd_render_submit_button( $this->action, $label );
}
}
13 changes: 11 additions & 2 deletions include/ui/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,22 @@ function bd_render_cron_settings( $slug, $addon_url ) {
* Render the submit button.
*
* @since 5.5
* @since 6.1.0 Added $label param.
*
* @param string $action The action attribute of the submit button.
* @param string $label The label for the button. Default empty. If empty, then 'Bulk Delete' is used.
*/
function bd_render_submit_button( $action ) {
function bd_render_submit_button( $action, $label = '' ) {
if ( empty( $label ) ) {
$label = __( 'Bulk Delete ', 'bulk-delete' );

}
?>
<p class="submit">
<button type="submit" name="bd_action" value="<?php echo esc_attr( $action ); ?>" class="button-primary"><?php _e( 'Bulk Delete ', 'bulk-delete' ); ?>&raquo;</button>
<button type="submit" name="bd_action" value="<?php echo esc_attr( $action ); ?>" class="button-primary"
data-label="<?php echo esc_attr( $label ); ?> &raquo;" data-schedule-label="<?php echo __( 'Schedule ', 'bulk-delete' ), esc_attr( $label ); ?> &raquo;">
<?php echo esc_html( $label ); ?> &raquo;
</button>
</p>
<?php
}
Expand Down

0 comments on commit 123cb89

Please sign in to comment.