Advertisement
sparkweb

Custom Functions to Extend the WordPress Custom Field Bulk E

Aug 28th, 2011
1,948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.16 KB | None | 0 0
  1. //Custom Functions to Extend the WordPress Custom Field Bulk Editor Plugin
  2. //These files can go in a plugin or in functions.php
  3.  
  4.  
  5. //First Function Adds Lines Before Built-in Custom Field Lines
  6. function add_my_custom_lines($post_type) {
  7.    
  8.     //If you only want to add this functionality to pages, you can use this to bail on the function if it isn't "page"
  9.     if ($post_type != 'page') return;
  10.    
  11.     //Write special code for each line you want to add
  12.     ?>
  13.         <tr>
  14.             <td>
  15.                 <?php $field_name = "my_custom_field_1"; ?>
  16.                 <label for="<?php echo $field_name; ?>" class="cfbe_special_label"><?php _e('My Custom Field 1'); ?></label>
  17.                 <input type="radio" name="<?php echo $field_name; ?>_status" id="<?php echo $field_name; ?>_status0" value="0" checked="checked" />
  18.                 <label for="<?php echo $field_name; ?>_status0" class="cfbe_leave_unchanged"><?php _e("Leave Unchanged"); ?></label>
  19.                 <input type="radio" name="<?php echo $field_name; ?>_status" id="<?php echo $field_name; ?>_status1" value="1" />
  20.                 <label for="<?php echo $field_name; ?>_status1"><?php _e("Change To"); ?>:</label>
  21.                 <input type="text" name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" value="" class="cfbe_field_name no_right_margin" onfocus="jQuery('#<?php echo $field_name; ?>_status1').prop('checked', true);" />
  22.                 <small>Reminder What This Field Is For</small>
  23.                 <div style="clear: both;"></div>
  24.             </td>
  25.         </tr>
  26.         <tr>
  27.             <td>
  28.                 <?php $field_name = "my_custom_field_2"; ?>
  29.                 <label for="<?php echo $field_name; ?>" class="cfbe_special_label"><?php _e('My Custom Field 2'); ?></label>
  30.                 <input type="radio" name="<?php echo $field_name; ?>_status" id="<?php echo $field_name; ?>_status0" value="0" checked="checked" />
  31.                 <label for="<?php echo $field_name; ?>_status0" class="cfbe_leave_unchanged"><?php _e("Leave Unchanged"); ?></label>
  32.                 <input type="radio" name="<?php echo $field_name; ?>_status" id="<?php echo $field_name; ?>_status1" value="1" />
  33.                 <label for="<?php echo $field_name; ?>_status1"><?php _e("Change To"); ?>:</label>
  34.                 <input type="text" name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" value="" class="cfbe_field_name no_right_margin" onfocus="jQuery('#<?php echo $field_name; ?>_status1').prop('checked', true);" />
  35.                 <small>Special Instructions For Field</small>
  36.                 <div style="clear: both;"></div>
  37.             </td>
  38.         </tr>
  39.     <?php
  40. }
  41.  
  42. //Assign to Action (before built in lines)
  43. //To do you own metabox, the action is 'cfbe_before_metabox'
  44. add_action('cfbe_before_fields', 'add_my_custom_lines');
  45.  
  46.  
  47.  
  48. //Function to run on every post being updated. Process your special custom fields here.
  49. function save_my_custom_fields($post_type, $post_id) {
  50.     //Optional. Bail if this isn't for pages
  51.     //Useful for your own Custom Post Type
  52.     if ($post_type != "page") return;
  53.    
  54.     //Save Your Fields
  55.     $field_name = "my_custom_field_1";
  56.     if ($_POST[$field_name] == 1) {
  57.         cfbe_save_meta_data($field_name, $_POST[$field_name]);
  58.     }
  59.     $field_name = "my_custom_field_2";
  60.     if ($_POST[$field_name] == 1) {
  61.         cfbe_save_meta_data($field_name, $_POST[$field_name]);
  62.     }
  63. }
  64.  
  65. //Add Save Action
  66. add_action('cfbe_save_fields', 'save_my_custom_fields', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement