/** * @covers GVCommon::has_gravityview_shortcode() * @covers ::has_gravityview_shortcode() */ function test_has_gravityview_shortcode() { $this->assertFalse(has_gravityview_shortcode('[gravityview]'), 'The function should only accept WP_Post object'); $no_shortcode = $this->factory->post->create_and_get(); $shortcode = $this->factory->post->create_and_get(array('post_content' => '[gravityview]')); $view = $this->factory->view->create_and_get(); $this->assertFalse(has_gravityview_shortcode($no_shortcode)); $this->assertTrue(has_gravityview_shortcode($shortcode)); $this->assertTrue(has_gravityview_shortcode($view)); }
/** * 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')); }