/** * return href for single entry * @param array|int $entry Entry array or entry ID * @param int|null $post_id If wanting to define the parent post, pass a post ID * @param boolean $add_directory_args True: Add args to help return to directory; False: only include args required to get to entry {@since 1.7.3} * @return string Link to the entry with the directory parent slug */ public static function entry_link($entry, $post_id = NULL, $add_directory_args = true) { if (!empty($entry) && !is_array($entry)) { $entry = GVCommon::get_entry($entry); } else { if (empty($entry)) { $entry = GravityView_frontend::getInstance()->getEntry(); } } // Second parameter used to be passed as $field; this makes sure it's not an array if (!is_numeric($post_id)) { $post_id = NULL; } // Get the permalink to the View $directory_link = self::directory_link($post_id, false); // No post ID? Get outta here. if (empty($directory_link)) { return ''; } $query_arg_name = GravityView_Post_Types::get_entry_var_name(); $entry_slug = self::get_entry_slug($entry['id'], $entry); if (get_option('permalink_structure') && !is_preview()) { $args = array(); $directory_link = trailingslashit($directory_link) . $query_arg_name . '/' . $entry_slug . '/'; } else { $args = array($query_arg_name => $entry_slug); } /** * @since 1.7.3 */ if ($add_directory_args) { if (!empty($_GET['pagenum'])) { $args['pagenum'] = intval($_GET['pagenum']); } /** * @since 1.7 */ if ($sort = rgget('sort')) { $args['sort'] = $sort; $args['dir'] = rgget('dir'); } } /** * Check if we have multiple views embedded in the same page and in that case make sure the single entry link * has the view id so that Advanced Filters can be applied correctly when rendering the single view * @see GravityView_frontend::get_context_view_id() */ if (class_exists('GravityView_View_Data') && GravityView_View_Data::getInstance()->has_multiple_views()) { $args['gvid'] = gravityview_get_view_id(); } return add_query_arg($args, $directory_link); }
/** * Set the current entry * @param array|int $entry Entry array or entry ID */ public function setEntry($entry) { if (!is_array($entry)) { $entry = GVCommon::get_entry($entry); } $this->entry = $entry; }
/** * Return a single entry object * * Since 1.4, supports custom entry slugs. The way that GravityView fetches an entry based on the custom slug is by searching `gravityview_unique_id` meta. The `$entry_slug` is fetched by getting the current query var set by `is_single_entry()` * * @access public * @param mixed $entry_id * @param boolean $force_allow_ids Force the get_entry() method to allow passed entry IDs, even if the `gravityview_custom_entry_slug_allow_id` filter returns false. * @return object or false */ function gravityview_get_entry($entry_slug, $force_allow_ids = false) { return GVCommon::get_entry($entry_slug, $force_allow_ids); }
/** * Return a single entry object * * Since 1.4, supports custom entry slugs. The way that GravityView fetches an entry based on the custom slug is by searching `gravityview_unique_id` meta. The `$entry_slug` is fetched by getting the current query var set by `is_single_entry()` * * @access public * @param mixed $entry_id * @param boolean $force_allow_ids Force the get_entry() method to allow passed entry IDs, even if the `gravityview_custom_entry_slug_allow_id` filter returns false. * @param boolean $check_entry_display Check whether the entry is visible for the current View configuration. Default: true {@since 1.14} * @return array|boolean */ function gravityview_get_entry($entry_slug, $force_allow_ids = false, $check_entry_display = true) { return GVCommon::get_entry($entry_slug, $force_allow_ids, $check_entry_display); }
/** * Get entry array from `entry_id` parameter. If no $entry_id * * @since 1.15 * @uses GVCommon::get_entry * @uses GravityView_frontend::getSingleEntry * * @param int $entry_id Gravity Forms Entry ID. If not passed, current View's current entry ID will be used, if found. * * @return array|bool Gravity Forms array, if found. Otherwise, false. */ private function get_entry($entry_id = 0) { $backup_entry = GravityView_frontend::getInstance()->getSingleEntry() ? GravityView_frontend::getInstance()->getEntry() : GravityView_View::getInstance()->getCurrentEntry(); if (empty($entry_id)) { if (!$backup_entry) { do_action('gravityview_log_error', __METHOD__ . ' No entry defined (or entry id not valid number)', $this->settings); return false; } $entry = $backup_entry; } else { $entry = wp_cache_get('gv_entry_link_entry_' . $entry_id, 'gravityview_entry_link_shortcode'); if (false === $entry) { $entry = GVCommon::get_entry($entry_id, true, false); wp_cache_add('gv_entry_link_entry_' . $entry_id, $entry, 'gravityview_entry_link_shortcode'); } } // No search results if (false === $entry) { do_action('gravityview_log_error', __METHOD__ . ' No entries match the entry ID defined', $entry_id); return false; } return $entry; }