function prevent_entry_submission_save($entry, $form)
{
    $form_id = $entry['form_id'];
    $forms_id = array(1, 2, 3, 4, 5, 6, 7, 8);
    /*the Id's you want entry not be save*/
    if (in_array($form_id, $forms_id)) {
        GFAPI::delete_entry($entry['id']);
    }
}
 /**
  * Delete entries
  * This function is used to delete entries with an ajax request
  * Could use better (or at least some) error handling
  */
 public function maybe_delete_entry()
 {
     if (isset($_POST["mode"]) && $_POST["mode"] == "delete" && isset($_POST["delete_id"]) && isset($_POST["form_id"])) {
         $form_id = $_POST["form_id"];
         $form = GFAPI::get_form($form_id);
         $settings = $this->get_form_settings($form);
         $enable_delete = $settings["enable_delete"];
         $delete_type = $settings["delete_type"];
         if ($enable_delete) {
             $delete_id = $_POST["delete_id"];
             $entry = GFAPI::get_entry($delete_id);
             if (!is_wp_error($entry)) {
                 if ($entry["created_by"] == $this->stickylist_get_current_user() || current_user_can('delete_others_posts') || current_user_can('stickylist_delete_entries')) {
                     if ($_POST["delete_post_id"] != null) {
                         $delete_post_id = $_POST["delete_post_id"];
                     } else {
                         $delete_post_id = "";
                     }
                     if ($delete_type == "trash") {
                         $entry["status"] = "trash";
                         $success = GFAPI::update_entry($entry, $delete_id);
                         if ($delete_post_id != "") {
                             wp_delete_post($delete_post_id, false);
                         }
                     }
                     if ($delete_type == "permanent") {
                         $success = GFAPI::delete_entry($delete_id);
                         if ($delete_post_id != "") {
                             wp_delete_post($delete_post_id, true);
                         }
                     }
                     if ($success) {
                         $notifications = $form["notifications"];
                         $notification_ids = array();
                         foreach ($notifications as $notification) {
                             $notification_type = $notification["stickylist_notification_type"];
                             if ($notification_type == "delete" || $notification_type == "all") {
                                 $id = $notification["id"];
                                 array_push($notification_ids, $id);
                             }
                         }
                         GFCommon::send_notifications($notification_ids, $form, $entry);
                     }
                 }
             }
         }
     }
 }
Example #3
0
 public function delete_entries($entry_ids)
 {
     $this->log_debug(__METHOD__ . '(): Running.');
     $capability = apply_filters('gform_web_api_capability_delete_entries', 'gravityforms_delete_entries');
     $this->authorize($capability);
     $count = 0;
     if (is_array($entry_ids)) {
         foreach ($entry_ids as $entry_id) {
             $this->log_debug(__METHOD__ . '(): Deleting entry id ' . $entry_id);
             $result = GFAPI::delete_entry($entry_id);
             if (is_wp_error($result)) {
                 break;
             }
             $count++;
         }
     } else {
         $result = GFAPI::delete_entry($entry_ids);
         $count++;
     }
     if (isset($result) && is_wp_error($result)) {
         $response = $this->get_error_response($result);
         $status = $this->get_error_status($result);
     } else {
         $status = 200;
         $response = sprintf(__('Entries deleted successfully: %d', 'gravityforms'), $count);
     }
     $this->end($status, $response);
 }
/**
 * This function will remove all of the music from the NNMTA music database.
 *
 * This function was created to support the scenario when the festival chariman needs
 * to update the music in the NNMTA music database. In order to do this, all of the existing
 * data is removed from the database prior to adding all of the new data. This ensures
 * that the new data is added appropriately without accidentally adding old, possibly
 * unwanted music data.
 *
 * @since 2.0.0
 * @author KREW
 */
function aria_remove_all_music_from_nnmta_database()
{
    $nnmta_music_database_form_id = aria_get_nnmta_database_form_id();
    $index = 0;
    $total_count = GFAPI::count_entries($nnmta_music_database_form_id);
    while ($index < $total_count) {
        $twenty_songs = GFAPI::get_entries($nnmta_music_database_form_id);
        for ($song_on_page = 0; $song_on_page < 20; $song_on_page++) {
            $deleted_song = GFAPI::delete_entry($twenty_songs[$song_on_page]['id']);
            if (is_wp_error($deleted_song)) {
                wp_die($deleted_song->get_error_message());
            }
        }
        $index += 20;
    }
    /*
    	foreach ($all_songs as $song) {
    		$deleted_song = GFAPI::delete_entry($song['id']);
    		if (is_wp_error($deleted_song)) {
    			wp_die($deleted_song->get_error_message());
    		}
    	}
    */
}
 /**
  * @since 1.13.1
  * @see GFAPI::delete_entry()
  * @return WP_Error|boolean GFAPI::delete_entry() returns a WP_Error on error
  */
 private function delete_or_trash_entry($entry)
 {
     $entry_id = $entry['id'];
     $mode = $this->get_delete_mode();
     if ('delete' === $mode) {
         do_action('gravityview_log_debug', __METHOD__ . ' Starting delete entry: ', $entry_id);
         // Delete the entry
         $delete_response = GFAPI::delete_entry($entry_id);
         if (!is_wp_error($delete_response)) {
             $delete_response = 'deleted';
             /**
              * @action `gravityview/delete-entry/deleted` Triggered when an entry is deleted
              * @since 1.16.4
              * @param  int $entry_id ID of the Gravity Forms entry
              * @param  array $entry Deleted entry array
              */
             do_action('gravityview/delete-entry/deleted', $entry_id, $entry);
         }
         do_action('gravityview_log_debug', __METHOD__ . ' Delete response: ', $delete_response);
     } else {
         do_action('gravityview_log_debug', __METHOD__ . ' Starting trash entry: ', $entry_id);
         $trashed = GFAPI::update_entry_property($entry_id, 'status', 'trash');
         new GravityView_Cache();
         if (!$trashed) {
             $delete_response = new WP_Error('trash_entry_failed', __('Moving the entry to the trash failed.', 'gravityview'));
         } else {
             /**
              * @action `gravityview/delete-entry/trashed` Triggered when an entry is trashed
              * @since 1.16.4
              * @param  int $entry_id ID of the Gravity Forms entry
              * @param  array $entry Deleted entry array
              */
             do_action('gravityview/delete-entry/trashed', $entry_id, $entry);
             $delete_response = 'trashed';
         }
         do_action('gravityview_log_debug', __METHOD__ . ' Trashed? ', $delete_response);
     }
     return $delete_response;
 }
 /**
  * This is the target for the gform_after_submission action hook.
  * Executed at the end of the submission process (after form validation, notification, and entry creation).
  *
  * @param array $entry The Entry Object containing the submitted form values
  * @param array $form  The Form Object containing all the form and field settings
  *
  * @return bool
  */
 function after_submission($entry, $form)
 {
     // Make sure the Gravity Forms Web API wrapper can be found in the includes folder of the add-on.
     // Download from here:
     // https://raw.githubusercontent.com/rocketgenius/webapiclient/master/includes/class-gf-web-api-wrapper.php
     require_once "includes/class-gf-web-api-wrapper.php";
     $addon_settings = $this->get_plugin_settings();
     if (!$addon_settings) {
         return;
     }
     $api_url = $addon_settings["site_url"];
     $public_key = $addon_settings["site_api_key"];
     $private_key = $addon_settings["site_private_key"];
     $identifier = !empty($addon_settings["identifier"]) ? $addon_settings["identifier"] : get_bloginfo();
     if (empty($api_url) || empty($public_key) || empty($private_key)) {
         return;
     }
     // Use the helper method to get the form settings and make sure it's enabled for this form
     $form_settings = $this->get_form_settings($form);
     if (!$form_settings || !$form_settings["isEnabled"]) {
         return;
     }
     $remote_form_id = $form_settings["site_form_id"];
     // Set up the Web API connection to the remote site
     $web_api = new GFWebAPIWrapper($api_url, $public_key, $private_key);
     // Create the form on the central server if no Form ID is currently set
     if (empty($remote_form_id)) {
         $remote_form_id = $web_api->create_form($form);
         // Save the remote Form ID in the settings
         $form_settings["site_form_id"] = $remote_form_id;
         $this->save_form_settings($form, $form_settings);
     }
     // Set the form_id for the entry to the remote Form ID
     $entry["form_id"] = $remote_form_id;
     // Set the entry meta so the remote site can identify that this entry is from this site
     $entry["gf_aggregator_id"] = $identifier;
     // Create the entry on the central server
     // Note: A better approach would be to spin this off into a wp_cron task.
     $web_api->create_entry($entry);
     // If the delete entries setting is activated then delete this entry.
     if ($form_settings["deleteEntries"]) {
         GFAPI::delete_entry($entry["id"]);
     }
 }
Example #7
0
 /**
  * @since 1.13.1
  * @see GFAPI::delete_entry()
  * @return WP_Error|boolean GFAPI::delete_entry() returns a WP_Error on error
  */
 private function delete_or_trash_entry($entry_id)
 {
     $mode = $this->get_delete_mode();
     if ('delete' === $mode) {
         do_action('gravityview_log_debug', __METHOD__ . ' Starting delete entry: ', $entry_id);
         // Delete the entry
         $delete_response = GFAPI::delete_entry($entry_id);
         if (!is_wp_error($delete_response)) {
             $delete_response = 'deleted';
         }
         do_action('gravityview_log_debug', __METHOD__ . ' Delete response: ', $delete_response);
     } else {
         do_action('gravityview_log_debug', __METHOD__ . ' Starting trash entry: ', $entry_id);
         $trashed = GFAPI::update_entry_property($entry_id, 'status', 'trash');
         new GravityView_Cache();
         if (!$trashed) {
             $delete_response = new WP_Error('trash_entry_failed', __('Moving the entry to the trash failed.', 'gravityview'));
         } else {
             $delete_response = 'trashed';
         }
         do_action('gravityview_log_debug', __METHOD__ . ' Trashed? ', $delete_response);
     }
     return $delete_response;
 }
Example #8
0
function btc_remove_racer()
{
    if (isset($_POST) && isset($_POST['key']) && is_numeric($_POST['key'])) {
        $res = GFAPI::delete_entry($_POST['key']);
    } else {
        echo 'error ' . $_POST['key'];
    }
    wp_die();
}
 /**
  * Delete entry
  */
 private function delete_entry($form_id)
 {
     $entry_id = isset($_SESSION['gform_sayg_entry_id_' . $form_id]) ? $_SESSION['gform_sayg_entry_id_' . $form_id] : NULL;
     $deleted_entry = GFAPI::delete_entry($entry_id);
     unset($_SESSION['gform_sayg_entry_id_' . $form_id]);
 }
function sticky_set_post_content($entry, $form)
{
    if ($form['isSticky']) {
        if (is_user_logged_in()) {
            $saved_option_key = sticky_getEntryOptionKeyForGF($form);
            $saved_option_value = get_option($saved_option_key);
            // Save the entry ID in wp_options if this is the first time the form is submitted by this user.
            // If we dont have a saved value, we save the entry ID
            if (!$saved_option_value) {
                update_option($saved_option_key, $entry['id']);
                //If we have a saved value, update and delete
            } else {
                // ...as long as the form doesnt allow multiple entries...
                if (!$form['isEnableMulipleEntry']) {
                    // We dont want to loose our starred and read status when we update
                    $original_entry = RGFormsModel::get_lead($saved_option_value);
                    $entry["is_starred"] = $original_entry["is_starred"];
                    // ...unless the user wants us to
                    if (!isset($form['isMarkUnread'])) {
                        $entry["is_read"] = $original_entry["is_read"];
                    }
                    $success = GFAPI::update_entry($entry, $saved_option_value);
                    $success = GFAPI::delete_entry($entry["id"]);
                    // ...and if it does, dont delete or update but save the new entry ID instead so that the sticky form is populated with the latest saved entry.
                } else {
                    update_option($saved_option_key, $entry['id']);
                }
            }
        }
    }
}
 public function gform_after_submission($entry, $form)
 {
     if (!rgempty('preventEntryCreation', $form)) {
         GFAPI::delete_entry($entry['id']);
     }
 }
 function gfee_after_submission($tmp_entry, $form)
 {
     // get the original entry we want to edit/update
     GFEE::set_entry_id($_POST['gfee_entry_id']);
     // NEED TO BEEF UP SECURITY HERE AS THIS VALUE CAN BE MODIFIED BY USER TO EDIT SOMEONE ELSE'S ENTRY
     $orig_entry_id = GFEE::$entry_id;
     $orig_entry = GFAPI::get_entry($orig_entry_id);
     // initialize deletefiles variable
     $deletefiles = array();
     // take care of certain fields that need special handling
     foreach ($form['fields'] as $field) {
         // don't touch admin-only fields since front-end can't modify those
         if (!$field['adminOnly']) {
             // handle file uploads
             if ($field['type'] == 'fileupload') {
                 // if user has deleted this file upload, save to list to delete later
                 if ($_POST['delete_file'] == $field['id']) {
                     $delete_file_path = get_file_path_from_gf_entry($orig_entry[$field['id']]);
                     $deletefiles[] = $delete_file_path;
                     // save new file upload field data
                     $orig_entry[$field['id']] = $tmp_entry[$field['id']];
                 }
                 // this currently only supports one file per field
                 if ($tmp_entry[$field['id']]) {
                     // new file(s) uploaded, we need to copy the files because the originals will be deleted with the temp entry by Gravity Forms
                     $file_path = get_file_path_from_gf_entry($tmp_entry[$field['id']]);
                     $tmp_file_path = $file_path . '.tmp';
                     copy($file_path, $tmp_file_path);
                     // save new file upload field data
                     $orig_entry[$field['id']] = $tmp_entry[$field['id']];
                 }
                 // handle checkboxes, address, and name fields
             } elseif ($field['type'] == 'checkbox' || $field['type'] == 'address' || $field['type'] == 'name') {
                 foreach ($field->inputs as $key => $input) {
                     // loop each field input and save it
                     $orig_entry[strval($input['id'])] = $tmp_entry[strval($input['id'])];
                 }
             } else {
                 // save updated field data to original entry
                 $orig_entry[$field['id']] = $tmp_entry[$field['id']];
             }
         }
     }
     // perform update entry with original entry data fields updated
     $update_success = GFAPI::update_entry($orig_entry);
     if ($update_success === true) {
         // delete temporary entry
         $delete_success = GFAPI::delete_entry($tmp_entry['id']);
         // delete any lingering files that shouldn't be around anymore
         foreach ($deletefiles as $filename) {
             if (file_exists($filename)) {
                 unlink($filename);
             }
         }
         // original file(s) should be deleted by Gravity Forms or us, need to rename temp file back to original name
         if ($tmp_file_path) {
             rename($tmp_file_path, $file_path);
         }
     }
 }
Example #13
0
/**
 * Delete Gravity Forms entry specified
 * @global object $wpdb
 *@param string $lead_id, id of gravity form entry to remove
 */
function ovr_delete_gf_entry($lead_id)
{
    global $wpdb;
    // Prepare variables.
    $lead_table = RGFormsModel::get_lead_table_name();
    $lead_notes_table = RGFormsModel::get_lead_notes_table_name();
    $lead_detail_table = RGFormsModel::get_lead_details_table_name();
    $lead_detail_long_table = RGFormsModel::get_lead_details_long_table_name();
    // Delete from lead detail long.
    $sql = $wpdb->prepare("DELETE FROM {$lead_detail_long_table} WHERE lead_detail_id IN(SELECT id FROM {$lead_detail_table} WHERE lead_id = %d)", $lead_id);
    $wpdb->query($sql);
    // Delete from lead details.
    $sql = $wpdb->prepare("DELETE FROM {$lead_detail_table} WHERE lead_id = %d", $lead_id);
    $wpdb->query($sql);
    // Delete from lead notes.
    $sql = $wpdb->prepare("DELETE FROM {$lead_notes_table} WHERE lead_id = %d", $lead_id);
    $wpdb->query($sql);
    // Delete from lead.
    $sql = $wpdb->prepare("DELETE FROM {$lead_table} WHERE id = %d", $lead_id);
    $wpdb->query($sql);
    // Finally, ensure everything is deleted (like stuff from Addons).
    GFAPI::delete_entry($lead_id);
}
function gform_disable_post_creation($entry, $form)
{
    GFAPI::delete_entry($entry['id']);
}
Example #15
0
function deleteAllMyEntries()
{
    // get current user info
    global $current_user;
    get_currentuserinfo();
    $user_id = $current_user->ID;
    // initialize
    $result = "";
    $my_lead_ids = array();
    $successes = 0;
    $failures = 0;
    $failure_msg = "";
    // find entries for this user in all forms that we want to wipe out
    $form_ids = array(1, 4, 7, 8, 10, 16, 18, 19, 20, 21, 22, 49);
    foreach ($form_ids as $form_id) {
        // reset running count of number of entries found
        $number_of_entries_f[$form_id] = 0;
        // get all leads for that form id
        $leads = RGFormsModel::get_leads($form_id);
        // get form meta and then user-login field id for each form
        $form_meta = RGFormsModel::get_form_meta($form_id);
        $form_title = $form_meta["title"];
        // get leads that match on user-login
        foreach ($leads as $lead) {
            if ($lead['created_by'] == $user_id) {
                array_push($my_lead_ids, $lead['id']);
                $number_of_entries_f[$form_id]++;
            }
        }
        $result .= $form_title . ": " . $number_of_entries_f[$form_id] . "<br/>";
    }
    // delete the entries
    foreach ($my_lead_ids as $lead_id) {
        $del_result = GFAPI::delete_entry($lead_id);
        //echo "dr: ".$del_result;
        if ($del_result == true) {
            $successes++;
        } else {
            $failures++;
            $failure_msg .= "<br>" . $del_result;
        }
    }
    $final_result = "<br><br><b>Reset of all forms is complete.</b><br/><br/>Details - Attempted to delete the following number of entries:<br/>" . $result;
    $final_result .= "<br/>Successes: " . $successes . "<br/>Failures: " . $failures . "<br>" . $failure_msg;
    return $final_result;
}
Example #16
0
 public function delete_entries($entry_ids)
 {
     $this->authorize("gravityforms_delete_entries");
     $count = 0;
     if (is_array($entry_ids)) {
         foreach ($entry_ids as $entry_id) {
             $result = GFAPI::delete_entry($entry_id);
             if (is_wp_error($result)) {
                 break;
             }
             $count++;
         }
     } else {
         $result = GFAPI::delete_entry($entry_ids);
         $count++;
     }
     if (isset($result) && is_wp_error($result)) {
         $response = $this->get_error_response($result);
         $status = $this->get_error_status($result);
     } else {
         $status = 200;
         $response = sprintf(__("Entries deleted successfully: %d", "gravityforms"), $count);
     }
     $this->end($status, $response);
 }
Example #17
0
 /**
  * Handle the deletion request, if $_GET['action'] is set to "delete"
  *
  * 1. Check referrer validity
  * 2. Make sure there's an entry with the slug of $_GET['entry_id']
  * 3. If so, attempt to delete the entry. If not, set the error status
  * 4. Remove `action=delete` from the URL
  * 5. Redirect to the page using `wp_safe_redirect()`
  *
  * @since 1.5.1
  * @uses GFAPI::delete_entry()
  * @uses wp_safe_redirect()
  * @return void
  */
 function process_delete()
 {
     // If the form is submitted
     if (RGForms::get("action") === "delete") {
         $nonce_key = self::get_nonce_key($_GET['entry_id']);
         // Make sure it's a valid request
         check_admin_referer($nonce_key, 'delete');
         // Get the entry slug
         $entry_slug = esc_attr($_GET['entry_id']);
         // See if there's an entry there
         $entry = gravityview_get_entry($entry_slug);
         if ($entry) {
             $has_permission = $this->user_can_delete_entry($entry);
             if (is_wp_error($has_permission)) {
                 $messages = array('message' => urlencode($has_permission->get_error_message()), 'status' => 'error');
             } else {
                 do_action('gravityview_log_debug', 'GravityView_Delete_Entry[process_delete] Starting delete entry: ', $entry);
                 // Delete the entry
                 $delete_response = GFAPI::delete_entry($entry['id']);
                 do_action('gravityview_log_debug', 'GravityView_Delete_Entry[process_delete] Delete response: ', $delete_response);
                 // GFAPI::delete_entry() returns a WP_Error on error
                 if (is_wp_error($delete_response)) {
                     $messages = array('message' => urlencode($delete_response->get_error_message()), 'status' => 'error');
                 } else {
                     $messages = array('status' => 'success');
                 }
             }
         } else {
             do_action('gravityview_log_debug', 'GravityView_Delete_Entry[process_delete] Delete entry failed: there was no entry with the entry slug ' . $entry_slug);
             $messages = array('message' => urlencode(__('The entry does not exist.', 'gravityview')), 'status' => 'error');
         }
         $redirect_to_base = esc_url(remove_query_arg(array('action')));
         $redirect_to = add_query_arg($messages, $redirect_to_base);
         wp_safe_redirect($redirect_to);
         exit;
     }
     // endif action is delete.
 }