/deprecated/includes/admin/post-metabox.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2.  
  3. add_action('add_meta_boxes', 'ninja_forms_add_custom_box'); 
  4.  
  5. /** Do something with the data entered */ 
  6. add_action('save_post', 'ninja_forms_save_postdata'); 
  7.  
  8. /** Adds a box to the main column on the Post and Page edit screens */ 
  9. function ninja_forms_add_custom_box() { 
  10. add_meta_box( 
  11. 'ninja_forms_selector',  
  12. __( 'Append A Ninja Form', 'ninja-forms'),  
  13. 'ninja_forms_inner_custom_box',  
  14. 'post',  
  15. 'side',  
  16. 'low' 
  17. ); 
  18. add_meta_box( 
  19. 'ninja_forms_selector',  
  20. __( 'Append A Ninja Form', 'ninja-forms'),  
  21. 'ninja_forms_inner_custom_box',  
  22. 'page',  
  23. 'side',  
  24. 'low' 
  25. ); 
  26.  
  27. /** Prints the box content */ 
  28. function ninja_forms_inner_custom_box() { 
  29.  
  30. $post_id = ! empty( $_REQUEST['post'] ) ? absint( $_REQUEST['post'] ) : 0; 
  31.  
  32. // Use nonce for verification 
  33. wp_nonce_field( 'ninja_forms_append_form', 'nf_append_form' ); 
  34.  
  35. // The actual fields for data entry 
  36. ?> 
  37. <select id="ninja_form_select" name="ninja_form_select"> 
  38. <option value="0">-- <?php _e('None', 'ninja-forms');?></option> 
  39. <?php 
  40. $all_forms = ninja_forms_get_all_forms(); 
  41. $form_id = get_post_meta( $post_id, 'ninja_forms_form', true ); 
  42. foreach( $all_forms as $form ) { 
  43. $title = $form['data']['form_title']; 
  44. $id = $form['id']; 
  45. ?> 
  46. <option value="<?php echo esc_attr( $id );?>"<?php selected( $id, $form_id );?>> 
  47. <?php echo $title;?> 
  48. </option> 
  49. <?php 
  50. ?> 
  51. </select> 
  52. <?php 
  53.  
  54. /** When the post is saved, saves our custom data */ 
  55. function ninja_forms_save_postdata( $post_id ) { 
  56. global $wpdb; 
  57. if(isset($_POST['nf_append_form'])) { 
  58. // verify if this is an auto save routine. 
  59. // If it is our form has not been submitted, so we dont want to do anything 
  60. if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
  61. return $post_id; 
  62.  
  63. // verify this came from the our screen and with proper authorization,  
  64. // because save_post can be triggered at other times 
  65.  
  66. if ( !wp_verify_nonce( $_POST['nf_append_form'], 'ninja_forms_append_form' ) ) 
  67. return $post_id; 
  68.  
  69. // Check permissions 
  70. if ( 'page' == $_POST['post_type'] ) { 
  71. if ( !current_user_can( 'edit_page', $post_id ) ) 
  72. return $post_id; 
  73. } else { 
  74. if ( !current_user_can( 'edit_post', $post_id ) ) 
  75. return $post_id; 
  76.  
  77. // OK, we're authenticated: we need to find and save the data 
  78. $post_id = absint( $_POST['post_ID'] ); 
  79. $form_id = absint( $_POST['ninja_form_select'] ); 
  80. if ( empty ( $form_id ) ) { 
  81. delete_post_meta( $post_id, 'ninja_forms_form' ); 
  82. } else { 
  83. update_post_meta( $post_id, 'ninja_forms_form', $form_id ); 
.