示例#1
0
/**
 * Delete a condition and all of its criteria
 *
 * @param $cond_id
 * @since 1.2.8
 * @return void
 */
function nf_cl_delete_condition($cond_id)
{
    // Delete our condition object
    nf_delete_object($cond_id);
    // Remove all of our criteria
    $criteria = nf_cl_get_criteria($cond_id);
    foreach ($criteria as $cr_id) {
        nf_delete_object($cr_id);
    }
}
示例#2
0
 /**
  * Delete this form
  * 
  * @access public
  * @since 2.9
  */
 public function delete()
 {
     global $wpdb;
     // Delete this object.
     nf_delete_object($this->form_id);
     // Delete any fields on this form.
     $wpdb->query($wpdb->prepare("DELETE FROM " . NINJA_FORMS_FIELDS_TABLE_NAME . " WHERE form_id = %d", $this->form_id));
 }
示例#3
0
/**
 * Delete an object. Also removes all of the objectmeta attached to the object and any references to it in the relationship table.
 *
 * @since 2.8
 * @param int $object_id
 * @return bool
 */
function nf_delete_object($object_id)
{
    global $wpdb;
    // Check to see if we have any object children.
    $children = nf_get_object_children($object_id, '', false, false);
    foreach ($children as $child_id) {
        nf_delete_object($child_id);
    }
    // Delete this object.
    $wpdb->query($wpdb->prepare('DELETE FROM ' . NF_OBJECTS_TABLE_NAME . ' WHERE id = %d', $object_id));
    // Delete any objectmeta attached to this object.
    $wpdb->query($wpdb->prepare('DELETE FROM ' . NF_OBJECT_META_TABLE_NAME . ' WHERE object_id = %d', $object_id));
    // Delete any references to this object in the relationship table
    $wpdb->query($wpdb->prepare('DELETE FROM ' . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . ' WHERE child_id = %d OR parent_id = %d', $object_id, $object_id));
    return true;
}
示例#4
0
/**
 * Delete a notification.
 *
 * Acts as a wrapper/alias for nf_delete_object
 *
 * @since 2.8
 * @param int $n_id
 * @return void
 */
function nf_delete_notification($n_id)
{
    nf_delete_object($n_id);
}
示例#5
0
function ninja_forms_delete_form($form_id = '')
{
    global $wpdb;
    // Bail if we aren't in the admin
    if (!is_admin()) {
        return false;
    }
    // Bail if we don't have proper permissions
    if (!current_user_can(apply_filters('nf_delete_form_capabilities', 'manage_options'))) {
        return false;
    }
    if ($form_id == '') {
        $ajax = true;
        $form_id = absint($_REQUEST['form_id']);
        check_ajax_referer('nf_ajax', 'nf_ajax_nonce');
    } else {
        $ajax = false;
    }
    $wpdb->query($wpdb->prepare("DELETE FROM " . NINJA_FORMS_TABLE_NAME . " WHERE id = %d", $form_id));
    $wpdb->query($wpdb->prepare("DELETE FROM " . NINJA_FORMS_FIELDS_TABLE_NAME . " WHERE form_id = %d", $form_id));
    // Delete any notifications attached to this form.
    // Grab notifications.
    $notifications = nf_get_notifications_by_form_id($form_id, false);
    foreach ($notifications as $n_id) {
        nf_delete_object($n_id);
    }
    if ($ajax) {
        die;
    }
}
示例#6
0
/**
 * Hook into our notification save action
 *
 * @since 1.2.8
 * @return void
 */
function nf_cl_save_notification($n_id, $data, $new)
{
    // Bail if we don't have any conditional data.
    if (!isset($data['conditions']) || !is_array($data['conditions'])) {
        // Loop through our current conditions and remove any that weren't sent.
        $conditions = nf_cl_get_conditions($n_id);
        foreach ($conditions as $cond_id) {
            nf_cl_delete_condition($cond_id);
        }
        return false;
    }
    // Loop through our current conditions and remove any that weren't sent.
    $conditions = nf_cl_get_conditions($n_id);
    foreach ($conditions as $cond_id) {
        if (!isset($data['conditions'][$cond_id])) {
            nf_cl_delete_condition($cond_id);
        }
    }
    // $data['conditions'] will store all the information about our conditions.
    foreach ($data['conditions'] as $cond_id => $d) {
        // Loop through our conditions and save the data.
        if ('new' == $cond_id) {
            // If we are creating a new condition, insert it and grab the id.
            $cond_id = nf_cl_insert_condition($n_id);
        }
        // Delete criteria that has been removed.
        $criteria = nf_cl_get_criteria($cond_id);
        foreach ($criteria as $cr_id) {
            if (!isset($d['criteria'][$cr_id])) {
                nf_delete_object($cr_id);
            }
        }
        // Loop through any new criteria.
        if (isset($d['criteria']['new'])) {
            foreach ($d['criteria']['new'] as $cr) {
                $cr_id = nf_cl_insert_criteria($cond_id);
                foreach ($cr as $key => $value) {
                    // Insert our meta values
                    nf_update_object_meta($cr_id, $key, $value);
                }
            }
            unset($d['criteria']['new']);
        }
        if (isset($d['criteria'])) {
            foreach ($d['criteria'] as $cr_id => $cr) {
                foreach ($cr as $key => $value) {
                    nf_update_object_meta($cr_id, $key, $value);
                }
            }
            unset($d['criteria']);
        }
        // Save our other condition values.
        foreach ($d as $key => $value) {
            nf_update_object_meta($cond_id, $key, $value);
        }
    }
}
 /**
  * Save admin edit screen
  *
  * @access public
  * @since 1.0
  * @return void
  */
 public function save_admin($id = '', $data)
 {
     if (isset($data['wh_args']) && is_array($data['wh_args'])) {
         $args = nf_get_object_children($id, 'wh_args');
         foreach ($args as $object_id => $vars) {
             if (!isset($data['wh_args'][$object_id])) {
                 nf_delete_object($object_id);
             }
         }
         if (isset($data['wh_args']['new'])) {
             foreach ($data['wh_args']['new'] as $vars) {
                 $object_id = nf_insert_object('wh_args');
                 nf_update_object_meta($object_id, 'key', $vars['key']);
                 nf_update_object_meta($object_id, 'field', $vars['field']);
                 nf_add_relationship($object_id, 'wh_args', $id, 'notification');
             }
             unset($data['wh_args']['new']);
         }
         foreach ($data['wh_args'] as $object_id => $vars) {
             if (!empty($object_id)) {
                 nf_update_object_meta($object_id, 'key', $vars['key']);
                 nf_update_object_meta($object_id, 'field', $vars['field']);
             }
         }
         unset($data['wh_args']);
     }
     return $data;
 }