PluginProbe ʕ •ᴥ•ʔ
XML Feed for Skroutz & BestPrice for WooCommerce / 1.0.3
XML Feed for Skroutz & BestPrice for WooCommerce v1.0.3
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.3 1.2.4
xml-feed-for-skroutz-for-woocommerce / includes / class-dc-skroutz-feed.php
xml-feed-for-skroutz-for-woocommerce / includes Last commit date
class-dc-skroutz-feed-activator.php 1 year ago class-dc-skroutz-feed-cli.php 1 year ago class-dc-skroutz-feed-i18n.php 1 year ago class-dc-skroutz-feed-loader.php 1 year ago class-dc-skroutz-feed.php 1 year ago dicha-skroutz-feed-create-cron.php 1 year ago index.php 1 year ago
class-dc-skroutz-feed.php
205 lines
1 <?php
2
3 /**
4 * The core plugin class.
5 *
6 * This is used to define internationalization, admin-specific hooks, and
7 * public-facing site hooks.
8 */
9 class Dicha_Skroutz_Feed {
10
11 /**
12 * The loader that's responsible for maintaining and registering all hooks that power
13 * the plugin.
14 *
15 * @var Dicha_Skroutz_Feed_Loader $loader Maintains and registers all hooks for the plugin.
16 */
17 protected $loader;
18
19 /**
20 * The unique identifier of this plugin.
21 *
22 * @var string $plugin_name The string used to uniquely identify this plugin.
23 */
24 protected $plugin_name;
25
26 /**
27 * The current version of the plugin.
28 *
29 * @var string $version The current version of the plugin.
30 */
31 protected $version;
32
33 /**
34 * Define the core functionality of the plugin.
35 *
36 * Set the plugin name and the plugin version that can be used throughout the plugin.
37 * Load the dependencies, define the locale, and set the hooks for the admin area and
38 * the public-facing side of the site.
39 */
40 public function __construct() {
41
42 $this->version = defined( 'DICHA_SKROUTZ_FEED_VERSION' ) ? DICHA_SKROUTZ_FEED_VERSION : '1.0.0';
43 $this->plugin_name = defined( 'DICHA_SKROUTZ_FEED_SLUG' ) ? DICHA_SKROUTZ_FEED_SLUG : 'xml-feed-for-skroutz-for-woocommerce';
44
45 $this->load_dependencies();
46 $this->set_locale();
47 $this->define_admin_hooks();
48 $this->define_feed_generation_hooks();
49 }
50
51 /**
52 * Load the required dependencies for this plugin.
53 *
54 * Include the following files that make up the plugin:
55 *
56 * - Dicha_Skroutz_Feed_Loader. Orchestrates the hooks of the plugin.
57 * - Dicha_Skroutz_Feed_i18n. Defines internationalization functionality.
58 * - Dicha_Skroutz_Feed_Admin. Defines all hooks for the admin area.
59 *
60 * Create an instance of the loader which will be used to register the hooks
61 * with WordPress.
62 */
63 private function load_dependencies() {
64
65 /**
66 * The class responsible for orchestrating the actions and filters of the
67 * core plugin.
68 */
69 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-dc-skroutz-feed-loader.php';
70
71 /**
72 * The class responsible for defining internationalization functionality
73 * of the plugin.
74 */
75 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-dc-skroutz-feed-i18n.php';
76
77 /**
78 * The class responsible for defining all actions that occur in the admin area.
79 */
80 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-dc-skroutz-feed-admin.php';
81 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-dc-skroutz-feed-creator.php';
82
83 /**
84 * The class responsible for WP CLI commands.
85 */
86 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-dc-skroutz-feed-cli.php';
87
88 $this->loader = new Dicha_Skroutz_Feed_Loader();
89 }
90
91 /**
92 * Define the locale for this plugin for internationalization.
93 *
94 * Uses the Dicha_Skroutz_Feed_i18n class in order to set the domain and to register the hook
95 * with WordPress.
96 */
97 private function set_locale() {
98
99 $plugin_i18n = new Dicha_Skroutz_Feed_i18n();
100
101 $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
102 }
103
104 /**
105 * Register all hooks related to the admin area functionality of the plugin.
106 */
107 private function define_admin_hooks() {
108
109 $plugin_admin = new Dicha_Skroutz_Feed_Admin( $this->get_plugin_name(), $this->get_version() );
110
111 // menu and settings hooks
112 if ( ( isset( $_GET['page'] ) && $_GET['page'] === $this->plugin_name ) || wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ?? '' ) ), 'dicha_skroutz_feed_option_group-options' ) ) {
113 $this->loader->add_action( 'admin_init', $plugin_admin, 'register_plugin_settings' );
114 $this->loader->add_action( 'digital_challenge_plugin_settings', $plugin_admin, 'render_plugin_settings' );
115 }
116
117 if ( isset( $_GET['page'] ) && $_GET['page'] === 'digital_challenge_plugins' && has_action( 'digital_challenge_plugin_settings' ) === false ) {
118 $this->loader->add_action( 'digital_challenge_plugin_settings', $plugin_admin, 'dc_render_settings_homepage' );
119 }
120
121 $this->loader->add_action( 'admin_menu', $plugin_admin, 'create_dc_toplevel_menu' );
122 $this->loader->add_action( 'digital_challenge_plugin_settings_tabs', $plugin_admin, 'create_plugin_settings_tab' );
123 $this->loader->add_action( 'admin_post_save_settings', $plugin_admin, 'save_settings' );
124 $this->loader->add_filter( 'plugin_action_links', $plugin_admin, 'add_plugin_action_links', 10, 2 );
125
126 // declare WC compatibilities
127 $this->loader->add_action( 'before_woocommerce_init', $plugin_admin, 'declare_compatibility_with_wc_features' );
128
129 // Product tabs and custom product/variation fields
130 $this->loader->add_filter( 'woocommerce_product_data_tabs', $plugin_admin, 'register_new_exports_tab' );
131 $this->loader->add_filter( 'woocommerce_product_data_panels', $plugin_admin, 'print_exports_tab_content' );
132 $this->loader->add_action( 'woocommerce_product_options_sku', $plugin_admin, 'add_ean_field_under_sku', 50 );
133 $this->loader->add_action( 'woocommerce_process_product_meta', $plugin_admin, 'save_product_custom_fields' );
134 $this->loader->add_action( 'woocommerce_variation_options_dimensions', $plugin_admin, 'print_variation_custom_fields', 10, 3 );
135 $this->loader->add_action( 'woocommerce_save_product_variation', $plugin_admin, 'save_variation_custom_fields', 10, 2 );
136
137
138 // Product list filters and new availability column
139 $this->loader->add_filter( 'manage_product_posts_columns', $plugin_admin, 'register_availability_column' );
140 $this->loader->add_filter( 'manage_product_posts_custom_column', $plugin_admin, 'fill_availability_column', 10, 2 );
141 $this->loader->add_action( 'restrict_manage_posts', $plugin_admin, 'print_custom_fields_filter_in_admin_list', 99 );
142 $this->loader->add_filter( 'parse_query', $plugin_admin, 'filter_by_custom_fields_query_mod' );
143
144
145 // Quick edit and bulk edit actions for Skroutz Availability field
146 $this->loader->add_action( 'woocommerce_product_quick_edit_end', $plugin_admin, 'add_availability_field_to_quick_edit_box', 20 );
147 $this->loader->add_action( 'woocommerce_product_bulk_edit_end', $plugin_admin, 'add_availability_field_to_bulk_edit_box' );
148 $this->loader->add_action( 'save_post', $plugin_admin, 'quick_and_bulk_edit_save_availability' );
149
150
151 // enqueues
152 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
153 $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
154 }
155
156 /**
157 * Register all hooks related to the XML feed generation.
158 */
159 private function define_feed_generation_hooks() {
160
161 $plugin_feed = new Dicha_Skroutz_Feed_Creator();
162
163 // feed generation related hooks
164 $this->loader->add_action( 'dicha_skroutz_feed_generation', $plugin_feed, 'create_feed' );
165 $this->loader->add_action( 'admin_post_dicha_skroutz_feed_create_feed', $plugin_feed, 'create_feed_manual_mode' );
166 $this->loader->add_filter( 'woocommerce_product_data_store_cpt_get_products_query', $plugin_feed, 'handle_skroutz_products_query_vars', 10, 2 );
167 }
168
169
170 /**
171 * Run the loader to execute all hooks with WordPress.
172 */
173 public function run() {
174 $this->loader->run();
175 }
176
177 /**
178 * The name of the plugin used to uniquely identify it within the context of
179 * WordPress and to define internationalization functionality.
180 *
181 * @return string The name of the plugin.
182 */
183 public function get_plugin_name() {
184 return $this->plugin_name;
185 }
186
187 /**
188 * The reference to the class that orchestrates the hooks with the plugin.
189 *
190 * @return Dicha_Skroutz_Feed_Loader Orchestrates the hooks of the plugin.
191 */
192 public function get_loader() {
193 return $this->loader;
194 }
195
196 /**
197 * Retrieve the version number of the plugin.
198 *
199 * @return string The version number of the plugin.
200 */
201 public function get_version() {
202 return $this->version;
203 }
204 }
205