Metabox.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. abstract class NF_Abstracts_Metabox
  3. {
  4. protected $_id = ''; // Dynamically set in constructor using the class name.
  5. protected $_title = ''; // Should be set (and translated) in the constructor.
  6. protected $_callback = 'render_metabox';
  7. protected $_post_types = array();
  8. protected $_context = 'side';
  9. protected $_priority = 'default';
  10. protected $_callback_args = array();
  11. protected $_capability = 'edit_post';
  12. public function __construct()
  13. {
  14. $this->_id = strtolower( get_class( $this ) );
  15. $this->_title = __( 'Metabox', 'ninja-forms' );
  16. add_action( 'save_post', array( $this, '_save_post' ) );
  17. add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
  18. }
  19. public function add_meta_boxes()
  20. {
  21. add_meta_box(
  22. $this->_id,
  23. $this->_title,
  24. array( $this, $this->_callback ),
  25. $this->_post_types,
  26. $this->_context,
  27. $this->_priority,
  28. $this->_callback_args
  29. );
  30. }
  31. abstract public function render_metabox( $post, $metabox );
  32. public function _save_post( $post_id )
  33. {
  34. // If this is an autosave, our form has not been submitted, so we don't want to do anything.
  35. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
  36. $this->save_post( $post_id );
  37. }
  38. protected function save_post( $post_id )
  39. {
  40. // This section intentionally left blank.
  41. }
  42. }