| @@ -32,8 +32,10 @@ | ||
| 32 | 32 | public function __construct() { |
| 33 | 33 | // Includes. |
| 34 | 34 | $this->includes(); |
| 35 | 35 | |
| 36 | + add_action( 'plugins_loaded', array( $this, 'maybe_define_awl_constant' ), 5 ); | |
| 37 | + | |
| 36 | 38 | // Register scripts. |
| 37 | 39 | add_action( 'wp_enqueue_scripts', array( $this, 'register_global_js_and_css' ) ); |
| 38 | 40 | |
| 39 | 41 | // Enqueue scripts. |
| @@ -40,8 +42,17 @@ | ||
| 40 | 42 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles_scripts' ) ); |
| 41 | 43 | |
| 42 | 44 | // Add identifier to body class. |
| 43 | 45 | add_filter( 'body_class', array( $this, 'add_body_class' ) ); |
| 46 | + | |
| 47 | + // Add row meta to the plugin screen. | |
| 48 | + add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); | |
| 49 | + | |
| 50 | + // Add settings link to the plugin screen. | |
| 51 | + add_filter( 'plugin_action_links_' . plugin_basename( MERCHANT_DIR . 'merchant.php' ), array( $this, 'settings_link' ) ); | |
| 52 | + | |
| 53 | + // WP Abilities API integration. | |
| 54 | + add_action( 'plugins_loaded', array( $this, 'load_abilities_bootstrap' ), 20 ); | |
| 44 | 55 | } |
| 45 | 56 | |
| 46 | 57 | /** |
| 47 | 58 | * Include required classes. |
| @@ -46,8 +57,9 @@ | ||
| 46 | 57 | /** |
| 47 | 58 | * Include required classes. |
| 48 | 59 | */ |
| 49 | 60 | public function includes() { |
| 61 | + | |
| 50 | 62 | // Essential functions. |
| 51 | 63 | require_once MERCHANT_DIR . 'inc/functions.php'; |
| 52 | 64 | |
| 53 | 65 | // Helpers. |
| @@ -67,8 +79,10 @@ | ||
| 67 | 79 | require_once MERCHANT_DIR . 'inc/classes/class-merchant-option.php'; |
| 68 | 80 | require_once MERCHANT_DIR . 'inc/classes/class-merchant-modules.php'; |
| 69 | 81 | require_once MERCHANT_DIR . 'inc/classes/class-merchant-custom-css.php'; |
| 70 | 82 | require_once MERCHANT_DIR . 'inc/classes/class-merchant-svg-icons.php'; |
| 83 | + require_once MERCHANT_DIR . 'inc/classes/class-merchant-db-tables.php'; | |
| 84 | + require_once MERCHANT_DIR . 'inc/classes/class-merchant-general-hooks.php'; | |
| 71 | 85 | |
| 72 | 86 | // Metabox |
| 73 | 87 | require_once MERCHANT_DIR . 'inc/classes/class-merchant-metabox.php'; |
| 74 | 88 | |
| @@ -77,8 +91,39 @@ | ||
| 77 | 91 | |
| 78 | 92 | // Modules global settings. |
| 79 | 93 | require_once MERCHANT_DIR . 'inc/modules/global-settings/global-settings.php'; |
| 80 | 94 | |
| 95 | + // Modules analytics | |
| 96 | + require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-db-orm.php'; | |
| 97 | + require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-logger.php'; | |
| 98 | + require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-data-provider.php'; | |
| 99 | + require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-data-reports.php'; | |
| 100 | + require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-data-ajax.php'; | |
| 101 | + require_once MERCHANT_DIR . 'inc/analytics/class-merchant-analytics-data-hooks.php'; | |
| 102 | + | |
| 103 | + // Usage Tracking. | |
| 104 | + require_once MERCHANT_DIR . 'inc/usage-tracking/class-merchant-usage-tracking.php'; | |
| 105 | + require_once MERCHANT_DIR . 'inc/usage-tracking/class-merchant-send-usage-task.php'; | |
| 106 | + | |
| 107 | + /* | |
| 108 | + * Action Scheduler requires a special loading procedure. | |
| 109 | + * Load on plugins_loaded to ensure it's available before init. | |
| 110 | + * | |
| 111 | + * @since {VERSION} | |
| 112 | + */ | |
| 113 | + add_action( | |
| 114 | + 'plugins_loaded', | |
| 115 | + static function() { | |
| 116 | + | |
| 117 | + //Check if Action Scheduler is already loaded. | |
| 118 | + if ( function_exists( 'as_schedule_recurring_action' ) ) { | |
| 119 | + return; | |
| 120 | + } | |
| 121 | + | |
| 122 | + require_once MERCHANT_DIR . 'vendor/woocommerce/action-scheduler/action-scheduler.php'; | |
| 123 | + }, | |
| 124 | + ); | |
| 125 | + | |
| 81 | 126 | // Modules (free and pro). |
| 82 | 127 | foreach ( Merchant_Admin_Modules::$modules_data as $module_id => $module_data ) { |
| 83 | 128 | if ( |
| 84 | 129 | defined( 'MERCHANT_PRO_VERSION' ) |
| @@ -102,8 +147,12 @@ | ||
| 102 | 147 | require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-blocksy-theme.php'; |
| 103 | 148 | require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-flatsome-theme.php'; |
| 104 | 149 | require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-breakdance-builder.php'; |
| 105 | 150 | require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-elementor-builder.php'; |
| 151 | + require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-bricks-builder.php'; | |
| 152 | + require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-woo-payments-plugin.php'; | |
| 153 | + require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-ohio-theme.php'; | |
| 154 | + require_once MERCHANT_DIR . 'inc/compatibility/class-merchant-woo-multi-currency.php'; | |
| 106 | 155 | |
| 107 | 156 | /** |
| 108 | 157 | * Hook 'merchant_admin_after_include_modules_classes'. |
| 109 | 158 | * |
| @@ -112,8 +161,23 @@ | ||
| 112 | 161 | do_action( 'merchant_admin_after_include_modules_classes' ); |
| 113 | 162 | } |
| 114 | 163 | |
| 115 | 164 | /** |
| 165 | + * Define MERCHANT_AWL_ACTIVE when White Label is applied. | |
| 166 | + * | |
| 167 | + * @return void | |
| 168 | + */ | |
| 169 | + public function maybe_define_awl_constant() { | |
| 170 | + if ( defined( 'MERCHANT_AWL_ACTIVE' ) ) { | |
| 171 | + return; | |
| 172 | + } | |
| 173 | + | |
| 174 | + if ( merchant_white_label_is_applied() ) { | |
| 175 | + define( 'MERCHANT_AWL_ACTIVE', true ); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + | |
| 179 | + /** | |
| 116 | 180 | * Add to body class. |
| 117 | 181 | */ |
| 118 | 182 | public function add_body_class( $classes ) { |
| 119 | 183 | $theme = wp_get_theme(); |
| @@ -125,8 +189,132 @@ | ||
| 125 | 189 | return $classes; |
| 126 | 190 | } |
| 127 | 191 | |
| 128 | 192 | /** |
| 193 | + * Bootstrap the WP Abilities API integration. | |
| 194 | + * | |
| 195 | + * Only loads on WordPress 6.9+ where the Abilities API exists. | |
| 196 | + * Zero overhead on older WordPress versions. | |
| 197 | + * | |
| 198 | + * @since 2.3.0 | |
| 199 | + */ | |
| 200 | + public function load_abilities_bootstrap() { | |
| 201 | + if ( ! function_exists( 'wp_register_ability' ) ) { | |
| 202 | + return; | |
| 203 | + } | |
| 204 | + | |
| 205 | + require_once MERCHANT_DIR . 'inc/abilities/class-merchant-abilities-bootstrap.php'; | |
| 206 | + Merchant_Abilities_Bootstrap::init(); | |
| 207 | + } | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * Show row meta on the plugin screen. | |
| 211 | + * | |
| 212 | + * @param mixed $links Plugin Row Meta. | |
| 213 | + * @param mixed $file Plugin Base file. | |
| 214 | + * | |
| 215 | + * @since 2.1.2 | |
| 216 | + * | |
| 217 | + * @return array | |
| 218 | + */ | |
| 219 | + public function plugin_row_meta($links, $file) { | |
| 220 | + if ( plugin_basename( MERCHANT_FILE ) !== $file ) { | |
| 221 | + return $links; | |
| 222 | + } | |
| 223 | + | |
| 224 | + /** | |
| 225 | + * The Merchant documentation URL. | |
| 226 | + * | |
| 227 | + * @since 2.1.2 | |
| 228 | + */ | |
| 229 | + $docs_url = apply_filters( 'merchant_docs_url', 'https://docs.athemes.com/documentation/merchant/' ); | |
| 230 | + | |
| 231 | + /** | |
| 232 | + * The Merchant landing page URL. | |
| 233 | + * | |
| 234 | + * @since 2.1.2 | |
| 235 | + */ | |
| 236 | + $plugin_site = apply_filters( 'merchant_plugin_site_url', 'https://athemes.com/merchant/' ); | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * The Merchant changelog URL. | |
| 240 | + * | |
| 241 | + * @since 2.1.2 | |
| 242 | + */ | |
| 243 | + $changelog = apply_filters( 'merchant_changelog_url', 'https://athemes.com/changelog/merchant/' ); | |
| 244 | + | |
| 245 | + $row_meta = array( | |
| 246 | + 'docs' => '<a href="' . esc_url( $docs_url ) . '" aria-label="' . esc_attr__( 'View Merchant documentation', 'merchant' ) . '" target="_blank">' . esc_html__( | |
| 247 | + 'Docs', | |
| 248 | + 'merchant' | |
| 249 | + ) . '</a>', | |
| 250 | + 'apidocs' => '<a href="' . esc_url( $plugin_site ) . '" aria-label="' . esc_attr__( 'View Merchant plugin site', 'merchant' ) . '" target="_blank">' . esc_html__( | |
| 251 | + 'Visit plugin site', | |
| 252 | + 'merchant' ) . '</a>', | |
| 253 | + 'support' => '<a href="' . esc_url( $changelog ) . '" aria-label="' . esc_attr__( 'View Merchant changelog', 'merchant' ) . '" target="_blank">' . esc_html__( 'Changelog', | |
| 254 | + 'merchant' ) . '</a>', | |
| 255 | + ); | |
| 256 | + | |
| 257 | + /** | |
| 258 | + * Filter the plugin row meta links. | |
| 259 | + * | |
| 260 | + * @since 2.1.2 | |
| 261 | + * | |
| 262 | + * @param array $row_meta The plugin row meta links. | |
| 263 | + * @param string $file The plugin file. | |
| 264 | + */ | |
| 265 | + $row_meta = apply_filters( 'merchant_plugin_row_meta', $row_meta, $file ); | |
| 266 | + | |
| 267 | + return array_merge( $links, $row_meta ); | |
| 268 | + } | |
| 269 | + | |
| 270 | + /** | |
| 271 | + * Add settings link to the Plugins page. | |
| 272 | + * | |
| 273 | + * @since 2.1.2 | |
| 274 | + * | |
| 275 | + * @param array $links Plugin row links. | |
| 276 | + * | |
| 277 | + * @return array $links | |
| 278 | + */ | |
| 279 | + public function settings_link( $links ) { | |
| 280 | + if ( ! merchant_pro_is_active() ) { | |
| 281 | + $url = merchant_admin_upgrade_link( | |
| 282 | + 'https://athemes.com/merchant/#pricing', | |
| 283 | + array(), | |
| 284 | + 'plugins-page-upgrade-link' | |
| 285 | + ); | |
| 286 | + $links['merchant-pro'] = sprintf( | |
| 287 | + '<a href="%1$s" aria-label="%2$s" target="_blank" rel="noopener noreferrer" | |
| 288 | + style="color: #00a32a; font-weight: 700;" | |
| 289 | + onmouseover="this.style.color=\'#008a20\';" | |
| 290 | + onmouseout="this.style.color=\'#00a32a\';" | |
| 291 | + >%3$s</a>', | |
| 292 | + esc_url( $url ), | |
| 293 | + esc_attr__( 'Upgrade to Merchant Pro', 'merchant' ), | |
| 294 | + esc_html__( 'Get Merchant Pro', 'merchant' ) | |
| 295 | + ); | |
| 296 | + } | |
| 297 | + | |
| 298 | + $custom['merchant-settings'] = sprintf( | |
| 299 | + '<a href="%s" aria-label="%s">%s</a>', | |
| 300 | + esc_url( | |
| 301 | + add_query_arg( | |
| 302 | + array( | |
| 303 | + 'page' => 'merchant', | |
| 304 | + 'section' => 'settings', | |
| 305 | + ), | |
| 306 | + admin_url( 'admin.php' ) | |
| 307 | + ) | |
| 308 | + ), | |
| 309 | + esc_attr__( 'Go to Merchant Settings page', 'merchant' ), | |
| 310 | + esc_html__( 'Settings', 'merchant' ) | |
| 311 | + ); | |
| 312 | + | |
| 313 | + return array_merge( $custom, (array) $links ); | |
| 314 | + } | |
| 315 | + | |
| 316 | + /** | |
| 129 | 317 | * Register scripts. |
| 130 | 318 | * Scripts that might be used by multiple modules should be registered here. |
| 131 | 319 | * |
| 132 | 320 | */ |
| @@ -304,18 +492,8 @@ | ||
| 304 | 492 | if ( Merchant_Modules::is_module_active( 'scroll-to-top-button' ) ) { |
| 305 | 493 | $setting['scroll_to_top'] = true; |
| 306 | 494 | } |
| 307 | 495 | |
| 308 | - // Animated Add to Cart | |
| 309 | - // TODO: Move this to the respective module class. | |
| 310 | - if ( Merchant_Modules::is_module_active( 'animated-add-to-cart' ) ) { | |
| 311 | - $trigger = Merchant_Admin_Options::get( 'animated-add-to-cart', 'trigger', 'on-mouse-hover' ); | |
| 312 | - | |
| 313 | - if ( 'on-page-load' === $trigger ) { | |
| 314 | - wp_enqueue_script( 'merchant-animated-add-to-cart', MERCHANT_URI . 'assets/js/modules/animated-add-to-cart.js', array( 'merchant' ), MERCHANT_VERSION, true ); | |
| 315 | - } | |
| 316 | - } | |
| 317 | - | |
| 318 | 496 | // Auto External Links |
| 319 | 497 | // TODO: Move this to the respective module class. |
| 320 | 498 | if ( Merchant_Modules::is_module_active( 'auto-external-links' ) ) { |
| 321 | 499 | $setting['auto_external_links'] = true; |
| @@ -326,19 +504,8 @@ | ||
| 326 | 504 | $setting['cookie_banner'] = true; |
| 327 | 505 | $setting['cookie_banner_duration'] = Merchant_Admin_Options::get( 'cookie-banner', 'cookie_duration', 365 ); |
| 328 | 506 | } |
| 329 | 507 | |
| 330 | - // Real Time Search | |
| 331 | - // TODO: Move this to the respective module class. | |
| 332 | - if ( Merchant_Modules::is_module_active( 'real-time-search' ) ) { | |
| 333 | - $setting['ajax_search'] = true; | |
| 334 | - $setting['ajax_search_results_amounth_per_search'] = Merchant_Admin_Options::get( 'real-time-search', 'results_amounth_per_search', 15 ); | |
| 335 | - $setting['ajax_search_results_order_by'] = Merchant_Admin_Options::get( 'real-time-search', 'results_order_by', 'title' ); | |
| 336 | - $setting['ajax_search_results_order'] = Merchant_Admin_Options::get( 'real-time-search', 'results_order', 'asc' ); | |
| 337 | - $setting['ajax_search_results_display_categories'] = Merchant_Admin_Options::get( 'real-time-search', 'display_categories', 0 ); | |
| 338 | - $setting['ajax_search_results_enable_search_by_sku'] = Merchant_Admin_Options::get( 'real-time-search', 'enable_search_by_sku', 0 ); | |
| 339 | - } | |
| 340 | - | |
| 341 | 508 | /** |
| 342 | 509 | * Hook 'merchant_enqueue_after_main_css_js' |
| 343 | 510 | * |
| 344 | 511 | * @since 1.0 |
| @@ -354,8 +521,13 @@ | ||
| 354 | 521 | |
| 355 | 522 | wp_localize_script( 'merchant', 'merchant', array( |
| 356 | 523 | 'general' => array( |
| 357 | 524 | 'wooCurrencySymbol' => class_exists( 'Woocommerce' ) ? html_entity_decode( get_woocommerce_currency_symbol() ) : '', |
| 525 | + 'wooCurrencyPosition' => class_exists( 'Woocommerce' ) ? get_option( 'woocommerce_currency_pos' ) : 'left', | |
| 526 | + 'wooThousandsSeparator' => class_exists( 'Woocommerce' ) ? wc_get_price_thousand_separator() : ',', | |
| 527 | + 'wooDecimalSeparator' => class_exists( 'Woocommerce' ) ? wc_get_price_decimal_separator() : '.', | |
| 528 | + 'wooNumberOfDecimals' => class_exists( 'Woocommerce' ) ? wc_get_price_decimals() : 2, | |
| 529 | + | |
| 358 | 530 | ), |
| 359 | 531 | 'setting' => $setting, |
| 360 | 532 | ) ); |
| 361 | 533 | } |