Skip to content

Commit d8ec650

Browse files
roidayantareq1988
authored andcommitted
Small fixes (#65)
* Add conditional test when to add wp3.8 style fix No need to include it for later wordpress versions so it won't break anything for future versions by mistake. Signed-off-by: Roi Dayan <[email protected]> * Invoke change event on wpsa-url input External js might listen to change event of the input field. Signed-off-by: Roi Dayan <[email protected]> * Allow optional label field It's not needed for example for the html field. Signed-off-by: Roi Dayan <[email protected]> * Small refactor to adding settings fields To be more readable. Signed-off-by: Roi Dayan <[email protected]>
1 parent 5626218 commit d8ec650

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/class.settings-api.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,16 @@ function admin_init() {
119119
foreach ( $this->settings_fields as $section => $field ) {
120120
foreach ( $field as $option ) {
121121

122+
$name = $option['name'];
122123
$type = isset( $option['type'] ) ? $option['type'] : 'text';
124+
$label = isset( $option['label'] ) ? $option['label'] : '';
125+
$callback = isset( $option['callback'] ) ? $option['callback'] : array( $this, 'callback_' . $type );
123126

124127
$args = array(
125-
'id' => $option['name'],
126-
'label_for' => $args['label_for'] = "{$section}[{$option['name']}]",
128+
'id' => $name,
129+
'label_for' => $args['label_for'] = "{$section}[{$name}]",
127130
'desc' => isset( $option['desc'] ) ? $option['desc'] : '',
128-
'name' => $option['label'],
131+
'name' => $label,
129132
'section' => $section,
130133
'size' => isset( $option['size'] ) ? $option['size'] : null,
131134
'options' => isset( $option['options'] ) ? $option['options'] : '',
@@ -138,7 +141,7 @@ function admin_init() {
138141
'step' => isset( $option['step'] ) ? $option['step'] : '',
139142
);
140143

141-
add_settings_field( $section . '[' . $option['name'] . ']', $option['label'], (isset($option['callback']) ? $option['callback'] : array($this, 'callback_' . $type )), $section, $section, $args );
144+
add_settings_field( "{$section}[{$name}]", $label, $callback, $section, $section, $args );
142145
}
143146
}
144147

@@ -594,22 +597,30 @@ function(){
594597

595598
file_frame.on('select', function () {
596599
attachment = file_frame.state().get('selection').first().toJSON();
597-
598-
self.prev('.wpsa-url').val(attachment.url);
600+
self.prev('.wpsa-url').val(attachment.url).change();
599601
});
600602

601603
// Finally, open the modal
602604
file_frame.open();
603605
});
604606
});
605607
</script>
608+
<?php
609+
$this->_style_fix();
610+
}
606611

612+
function _style_fix() {
613+
global $wp_version;
614+
615+
if (version_compare($wp_version, '3.8', '<=')):
616+
?>
607617
<style type="text/css">
608618
/** WordPress 3.8 Fix **/
609619
.form-table th { padding: 20px 10px; }
610620
#wpbody-content .metabox-holder { padding-top: 5px; }
611621
</style>
612622
<?php
623+
endif;
613624
}
614625

615626
}

0 commit comments

Comments
 (0)