Custom sport selector and input

This commit is contained in:
Brian Miyaji
2014-02-15 23:47:41 +11:00
parent 85b2cb380d
commit e800084fc4
2 changed files with 14 additions and 2 deletions

View File

@@ -40,12 +40,16 @@ function sportspress_sport_callback() {
$options = get_option( 'sportspress' );
$selected = sportspress_array_value( $options, 'sport', null );
$custom_sport_name = sportspress_array_value( $options, 'custom_sport_name', null );
?>
<select id="sportspress_sport" name="sportspress[sport]">
<option value><?php _e( '-- Select --', 'sportspress' ); ?></option>
<?php foreach( $sportspress_sports as $slug => $sport ): ?>
<option value="<?php echo $slug; ?>" <?php selected( $selected, $slug ); ?>><?php echo $sport['name']; ?></option>
<?php endforeach; ?>
<option value="custom" <?php selected( $selected, 'custom' ); ?>><?php _e( 'Custom', 'sportspress' ); ?></option>
</select>
<input id="sportspress_custom_sport_name" name="sportspress[custom_sport_name]" type="text" placeholder="<?php _e( 'Sport', 'sportspress' ); ?>" value="<?php echo $custom_sport_name; ?>"<?php if ( $selected != 'custom' ): ?> class="hidden"<?php endif; ?>></p>
<?php
}
@@ -167,7 +171,7 @@ function sportspress_sport_validate( $input ) {
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'sp_preset',
'key' => '_sp_preset',
'value' => 1
)
)
@@ -198,7 +202,7 @@ function sportspress_sport_validate( $input ) {
$id = wp_insert_post( $post );
// Flag as preset
update_post_meta( $id, 'sp_preset', 1 );
update_post_meta( $id, '_sp_preset', 1 );
// Update meta
if ( array_key_exists( 'meta', $post ) ):

View File

@@ -1,5 +1,13 @@
jQuery(document).ready(function($){
$("body.settings_page_sportspress #sportspress_sport").change(function() {
$target = $("#sportspress_custom_sport_name");
if ( $(this).val() == "custom" )
$target.show();
else
$target.hide();
});
// Auto key placeholder
$("#poststuff #title").on("keyup", function() {
$("#sp_key").attr("placeholder", $(this).val().replace(/[^a-z]/gi,"").toLowerCase());