PluginProbe
Slider Block by Sliderberg – Slider & Carousel Plugin for Block Editor / 1.2.0
Slider Block by Sliderberg – Slider & Carousel Plugin for Block Editor v1.2.0
1.2.2 1.2.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.7 1.0.8 1.0.9
sliderberg / sliderberg.php

sliderberg.php in Slider Block by Sliderberg – Slider & Carousel Plugin for Block Editor 1.2.0, at sliderberg.php

207 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Sliderberg
4 * Plugin URI: https://sliderberg.com/
5 * Description: Slider Block For the Block Editor (Gutenberg). Slide Anything With Ease.
6 * Version: 1.2.0
7 * Author: DotCamp
8 * Author URI: https://dotcamp.com/
9 * License: GPL v2 or later
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: sliderberg
12 * Domain Path: /languages
13 */
14
15 // If this file is called directly, abort.
16 if (!defined('WPINC')) {
17 die;
18 }
19
20 // Define plugin constants
21 define( 'SLIDERBERG_VERSION', '1.2.0' );
22 define('SLIDERBERG_PLUGIN_DIR', plugin_dir_path(__FILE__));
23 define('SLIDERBERG_PLUGIN_URL', plugin_dir_url(__FILE__));
24
25 if ( ! function_exists( 'sli_fs' ) ) {
26 // Create a helper function for easy SDK access.
27 function sli_fs() {
28 global $sli_fs;
29
30 if ( ! isset( $sli_fs ) ) {
31 // Include Freemius SDK.
32 require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
33 $sli_fs = fs_dynamic_init( array(
34 'id' => '19340',
35 'slug' => 'sliderberg',
36 'type' => 'plugin',
37 'public_key' => 'pk_f6a90542b187793a33ebb75752ce7', // This is a public key, safe to expose
38 'is_premium' => false,
39 'has_addons' => false,
40 'has_paid_plans' => false,
41 'menu' => array(
42 'slug' => 'sliderberg-welcome',
43 'contact' => false,
44 ),
45 ) );
46 }
47
48 return $sli_fs;
49 }
50
51 // Init Freemius.
52 sli_fs();
53 // Signal that SDK was initiated.
54 do_action( 'sli_fs_loaded' );
55 }
56
57 // Include security helpers (must load before admin-welcome.php)
58 require_once SLIDERBERG_PLUGIN_DIR . 'includes/security.php';
59
60 // Include admin welcome page
61 require_once SLIDERBERG_PLUGIN_DIR . 'includes/admin-welcome.php';
62
63 // Include slider and slide renderer
64 require_once SLIDERBERG_PLUGIN_DIR . 'includes/slider-renderer.php';
65 require_once SLIDERBERG_PLUGIN_DIR . 'includes/slide-renderer.php';
66
67 // Include review handler
68 require_once SLIDERBERG_PLUGIN_DIR . 'includes/class-review-handler.php';
69
70 /**
71 * Registers the block using the metadata loaded from the `block.json` file.
72 * Behind the scenes, it registers also all assets so they can be enqueued
73 * through the block editor in the corresponding context.
74 *
75 * @see https://developer.wordpress.org/reference/functions/register_block_type/
76 */
77 function sliderberg_init() {
78
79 // Version assets by file modification time to avoid cache issues
80 $style_version = file_exists( SLIDERBERG_PLUGIN_DIR . 'build/style-index.css' ) ? filemtime( SLIDERBERG_PLUGIN_DIR . 'build/style-index.css' ) : SLIDERBERG_VERSION;
81 $editor_version = file_exists( SLIDERBERG_PLUGIN_DIR . 'build/index.css' ) ? filemtime( SLIDERBERG_PLUGIN_DIR . 'build/index.css' ) : SLIDERBERG_VERSION;
82 $view_version = file_exists( SLIDERBERG_PLUGIN_DIR . 'build/view.js' ) ? filemtime( SLIDERBERG_PLUGIN_DIR . 'build/view.js' ) : SLIDERBERG_VERSION;
83 $editor_js_version = file_exists( SLIDERBERG_PLUGIN_DIR . 'build/index.js' ) ? filemtime( SLIDERBERG_PLUGIN_DIR . 'build/index.js' ) : SLIDERBERG_VERSION;
84
85 // Load editor script dependencies from asset file
86 $editor_asset_file = SLIDERBERG_PLUGIN_DIR . 'build/index.asset.php';
87 $editor_dependencies = array('wp-blocks', 'wp-element', 'wp-editor');
88 if ( file_exists( $editor_asset_file ) ) {
89 $editor_asset = require $editor_asset_file;
90 $editor_dependencies = isset( $editor_asset['dependencies'] ) ? $editor_asset['dependencies'] : $editor_dependencies;
91 }
92
93 // Register editor script FIRST (required by block.json)
94 wp_register_script(
95 'sliderberg-editor',
96 SLIDERBERG_PLUGIN_URL . 'build/index.js',
97 $editor_dependencies,
98 $editor_js_version,
99 true
100 );
101
102 // Register block styles
103 wp_register_style(
104 'sliderberg-style',
105 SLIDERBERG_PLUGIN_URL . 'build/style-index.css',
106 array(),
107 $style_version
108 );
109
110 // Register editor styles
111 wp_register_style(
112 'sliderberg-editor',
113 SLIDERBERG_PLUGIN_URL . 'build/index.css',
114 array(),
115 $editor_version
116 );
117
118 // Register view script and styles (includes Swiper CSS)
119 $view_css_version = file_exists( SLIDERBERG_PLUGIN_DIR . 'build/view.css' ) ? filemtime( SLIDERBERG_PLUGIN_DIR . 'build/view.css' ) : SLIDERBERG_VERSION;
120
121 wp_register_style(
122 'sliderberg-view',
123 SLIDERBERG_PLUGIN_URL . 'build/view.css',
124 array(),
125 $view_css_version
126 );
127
128 wp_register_script(
129 'sliderberg-view',
130 SLIDERBERG_PLUGIN_URL . 'build/view.js',
131 array(),
132 $view_version,
133 true
134 );
135
136 // Register blocks AFTER assets are registered
137 // Register slider block with PHP rendering
138 sliderberg_register_slider_block();
139
140 // Register slide block with PHP rendering
141 sliderberg_register_slide_block();
142 }
143 add_action('init', 'sliderberg_init');
144
145 // Initialize review handler
146 add_action('init', function() {
147 new \SliderBerg\Review_Handler();
148 });
149
150 // Load plugin text domain
151 add_action('plugins_loaded', function() {
152 load_plugin_textdomain('sliderberg', false, dirname(plugin_basename(__FILE__)) . '/languages');
153 });
154
155 // Enqueue editor assets
156 function sliderberg_editor_assets() {
157 wp_enqueue_script( 'sliderberg-editor' );
158
159 // Pass pro status and upgrade URL to the editor JS.
160 // isPro is true when the pro plugin is active and its class is loaded.
161 $is_pro = class_exists( 'SliderbergPro\Pro_Features' );
162 $upgrade_url = 'https://sliderberg.com/pricing/';
163
164 // Scan assets/images/upsell/ and build a feature-key → URL map.
165 // Drop any image named by feature key (e.g. cube-effect.gif) there; no rebuild needed.
166 $images_dir = plugin_dir_path( __FILE__ ) . 'assets/images/upsell/';
167 $images_url = plugins_url( 'assets/images/upsell/', __FILE__ );
168 $upsell_images = array();
169
170 if ( is_dir( $images_dir ) ) {
171 $allowed_ext = array( 'gif', 'png', 'jpg', 'jpeg', 'webp', 'svg' );
172 foreach ( glob( $images_dir . '*' ) as $file ) {
173 $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
174 if ( in_array( $ext, $allowed_ext, true ) ) {
175 $key = pathinfo( $file, PATHINFO_FILENAME );
176 $upsell_images[ $key ] = $images_url . basename( $file );
177 }
178 }
179 }
180
181 wp_localize_script(
182 'sliderberg-editor',
183 'sliderbergData',
184 array(
185 'isPro' => $is_pro,
186 'upgradeUrl' => esc_url( $upgrade_url ),
187 'upsellImages' => $upsell_images,
188 )
189 );
190 }
191 add_action( 'enqueue_block_editor_assets', 'sliderberg_editor_assets' );
192
193 // Enqueue frontend assets
194 function sliderberg_frontend_assets() {
195 // Only enqueue if we have sliderberg blocks on the page
196 if (has_block('sliderberg/sliderberg')) {
197 wp_enqueue_style('sliderberg-style');
198 wp_enqueue_style('sliderberg-view');
199 wp_enqueue_script('sliderberg-view');
200
201 // Pro add-ons can enqueue wp-hooks here to enable frontend filters:
202 // wp_enqueue_script('wp-hooks');
203 }
204 }
205 add_action('wp_enqueue_scripts', 'sliderberg_frontend_assets');
206
207