Fields.php 959 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. class NF_AJAX_Controllers_Fields extends NF_Abstracts_Controller
  3. {
  4. private $publish_processing;
  5. public function __construct()
  6. {
  7. add_action( 'wp_ajax_nf_maybe_delete_field', array( $this,
  8. 'maybe_delete_field' ) );
  9. }
  10. /**
  11. * Check if the field has data, if so let the front-end know to show
  12. * delete field modal
  13. */
  14. public function maybe_delete_field() {
  15. $field_id = $_REQUEST[ 'fieldID' ];
  16. // $field_key = $_REQUEST[ 'fieldKey' ];
  17. global $wpdb;
  18. // query for checking postmeta for submission data for field
  19. $sql = $wpdb->prepare( "SELECT meta_value FROM `" . $wpdb->prefix . "postmeta`
  20. WHERE meta_key = '_field_%d' LIMIT 1", $field_id );
  21. $result = $wpdb->get_results( $sql, 'ARRAY_N' );
  22. $has_data = false;
  23. // if there are results, has_data is true
  24. if( 0 < count( $result ) ) {
  25. $has_data = true;
  26. }
  27. $this->_data[ 'field_has_data' ] = $has_data;
  28. $this->_respond();
  29. }
  30. }