PluginProbe
MarqueeX – Smooth Marquee Slider, News Ticker & Post Marquee for Block Editor & Elementor / 0.6.0
MarqueeX – Smooth Marquee Slider, News Ticker & Post Marquee for Block Editor & Elementor v0.6.0
0.6.0 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.0 0.3.3 0.3.2 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.1.0 0.1.1 0.1.2 0.2.0 0.2.1 0.2.2 0.2.3 0.3.0 0.3.1
marqueex / includes / Admin / Enqueue.php

Enqueue.php in MarqueeX – Smooth Marquee Slider, News Ticker & Post Marquee for Block Editor & Elementor 0.6.0, at includes/Admin/Enqueue.php

151 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Wpxero\Marqueex\Admin;
4
5 use Wpxero\Marqueex\Traits\Singleton;
6 use Wpxero\Marqueex\Core\Settings;
7 use Wpxero\Marqueex\MarqueeX;
8 use Wpxero\Marqueex\Core\Upsell;
9
10 if (!defined('ABSPATH')) {
11 exit; // Exit if accessed directly
12 }
13
14 /**
15 * Class Enqueue
16 */
17 class Enqueue {
18 use Singleton;
19
20 /**
21 * Initialize the class
22 */
23 private function __construct() {
24 add_action('admin_enqueue_scripts', [$this, 'enqueue_scripts']);
25 add_action('admin_body_class', [$this, 'add_custom_body_class']);
26 add_action('admin_init', [$this, 'redirect_to_welcome_screen']);
27 add_filter('plugin_action_links_' . plugin_basename(MARQUEEX_FILE), [$this, 'marqueex_settings_link']);
28 }
29
30 public function marqueex_settings_link($links) {
31 $settings_link = '<a href="' . admin_url('admin.php?page=marqueex&sub_page=settings') . '">Settings</a>';
32 array_unshift($links, $settings_link);
33
34 if (Upsell::should_show()) {
35 $links['upgrade'] = sprintf(
36 '<a href="%1$s" style="color:#39b54a;font-weight:700;">%2$s</a>',
37 esc_url(Upsell::url('plugin-row')),
38 esc_html(Upsell::cta_label())
39 );
40 }
41
42 return $links;
43 }
44
45 /**
46 *
47 * Add custom body class to admin pages for Marqueex plugin.
48 *
49 * @param array $classes Existing body classes.
50 * @return array Modified body classes.
51 */
52 // add body class for extenderx
53 public function add_custom_body_class($classes) {
54 // Check if we are on editing screen in WordPress admin
55 if (is_admin() && isset($_GET['action']) && $_GET['action'] === 'edit') { // phpcs:ignore
56 $classes .= ' marqueex-admin-page';
57 }
58 return $classes;
59 }
60
61 /**
62 * Enqueue admin scripts and styles
63 *
64 * @param string $hook_suffix The current admin page.
65 */
66 public function enqueue_scripts($hook_suffix) {
67 // Only load on MarqueeX admin pages
68 if (strpos($hook_suffix, 'marqueex') === false) {
69 return;
70 }
71
72 $admin_assets = MARQUEEX_DIR_PATH . 'admin/dependencies.php';
73 if (file_exists($admin_assets)) {
74 $admin_assets = require $admin_assets;
75
76 wp_enqueue_script(
77 'marqueex-admin',
78 MARQUEEX_ADMIN_URL . 'admin/marqueex-admin.js',
79 $admin_assets['dependencies'],
80 $admin_assets['version'],
81 true
82 );
83
84 // Load translations for the React dashboard. Without this the JS
85 // __() strings never resolve to a locale, even when .json files exist.
86 wp_set_script_translations(
87 'marqueex-admin',
88 'marqueex',
89 MARQUEEX_DIR_PATH . 'languages'
90 );
91
92 // Get current settings deep-merged with the canonical defaults.
93 $complete_settings = Settings::get();
94
95 wp_localize_script(
96 'marqueex-admin',
97 'marqueexAdminData',
98 [
99 'settings' => $complete_settings,
100 'version' => MARQUEEX_VERSION,
101 'ajax_url' => admin_url('admin-ajax.php'),
102 'nonce' => wp_create_nonce('marqueex-admin-nonce'),
103 'rest_url' => rest_url('wpxero/marqueex/v1'),
104 // First-run onboarding panel + footer links.
105 'showOnboarding' => Settings::should_show_onboarding(),
106 'isPremium' => MarqueeX::is_premium_active(),
107 // Whether to offer Pro at all. Distinct from isPremium: a site
108 // can have paid and not yet activated, and should not be sold to.
109 'showUpgrade' => Upsell::should_show(),
110 'upgradeUrl' => Upsell::url('admin-header'),
111 'upgradeLabel' => Upsell::cta_label(),
112 'hasElementor' => class_exists('\\Elementor\\Plugin'),
113 'newPageUrl' => admin_url('post-new.php?post_type=page'),
114 'docsUrl' => 'https://wpxero.com/plugins/marqueex/docs/',
115 'supportUrl' => 'https://wordpress.org/support/plugin/marqueex/',
116 ]
117 );
118
119 wp_enqueue_style(
120 'marqueex-admin',
121 MARQUEEX_ADMIN_URL . 'admin/style-marqueex.css',
122 [],
123 $admin_assets['version']
124 );
125 }
126 }
127 /**
128 * Redirect to Welcome page after activation.
129 */
130 public function redirect_to_welcome_screen() {
131 // Bail if no activation redirect.
132 if (! get_transient('_marqueex_welcome_screen_activation_redirect')) {
133 return;
134 }
135
136 // Delete the redirect transient.
137 delete_transient('_marqueex_welcome_screen_activation_redirect');
138
139 // Bail if activating from network, or bulk.
140 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
141 if (is_network_admin() || isset($_GET['activate-multi'])) {
142 return;
143 }
144
145 // Redirect to the settings screen, where the first-run onboarding panel
146 // greets them above the tabs.
147 wp_safe_redirect(admin_url('admin.php?page=marqueex'));
148 exit;
149 }
150 }
151