Advertisement
Guest User

cptr_save

a guest
Jun 5th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. function cptr_save() {
  2.     global $post_ID;
  3.  
  4.     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
  5.     if (!isset($_POST['myplugin_noncename'])) return;
  6.     if (!wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__))) return;
  7.     if (!current_user_can( 'edit_post', $post_ID ) ) return;
  8.  
  9.     $id = $_POST['post_ID'];
  10.     $related = isset($_POST['reladded']) ? $_POST['reladded'] : array();
  11.     update_post_meta($id, CI_CPTR_POST_RELATED, $related);
  12.    
  13.     $update_later = get_option('ci_cptr_temp_update_later');
  14.     if($update_later===false) $update_later = array();
  15.     $update_later[$post_ID] = $related;
  16.     update_option('ci_cptr_temp_update_later', $update_later);
  17.  
  18. }
  19.  
  20. add_action('init', 'ci_cptr_update_later');
  21.  
  22.  
  23. function ci_cptr_update_later()
  24. {
  25.   if(!is_admin()) return;
  26.   $update_later = get_option('ci_cptr_temp_update_later');
  27.   if($update_later===false) $update_later = array();
  28.  
  29.   foreach($update_later as $key=>$value)
  30.   {
  31.         // You can use $key as the ID of the post that the $rel_id's were associated from.
  32.         foreach ($value as $rel_id) {
  33.             $my_post = array( 'id' => $rel_id, 'post_status' => 'publish');
  34.             wp_update_post( $my_post );
  35.         }
  36.  
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement