Plugin Directory

Changeset 2674358


Ignore:
Timestamp:
02/07/2022 03:11:21 PM (4 years ago)
Author:
wupo
Message:

## [2.0.0] - 2022-02-07
### Added

  • New licensing system with plugin updates from within WordPress
  • Compatibility with WooCommerce 6.1.x and WordPress 5.9.x
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wupo-group-attributes/trunk/includes/class-wugrat.php

    r2674325 r2674358  
    1515 * @author     wupo
    1616 */
    17 class Wugrat
    18 {
    19     /**
    20      * The loader that's responsible for maintaining and registering all hooks that power
    21      * the plugin.
    22      *
    23      * @since    1.0.0
    24      * @access   protected
    25      * @var      Wugrat_Loader    $loader    Maintains and registers all hooks for the plugin.
    26      */
    27     protected  $loader ;
    28     /**
    29      * The unique identifier of this plugin.
    30      *
    31      * @since    1.0.0
    32      * @access   protected
    33      * @var      string    $plugin_name    The string used to uniquely identify this plugin.
    34      */
    35     protected  $plugin_name ;
    36     /**
    37      * The current version of the plugin.
    38      *
    39      * @since    1.0.0
    40      * @access   protected
    41      * @var      string    $version    The current version of the plugin.
    42      */
    43     protected  $version ;
    44     /**
    45      * Define the core functionality of the plugin.
    46      *
    47      * Set the plugin name and the plugin version that can be used throughout the plugin.
    48      * Load the dependencies, define the locale, and set the hooks for the admin area and
    49      * the public-facing side of the site.
    50      *
    51      * @since    1.0.0
    52      */
    53     public function __construct()
    54     {
    55         if ( defined( 'WUGRAT_NAME' ) ) {
    56             $this->plugin_name = WUGRAT_NAME;
    57         }
    58        
     17class Wugrat {
     18
     19    /**
     20     * The loader that's responsible for maintaining and registering all hooks that power
     21     * the plugin.
     22     *
     23     * @since    1.0.0
     24     * @access   protected
     25     * @var      Wugrat_Loader    $loader    Maintains and registers all hooks for the plugin.
     26     */
     27    protected $loader;
     28
     29    /**
     30     * The unique identifier of this plugin.
     31     *
     32     * @since    1.0.0
     33     * @access   protected
     34     * @var      string    $plugin_name    The string used to uniquely identify this plugin.
     35     */
     36    protected $plugin_name;
     37
     38    /**
     39     * The current version of the plugin.
     40     *
     41     * @since    1.0.0
     42     * @access   protected
     43     * @var      string    $version    The current version of the plugin.
     44     */
     45    protected $version;
     46
     47    /**
     48     * Define the core functionality of the plugin.
     49     *
     50     * Set the plugin name and the plugin version that can be used throughout the plugin.
     51     * Load the dependencies, define the locale, and set the hooks for the admin area and
     52     * the public-facing side of the site.
     53     *
     54     * @since    1.0.0
     55     */
     56    public function __construct() {
     57        if ( defined( 'WUGRAT_NAME' ) ) {
     58            $this->plugin_name = WUGRAT_NAME;
     59        }
    5960        if ( defined( 'WUGRAT_VERSION' ) ) {
    6061            $this->version = WUGRAT_VERSION;
     
    6263            $this->version = '1.0.0';
    6364        }
    64        
    65         $this->load_dependencies();
    66         $this->set_locale();
    67         $this->define_admin_hooks();
    68         $this->define_public_hooks();
    69     }
    70    
    71     /**
    72      * Load the required dependencies for this plugin.
    73      *
    74      * Include the following files that make up the plugin:
    75      *
    76      * - Wugrat_Loader. Orchestrates the hooks of the plugin.
    77      * - Wugrat_i18n. Defines internationalization functionality.
    78      * - Wugrat_Admin. Defines all hooks for the admin area.
    79      * - Wugrat_Public. Defines all hooks for the public side of the site.
    80      *
    81      * Create an instance of the loader which will be used to register the hooks
    82      * with WordPress.
    83      *
    84      * @since    1.0.0
    85      * @access   private
    86      */
    87     private function load_dependencies()
    88     {
    89         /**
    90          * The class responsible for orchestrating the actions and filters of the
    91          * core plugin.
    92          */
    93         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wugrat-loader.php';
    94         /**
    95          * The class responsible for defining internationalization functionality
    96          * of the plugin.
    97          */
    98         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wugrat-i18n.php';
    99         /**
    100          * The class responsible for defining all actions that occur in the admin area.
    101          */
     65
     66        $this->load_dependencies();
     67        $this->set_locale();
     68        $this->define_admin_hooks();
     69        $this->define_public_hooks();
     70    }
     71
     72    /**
     73     * Load the required dependencies for this plugin.
     74     *
     75     * Include the following files that make up the plugin:
     76     *
     77     * - Wugrat_Loader. Orchestrates the hooks of the plugin.
     78     * - Wugrat_i18n. Defines internationalization functionality.
     79     * - Wugrat_Admin. Defines all hooks for the admin area.
     80     * - Wugrat_Public. Defines all hooks for the public side of the site.
     81     *
     82     * Create an instance of the loader which will be used to register the hooks
     83     * with WordPress.
     84     *
     85     * @since    1.0.0
     86     * @access   private
     87     */
     88    private function load_dependencies() {
     89        /**
     90         * The class responsible for orchestrating the actions and filters of the
     91         * core plugin.
     92         */
     93        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wugrat-loader.php';
     94
     95        /**
     96         * The class responsible for defining internationalization functionality
     97         * of the plugin.
     98         */
     99        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wugrat-i18n.php';
     100
     101        /**
     102         * The class responsible for defining all actions that occur in the admin area.
     103         */
    102104        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wugrat-admin.php';
    103         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wugrat-pro-admin.php';
    104         /**
    105         * The class responsible for defining all actions that occur in the public-facing
    106         * side of the site.
    107         */
     105
     106        /**
     107        * The class responsible for defining all actions that occur in the public-facing
     108        * side of the site.
     109        */
    108110        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wugrat-public.php';
    109         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wugrat-pro-public.php';
    110         $this->loader = new Wugrat_Loader();
    111     }
    112    
    113     /**
    114      * Define the locale for this plugin for internationalization.
    115      *
    116      * Uses the Wugrat_Pro_i18n class in order to set the domain and to register the hook
    117      * with WordPress.
    118      *
    119      * @since    1.0.0
    120      * @access   private
    121      */
    122     private function set_locale()
    123     {
    124         $plugin_i18n = new Wugrat_i18n();
    125         $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
    126     }
    127    
    128     /**
    129      * Register all of the hooks related to the admin area functionality
    130      * of the plugin.
    131      *
    132      * @since    1.0.0
    133      * @access   private
    134      */
    135     private function define_admin_hooks()
    136     {
    137         $plugin_admin = new Wugrat_Admin( 'wugrat', $this->get_version() );
    138         // Free Version
     111
     112        if (wugrat_fs()->can_use_premium_code__premium_only()) {
     113            require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wugrat-pro-admin.php';
     114            require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wugrat-pro-public.php';
     115        }
     116
     117        $this->loader = new Wugrat_Loader();
     118    }
     119
     120    /**
     121     * Define the locale for this plugin for internationalization.
     122     *
     123     * Uses the Wugrat_Pro_i18n class in order to set the domain and to register the hook
     124     * with WordPress.
     125     *
     126     * @since    1.0.0
     127     * @access   private
     128     */
     129    private function set_locale() {
     130        $plugin_i18n = new Wugrat_i18n();
     131
     132        $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
     133    }
     134
     135    /**
     136     * Register all of the hooks related to the admin area functionality
     137     * of the plugin.
     138     *
     139     * @since    1.0.0
     140     * @access   private
     141     */
     142    private function define_admin_hooks() {
     143        $plugin_admin = new Wugrat_Admin('wugrat', $this->get_version());
     144
     145        // Free Version
    139146        // ************
     147
    140148        // Datamodel
    141         $this->loader->add_action( 'init', $plugin_admin, 'register_taxonomy_wugrat_group' );
     149        $this->loader->add_action('init', $plugin_admin, 'register_taxonomy_wugrat_group');
     150
    142151        // Scripts
    143         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_style' );
    144         $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_script' );
    145         $this->loader->add_action( 'admin_head', $plugin_admin, 'enqueue_script_function' );
     152        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_style');
     153        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_script');
     154        $this->loader->add_action('admin_head', $plugin_admin, 'enqueue_script_function');
     155
    146156        // Admin UI
    147         $this->loader->add_action( 'admin_menu', $plugin_admin, 'submenu_group_add' );
    148         $this->loader->add_action( 'parent_file', $plugin_admin, 'submenu_group_highlight_when_active' );
    149         $this->loader->add_filter(
    150             'woocommerce_settings_tabs_array',
    151             $plugin_admin,
    152             'wc_settings_wugrat_tab_add',
    153             50
    154         );
    155         $this->loader->add_filter( 'woocommerce_settings_tabs_wugrat_settings_tab', $plugin_admin, 'wc_settings_wugrat_tab' );
    156         $this->loader->add_filter( 'woocommerce_update_options_wugrat_settings_tab', $plugin_admin, 'wc_settings_wugrat_tab_save' );
    157         $this->loader->add_action( 'admin_init', $plugin_admin, 'wc_settings_wugrat_tab_save_initial' );
    158         $this->loader->add_filter( 'plugin_action_links_' . WUGRAT_BASENAME, $plugin_admin, 'add_link_to_settings_on_plugin_page' );
     157        $this->loader->add_action('admin_menu', $plugin_admin, 'submenu_group_add');
     158        $this->loader->add_action('parent_file', $plugin_admin, 'submenu_group_highlight_when_active');
     159        $this->loader->add_filter('woocommerce_settings_tabs_array', $plugin_admin, 'wc_settings_wugrat_tab_add', 50);
     160        $this->loader->add_filter('woocommerce_settings_tabs_wugrat_settings_tab', $plugin_admin, 'wc_settings_wugrat_tab');
     161        $this->loader->add_filter('woocommerce_update_options_wugrat_settings_tab', $plugin_admin, 'wc_settings_wugrat_tab_save');
     162        $this->loader->add_action('admin_init', $plugin_admin, 'wc_settings_wugrat_tab_save_initial');
     163        $this->loader->add_filter('plugin_action_links_'.WUGRAT_BASENAME, $plugin_admin, 'add_link_to_settings_on_plugin_page');
     164
    159165        // Admin Wugrat Group
    160         $this->loader->add_action( 'admin_init', $plugin_admin, 'group_customize_table' );
    161         $this->loader->add_filter(
    162             'get_terms',
    163             $plugin_admin,
    164             'group_table_sorting',
    165             10,
    166             3
    167         );
    168         $this->loader->add_action( 'create_wugrat_group', $plugin_admin, 'group_create_term' );
    169         $this->loader->add_action( 'delete_wugrat_group', $plugin_admin, 'group_delete_term' );
     166        $this->loader->add_action('admin_init', $plugin_admin, 'group_customize_table');
     167        $this->loader->add_filter('get_terms', $plugin_admin, 'group_table_sorting', 10, 3);
     168        $this->loader->add_action('create_wugrat_group', $plugin_admin, 'group_create_term');
     169        $this->loader->add_action('delete_wugrat_group', $plugin_admin, 'group_delete_term');
     170
    170171        // Admin Attributes Edit
    171         $this->loader->add_action(
    172             'woocommerce_attribute_updated',
    173             $plugin_admin,
    174             'group_update_children_reference',
    175             10,
    176             3
    177         );
     172        $this->loader->add_action('woocommerce_attribute_updated', $plugin_admin, 'group_update_children_reference', 10, 3);
     173
    178174        // Admin Product Edit
    179         $this->loader->add_action( 'woocommerce_product_options_attributes', $plugin_admin, 'product_edit_add_group_attribute_toolbar' );
    180         $this->loader->add_action(
    181             'woocommerce_after_product_attribute_settings',
    182             $plugin_admin,
    183             'product_edit_add_group_name_to_single_attribute_metabox',
    184             10,
    185             2
    186         );
     175        $this->loader->add_action('woocommerce_product_options_attributes', $plugin_admin, 'product_edit_add_group_attribute_toolbar');
     176        $this->loader->add_action('woocommerce_after_product_attribute_settings', $plugin_admin, 'product_edit_add_group_name_to_single_attribute_metabox', 10, 2);
     177
    187178        // Admin AJAX
    188         $this->loader->add_action( 'wp_ajax_wugrat_add_attribute_group', $plugin_admin, 'ajax_add_attribute_group' );
    189         $this->loader->add_action( 'wp_ajax_wugrat_group_attributes_ordering', $plugin_admin, 'ajax_group_attributes_ordering' );
    190     }
    191    
    192     /**
    193      * Register all of the hooks related to the public-facing functionality
    194      * of the plugin.
    195      *
    196      * @since    1.0.0
    197      * @access   private
    198      */
    199     private function define_public_hooks()
    200     {
    201         // Free Version
     179        $this->loader->add_action('wp_ajax_wugrat_add_attribute_group', $plugin_admin, 'ajax_add_attribute_group');
     180        $this->loader->add_action('wp_ajax_wugrat_group_attributes_ordering', $plugin_admin, 'ajax_group_attributes_ordering');
     181
     182
     183        // Pro Version
     184        // ***********
     185
     186        if ( wugrat_fs()->can_use_premium_code__premium_only() ) {
     187            $plugin_admin_pro = new Wugrat_Pro_Admin( $this->get_plugin_name(), $this->get_version() );
     188
     189            // Datamodel
     190            $this->loader->add_action( 'init', $plugin_admin_pro, 'register_taxonomy_wugrat_group_set' );
     191
     192            // Scripts
     193            $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin_pro, 'enqueue_style' );
     194            $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin_pro, 'enqueue_script' );
     195            $this->loader->add_action( 'admin_head', $plugin_admin_pro, 'enqueue_script_function' );
     196
     197            // Admin UI
     198            $this->loader->add_action( 'admin_menu', $plugin_admin_pro, 'submenu_group_set_add' );
     199            $this->loader->add_action( 'parent_file', $plugin_admin_pro, 'submenu_group_set_highlight_when_active' );
     200
     201            // Admin Wugrat Group Set
     202            $this->loader->add_action( 'admin_init', $plugin_admin_pro, 'group_set_customize_table' );
     203
     204            // Admin Attributes Edit
     205
     206            // Admin Product Edit
     207
     208            // Admin AJAX
     209            $this->loader->add_action( 'wp_ajax_wugrat_add_attribute_group_set', $plugin_admin_pro, 'ajax_add_attribute_group_set' );
     210        }
     211    }
     212
     213    /**
     214     * Register all of the hooks related to the public-facing functionality
     215     * of the plugin.
     216     *
     217     * @since    1.0.0
     218     * @access   private
     219     */
     220    private function define_public_hooks() {
     221        // Free Version
    202222        // ************
    203         $plugin_public = new Wugrat_Public( 'wugrat', $this->get_version() );
    204         $is_plugin_active = get_option( 'wc_wugrat_settings_tab_general_enable_wugrat' );
     223
     224        $plugin_public = new Wugrat_Public('wugrat', $this->get_version());
     225
     226        $is_plugin_active = get_option('wc_wugrat_settings_tab_general_enable_wugrat');
     227
    205228        // Scripts
    206         $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
    207         $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
     229        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
     230        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
     231
    208232        // Product rendering
    209        
    210         if ( $is_plugin_active === 'yes' ) {
    211             $layout_id = get_option( 'wc_wugrat_settings_tab_styling_layout' );
    212             if ( wugrat_fs()->is_free_plan() || $layout_id == 1 ) {
    213                 $this->loader->add_filter(
    214                     'woocommerce_display_product_attributes',
    215                     $plugin_public,
    216                     'wugrat_display_product_attributes',
    217                     10,
    218                     2
    219                 );
     233        if ($is_plugin_active === 'yes') {
     234            $layout_id = get_option('wc_wugrat_settings_tab_styling_layout');
     235
     236            if (wugrat_fs()->is_free_plan() || $layout_id == 1) {
     237                $this->loader->add_filter('woocommerce_display_product_attributes', $plugin_public, 'wugrat_display_product_attributes', 10, 2);
    220238            }
    221239        }
    222    
    223     }
    224    
    225     /**
    226      * Run the loader to execute all of the hooks with WordPress.
    227      *
    228      * @since    1.0.0
    229      */
    230     public function run()
    231     {
    232         $this->loader->run();
    233     }
    234    
    235     /**
    236      * The name of the plugin used to uniquely identify it within the context of
    237      * WordPress and to define internationalization functionality.
    238      *
    239      * @since     1.0.0
    240      * @return    string    The name of the plugin.
    241      */
    242     public function get_plugin_name()
    243     {
    244         return $this->plugin_name;
    245     }
    246    
    247     /**
    248      * The reference to the class that orchestrates the hooks with the plugin.
    249      *
    250      * @since     1.0.0
    251      * @return    Wugrat_Loader    Orchestrates the hooks of the plugin.
    252      */
    253     public function get_loader()
    254     {
    255         return $this->loader;
    256     }
    257    
    258     /**
    259      * Retrieve the version number of the plugin.
    260      *
    261      * @since     1.0.0
    262      * @return    string    The version number of the plugin.
    263      */
    264     public function get_version()
    265     {
    266         return $this->version;
    267     }
    268 
     240
     241
     242        // Pro Version
     243        // ***********
     244        if ( wugrat_fs()->can_use_premium_code__premium_only() ) {
     245            $plugin_public_pro = new Wugrat_Pro_Public( $this->get_plugin_name(), $this->get_version() );
     246
     247            // Scripts
     248            $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public_pro, 'enqueue_styles' );
     249            $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public_pro, 'enqueue_scripts' );
     250
     251            // Product rendering
     252            if ( $is_plugin_active === 'yes' ) {
     253                $layout_id = get_option( 'wc_wugrat_settings_tab_styling_layout' );
     254
     255                if ( $layout_id > 1 ) {
     256                    $this->loader->add_filter( 'woocommerce_display_product_attributes', $plugin_public_pro, 'wugrat_pro_display_product_attributes', 10, 2 );
     257                }
     258
     259                $this->loader->add_filter( 'wc_get_template', $plugin_public_pro, 'template_select_layout', 10, 3 );
     260            }
     261
     262            add_shortcode( 'wugrat_attributes', array( $plugin_public_pro, 'shortcode_attribute_group' ) );
     263        }
     264    }
     265
     266    /**
     267     * Run the loader to execute all of the hooks with WordPress.
     268     *
     269     * @since    1.0.0
     270     */
     271    public function run() {
     272        $this->loader->run();
     273    }
     274
     275    /**
     276     * The name of the plugin used to uniquely identify it within the context of
     277     * WordPress and to define internationalization functionality.
     278     *
     279     * @since     1.0.0
     280     * @return    string    The name of the plugin.
     281     */
     282    public function get_plugin_name() {
     283        return $this->plugin_name;
     284    }
     285
     286    /**
     287     * The reference to the class that orchestrates the hooks with the plugin.
     288     *
     289     * @since     1.0.0
     290     * @return    Wugrat_Loader    Orchestrates the hooks of the plugin.
     291     */
     292    public function get_loader() {
     293        return $this->loader;
     294    }
     295
     296    /**
     297     * Retrieve the version number of the plugin.
     298     *
     299     * @since     1.0.0
     300     * @return    string    The version number of the plugin.
     301     */
     302    public function get_version() {
     303        return $this->version;
     304    }
    269305}
Note: See TracChangeset for help on using the changeset viewer.