PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 3.2.0
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v3.2.0
3.2.0 3.1.0 3.0.0 2.13.2 2.13.1 2.13.0 trunk 1.0.0 2.1.0 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.1 2.5.3 2.5.4 2.5.5 All 57 releases
slider-blocks / includes / Plugin.php

Plugin.php in GutSlider – All in One Slider and Carousel Blocks for Gutenberg 3.2.0, at includes/Plugin.php

164 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 declare( strict_types=1 );
3
4 namespace GutSlider;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 /**
11 * Main plugin singleton class.
12 *
13 * Orchestrates the initialization of all plugin components including
14 * block registration, asset enqueuing, REST API, and style generation.
15 *
16 * @package GutSlider
17 * @since 3.0.0
18 */
19 final class Plugin {
20
21 /**
22 * Singleton instance.
23 *
24 * @since 3.0.0
25 * @var self|null
26 */
27 private static ?self $instance = null;
28
29 /**
30 * Private constructor to prevent direct instantiation.
31 *
32 * @since 3.0.0
33 */
34 private function __construct() {}
35
36 /**
37 * Get the singleton instance.
38 *
39 * Creates and initializes the plugin instance on first call.
40 * Subsequent calls return the existing instance.
41 *
42 * @since 3.0.0
43 *
44 * @return self The plugin instance.
45 */
46 public static function get_instance(): self {
47 if ( null === self::$instance ) {
48 self::$instance = new self();
49 self::$instance->init();
50 }
51
52 return self::$instance;
53 }
54
55 /**
56 * Initialize all plugin components.
57 *
58 * Instantiates each component class which registers its own hooks
59 * internally. Also sets up the activation redirect handler.
60 *
61 * @since 3.0.0
62 *
63 * @return void
64 */
65 private function init(): void {
66 // Activation redirect.
67 add_action( 'admin_init', array( $this, 'maybe_redirect_after_activation' ) );
68
69 // Initialize components.
70 new Blocks\BlocksCategory();
71 new Blocks\RegisterBlocks();
72 new Blocks\Pattern();
73 new Blocks\VideoEmbeds();
74 new Blocks\PostSliderRest();
75 new Blocks\PostSlider();
76 new Blocks\TermColors();
77 new Blocks\FlexibleSlider();
78 new Blocks\Marquee();
79 new Blocks\StaticSlider();
80 new Assets\EnqueueAssets();
81 new Assets\LoadFonts();
82 new Style\DynamicStyle();
83 new Api\BlocksApi();
84 }
85
86 /**
87 * Handle post-activation redirect to the welcome page.
88 *
89 * Checks for the activation flag in options and redirects to the
90 * plugin's admin page on first admin page load after activation.
91 *
92 * @since 3.0.0
93 *
94 * @return void
95 */
96 public function maybe_redirect_after_activation(): void {
97 if ( get_option( 'gutsliderblocks_do_activation_redirect', false ) ) {
98 delete_option( 'gutsliderblocks_do_activation_redirect' );
99 wp_safe_redirect( admin_url( 'admin.php?page=gutslider-blocks' ) );
100 exit;
101 }
102 }
103
104 /**
105 * Set the activation redirect flag.
106 *
107 * Called on plugin activation via register_activation_hook.
108 *
109 * @since 3.0.0
110 *
111 * @return void
112 */
113 public static function on_activation(): void {
114 add_option( 'gutsliderblocks_do_activation_redirect', true );
115 }
116
117 /**
118 * Clean up plugin data on deactivation.
119 *
120 * Removes generated CSS files and their directory from the
121 * WordPress uploads folder.
122 *
123 * @since 3.0.0
124 *
125 * @return void
126 */
127 public static function cleanup(): void {
128 $upload_dir = wp_upload_dir();
129 $css_dir = $upload_dir['basedir'] . '/gutslider-styles';
130
131 if ( ! file_exists( $css_dir ) ) {
132 return;
133 }
134
135 global $wp_filesystem;
136
137 if ( empty( $wp_filesystem ) ) {
138 require_once ABSPATH . '/wp-admin/includes/file.php';
139 WP_Filesystem();
140 }
141
142 $files = glob( $css_dir . '/*' );
143
144 if ( is_array( $files ) ) {
145 foreach ( $files as $file ) {
146 if ( is_file( $file ) ) {
147 $wp_filesystem->delete( $file );
148 }
149 }
150 }
151
152 $wp_filesystem->rmdir( $css_dir );
153
154 // Remove parent directory if empty.
155 $parent_dir = dirname( $css_dir );
156 if ( file_exists( $parent_dir ) ) {
157 $parent_contents = glob( "$parent_dir/*" );
158 if ( is_array( $parent_contents ) && count( $parent_contents ) === 0 ) {
159 $wp_filesystem->rmdir( $parent_dir );
160 }
161 }
162 }
163 }
164