| @@ -1,78 +1,143 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Plugin Name: GutSlider - All in One Slider Blocks for Gutenberg | |
| 3 | + * Plugin Name: GutSlider - All in One Block Slider for Gutenberg | |
| 4 | 4 | * Description: A collection of custom Gutenberg Slider Blocks to slide your content. |
| 5 | 5 | * Requires at least: 6.5 |
| 6 | 6 | * Requires PHP: 7.4 |
| 7 | - * Version: 3.1.0 | |
| 8 | - * Author: Binsaifullah | |
| 7 | + * Version: 2.9.7 | |
| 8 | + * Author: Gutenbergkits | |
| 9 | + * Author URI: https://gutenbergkits.com | |
| 9 | 10 | * License: GPLv2 or later |
| 10 | 11 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 | 12 | * Text Domain: slider-blocks |
| 12 | 13 | * |
| 13 | - * @package GutSlider | |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 17 | - exit; | |
| 18 | -} | |
| 16 | +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. | |
| 19 | 17 | |
| 20 | 18 | /** |
| 21 | - * Plugin version constant. | |
| 22 | - * | |
| 23 | - * @since 1.0.0 | |
| 24 | - * @var string | |
| 19 | + * Blocks Final Class | |
| 20 | + * return GutSliderBlocks | |
| 25 | 21 | */ |
| 26 | -define( 'GUTSLIDER_VERSION', '3.1.0' ); | |
| 22 | + if( ! class_exists( 'GutSliderBlocks' ) ) { | |
| 27 | 23 | |
| 28 | -/** | |
| 29 | - * Plugin directory URL with trailing slash. | |
| 30 | - * | |
| 31 | - * @since 1.0.0 | |
| 32 | - * @var string | |
| 33 | - */ | |
| 34 | -define( 'GUTSLIDER_URL', plugin_dir_url( __FILE__ ) ); | |
| 24 | + final class GutSliderBlocks { | |
| 35 | 25 | |
| 36 | -/** | |
| 37 | - * Plugin directory path with trailing slash. | |
| 38 | - * | |
| 39 | - * @since 1.0.0 | |
| 40 | - * @var string | |
| 41 | - */ | |
| 42 | -define( 'GUTSLIDER_DIR_PATH', plugin_dir_path( __FILE__ ) ); | |
| 26 | + private static $instance = null; | |
| 43 | 27 | |
| 44 | -/** | |
| 45 | - * Plugin directory path without trailing slash. | |
| 46 | - * | |
| 47 | - * @since 1.0.0 | |
| 48 | - * @var string | |
| 49 | - */ | |
| 50 | -define( 'GUTSLIDER_DIR', __DIR__ ); | |
| 28 | + /** | |
| 29 | + * The constructor function initializes constants, includes necessary files, loads a text domain, and | |
| 30 | + * sets up activation redirection for a PHP class. | |
| 31 | + */ | |
| 32 | + private function __construct() { | |
| 33 | + $this->define_constants(); | |
| 34 | + $this->includes(); | |
| 35 | + add_action( 'init', [ $this, 'load_textdomain' ] ); | |
| 36 | + register_activation_hook( __FILE__, [ $this, 'set_activation_redirect' ] ); | |
| 37 | + add_action( 'admin_init', [ $this, 'redirect_to_welcome_page' ] ); | |
| 38 | + } | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Define the plugin constants | |
| 42 | + * return void | |
| 43 | + */ | |
| 44 | + private function define_constants() { | |
| 45 | + define( 'GUTSLIDER_VERSION', '2.9.7' ); | |
| 46 | + define( 'GUTSLIDER_URL', plugin_dir_url( __FILE__ ) ); | |
| 47 | + define('GUTSLIDER_DIR_PATH', plugin_dir_path(__FILE__)); | |
| 48 | + define( 'GUTSLIDER_DIR', __DIR__ ); | |
| 49 | + } | |
| 51 | 50 | |
| 52 | -// Load PSR-4 autoloader. | |
| 53 | -require_once GUTSLIDER_DIR . '/includes/Autoloader.php'; | |
| 54 | -( new GutSlider_Autoloader( GUTSLIDER_DIR . '/includes/' ) )->register(); | |
| 51 | + /** | |
| 52 | + * Initialize the plugin | |
| 53 | + * return GutSliderBlocks | |
| 54 | + */ | |
| 55 | + public static function init() { | |
| 56 | + if( is_null( self::$instance ) ) { | |
| 57 | + self::$instance = new self(); | |
| 58 | + } | |
| 59 | + return self::$instance; | |
| 60 | + } | |
| 55 | 61 | |
| 56 | -// Load backward-compatibility global functions. | |
| 57 | -require_once GUTSLIDER_DIR . '/includes/compat.php'; | |
| 62 | + /** | |
| 63 | + * Include the files | |
| 64 | + * return void | |
| 65 | + */ | |
| 66 | + public function includes() { | |
| 67 | + require_once GUTSLIDER_DIR . '/includes/init.php'; | |
| 68 | + require_once GUTSLIDER_DIR . '/admin/admin.php'; | |
| 69 | + } | |
| 58 | 70 | |
| 59 | -// Load admin (outside refactoring scope). | |
| 60 | -require_once GUTSLIDER_DIR . '/admin/admin.php'; | |
| 71 | + /** | |
| 72 | + * Load the plugin text domain | |
| 73 | + * return void | |
| 74 | + */ | |
| 75 | + public function load_textdomain() { | |
| 76 | + load_plugin_textdomain( 'slider-blocks', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); | |
| 77 | + } | |
| 61 | 78 | |
| 62 | -// Register activation and deactivation hooks. | |
| 63 | -register_activation_hook( __FILE__, array( GutSlider\Plugin::class, 'on_activation' ) ); | |
| 64 | -register_deactivation_hook( __FILE__, array( GutSlider\Plugin::class, 'cleanup' ) ); | |
| 79 | + /** | |
| 80 | + * Set the activation redirect | |
| 81 | + * return void | |
| 82 | + */ | |
| 83 | + public function set_activation_redirect() { | |
| 84 | + add_option( 'gutsliderblocks_do_activation_redirect', true ); | |
| 85 | + } | |
| 65 | 86 | |
| 66 | -/** | |
| 67 | - * Return the main plugin singleton instance. | |
| 68 | - * | |
| 69 | - * @since 1.0.0 | |
| 70 | - * | |
| 71 | - * @return GutSlider\Plugin The plugin instance. | |
| 72 | - */ | |
| 73 | -function gutsliderblocks(): GutSlider\Plugin { | |
| 74 | - return GutSlider\Plugin::get_instance(); | |
| 75 | -} | |
| 87 | + /** | |
| 88 | + * Redirect to the welcome page | |
| 89 | + * return void | |
| 90 | + */ | |
| 91 | + public function redirect_to_welcome_page() { | |
| 92 | + if ( is_admin() && get_option( 'gutsliderblocks_do_activation_redirect', false ) ) { | |
| 93 | + delete_option( 'gutsliderblocks_do_activation_redirect' ); | |
| 94 | + wp_safe_redirect( admin_url( 'admin.php?page=gutslider-blocks' ) ); | |
| 95 | + exit; // Added exit after redirect | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * Cleanup the plugin data | |
| 101 | + * return void | |
| 102 | + */ | |
| 103 | + public static function cleanup() { | |
| 104 | + $upload_dir = wp_upload_dir(); | |
| 105 | + $css_dir = $upload_dir['basedir'] . '/gutslider-styles'; | |
| 76 | 106 | |
| 77 | -// Boot the plugin. | |
| 78 | -gutsliderblocks(); | |
| 107 | + if ( file_exists( $css_dir ) ) { | |
| 108 | + global $wp_filesystem; | |
| 109 | + if ( empty( $wp_filesystem ) ) { | |
| 110 | + require_once( ABSPATH . '/wp-admin/includes/file.php' ); | |
| 111 | + WP_Filesystem(); | |
| 112 | + } | |
| 113 | + | |
| 114 | + $files = glob( $css_dir . '/*' ); | |
| 115 | + foreach ( $files as $file ) { | |
| 116 | + if ( is_file( $file ) ) { | |
| 117 | + $wp_filesystem->delete( $file ); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + $wp_filesystem->rmdir( $css_dir ); | |
| 121 | + } | |
| 122 | + | |
| 123 | + // Remove parent directory if it's empty | |
| 124 | + $parent_dir = dirname( $css_dir ); | |
| 125 | + if ( file_exists( $parent_dir ) && ( count( glob( "$parent_dir/*" ) ) === 0 ) ) { | |
| 126 | + $wp_filesystem->rmdir( $parent_dir ); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + } | |
| 131 | + | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * Initialize the GutSliderBlocks | |
| 136 | + * return GutSliderBlocks | |
| 137 | + */ | |
| 138 | + function gutsliderblocks() { | |
| 139 | + return GutSliderBlocks::init(); | |
| 140 | + } | |
| 141 | + | |
| 142 | + // kick-off the plugin | |
| 143 | + gutsliderblocks(); | |