/** * Generate a nonce link with the base URL of the current View embed * * We don't want to link to the single entry, because when deleted, there would be nothing to return to. * * @since 1.5.1 * @param array $entry Gravity Forms entry array * @return string|null If directory link is valid, the URL to process the delete request. Otherwise, `NULL`. */ public static function get_delete_link($entry, $view_id = 0, $post_id = null) { self::getInstance()->set_entry($entry); $base = GravityView_API::directory_link($post_id, true); if (empty($base)) { do_action('gravityview_log_error', __METHOD__ . ' - Post ID does not exist: ' . $post_id); return NULL; } // Use the slug instead of the ID for consistent security $entry_slug = GravityView_API::get_entry_slug($entry['id'], $entry); $view_id = empty($view_id) ? gravityview_get_view_id() : $view_id; $actionurl = add_query_arg(array('action' => 'delete', 'entry_id' => $entry_slug, 'gvid' => $view_id, 'view_id' => $view_id), $base); $url = wp_nonce_url($actionurl, 'delete_' . $entry_slug, 'delete'); return $url; }
function gv_directory_link($post = NULL, $add_pagination = true) { return GravityView_API::directory_link($post, $add_pagination); }
/** * @covers ::gv_directory_link() * @covers GravityView_API::directory_link() */ public function test_directory_link() { $post_array = array('post_content' => 'asdasdsd', 'post_type' => 'post', 'post_status' => 'publish'); $post_id = wp_insert_post($post_array); $view_post_type_id = $this->_get_new_view_id(); $_GET['pagenum'] = 2; $add_pagination = false; $this->assertEquals(site_url('?p=' . $post_id), GravityView_API::directory_link($post_id, $add_pagination)); $add_pagination = true; $this->assertEquals(site_url('?p=' . $post_id . '&pagenum=2'), GravityView_API::directory_link($post_id, $add_pagination)); // Make sure the cache is working properly $this->assertEquals(site_url('?p=' . $post_id), wp_cache_get('gv_directory_link_' . $post_id)); // // Use $gravityview_view data // global $gravityview_view; global $post; $post = get_post($view_post_type_id); GravityView_frontend::getInstance()->parse_content(); $gravityview_view->setViewId($view_post_type_id); // Test post_id has been set $gravityview_view->setPostId($post_id); /* TODO - fix this assertion */ $this->assertEquals(site_url('?p=' . $post_id . '&pagenum=2'), GravityView_API::directory_link()); $gravityview_view->setPostId($post_id); // // TESTING AJAX // define('DOING_AJAX', true); // No passed post_id; use $_POST when DOING_AJAX is set $this->assertNull(GravityView_API::directory_link()); $_POST['post_id'] = $post_id; // No passed post_id; use $_POST when DOING_AJAX is set $this->assertEquals(site_url('?p=' . $post_id . '&pagenum=2'), GravityView_API::directory_link()); }