Commits

Doug Stewart  committed b4042cf

Very close to imageradio working correctly.

  • Participants
  • Parent commits b90468f
  • Branches develop

Comments (0)

Files changed (2)

File includes/functions/admin.php

  * @param string $shortname 
  */
 function lblg_options_walker( $options, $default_options, $shortname ){
-
 	$section = '';
 	$lblg_options_group = $shortname . '_theme_options';
 
 			lblg_option_wrapper_header( $value );
 			if( $value['options'] === array_values($value['options'])){
 		 		foreach ( $value['options'] as $option ) {
-						$radio_setting = $lblg_options[$key];
-						$tmp_name = $lblg_options_group . '['. $key . ']';
-						$input_name = $option['input'];
-						$input_img = $option['image'];
-						echo sprintf( '<label class="lbimageradio"><input type="radio" name="%s" value="%s" %s /><img src="%s" /></label>', $tmp_name, $input_name, checked( $option, $options[$key], false ), $input_img) . "\n";
-			    		//echo "<label class=\"lbimageradio\"><input type=\"radio\" name=\"$tmp_name\" value=\"$option\"" . checked( $option, $options[$key], false ) . " />$option</label>\n";
+					$radio_setting = $lblg_options[$key];
+					$tmp_name = $lblg_options_group . '['. $key . ']';
+					$input_name = $option['input'];
+					$input_img = $option['image'];
+					print_r($options);
+					echo sprintf( '<label class="lbimageradio"><input type="radio" name="%s" value="%s" %s /><img src="%s" title="%s" /></label>', $tmp_name, $input_name, checked( $input_name, $options[$key], false ), $input_img, $input_name) . "\n";
 				}
 			} else {
 		 		foreach ( $value['options'] as $opt_key => $opt_value ) {
 			}
 		 
 			lblg_option_wrapper_footer( $value );
+			break;
 			
-			break;
 			// Prints a checbox <input> element
 			case "checkbox":
 			add_settings_field( $key, $value['name'], '', $lblg_options_group, $section );
 		lblg_options_walker( $lblg_options, $lblg_default_options[$current_tab]['contents'], $lblg_shortname );
 	}
 }
-add_action( 'lblg_print_options', 'lblg_display_options' );
+add_action( 'lblg_print_options', 'lblg_display_options' );
+
+function lblg_admin_styling() {
+?>
+<style type="text/css" media="screen">
+	.lbimageradio input[type="radio"] {
+		display: none;
+	}
+	.lbimageradio img {
+		border-width: 2px;
+		border-style: solid;
+		border-color: transparent;
+		margin: 5px;
+		padding: 5px;
+	}
+</style>	
+<?php
+}
+add_action( 'admin_head', 'lblg_admin_styling' );

File includes/functions/options.php

 				break;
 				case 'subhead':
 				break;
-				case 'imageradio':
-				//$stripped_opts[$key] = ;
-				echo '$std: ';
-				print_r($value['std']);
-				break;
 				default:
 				$stripped_opts[$key] = $value['std'];
 				break;
 function lblg_sanitize_options( $input ){
 	global $lblg_shortname, $lblg_default_options, $lblg_options, $lblg_defaults;
 
-	//var_dump($input);
-	//var_dump($lblg_options);
-	var_dump($lblg_defaults);
+	//print_r($input);
 	$submit = ( ! empty( $input['save']) ? true : false );
 	$reset = ( ! empty( $input['reset']) ? true : false );
 	$tabbed = ( !empty( $input['tab']) ? true : false );
 			// Admin is one screen, no tabs, so all the options are displayed at once.
 			foreach( $valid_input as $key => $value ){
 				$tmp_type = $lblg_default_options[$key]['type'];
-			
+				$tmp_options = $lblg_default_options['contents'][$key]['options'];
+
 				switch( $tmp_type ){
 					case 'text':
 					case 'textarea':
 
 					case 'select':
 					case 'radio':
+					// HERE. THIS NEEDS FIXING FOR IMGRADIO.
 					//case 'imageradio':
-					print_r($input[$key]);
-					echo $key;
 						if( isset($input[$key]) ){
-							$valid_input[$key] = ( in_array( $input[$key], $lblg_default_options[$key]['options']) ? $input[$key] : $valid_input[$key] );
+							$valid_input[$key] = ( in_array( $input[$key], $tmp_options ) ? $input[$key] : $valid_input[$key] );
 						}
 					break;
 
+					case 'imageradio':
+						$tmp_inputs = wp_list_pluck( $tmp_options, 'input' );
+						if( isset($input[$key]) ){
+							$valid_input[$key] = ( in_array( $input[$key], $tmp_inputs ) ? $input[$key] : $valid_input[$key] );
+						}
+					break;
+					
 					case 'checkbox':
 						$valid_input[$key] = (( isset($input[$key]) && ( '1' == $input[$key] ) ) ? '1' : '0' );
 					break;
 				$tab = $input['tab'];
 				foreach( $valid_input as $key => $value ){
 					$tmp_type = $lblg_default_options[$tab]['contents'][$key]['type'];
+					$tmp_options = $lblg_default_options[$tab]['contents'][$key]['options'];
 
 					switch( $tmp_type ){
 						case 'text':
 						case 'select':
 						case 'radio':
 							if( isset($input[$key]) ){
-								$valid_input[$key] = ( in_array( $input[$key], $lblg_default_options[$tab]['contents'][$key]['options']) ? $input[$key] : $valid_input[$key] );
+								$valid_input[$key] = ( in_array( $input[$key], $tmp_options ) ? $input[$key] : $valid_input[$key] );
 							}
 						break;
-
+						
+						case 'imageradio':
+							$tmp_inputs = wp_list_pluck( $tmp_options, 'input' );
+							$valid_input[$key] = ( in_array( $input[$key], $tmp_inputs ) ? $input[$key] : $valid_input[$key] );
+						break;
+						
 						case 'checkbox':
 							$valid_input[$key] = (( isset($input[$key]) && ( '1' == $input[$key] ) ) ? '1' : '0' );
 						break;