/** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args * Widget arguments. * @param array $instance * Saved values from database. * @since 2.0.0 * @author Panagiotis Vagenas <*****@*****.**> */ public function widget($args, $instance) { global $post; // get instance of main plugin $plugin = easyRelatedPosts::get_instance(); // check if it's time to take action if (is_single($post->ID)) { if ($plugin->isInExcludedPostTypes($post) || $plugin->isInExcludedTaxonomies($post)) { return; } // Fill missing options if (empty($instance)) { $instance = erpDefaults::$comOpts + erpDefaults::$widOpts; } else { $instance = $instance + erpDefaults::$comOpts + erpDefaults::$widOpts; } erpPaths::requireOnce(erpPaths::$erpRelated); erpPaths::requireOnce(erpPaths::$erpMainOpts); erpPaths::requireOnce(erpPaths::$erpWidOpts); $mainOpts = new erpMainOpts(); $instance['tags'] = $mainOpts->getTags(); $instance['categories'] = $mainOpts->getCategories(); $instance['postTypes'] = $mainOpts->getPostTypes(); $widOpts = new erpWidOpts($instance); // Get related $relatedObj = erpRelated::get_instance($widOpts); $wpQ = $relatedObj->getRelated($post->ID); // If we have some posts to show if ($wpQ->have_posts()) { // Get template instance for the specific widget number erpPaths::requireOnce(erpPaths::$VPluginThemeFactory); VPluginThemeFactory::registerThemeInPathRecursive(erpPaths::getAbsPath(erpPaths::$widgetThemesFolder), $instance['dsplLayout']); $theme = VPluginThemeFactory::getThemeByName($instance['dsplLayout']); if (!$theme) { return $this->displayEmptyWidget($args, $instance); } $theme->setOptions($instance); $theme->formPostData($wpQ, $widOpts, $relatedObj->getRatingsFromRelDataObj()); $content = $theme->renderW($this->number); echo $args['before_widget']; echo $args['before_title'] . $instance['title'] . $args['after_title']; echo $content; echo $args['after_widget']; } else { // else diplay empty widget $this->displayEmptyWidget($args, $instance); } } }
/** * Initialize the plugin by loading admin scripts & styles and adding a * settings page and menu. * * @since 2.0.0 */ private function __construct() { /** * ***************************************************** * admin class should only be available for super admins * ***************************************************** */ if (!is_super_admin()) { return; } /** * ****************************************************** * Call $plugin_slug from public plugin class. * ***************************************************** */ $plugin = easyRelatedPosts::get_instance(); $this->plugin_slug = $plugin->get_plugin_slug(); // Load admin style sheet and JavaScript. add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles')); add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts')); /** * ****************************************************** * Add the options page and menu item. * ***************************************************** */ add_action('admin_menu', array($this, 'add_plugin_admin_menu')); /** * ****************************************************** * Add an action link pointing to the options page. * ***************************************************** */ $plugin_basename = plugin_basename(plugin_dir_path(__DIR__) . 'easy_related_posts.php'); add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links')); /** * ****************************************************** * Save options * ***************************************************** */ add_action('admin_post_save_' . EPR_MAIN_OPTIONS_ARRAY_NAME, array($this, 'saveOptions')); /** * ****************************************************** * Ajax hooks * ***************************************************** */ add_action('wp_ajax_loadTemplateOptions', array($this, 'loadTemplateOptions')); }