/**
  * Read the $post and process the View data inside
  * @param  array  $wp Passed in the `wp` hook. Not used.
  * @return void
  */
 function parse_content($wp = array())
 {
     global $post;
     // If in admin and NOT AJAX request, get outta here.
     if (GravityView_Plugin::is_admin()) {
         return;
     }
     // Calculate requested Views
     $this->setGvOutputData(GravityView_View_Data::getInstance($post));
     // !important: we need to run this before getting single entry (to kick the advanced filter)
     $this->set_context_view_id();
     $this->setIsGravityviewPostType(get_post_type($post) === 'gravityview');
     $post_id = $this->getPostId() ? $this->getPostId() : (isset($post) ? $post->ID : null);
     $this->setPostId($post_id);
     $post_has_shortcode = !empty($post->post_content) ? gravityview_has_shortcode_r($post->post_content, 'gravityview') : false;
     $this->setPostHasShortcode($this->isGravityviewPostType() ? null : !empty($post_has_shortcode));
     // check if the View is showing search results (only for multiple entries View)
     $this->setIsSearch($this->is_searching());
     unset($entry, $post_id, $post_has_shortcode);
 }
 /**
  * @param array $atts User defined attributes in shortcode tag.
  * @param null $content
  * @param string $shortcode_tag
  *
  * @return string|null
  */
 public function shortcode($atts = array(), $content = NULL, $shortcode_tag = '')
 {
     // Don't process except on frontend
     if (GravityView_Plugin::is_admin()) {
         return null;
     }
     $this->passed_atts = $atts;
     $this->passed_content = $content;
     $this->shortcode = $shortcode_tag;
     $this->parse_atts();
     // We need an "if"
     if (false === $this->if) {
         do_action('gravityview_log_error', __METHOD__ . ' $atts->if is empty.', $this->atts);
         return null;
     }
     $setup = $this->setup_operation_and_comparison();
     // We need an operation and comparison value
     if (!$setup) {
         do_action('gravityview_log_error', __METHOD__ . ' No valid operators were passed.', $this->atts);
         return null;
     }
     // Set the content and else_content
     $this->set_content_and_else_content();
     // Check if it's a match
     $this->set_is_match();
     // Return the value!
     return $this->get_output();
 }
 /**
  * Add $this->shortcode_name shortcode to output self::render_frontend()
  */
 function add_shortcode($run_on_singular = true)
 {
     global $post;
     if (GravityView_Plugin::is_admin()) {
         return;
     }
     if (empty($this->shortcode_name)) {
         return;
     }
     // If the widget shouldn't output on single entries, don't show it
     if (empty($this->show_on_single) && class_exists('GravityView_frontend') && GravityView_frontend::is_single_entry()) {
         do_action('gravityview_log_debug', sprintf('%s[add_shortcode]: Skipping; set to not run on single entry.', get_class($this)));
         add_shortcode($this->shortcode_name, '__return_null');
         return;
     }
     if (!has_gravityview_shortcode($post)) {
         do_action('gravityview_log_debug', sprintf('%s[add_shortcode]: No shortcode present; not adding render_frontend shortcode.', get_class($this)));
         add_shortcode($this->shortcode_name, '__return_null');
         return;
     }
     add_shortcode($this->shortcode_name, array($this, 'render_shortcode'));
 }
 /**
  * Register the updater for the Extension using GravityView license information
  *
  * @return void
  */
 public function settings()
 {
     // If doing ajax, get outta here
     if (false === GravityView_Plugin::is_admin()) {
         return;
     }
     if (!class_exists('EDD_SL_Plugin_Updater')) {
         include_once plugin_dir_path(__FILE__) . 'lib/EDD_SL_Plugin_Updater.php';
     }
     $license = $this->get_license();
     // Don't update if invalid license.
     if (false === $license || empty($license['status']) || strtolower($license['status']) !== 'valid') {
         return;
     }
     new EDD_SL_Plugin_Updater($this->_remote_update_url, $this->_path, array('version' => $this->_version, 'license' => $license['license'], 'item_name' => $this->_title, 'author' => strip_tags($this->_author)));
 }
 /**
  * Generate a link to an entry. The link can be an edit, delete, or standard link.
  *
  * @since 1.15
  *
  * @param array $atts {
  *    @type string $action What type of link to generate. Options: `read`, `edit`, and `delete`. Default: `read`
  *    @type string $view_id Define the ID for the View. If not set, use current View ID, if exists.
  *    @type string $entry_id ID of the entry to edit. If undefined, uses the current entry ID, if exists.
  *    @type string $post_id ID of the base post or page to use for an embedded View
  *    @type string $link_atts Pass anchor tag attributes (`target=_blank` to open Edit Entry link in a new window, for example)
  *    @type string $return What should the shortcode return: link HTML (`html`) or the URL (`url`). Default: `html`
  *    @type string $field_values Only used for `action="edit"`. Parameters to pass in to the prefill data in Edit Entry form. Uses the same format as Gravity Forms "Allow field to be populated dynamically" {@see https://www.gravityhelp.com/documentation/article/allow-field-to-be-populated-dynamically/ }
  * }
  *
  * @param string|null $content Used as link anchor text, if specified.
  * @param string $context Current shortcode being called. Not used.
  *
  * @return null|string If admin or an error occurred, returns null. Otherwise, returns entry link output. If `$atts['return']` is 'url', the entry link URL. Otherwise, entry link `<a>` HTML tag.
  */
 private function shortcode($atts, $content = null, $context = 'gv_entry_link')
 {
     // Don't process when saving post. Keep processing if it's admin-ajax.php
     if (!class_exists('GravityView_Plugin') || GravityView_Plugin::is_admin()) {
         return null;
     }
     // Make sure GV is loaded
     if (!class_exists('GravityView_frontend') || !class_exists('GravityView_View')) {
         do_action('gravityview_log_error', __METHOD__ . ' GravityView_frontend or GravityView_View do not exist.');
         return null;
     }
     $this->settings = shortcode_atts(self::$defaults, $atts, $context);
     $this->view_id = empty($this->settings['view_id']) ? GravityView_View::getInstance()->getViewId() : absint($this->settings['view_id']);
     if (empty($this->view_id)) {
         do_action('gravityview_log_error', __METHOD__ . ' A View ID was not defined and we are not inside a View');
         return null;
     }
     $this->entry = $this->get_entry($this->settings['entry_id']);
     do_action('gravityview_log_debug', __METHOD__ . ' ' . $context . ' $atts: ', $atts);
     if (!$this->has_cap()) {
         do_action('gravityview_log_error', __METHOD__ . ' User does not have the capability to ' . esc_attr($this->settings['action']) . ' this entry: ' . $this->entry['id']);
         return null;
     }
     $url = $this->get_url();
     if (!$url) {
         do_action('gravityview_log_error', __METHOD__ . ' Link returned false; View or Post may not exist.');
         return false;
     }
     // Get just the URL, not the tag
     if ('url' === $this->settings['return']) {
         return $url;
     }
     $link_atts = $this->get_link_atts();
     $link_text = $this->get_anchor_text($content);
     return gravityview_get_link($url, $link_text, $link_atts);
 }