PluginProbe
GutSlider – All in One Slider and Carousel Blocks for Gutenberg / 2.11.3
GutSlider – All in One Slider and Carousel Blocks for Gutenberg v2.11.3
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 2.6.1 All 56 releases
slider-blocks / includes / Plugin.php

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

156 lines 3.3 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 Assets\EnqueueAssets();
73 new Assets\LoadFonts();
74 new Style\DynamicStyle();
75 new Api\BlocksApi();
76 }
77
78 /**
79 * Handle post-activation redirect to the welcome page.
80 *
81 * Checks for the activation flag in options and redirects to the
82 * plugin's admin page on first admin page load after activation.
83 *
84 * @since 3.0.0
85 *
86 * @return void
87 */
88 public function maybe_redirect_after_activation(): void {
89 if ( get_option( 'gutsliderblocks_do_activation_redirect', false ) ) {
90 delete_option( 'gutsliderblocks_do_activation_redirect' );
91 wp_safe_redirect( admin_url( 'admin.php?page=gutslider-blocks' ) );
92 exit;
93 }
94 }
95
96 /**
97 * Set the activation redirect flag.
98 *
99 * Called on plugin activation via register_activation_hook.
100 *
101 * @since 3.0.0
102 *
103 * @return void
104 */
105 public static function on_activation(): void {
106 add_option( 'gutsliderblocks_do_activation_redirect', true );
107 }
108
109 /**
110 * Clean up plugin data on deactivation.
111 *
112 * Removes generated CSS files and their directory from the
113 * WordPress uploads folder.
114 *
115 * @since 3.0.0
116 *
117 * @return void
118 */
119 public static function cleanup(): void {
120 $upload_dir = wp_upload_dir();
121 $css_dir = $upload_dir['basedir'] . '/gutslider-styles';
122
123 if ( ! file_exists( $css_dir ) ) {
124 return;
125 }
126
127 global $wp_filesystem;
128
129 if ( empty( $wp_filesystem ) ) {
130 require_once ABSPATH . '/wp-admin/includes/file.php';
131 WP_Filesystem();
132 }
133
134 $files = glob( $css_dir . '/*' );
135
136 if ( is_array( $files ) ) {
137 foreach ( $files as $file ) {
138 if ( is_file( $file ) ) {
139 $wp_filesystem->delete( $file );
140 }
141 }
142 }
143
144 $wp_filesystem->rmdir( $css_dir );
145
146 // Remove parent directory if empty.
147 $parent_dir = dirname( $css_dir );
148 if ( file_exists( $parent_dir ) ) {
149 $parent_contents = glob( "$parent_dir/*" );
150 if ( is_array( $parent_contents ) && count( $parent_contents ) === 0 ) {
151 $wp_filesystem->rmdir( $parent_dir );
152 }
153 }
154 }
155 }
156