Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1.  
  2. function fundcode_association_save_meta_box( $post_id ) {
  3. $err = false;
  4. $message = '';
  5.  
  6. // Check if our nonce is set.
  7. if ( ! isset( $_POST['fundcode_post_class_nonce'] ) ) {
  8. return;
  9. }
  10.  
  11. // Verify that the nonce is valid.
  12. if ( ! wp_verify_nonce( $_POST['fundcode_post_class_nonce'], basename( __FILE__ ) ) ) {
  13.  
  14. return;
  15. }
  16.  
  17. // If this is an autosave, our form has not been submitted, so we don't want to do anything.
  18. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  19. return;
  20. }
  21.  
  22. // Save occasion
  23. if( isset( $_POST['fundcode-occasion'] ) )
  24. {
  25. if(!empty($_POST['fundcode-occasion']))
  26. {
  27. $my_data = sanitize_text_field( $_POST['fundcode-occasion'] );
  28. update_post_meta( $post_id, 'fundcode_occasion', $my_data );
  29. }
  30. else
  31. {
  32. $err = true;
  33. $message .= "Occasion can't be empty.<br />";
  34. update_post_meta( $post_id, 'fundcode_occasion', null );
  35. }
  36. }
  37.  
  38. // Save association
  39. if( isset( $_POST['fundcode-association'] ) )
  40. {
  41. if(!empty($_POST['fundcode-association']))
  42. {
  43. $my_data = sanitize_text_field( $_POST['fundcode-association'] );
  44. update_post_meta( $post_id, 'fundcode_association', $my_data );
  45. }
  46. else
  47. {
  48. $err = true;
  49. $message .= "Association can't be empty.<br />";
  50. update_post_meta( $post_id, 'fundcode_association', null );
  51. }
  52. }
  53.  
  54. if($err)
  55. {
  56. update_option('fundcode_admin_errors', $message);
  57. }
  58. else
  59. {
  60. update_option('fundcode_admin_errors', false);
  61. }
  62. }
  63.  
  64. add_action( 'save_post', 'fundcode_association_save_meta_box', 1 );
  65.  
  66. function fundcode_admin_notice_handler() {
  67. $errors = get_option('fundcode_admin_errors');
  68.  
  69. if($errors)
  70. {
  71. echo '<div class="error"><p>' . $errors . '</p></div>';
  72. }
  73. }
  74.  
  75. add_action( 'admin_notices', 'fundcode_admin_notice_handler' );
  76.  
  77. // Clear any errors
  78. function fundcode_clear_errors() {
  79. update_option('fundcode_admin_errors', false);
  80. }
  81.  
  82. add_action( 'admin_footer', 'fundcode_clear_errors' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement