PluginProbe
Flipbox / trunk
Flipbox vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.4.0
flipbox / flipbox.php

flipbox.php in Flipbox trunk, at flipbox.php

159 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: Flipbox
5 * Plugin URI: https://essential-blocks.com
6 * Description: Deliver your content beautifully to grab attention with an animated Flipbox block.
7 * Version: 1.4.0
8 * Author: WPDeveloper
9 * Author URI: https://wpdeveloper.net
10 * License: GPL-2.0-or-later
11 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
12 * Text Domain: flipbox
13 * Requires at least: 6.0
14 * Tested up to: 7.0
15 * Requires PHP: 7.4
16 *
17 * @package flipbox
18 */
19
20 // Exit if accessed directly.
21 if ( ! defined( 'ABSPATH' ) ) {
22 exit;
23 }
24
25 /**
26 * Registers all block assets so that they can be enqueued through the block editor
27 * in the corresponding context.
28 *
29 * @see https://developer.wordpress.org/block-editor/tutorials/block-tutorial/applying-styles-with-stylesheets/
30 */
31
32 if ( ! defined( 'EB_FLIPBOX_BLOCKS_VERSION' ) ) {
33 define( 'EB_FLIPBOX_BLOCKS_VERSION', '1.4.0' );
34 }
35 if ( ! defined( 'EB_FLIPBOX_BLOCKS_ADMIN_URL' ) ) {
36 define( 'EB_FLIPBOX_BLOCKS_ADMIN_URL', plugin_dir_url( __FILE__ ) );
37 }
38 if ( ! defined( 'EB_FLIPBOX_BLOCKS_ADMIN_PATH' ) ) {
39 define( 'EB_FLIPBOX_BLOCKS_ADMIN_PATH', dirname( __FILE__ ) );
40 }
41
42 require_once __DIR__ . '/includes/font-loader.php';
43 require_once __DIR__ . '/includes/post-meta.php';
44 require_once __DIR__ . '/includes/helpers.php';
45
46 /**
47 * `lib/style-handler` is a git submodule. It is absent from a checkout that was
48 * never initialised with `git submodule update --init`, so requiring it
49 * unconditionally fatals the whole site. Guard it.
50 */
51 if ( file_exists( __DIR__ . '/lib/style-handler/style-handler.php' ) ) {
52 require_once __DIR__ . '/lib/style-handler/style-handler.php';
53 }
54
55 function create_block_flipbox_block_init() {
56 $script_asset_path = EB_FLIPBOX_BLOCKS_ADMIN_PATH . "/dist/index.asset.php";
57 if ( ! file_exists( $script_asset_path ) ) {
58 throw new Error(
59 'You need to run `npm start` or `npm run build` for the "flipbox/flipbox-block" block first.'
60 );
61 }
62 $index_js = EB_FLIPBOX_BLOCKS_ADMIN_URL . 'dist/index.js';
63 $script_asset = require $script_asset_path;
64 $all_dependencies = array_merge( $script_asset['dependencies'], [
65 'wp-blocks',
66 'wp-i18n',
67 'wp-element',
68 'wp-block-editor',
69 'eb-flipbox-blocks-controls-util',
70 'essential-blocks-eb-animation'
71 ] );
72
73 wp_register_script(
74 'eb-flipbox-block-editor-js',
75 $index_js,
76 $all_dependencies,
77 $script_asset['version']
78 );
79
80 $load_animation_js = EB_FLIPBOX_BLOCKS_ADMIN_URL . 'assets/js/eb-animation-load.js';
81 wp_register_script(
82 'essential-blocks-eb-animation',
83 $load_animation_js,
84 [],
85 EB_FLIPBOX_BLOCKS_VERSION,
86 true
87 );
88
89 $frontend_js = EB_FLIPBOX_BLOCKS_ADMIN_URL . 'dist/frontend/index.js';
90 wp_register_script(
91 'essential-blocks-frontend-js',
92 $frontend_js,
93 ['essential-blocks-eb-animation'],
94 EB_FLIPBOX_BLOCKS_VERSION,
95 true
96 );
97
98 $animate_css = EB_FLIPBOX_BLOCKS_ADMIN_URL . 'assets/css/animate.min.css';
99 wp_register_style(
100 'essential-blocks-animation',
101 $animate_css,
102 [],
103 EB_FLIPBOX_BLOCKS_VERSION
104 );
105
106 $fontpicker_theme = 'assets/css/fonticonpicker.base-theme.react.css';
107 wp_register_style(
108 'fontpicker-default-theme',
109 plugins_url( $fontpicker_theme, __FILE__ ),
110 [],
111 EB_FLIPBOX_BLOCKS_VERSION
112 );
113
114 $fontpicker_material_theme = 'assets/css/fonticonpicker.material-theme.react.css';
115 wp_register_style(
116 'fontpicker-matetial-theme',
117 plugins_url( $fontpicker_material_theme, __FILE__ ),
118 [],
119 EB_FLIPBOX_BLOCKS_VERSION
120 );
121
122 $fontawesome_css = 'assets/css/fontawesome/css/all.min.css';
123 wp_register_style(
124 'fontawesome-frontend-css',
125 plugins_url( $fontawesome_css, __FILE__ ),
126 [],
127 EB_FLIPBOX_BLOCKS_VERSION
128 );
129
130 $style_css = EB_FLIPBOX_BLOCKS_ADMIN_URL . 'dist/style.css';
131 $style_css_path = EB_FLIPBOX_BLOCKS_ADMIN_PATH . '/dist/style.css';
132 // filemtime() emits a warning and returns false when the file is missing;
133 // on PHP 8 that false then reaches wp_register_style() as the version.
134 $style_css_ver = file_exists( $style_css_path ) ? filemtime( $style_css_path ) : EB_FLIPBOX_BLOCKS_VERSION;
135 wp_register_style(
136 'eb-flipbox-block-frontend-style',
137 $style_css,
138 ['fontawesome-frontend-css', 'essential-blocks-animation'],
139 $style_css_ver
140 );
141
142 if ( ! WP_Block_Type_Registry::get_instance()->is_registered( 'essential-blocks/flipbox' ) ) {
143 register_block_type(
144 Flipbox_Helper::get_block_register_path( 'flipbox/flipbox-block', EB_FLIPBOX_BLOCKS_ADMIN_PATH ),
145 [
146 'editor_script' => 'eb-flipbox-block-editor-js',
147 'style' => 'eb-flipbox-block-frontend-style',
148 'render_callback' => function ( $attributes, $content ) {
149 if ( ! is_admin() ) {
150 wp_enqueue_script( 'essential-blocks-frontend-js' );
151 }
152 return $content;
153 }
154 ]
155 );
156 }
157 }
158 add_action( 'init', 'create_block_flipbox_block_init', 99 );
159