Skip to content

Commit 9a84b80

Browse files
committed
Refactor Browse string to Choose File
Browse is not part of the Wordpress translatation file so it doesn't get translated. Choose File is and will be translated according to the langauge Wordpress is set. Also add option to pass button label. Signed-off-by: Roi Dayan <[email protected]>
1 parent eaacd6a commit 9a84b80

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

example/oop-example.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ function get_settings_fields() {
130130
'label' => __( 'File', 'wedevs' ),
131131
'desc' => __( 'File description', 'wedevs' ),
132132
'type' => 'file',
133-
'default' => ''
133+
'default' => '',
134+
'options' => array(
135+
'button_label' => 'Choose Image'
136+
)
134137
)
135138
),
136139
'wedevs_advanced' => array(

src/class.settings-api.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,14 @@ function callback_file( $args ) {
343343
$value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
344344
$size = isset( $args['size'] ) && !is_null( $args['size'] ) ? $args['size'] : 'regular';
345345
$id = $args['section'] . '[' . $args['id'] . ']';
346+
if ( isset( $args['options'] ) && isset( $args['options']['button_label'] ) ) {
347+
$label = $args['options']['button_label'];
348+
} else {
349+
$label = __( 'Choose File' );
350+
}
346351

347352
$html = sprintf( '<input type="text" class="%1$s-text wpsa-url" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
348-
$html .= '<input type="button" class="button wpsa-browse" value="'.__( 'Browse' ).'" />';
353+
$html .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
349354
$html .= $this->get_field_description( $args );
350355

351356
echo $html;

0 commit comments

Comments
 (0)