NF_Admin_Metaboxes_AppendAForm

The Ninja Forms NF Admin Metaboxes AppendAForm class.

Defined (1)

The class is defined in the following location(s).

/includes/Admin/Metaboxes/AppendAForm.php  
  1. final class NF_Admin_Metaboxes_AppendAForm extends NF_Abstracts_Metabox 
  2. protected $_post_types = array( 'post', 'page' ); 
  3.  
  4. public function __construct() 
  5. parent::__construct(); 
  6.  
  7. $this->_title = __( 'Append a Ninja Forms', 'ninja-forms' ); 
  8.  
  9. add_filter( 'the_content', array( $this, 'append_form' ) ); 
  10.  
  11. public function append_form( $content ) 
  12. $post = $GLOBALS['post']; 
  13. $form_id = get_post_meta( $post->ID, 'ninja_forms_form', TRUE ); 
  14.  
  15. if( ! $form_id ) return $content; 
  16.  
  17. return $content . "[ninja_forms id=$form_id]"; 
  18.  
  19. public function save_post( $post_id ) 
  20. if ( 
  21. defined('DOING_AUTOSAVE') && DOING_AUTOSAVE 
  22. || ! isset( $_POST['nf_append_form'] ) 
  23. || ! wp_verify_nonce( $_POST['nf_append_form'], 'ninja_forms_append_form' ) 
  24. || ( 'page' == $_POST['post_type'] && !current_user_can( 'edit_page', $post_id ) ) 
  25. || ( 'post' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) ) 
  26. ) return $post_id; 
  27.  
  28. $post_id = absint( $post_id ); 
  29.  
  30. $form_id = absint( $_POST['ninja_form_select'] ); 
  31.  
  32. if ( empty ( $form_id ) ) { 
  33. delete_post_meta( $post_id, 'ninja_forms_form' ); 
  34. } else { 
  35. update_post_meta( $post_id, 'ninja_forms_form', $form_id ); 
  36.  
  37. public function render_metabox( $post, $metabox ) 
  38. wp_nonce_field( 'ninja_forms_append_form', 'nf_append_form' ); 
  39.  
  40. $forms = Ninja_Forms()->form()->get_forms(); 
  41.  
  42. $form_id = get_post_meta( $post->ID, 'ninja_forms_form', true ); 
  43.  
  44. $none_text = '-- ' . __( 'None', 'ninja-forms' ); 
  45.  
  46. Ninja_Forms()->template( 'admin-metabox-append-a-form.html.php', compact( 'forms', 'form_id', 'none_text' ) );