| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: SlingBlocks – Gutenberg Blocks by FunnelKit (Formerly WooFunnels) |
| 4 |
* Description: A minimalist Gutenberg Block Plugin that extends Gutenberg to provide page building capabilities. |
| 5 |
* Version: 1.7.0 |
| 6 |
* Text Domain: slingblocks |
| 7 |
* Plugin URI: https://funnelkit.com/ |
| 8 |
* Author: FunnelKit (formerly WooFunnels) |
| 9 |
* Author URI: https://funnelkit.com |
| 10 |
* Domain Path: /languages |
| 11 |
* Requires at least: 5.6 |
| 12 |
* Tested up to: 6.8.1 |
| 13 |
* Requires PHP: 7.2 |
| 14 |
* |
| 15 |
* @package slingblocks |
| 16 |
*/ |
| 17 |
|
| 18 |
defined( 'ABSPATH' ) || exit; |
| 19 |
|
| 20 |
if ( ! class_exists( 'SLINGBLOCKS' ) ) { |
| 21 |
|
| 22 |
/** |
| 23 |
* SLINGBLOCKS |
| 24 |
*/ |
| 25 |
class SLINGBLOCKS { |
| 26 |
|
| 27 |
/** |
| 28 |
* __construct |
| 29 |
* |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
public function __construct() { |
| 33 |
$this->define_constant(); |
| 34 |
add_action( 'plugins_loaded', array( $this, 'plugin_loaded' ) ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Define Constant |
| 39 |
* |
| 40 |
* @return void |
| 41 |
*/ |
| 42 |
public function define_constant() { |
| 43 |
defined( 'SLINGBLOCKS_PLUGIN_VERSION' ) || define( 'SLINGBLOCKS_PLUGIN_VERSION', time() ); |
| 44 |
defined( 'SLINGBLOCKS_PLUGIN_FILE' ) || define( 'SLINGBLOCKS_PLUGIN_FILE', plugin_dir_path( __FILE__ ) ); |
| 45 |
defined( 'SLINGBLOCKS_ABSPATH_URL' ) || define( 'SLINGBLOCKS_ABSPATH_URL', plugin_dir_url( __FILE__ ) ); |
| 46 |
defined( 'SLINGBLOCKS_I18N' ) || define( 'SLINGBLOCKS_I18N', 'slingblocks' ); |
| 47 |
( defined( 'SLINGBLOCKS_IS_DEV' ) && true === SLINGBLOCKS_IS_DEV ) ? define( 'SLINGBLOCKS_VERSION', time() ) : define( 'SLINGBLOCKS_VERSION', SLINGBLOCKS_PLUGIN_VERSION ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Plugin Loaded |
| 52 |
* |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public function plugin_loaded() { |
| 56 |
$this->register_block_categories(); |
| 57 |
$this->load_require_files(); |
| 58 |
|
| 59 |
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) ); |
| 60 |
add_action( 'init', array( $this, 'init_loaded' ), 1 ); |
| 61 |
add_filter( 'admin_body_class', [ $this, 'slb_blocks_admin_body_class' ] ); |
| 62 |
add_action( 'admin_footer', [ $this, 'bwf_render_default_font' ] ); |
| 63 |
|
| 64 |
/** Add theme classes for compatibility detection. */ |
| 65 |
add_action( 'body_class', array( $this, 'bwf_body_class_theme_compatibility' ) ); |
| 66 |
if ( ! is_admin() ) { |
| 67 |
add_action( 'wp_head', array( $this, 'load_page_template_style' ) ); |
| 68 |
add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts_front' ),9999 ); |
| 69 |
add_filter( 'template_include', array( $this, 'wp_template_include' ), 11 /* After Plugins/WooCommerce */ ); |
| 70 |
require_once( plugin_dir_path( __FILE__ ) . 'font/fonts.php' ); |
| 71 |
} |
| 72 |
|
| 73 |
/** Load compatibilities */ |
| 74 |
$this->load_all_compatibilities(); |
| 75 |
} |
| 76 |
|
| 77 |
public function bwf_body_class_theme_compatibility( $classes ) { |
| 78 |
if ( defined( 'ASTRA_THEME_VERSION' ) ) { |
| 79 |
$classes[] = 'slingblocks--is-astra-theme'; |
| 80 |
} else if ( class_exists( 'Blocksy_Translations_Manager' ) ) { |
| 81 |
$classes[] = 'slingblocks--is-blocksy-theme'; |
| 82 |
} else if ( defined( 'NEVE_VERSION' ) ) { |
| 83 |
$classes[] = 'slingblocks--is-neve-theme'; |
| 84 |
} else if ( defined( 'KADENCE_VERSION' ) ) { |
| 85 |
$classes[] = 'slingblocks--is-kadence-theme'; |
| 86 |
} else if ( class_exists( 'Storefront' ) ) { |
| 87 |
$classes[] = 'slingblocks--is-storefront-theme'; |
| 88 |
} |
| 89 |
|
| 90 |
return $classes; |
| 91 |
} |
| 92 |
|
| 93 |
public function load_require_files() { |
| 94 |
//load necessary files |
| 95 |
require_once SLINGBLOCKS_PLUGIN_FILE . 'includes/functions.php'; |
| 96 |
require_once SLINGBLOCKS_PLUGIN_FILE . 'includes/class-slingblocks-css.php'; |
| 97 |
require_once SLINGBLOCKS_PLUGIN_FILE . 'includes/class-slingblocks-frontend-css.php'; |
| 98 |
require_once SLINGBLOCKS_PLUGIN_FILE . 'includes/class-render-blocks.php'; |
| 99 |
} |
| 100 |
|
| 101 |
public function wp_template_include( $template ) { |
| 102 |
if ( ! is_singular() ) { |
| 103 |
return $template; |
| 104 |
} |
| 105 |
|
| 106 |
if ( 'slb-template-boxed' === get_page_template_slug() ) { |
| 107 |
return __DIR__ . '/templates/slb-template-boxed.php'; |
| 108 |
} |
| 109 |
if ( 'slb-template-canvas' === get_page_template_slug() ) { |
| 110 |
return __DIR__ . '/templates/slb-template-canvas.php'; |
| 111 |
} |
| 112 |
|
| 113 |
return $template; |
| 114 |
} |
| 115 |
|
| 116 |
public function init_loaded() { |
| 117 |
// Register Gutenberg Block Meta for default font |
| 118 |
register_post_meta( '', 'bwfblock_default_font', array( |
| 119 |
'show_in_rest' => true, |
| 120 |
'single' => true, |
| 121 |
'type' => 'string', |
| 122 |
) ); |
| 123 |
|
| 124 |
|
| 125 |
// Add Custom Template |
| 126 |
add_filter( 'theme_post_templates', array( $this, 'wp_add_page_templates' ) ); |
| 127 |
add_filter( 'theme_page_templates', array( $this, 'wp_add_page_templates' ) ); |
| 128 |
} |
| 129 |
|
| 130 |
// Add class in editor body |
| 131 |
public function slb_blocks_admin_body_class( $classes ) { |
| 132 |
$screen = get_current_screen(); |
| 133 |
if ( 'post' == $screen->base ) { |
| 134 |
global $post; |
| 135 |
$template_file = get_post_meta( $post->ID, '_wp_page_template', true ); |
| 136 |
$template_canvas = [ |
| 137 |
'slb-template-canvas', //slingblock canvas |
| 138 |
'wflp-canvas.php', // funnel landing canvas |
| 139 |
'wfoty-canvas.php' //funnel Optin thankyou canvas |
| 140 |
]; |
| 141 |
$template_boxed = [ |
| 142 |
'slb-template-boxed', //slingblock boxed |
| 143 |
'wflp-boxed.php', // funnel landing boxed |
| 144 |
'wfoty-boxed.php' //funnel Optin thankyou boxed |
| 145 |
]; |
| 146 |
|
| 147 |
if ( in_array( $template_file, $template_canvas ) ) { |
| 148 |
$classes .= ' slb-editor-width-canvas'; |
| 149 |
} |
| 150 |
if ( in_array( $template_file, $template_boxed ) ) { |
| 151 |
$classes .= ' slb-editor-width-boxed'; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
return $classes; |
| 156 |
} |
| 157 |
|
| 158 |
public function wp_add_page_templates( $page_templates ) { |
| 159 |
$slb_templates = [ |
| 160 |
'slb-template-boxed' => esc_html__( 'Sling Block Boxed', SLINGBLOCKS_I18N ), |
| 161 |
'slb-template-canvas' => esc_html__( 'Sling Block Canvas', SLINGBLOCKS_I18N ), |
| 162 |
]; |
| 163 |
|
| 164 |
return array_merge( $page_templates, $slb_templates ); |
| 165 |
} |
| 166 |
|
| 167 |
public function register_block_categories() { |
| 168 |
if ( version_compare( $GLOBALS['wp_version'], '5.8-alpha-1', '<' ) ) { |
| 169 |
add_filter( 'block_categories', array( $this, 'add_block_categories' ), 10, 2 ); |
| 170 |
|
| 171 |
return; |
| 172 |
} |
| 173 |
add_filter( 'block_categories_all', array( $this, 'add_block_categories' ), 10, 2 ); |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Add Block Category. |
| 178 |
* |
| 179 |
* @param array $categories Block categories. |
| 180 |
* |
| 181 |
* @return array updated categories. |
| 182 |
*/ |
| 183 |
public function add_block_categories( $categories ) { |
| 184 |
return array_merge( array( |
| 185 |
array( |
| 186 |
'slug' => 'slingblocks', |
| 187 |
'title' => esc_html__( 'SlingBlocks', SLINGBLOCKS_I18N ), |
| 188 |
), |
| 189 |
), $categories ); |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Enqueue assets for block. |
| 194 |
*/ |
| 195 |
public function enqueue_block_editor_assets() { |
| 196 |
$app_name = 'slingblocks-editor'; |
| 197 |
$editor_dir = ( defined( 'SLINGBLOCKS_REACT_ENVIRONMENT' ) && 0 == SLINGBLOCKS_REACT_ENVIRONMENT ) ? SLINGBLOCKS_REACT_DEV_URL : plugin_dir_url( __FILE__ ) . 'dist'; |
| 198 |
$assets_path = defined( 'SLINGBLOCKS_REACT_ENVIRONMENT' ) && 1 === SLINGBLOCKS_REACT_ENVIRONMENT ? plugin_dir_url( __FILE__ ) . "dist/$app_name.asset.php" : __DIR__ . "/dist/$app_name.asset.php"; |
| 199 |
$assets = file_exists( $assets_path ) ? include $assets_path : array( |
| 200 |
'dependencies' => array( |
| 201 |
'wp-plugins', |
| 202 |
'wp-element', |
| 203 |
'wp-edit-post', |
| 204 |
'wp-i18n', |
| 205 |
'wp-api-request', |
| 206 |
'wp-data', |
| 207 |
'wp-hooks', |
| 208 |
'wp-plugins', |
| 209 |
'wp-components', |
| 210 |
'wp-blocks', |
| 211 |
'wp-editor', |
| 212 |
'wp-compose', |
| 213 |
'lodash', |
| 214 |
), |
| 215 |
'version' => SLINGBLOCKS_VERSION, |
| 216 |
); |
| 217 |
|
| 218 |
$js_path = "/$app_name.js"; |
| 219 |
$style_path = "/$app_name.css"; |
| 220 |
$deps = ( isset( $assets['dependencies'] ) ? array_merge( $assets['dependencies'], array( 'jquery' ) ) : array( 'jquery' ) ); |
| 221 |
$deps = array_merge( $deps, array( 'fontawesome-shims-js', 'fontawesome-svg-js' ) ); |
| 222 |
$version = $assets['version']; |
| 223 |
|
| 224 |
$script_deps = array_filter( $deps, function ( $dep ) { |
| 225 |
return ! is_null( $dep ) && false === strpos( $dep, 'css' ); |
| 226 |
} ); |
| 227 |
|
| 228 |
wp_enqueue_script( 'fontawesome-shims-js', plugin_dir_url( __FILE__ ) . 'font/fontawesome-v4-shims.min.js', // mapping between fa-v4 and fa-v5 naming |
| 229 |
null, null, true ); |
| 230 |
wp_enqueue_script( 'fontawesome-svg-js', plugin_dir_url( __FILE__ ) . 'font/fontawesome.min.js', // get fontawesome svg from js by FontAwesome.icon object |
| 231 |
null, null, true ); |
| 232 |
|
| 233 |
wp_enqueue_script( 'slingblocks-editor', $editor_dir . $js_path, $script_deps, $version, true ); |
| 234 |
$slingblocksfonts_path = __DIR__ . '/font/gfonts-array.php'; |
| 235 |
$slingblocksfont_names_path = __DIR__ . '/font/gfonts-names-array.php'; |
| 236 |
$slingblockssystem_font_path = __DIR__ . '/font/standard-fonts.php'; |
| 237 |
wp_enqueue_script( 'web-font', plugin_dir_url( __FILE__ ) . 'font/webfont.js', array(), true ); |
| 238 |
wp_localize_script( 'slingblocks-editor', 'slingblocks', array( |
| 239 |
'i18n' => SLINGBLOCKS_I18N, |
| 240 |
'slingblocks_g_fonts' => file_exists( $slingblocksfonts_path ) ? include $slingblocksfonts_path : array(), |
| 241 |
'slingblocks_g_font_names' => file_exists( $slingblocksfont_names_path ) ? include $slingblocksfont_names_path : array(), |
| 242 |
'slingblockssystem_font_path' => file_exists( $slingblockssystem_font_path ) ? include $slingblockssystem_font_path : array(), |
| 243 |
'wp_version' => $GLOBALS['wp_version'] |
| 244 |
) ); |
| 245 |
// Enqueue our plugin Css. |
| 246 |
wp_enqueue_style( 'slingblocks-editor', $editor_dir . $style_path, array(), $version ); |
| 247 |
|
| 248 |
if ( function_exists( 'wp_set_script_translations' ) ) { |
| 249 |
wp_set_script_translations( 'slingblocks-editor', SLINGBLOCKS_I18N ); |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* default : 980px |
| 254 |
*/ |
| 255 |
$tmpt_boxed_width = apply_filters( 'slb_template_boxed_width', '' ); |
| 256 |
if ( ! empty( $tmpt_boxed_width ) ) { |
| 257 |
$boxed_tmpt_width = "body.slb-editor-width-boxed .editor-post-title__block, body.slb-editor-width-boxed .editor-default-block-appender, body.slb-editor-width-boxed .block-editor-block-list__block, body.slb-editor-width-boxed .block-editor-default-block-appender, body.slb-editor-width-boxed .wp-block{ max-width: $tmpt_boxed_width !important}"; |
| 258 |
wp_add_inline_style( 'slingblocks-editor', $boxed_tmpt_width ); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
public function bwf_render_default_font() { |
| 263 |
global $post; |
| 264 |
if ( ! $post instanceof WP_Post ) { |
| 265 |
return; |
| 266 |
} |
| 267 |
|
| 268 |
$default_font = get_post_meta( $post->ID, 'bwfblock_default_font', true ); |
| 269 |
if ( ! empty( $default_font ) ) { |
| 270 |
echo "<style id='bwfblock-default-font'>#editor .editor-styles-wrapper, #editor .editor-styles-wrapper p, #editor .editor-styles-wrapper h1, #editor .editor-styles-wrapper h2, #editor .editor-styles-wrapper h3, #editor .editor-styles-wrapper h4, #editor .editor-styles-wrapper h5, #editor .editor-styles-wrapper h6, #editor .editor-styles-wrapper ul, #editor .editor-styles-wrapper li { font-family:" . esc_html( $default_font ) . " }</style>"; |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
/** |
| 275 |
* Enqueue Front Style. |
| 276 |
*/ |
| 277 |
public function wp_enqueue_scripts_front() { |
| 278 |
//Check if page is is_singular |
| 279 |
if ( ! is_singular() ) { |
| 280 |
return; |
| 281 |
} |
| 282 |
|
| 283 |
// return if slingblocks is not available in post content |
| 284 |
if ( empty( SLINGBLOCKS_Frontend_CSS::$slingblocks ) ) { |
| 285 |
return; |
| 286 |
} |
| 287 |
|
| 288 |
// Enqueue our plugin Css. |
| 289 |
$slingblocks_front_dir = ( defined( 'SLINGBLOCKS_REACT_ENVIRONMENT' ) && 0 == SLINGBLOCKS_REACT_ENVIRONMENT ) ? SLINGBLOCKS_REACT_DEV_URL : plugin_dir_url( __FILE__ ) . 'dist'; |
| 290 |
|
| 291 |
$stylesheet_file = '/slingblocks.css'; |
| 292 |
$script_file = '/slingblocks.js'; |
| 293 |
|
| 294 |
wp_enqueue_style( 'slingblocks', $slingblocks_front_dir . $stylesheet_file, array(), SLINGBLOCKS_VERSION ); |
| 295 |
wp_enqueue_script( 'slingblocks', $slingblocks_front_dir . $script_file, array( 'jquery' ), SLINGBLOCKS_VERSION, true ); |
| 296 |
|
| 297 |
if ( in_array( 'sling-block/countdown', SLINGBLOCKS_Frontend_CSS::$slingblocks ) ) { |
| 298 |
wp_enqueue_script( 'slingblocks-countdown-js', $slingblocks_front_dir . '/slingblocks-countdown.js', array(), SLINGBLOCKS_VERSION, true ); |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
/** |
| 303 |
* Load slingblock template inline style |
| 304 |
*/ |
| 305 |
public function load_page_template_style() { |
| 306 |
//Check if page is is_singular |
| 307 |
if ( ! is_singular() ) { |
| 308 |
return; |
| 309 |
} |
| 310 |
|
| 311 |
$page_template = get_page_template_slug(); |
| 312 |
if ( '' === $page_template || ! ( 'slb-template-canvas' === $page_template || 'slb-template-boxed' === $page_template ) ) { |
| 313 |
return; |
| 314 |
} |
| 315 |
|
| 316 |
$template_style = '.slb-boxed{max-width:1200px;width:100%;margin:0 auto}.slb-container:not(.slb-boxed)>*{padding-left:15px;padding-right:15px}@media screen and (max-width:1220px){.slb-boxed>*{padding-left:15px;padding-right:15px}}'; |
| 317 |
|
| 318 |
$tmpt_boxed_width = apply_filters( 'slb_template_boxed_width', '' ); // default is 1200px |
| 319 |
if ( ! empty( $tmpt_boxed_width ) ) { |
| 320 |
$template_style .= ".slb-container.slb-boxed{max-width:$tmpt_boxed_width}"; |
| 321 |
} |
| 322 |
|
| 323 |
wp_register_style( 'slingblocks-template', false ); |
| 324 |
wp_enqueue_style( 'slingblocks-template' ); |
| 325 |
wp_add_inline_style( 'slingblocks-template', $template_style ); |
| 326 |
} |
| 327 |
|
| 328 |
public function load_all_compatibilities() { |
| 329 |
/** Compatibilities folder */ |
| 330 |
$dir = plugin_dir_path( __FILE__ ) . 'compatibilities'; |
| 331 |
|
| 332 |
/** Plugins loaded hook */ |
| 333 |
foreach ( glob( $dir . '/plugins_loaded/class-*.php' ) as $_field_filename ) { |
| 334 |
require_once( $_field_filename ); |
| 335 |
} |
| 336 |
|
| 337 |
/** After Setup theme hook */ |
| 338 |
add_action( 'after_setup_theme', function () use ( $dir ) { |
| 339 |
foreach ( glob( $dir . '/after_setup_theme/class-*.php' ) as $_field_filename ) { |
| 340 |
require_once( $_field_filename ); |
| 341 |
} |
| 342 |
} ); |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
new SLINGBLOCKS(); |
| 347 |
} |
| 348 |
|