/** * Checks if current post belongs in an excluded post type * Returns true iff post is of excluded types defined in main options * * @author Panagiotis Vagenas <*****@*****.**> * @since 1.0.0 */ public function isInExcludedPostTypes($post) { $postType = get_post_type($post); if (!empty($postType) && is_array($this->mainOpts->getPostTypes()) && in_array($postType, $this->mainOpts->getPostTypes())) { return TRUE; } return FALSE; }
/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args * Widget arguments. * @param array $instance * Saved values from database. * @since 1.0.0 * @author Panagiotis Vagenas <*****@*****.**> */ public function widget($args, $instance) { global $post; // get instance of main plugin $plugin = easyRelatedPostsPRO::get_instance(); // check if it's time to take action if (!is_single($post->ID)) { return; } if ($plugin->isInExcludedPostTypes($post) || $plugin->isInExcludedTaxonomies($post)) { return; } // Fill missing options if (empty($instance)) { $instance = erpPRODefaults::$comOpts + erpPRODefaults::$widOpts; } else { $instance = $instance + erpPRODefaults::$comOpts + erpPRODefaults::$widOpts; } erpPROPaths::requireOnce(erpPROPaths::$erpProRelated); erpPROPaths::requireOnce(erpPROPaths::$erpPROMainOpts); erpPROPaths::requireOnce(erpPROPaths::$erpPROWidOpts); $mainOpts = new erpPROMainOpts(); $instance['tags'] = $mainOpts->getTags(); $instance['categories'] = $mainOpts->getCategories(); $instance['postTypes'] = $mainOpts->getPostTypes(); $widOpts = new erpPROWidOpts($instance); // Get related $relatedObj = erpProRelated::get_instance($widOpts); $wpQ = $relatedObj->getRelated($post->ID); // If we have some posts to show if (!$wpQ->have_posts()) { $this->displayEmptyWidget($args, $instance); } erpPROPaths::requireOnce(erpPROPaths::$VPluginThemeFactory); VPluginThemeFactory::registerThemeInPathRecursive(erpPROPaths::getAbsPath(erpPROPaths::$widgetThemesFolder), $instance['dsplLayout']); $theme = VPluginThemeFactory::getThemeByName($instance['dsplLayout'], 'widget'); if (!$theme) { return $this->displayEmptyWidget($args, $instance); } $theme->setOptions($instance); $theme->formPostData($wpQ, $widOpts, $relatedObj->getRatingsFromRelDataObj()); $content = $theme->renderW($this->number); // display rel content echo $args['before_widget']; echo $args['before_title'] . $instance['title'] . $args['after_title']; echo $content; echo $args['after_widget']; }