/** * @covers GravityView_Edit_Entry::get_edit_link() */ function test_get_edit_link() { $form = $this->factory->form->create_and_get(); $editor = $this->factory->user->create_and_set(array('user_login' => 'editor', 'role' => 'editor')); $entry = $this->factory->entry->create_and_get(array('form_id' => $form['id'], 'created_by' => $editor->ID)); $view = $this->factory->view->create_and_get(array('form_id' => $form['id'], 'settings' => array('user_edit' => 1))); $this->assertNotEmpty($view, 'There was an error creating the View'); $post_title = new WP_UnitTest_Generator_Sequence(__METHOD__ . ' %s'); $post_id = $this->factory->post->create(array('post_title' => $post_title->next(), 'post_content' => sprintf('[gravityview id="%d"]', $view->ID))); $nonce_key = GravityView_Edit_Entry::get_nonce_key($view->ID, $entry['form_id'], $entry['id']); $nonce = wp_create_nonce($nonce_key); ### ### NO POST ### $edit_link_no_post = GravityView_Edit_Entry::get_edit_link($entry, $view->ID); // A link to the raw $this->assertEquals('?page=gf_entries&view=entry&edit=' . $nonce, $edit_link_no_post); $args = array('p' => $post_id, 'entry' => $entry['id'], 'gvid' => $view->ID, 'page' => 'gf_entries', 'view' => 'entry', 'edit' => $nonce); // When running all tests, this test thinks we have multiple Views. Correct that. GravityView_View::getInstance()->setViewId($view->ID); ### ### WITH POST ### $edit_link_with_post = GravityView_Edit_Entry::get_edit_link($entry, $view->ID, $post_id); $this->assertEquals(add_query_arg($args, 'http://example.org/'), $edit_link_with_post); }
/** * Get the URL for the Edit Entry link * * @param array $entry GF Entry array * @param int $view_id View ID * @param int $post_id Optional: alternative base URL for embedded Views */ private function get_edit_url($entry, $view_id, $post_id, $settings = array()) { $href = GravityView_Edit_Entry::get_edit_link($entry, $view_id, $post_id); // Allow passing params to dynamically populate if (!empty($settings['field_values'])) { parse_str($settings['field_values'], $field_values); $href = add_query_arg($field_values, $href); } return $href; }
/** * Get the URL for the entry. * * Uses the `post_id`, `view_id` params as defined in the shortcode attributes. * * @since 1.15 * * @param string|null $content Content inside shortcode, if defined * * @return string|boolean If URL is fetched, the URL to the entry link. If not found, returns false. */ private function get_url() { // if post_id is not defined, default to view_id $post_id = empty($this->settings['post_id']) ? $this->view_id : absint($this->settings['post_id']); switch ($this->settings['action']) { case 'edit': $url = GravityView_Edit_Entry::get_edit_link($this->entry, $this->view_id, $post_id); break; case 'delete': $url = GravityView_Delete_Entry::get_delete_link($this->entry, $this->view_id, $post_id); break; case 'read': default: $url = GravityView_API::entry_link($this->entry, $post_id); } $url = $this->maybe_add_field_values_query_args($url); return $url; }
function makeAdminCopyEntry() { $entryID = isset($_POST['copy_entry_id']) ? $_POST['copy_entry_id'] : 0; $copy2Form = isset($_POST['copy2Form']) ? $_POST['copy2Form'] : ''; $view_id = isset($_POST['view_id']) ? $_POST['view_id'] : 0; if ($entryID != 0 and $copy2Form != '' && $view_id != 0) { //get entry data $lead = GFAPI::get_entry(esc_attr($entryID)); //get new form field ID's $form = GFAPI::get_form($copy2Form); /*The following fields will not be copied from one entry to another * Page 4 review fields: * 295 - Are you 18 years or older * 114 - Full Name * 297 - I am the parent and/or legal guardian of * 115 - Date * 117 - Release and consent * all admin only fields */ $doNotCopy = array(295, 114, 297, 115, 117); /*loop thru fields in existing entry and if they are in the new form copy them */ $newEntry = array(); $newEntry['form_id'] = $copy2Form; foreach ($form['fields'] as $field) { //skip doNotCopy fields if (!in_array($field['id'], $doNotCopy)) { //do not copy admin only fields $adminOnly = isset($field['adminOnly']) ? $field['adminOnly'] : FALSE; if (!$adminOnly) { if (is_array($field['inputs'])) { foreach ($field['inputs'] as $inputs) { $fieldID = $inputs['id']; if (isset($lead[$fieldID])) { $newEntry[$fieldID] = $lead[$fieldID]; } } } if (isset($lead[$field['id']])) { $newEntry[$field['id']] = $lead[$field['id']]; } } } } $newEntry['303'] = 'In Progress'; //in-progress $newEntry_id = GFAPI::add_entry($newEntry); $entry = GFAPI::get_entry($newEntry_id); $href = GravityView_Edit_Entry::get_edit_link($entry, $view_id); echo 'New Entry created:' . $newEntry_id . '. Please click <a href="entry/' . $newEntry_id . '/' . $href . '">here</a> to finish the submission process'; } else { echo 'Error in creating a new entry. Proper data was not received.'; } exit; }
<?php $gravityview_view = GravityView_View::getInstance(); $view_id = $gravityview_view->getViewId(); extract($gravityview_view->getCurrentField()); // Only show the link to logged-in users. if (!GravityView_Edit_Entry::check_user_cap_edit_entry($entry)) { return; } $link_text = empty($field_settings['edit_link']) ? __('Edit Entry', 'gravityview') : $field_settings['edit_link']; $link_atts = empty($field_settings['new_window']) ? '' : 'target="_blank"'; $output = apply_filters('gravityview_entry_link', GravityView_API::replace_variables($link_text, $form, $entry)); $href = GravityView_Edit_Entry::get_edit_link($entry, $view_id); echo gravityview_get_link($href, $output, $link_atts);