/**
 * Register plugin widgets.
 */
function nscw_register_plugin_widgets()
{
    $obj_nscw = NS_Category_Widget::get_instance();
    $nscw_field_enable_ns_category_widget = $obj_nscw->get_option('nscw_field_enable_ns_category_widget');
    if (1 == $nscw_field_enable_ns_category_widget) {
        register_widget('NSCW_Widget');
    }
}
 /**
  * Initialize the plugin by loading admin scripts & styles and adding a
  * settings page and menu.
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     $plugin = NS_Category_Widget::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $this->options = $plugin->get_options_array();
     // 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(realpath(dirname(__FILE__))) . $this->plugin_slug . '.php');
     add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links'));
     /*
      * Define custom functionality.
      */
     add_action('admin_init', array($this, 'plugin_register_settings'));
     if ($this->options['nscw_field_enable_ns_category_widget']) {
         add_action('admin_enqueue_scripts', array($this, 'nscw_scripts_enqueue'));
         add_action('wp_ajax_populate_categories', array($this, 'ns_category_widget_ajax_populate_categories'));
         add_action('wp_ajax_nopriv_populate_categories', array($this, 'ns_category_widget_ajax_populate_categories'));
     }
 }
Example #3
0
    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', $instance['title']);
        $taxonomy = $instance['taxonomy'];
        $parent_category = $instance['parent_category'];
        $depth = $instance['depth'];
        $orderby = $instance['orderby'];
        $order = $instance['order'];
        $hide_empty = $instance['hide_empty'];
        $show_post_count = $instance['show_post_count'];
        $number = $instance['number'];
        $include_category = $instance['include_category'];
        $exclude_category = $instance['exclude_category'];
        if ('' != $exclude_category) {
            $include_category = '';
        }
        $enable_tree = $instance['enable_tree'];
        $tree_show_icons = $instance['tree_show_icons'];
        $tree_show_dots = $instance['tree_show_dots'];
        $tree_save_state = $instance['tree_save_state'];
        echo $before_widget;
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        $cat_args = array('title_li' => '', 'depth' => $depth, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => $hide_empty, 'show_count' => $show_post_count, 'number' => $number, 'include' => $include_category, 'exclude' => $exclude_category, 'taxonomy' => $taxonomy);
        if ($parent_category) {
            $cat_args['child_of'] = $parent_category;
        }
        $class_text = 'nscw-inactive-tree';
        if (1 == $enable_tree) {
            $class_text = 'nscw-active-tree';
        }
        echo '<div class="' . $class_text . '">';
        echo '<ul class="cat-list">';
        wp_list_categories(apply_filters('widget_categories_args', $cat_args));
        echo '</ul>';
        echo '</div>';
        $obj_nscw = NS_Category_Widget::get_instance();
        $nscw_field_enable_tree_script = $obj_nscw->get_option('nscw_field_enable_tree_script');
        if (1 == $enable_tree && 1 == $nscw_field_enable_tree_script) {
            $tree_plugins = array();
            if (1 == $tree_save_state) {
                $tree_plugins[] = 'state';
            }
            ?>
      <script>
        (function ( $ ) {
          "use strict";

          $(function () {

            $('#<?php 
            echo $widget_id;
            ?>
 div').jstree({
              'plugins':[<?php 
            echo '"' . implode('","', $tree_plugins) . '"';
            ?>
],
              'core' : {
                'themes' : {
                  'icons' : <?php 
            echo 1 == $tree_show_icons ? 'true' : 'false';
            ?>
,
                  'dots' : <?php 
            echo 1 == $tree_show_dots ? 'true' : 'false';
            ?>
                }
              }
            });
            //
            $('body').on('click','#<?php 
            echo $widget_id;
            ?>
 div a', function(e){
              window.location = $(this).attr('href');
            });
          });

        }(jQuery));

      </script>
      <?php 
        }
        //end if
        echo $after_widget;
    }
 /**
  * Return an instance of this class.
  *
  * @since     1.0.0
  *
  * @return    object    A single instance of this class.
  */
 public static function get_instance()
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }