From Dan, 10 Years ago, written in Plain Text.
Embed
  1. function myplaylist_inner_sched_custom_box() {
  2.         global $post;
  3.         // Use nonce for verification
  4.         wp_nonce_field( plugin_basename( __FILE__ ), 'dynamicMetaSched_noncename' );
  5.         ?>
  6.             <div id="meta_inner">
  7.             <?php
  8.        
  9.             //get the saved meta as an array
  10.             $shifts = get_post_meta($post->ID,'show_sched',false);
  11.            
  12.                 //print_r($shifts);
  13.  
  14.             $c = 0;
  15.             if (isset($shifts[0]) && is_array($shifts[0])){
  16.                 foreach($shifts[0] as $track ){
  17.                     if (isset($track['day']) || isset($track['time'])){
  18.                         ?>
  19.                         <p>
  20.                                 <?php _e('Day', 'radio-station'); ?>:
  21.                                 <select name="show_sched[<?php echo $c; ?>][day]">
  22.                                         <option value=""></option>
  23.                                         <option value="Monday"<?php if($track['day'] == "Monday") { echo ' selected="selected"'; } ?>><?php _e('Monday', 'radio-station'); ?></option>
  24.                                         <option value="Tuesday"<?php if($track['day'] == "Tuesday") { echo ' selected="selected"'; } ?>><?php _e('Tuesday', 'radio-station'); ?></option>
  25.                                         <option value="Wednesday"<?php if($track['day'] == "Wednesday") { echo ' selected="selected"'; } ?>><?php _e('Wednesday', 'radio-station'); ?></option>
  26.                                         <option value="Thursday"<?php if($track['day'] == "Thursday") { echo ' selected="selected"'; } ?>><?php _e('Thursday', 'radio-station'); ?></option>
  27.                                         <option value="Friday"<?php if($track['day'] == "Friday") { echo ' selected="selected"'; } ?>><?php _e('Friday', 'radio-station'); ?></option>
  28.                                         <option value="Saturday"<?php if($track['day'] == "Saturday") { echo ' selected="selected"'; } ?>><?php _e('Saturday', 'radio-station'); ?></option>
  29.                                         <option value="Sunday"<?php if($track['day'] == "Sunday") { echo ' selected="selected"'; } ?>><?php _e('Sunday', 'radio-station'); ?></option>
  30.                                 </select>
  31.                                  -
  32.                                 <?php _e('Start Time', 'radio-station'); ?>:
  33.                                 <select name="show_sched[<?php echo $c; ?>][start_hour]">
  34.                                         <option value=""></option>
  35.                                 <?php for($i=1; $i<=12; $i++): ?>
  36.                                         <option value="<?php echo $i; ?>"<?php if($track['start_hour'] == $i) { echo ' selected="selected"'; } ?>><?php echo $i; ?></option>
  37.                                 <?php endfor; ?>
  38.                                 </select>
  39.                                 <select name="show_sched[<?php echo $c; ?>][start_min]">
  40.                                         <option value=""></option>
  41.                                 <?php for($i=0; $i<60; $i++): ?>
  42.                                         <?php
  43.                                                                 $min = $i;
  44.                                                                 if($i < 10) {
  45.                                                                         $min = '0'.$i;
  46.                                                                 }
  47.                                                         ?>
  48.                                         <option value="<?php echo $min; ?>"<?php if($track['start_min'] == $min) { echo ' selected="selected"'; } ?>><?php echo $min; ?></option>
  49.                                 <?php endfor; ?>
  50.                                 </select>
  51.                                 <select name="show_sched[<?php echo $c; ?>][start_meridian]">
  52.                                         <option value=""></option>
  53.                                         <option value="am"<?php if($track['start_meridian'] == "am") { echo ' selected="selected"'; } ?>>am</option>
  54.                                         <option value="pm"<?php if($track['start_meridian'] == "pm") { echo ' selected="selected"'; } ?>>pm</option>
  55.                                 </select>
  56.                                
  57.                                  -  
  58.                                 <?php _e('End Time', 'radio-station'); ?>:
  59.                                 <select name="show_sched[<?php echo $c; ?>][end_hour]">
  60.                                         <option value=""></option>
  61.                                 <?php for($i=1; $i<=12; $i++): ?>
  62.                                         <option value="<?php echo $i; ?>"<?php if($track['end_hour'] == $i) { echo ' selected="selected"'; } ?>><?php echo $i; ?></option>
  63.                                 <?php endfor; ?>
  64.                                 </select>
  65.                                 <select name="show_sched[<?php echo $c; ?>][end_min]">
  66.                                         <option value=""></option>
  67.                                 <?php for($i=0; $i<60; $i++): ?>
  68.                                         <?php
  69.                                                                 $min = $i;
  70.                                                                 if($i < 10) {
  71.                                                                         $min = '0'.$i;
  72.                                                                 }
  73.                                                         ?>
  74.                                         <option value="<?php echo $min; ?>"<?php if($track['end_min'] == $min) { echo ' selected="selected"'; } ?>><?php echo $min; ?></option>
  75.                                 <?php endfor; ?>
  76.                                 </select>
  77.                                 <select name="show_sched[<?php echo $c; ?>][end_meridian]">
  78.                                         <option value=""></option>
  79.                                         <option value="am"<?php if($track['end_meridian'] == "am") { echo ' selected="selected"'; } ?>>am</option>
  80.                                         <option value="pm"<?php if($track['end_meridian'] == "pm") { echo ' selected="selected"'; } ?>>pm</option>
  81.                                 </select>
  82.                                 <input type="checkbox" name="show_sched[<?php echo $c; ?>][encore]" <?php if(isset($track['encore']) && $track['encore'] == 'on') { echo 'checked="checked"'; } ?>/> <?php _e('Encore', 'radio-station'); ?>
  83.                                 <span class="remove button-secondary" style="cursor: pointer;"><?php _e('Remove', 'radio-station'); ?></span>
  84.                                
  85.                                  -
  86.                                 <?php _e('Week', 'radio-station'); ?>:
  87.                                 <select name="show_sched[<?php echo $c; ?>][frequency][]" multiple="multiple" size="4">
  88.                                         <option value=""></option>
  89.                                 <?php for($i=1; $i<=6; $i++): ?>
  90.                                         <option value="<?php echo $i; ?>"<?php if($track['frequency'] == $i) { echo ' selected="selected"'; } ?>><?php echo $i; ?></option>
  91.                                 <?php endfor; ?>
  92.                                 </select>
  93.                         </p>
  94.                         <?php
  95.                         $c = $c +1;
  96.                     }
  97.                 }
  98.             }
  99.        
  100.             ?>
  101.         <span id="here"></span>
  102.         <a class="add button-primary" style="cursor: pointer; display:block; width: 150px; padding: 8px; text-align: center; line-height: 1em;"><?php echo __('Add Shift', 'radio-station'); ?></a>
  103.         <script>
  104.             var shiftaddb =jQuery.noConflict();
  105.             shiftaddb(document).ready(function() {
  106.                 var count = <?php echo $c; ?>;
  107.                 shiftaddb(".add").click(function() {
  108.                     count = count + 1;
  109.                                 output = '<p><?php _e('Day', 'radio-station'); ?>: ';
  110.                                 output += '<select name="show_sched[' + count + '][day]">';
  111.                                 output += '<option value=""></option>';
  112.                                 output += '<option value="Monday"><?php _e('Monday', 'radio-station'); ?></option>';
  113.                                 output += '<option value="Tuesday"><?php _e('Tuesday', 'radio-station'); ?></option>';
  114.                                 output += '<option value="Wednesday"><?php _e('Wednesday', 'radio-station'); ?></option>';
  115.                                 output += '<option value="Thursday"><?php _e('Thursday', 'radio-station'); ?></option>';
  116.                                 output += '<option value="Friday"><?php _e('Friday', 'radio-station'); ?></option>';
  117.                                 output += '<option value="Saturday"><?php _e('Saturday', 'radio-station'); ?></option>';
  118.                                 output += '<option value="Sunday"><?php _e('Sunday', 'radio-station'); ?></option>';
  119.                                 output += '</select>';
  120.                                 output += ' - <?php _e('Start Time', 'radio-station'); ?>: ';
  121.                                
  122.                                 output += '<select name="show_sched[' + count + '][start_hour]">';
  123.                                 output += '<option value=""></option>';
  124.                         <?php for($i=1; $i<=12; $i++): ?>
  125.                         output += '<option value="<?php echo $i; ?>"><?php echo $i; ?></option>';
  126.                                 <?php endfor; ?>
  127.                                 output += '</select> ';
  128.                                 output += '<select name="show_sched[' + count + '][start_min]">';
  129.                                 output += '<option value=""></option>';
  130.                                 <?php for($i=0; $i<60; $i++): ?>
  131.                                 <?php
  132.                                         $min = $i;
  133.                                         if($i < 10) {
  134.                                                 $min = '0'.$i;
  135.                                         }
  136.                                 ?>
  137.                         output += '<option value="<?php echo $min; ?>"><?php echo $min; ?></option>';
  138.                                 <?php endfor; ?>
  139.                                 output += '</select> ';
  140.                                 output += '<select name="show_sched[' + count + '][start_meridian]">';
  141.                                 output += '<option value=""></option>';
  142.                         output += '<option value="am">am</option>';
  143.                         output += '<option value="pm">pm</option>';
  144.                                 output += '</select> ';
  145.  
  146.                                 output += ' - <?php _e('End Time', 'radio-station'); ?>: ';
  147.                                 output += '<select name="show_sched[' + count + '][end_hour]">';
  148.                                 output += '<option value=""></option>';
  149.                                 <?php for($i=1; $i<=12; $i++): ?>
  150.                                 output += '<option value="<?php echo $i; ?>"><?php echo $i; ?></option>';
  151.                                 <?php endfor; ?>
  152.                                 output += '</select> ';
  153.                                 output += '<select name="show_sched[' + count + '][end_min]">';
  154.                                 output += '<option value=""></option>';
  155.                                 <?php for($i=0; $i<60; $i++): ?>
  156.                                 <?php
  157.                                         $min = $i;
  158.                                         if($i < 10) {
  159.                                                 $min = '0'.$i;
  160.                                         }
  161.                                 ?>
  162.                         output += '<option value="<?php echo $min; ?>"><?php echo $min; ?></option>';
  163.                                 <?php endfor; ?>
  164.                                 output += '</select> ';
  165.                                 output += '<select name="show_sched[' + count + '][end_meridian]">';
  166.                                 output += '<option value=""></option>';
  167.                         output += '<option value="am">am</option>';
  168.                         output += '<option value="pm">pm</option>';
  169.                                 output += '</select> ';
  170.  
  171.                                 output += '<input type="checkbox" name="show_sched[' + count + '][encore]" /> <?php _e('Encore', 'radio-station'); ?> ';
  172.  
  173.                                 output += '<span class="remove button-secondary" style="cursor: pointer;"><?php _e('Remove', 'radio-station'); ?></span>';
  174.                                
  175.                                 output += ' - <?php _e('Week', 'radio-station'); ?>: ';
  176.                                 output += '<select name="show_sched[' + count + '][show_frequency]" multiple="multiple" size="4">';
  177.                                 output += '<option value=""></option>';
  178.                         <?php for($i=1; $i<=5; $i++): ?>       
  179.                         output += '<option value="<?php echo $i; ?>"><?php echo $i; ?></option>';
  180.                         <?php endfor; ?>
  181.                                 output += '</select></p> ';
  182.                                 shiftaddb('#here').append( output );
  183.  
  184.                     return false;
  185.                 });
  186.                 shiftaddb(".remove").live('click', function() {
  187.                         shiftaddb(this).parent().remove();
  188.                 });
  189.             });
  190.             </script>
  191.         </div>
  192. <?php
  193. }
  194.  
  195. //save the custom fields when a show is saved
  196. function myplaylist_save_showpostdata( $post_id ) {
  197.         // verify if this is an auto save routine.
  198.         // If it is our form has not been submitted, so we dont want to do anything
  199.         if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  200.         return;
  201.  
  202.         // verify this came from the our screen and with proper authorization,
  203.         // because save_post can be triggered at other times
  204.         if (isset($_POST['dynamicMetaUser_noncename'])){
  205.                 if ( !wp_verify_nonce( $_POST['dynamicMetaUser_noncename'], plugin_basename( __FILE__ ) ) )
  206.                 return;
  207.         }else{return;
  208.         }
  209.        
  210.         if (isset($_POST['dynamicMetaSched_noncename'])){
  211.                 if ( !wp_verify_nonce( $_POST['dynamicMetaSched_noncename'], plugin_basename( __FILE__ ) ) )
  212.                 return;
  213.         }else{return;
  214.         }
  215.        
  216.         // OK, we're authenticated: we need to find and save the data
  217.         $djs = $_POST['show_user_list'];
  218.         $sched = $_POST['show_sched'];
  219.         $file = $_POST['show_file'];
  220.         $email = $_POST['show_email'];
  221.         $active = $_POST['show_active'];
  222.         $link = $_POST['show_link'];
  223.        
  224.         update_post_meta($post_id,'show_user_list',$djs);
  225.         update_post_meta($post_id,'show_sched',$sched);
  226.         update_post_meta($post_id,'show_file',$file);
  227.         update_post_meta($post_id,'show_email',$email);
  228.         update_post_meta($post_id,'show_active',$active);
  229.         update_post_meta($post_id,'show_link',$link);
  230. }
  231. add_action( 'save_post', 'myplaylist_save_showpostdata' );

Replies to entire custom meta box code rss

Title Name Language When
Re: entire custom meta box code Colossal Mousedeer text 10 Years ago.