nf_delete_object

Delete an object.

Description

nf_delete_object( (int) $object_id ); 

Also removes all of the objectmeta attached to the object and any references to it in the relationship table.

Parameters (1)

0. $object_id (int)
The object id.

Usage

  1. if ( !function_exists( 'nf_delete_object' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/functions.php'; 
  3.  
  4. // The object id. 
  5. $object_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = nf_delete_object($object_id); 
  9.  

Defined (1)

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

/deprecated/includes/functions.php  
  1. function nf_delete_object( $object_id ) { 
  2. global $wpdb; 
  3.  
  4. // Check to see if we have any object children. 
  5. $children = nf_get_object_children( $object_id, '', false, false ); 
  6.  
  7. foreach ( $children as $child_id ) { 
  8. nf_delete_object( $child_id ); 
  9.  
  10. // Delete this object. 
  11. $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . NF_OBJECTS_TABLE_NAME .' WHERE id = %d', $object_id ) ); 
  12.  
  13. // Delete any objectmeta attached to this object. 
  14. $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . NF_OBJECT_META_TABLE_NAME .' WHERE object_id = %d', $object_id ) ); 
  15.  
  16. // Delete any references to this object in the relationship table 
  17. $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . NF_OBJECT_RELATIONSHIPS_TABLE_NAME .' WHERE child_id = %d OR parent_id = %d', $object_id, $object_id ) ); 
  18.  
  19. return true;