PluginProbe
Progress Bars / 1.3.0
Progress Bars v1.3.0
trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0
progress-bars / progress-bars.php

progress-bars.php in Progress Bars 1.3.0, at progress-bars.php

187 lines 7.4 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: Progress Bar
5 * Plugin URI: https://essential-blocks.com
6 * Description: Make your website interactive with stunning progress bar
7 * Version: 1.3.0
8 * Author: WPDeveloper
9 * Author URI: https://wpdeveloper.net
10 * License: GPL-3.0-or-later
11 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
12 * Text Domain: progress-bars
13 * Requires PHP: 7.4
14 * Requires at least: 6.0
15 * Tested up to: 7.0
16 *
17 * @package progress-bars
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 require_once __DIR__ . '/includes/font-loader.php';
33 require_once __DIR__ . '/includes/post-meta.php';
34 require_once __DIR__ . '/includes/helpers.php';
35
36 /**
37 * `lib/style-handler` ships as a git submodule. In a checkout — or a release zip —
38 * built without `git submodule update --init`, the directory is empty and an
39 * unconditional require is a fatal error.
40 *
41 * The guard keeps the plugin loading, but this component is what writes the
42 * per-post CSS the frontend depends on. Without it the editor still looks
43 * correct (it renders its own <style> tag) while the frontend loses every
44 * generated style: colours, sizes, spacing and the Show Inline layout. That
45 * silent, frontend-only breakage is very hard to diagnose, so surface it.
46 */
47 if ( file_exists( __DIR__ . '/lib/style-handler/style-handler.php' ) ) {
48 require_once __DIR__ . '/lib/style-handler/style-handler.php';
49 } else {
50 add_action( 'admin_notices', 'progress_bars_missing_style_handler_notice' );
51 }
52
53 if ( ! function_exists( 'progress_bars_missing_style_handler_notice' ) ) :
54 /**
55 * Admin notice shown when the style-handler runtime file is absent.
56 *
57 * The cause differs by context and so does the remedy, so name both rather than
58 * guessing. A git checkout is missing an uninitialised submodule and is repaired
59 * with git; an installed copy was packaged incomplete and can only be replaced.
60 * Neither is fixed by rebuilding assets, so the notice must not suggest it.
61 */
62 function progress_bars_missing_style_handler_notice() {
63 if ( ! current_user_can( 'activate_plugins' ) ) {
64 return;
65 }
66
67 echo '<div class="notice notice-error"><p><strong>' .
68 esc_html__( 'Progress Bar', 'progress-bars' ) . ':</strong> ' .
69 sprintf(
70 /* translators: %s: path of the missing file, relative to the plugin directory. */
71 esc_html__( 'the required file %s is missing, so block styles will not be applied on the frontend.', 'progress-bars' ),
72 '<code>lib/style-handler/style-handler.php</code>'
73 ) .
74 '</p><p>' .
75 esc_html__( 'It ships from a git submodule. In a development checkout, run this in the plugin directory:', 'progress-bars' ) .
76 ' <code>git submodule update --init --recursive</code></p><p>' .
77 esc_html__( 'If this is an installed copy of the plugin rather than a checkout, the package itself is incomplete — reinstall the official complete package.', 'progress-bars' ) .
78 '</p></div>';
79 }
80 endif;
81
82 if ( ! function_exists( 'create_block_progress_bar_block_init' ) ) :
83 function create_block_progress_bar_block_init() {
84 $dir = dirname( __FILE__ );
85
86 if ( ! defined( 'PROGRESS_BARS_BLOCKS_VERSION' ) ) {
87 define( 'PROGRESS_BARS_BLOCKS_VERSION', "1.3.0" );
88 }
89 if ( ! defined( 'PROGRESS_BARS_BLOCKS_ADMIN_URL' ) ) {
90 define( 'PROGRESS_BARS_BLOCKS_ADMIN_URL', plugin_dir_url( __FILE__ ) );
91 }
92 if ( ! defined( 'PROGRESS_BARS_BLOCKS_ADMIN_PATH' ) ) {
93 define( 'PROGRESS_BARS_BLOCKS_ADMIN_PATH', dirname( __FILE__ ) );
94 }
95
96 $script_asset_path = PROGRESS_BARS_BLOCKS_ADMIN_PATH . "/dist/index.asset.php";
97 if ( ! file_exists( $script_asset_path ) ) {
98 throw new Error(
99 'You need to run `npm start` or `npm run build` for the "progress-bars/progress-bar-block" block first.'
100 );
101 }
102 $index_js = PROGRESS_BARS_BLOCKS_ADMIN_URL . 'dist/index.js';
103 $script_asset = require $script_asset_path;
104 $all_dependencies = array_merge( $script_asset['dependencies'], [
105 'wp-blocks',
106 'wp-i18n',
107 'wp-element',
108 'wp-block-editor',
109 'progress-bars-blocks-controls-util',
110 'essential-blocks-eb-animation'
111 ] );
112
113 wp_register_script(
114 'progress-bars-block-editor-js',
115 $index_js,
116 $all_dependencies,
117 $script_asset['version']
118 );
119
120 $load_animation_js = PROGRESS_BARS_BLOCKS_ADMIN_URL . 'assets/js/eb-animation-load.js';
121 wp_register_script(
122 'essential-blocks-eb-animation',
123 $load_animation_js,
124 [],
125 PROGRESS_BARS_BLOCKS_VERSION,
126 true
127 );
128
129 $animate_css = PROGRESS_BARS_BLOCKS_ADMIN_URL . 'assets/css/animate.min.css';
130 wp_register_style(
131 'essential-blocks-animation',
132 $animate_css,
133 [],
134 PROGRESS_BARS_BLOCKS_VERSION
135 );
136
137 $style_css = PROGRESS_BARS_BLOCKS_ADMIN_URL . 'dist/style.css';
138 $style_css_path = PROGRESS_BARS_BLOCKS_ADMIN_PATH . '/dist/style.css';
139 // filemtime() emits a warning and returns false when the file is absent.
140 $style_css_ver = file_exists( $style_css_path ) ? filemtime( $style_css_path ) : PROGRESS_BARS_BLOCKS_VERSION;
141 wp_register_style(
142 'progress-bars-block-frontend-style',
143 $style_css,
144 [ 'essential-blocks-animation' ],
145 $style_css_ver
146 );
147
148 /**
149 * `include_once` returns bool `true` if the file was already included earlier in
150 * the request, which would make the array accesses below an offset-on-bool
151 * warning under PHP 7.4+ / 8.x. Use `require` so the array is always returned.
152 */
153 $frontend_asset_path = PROGRESS_BARS_BLOCKS_ADMIN_PATH . '/dist/frontend/index.asset.php';
154 if ( file_exists( $frontend_asset_path ) ) {
155 $frontend_js_path = require $frontend_asset_path;
156 $frontend_js = "dist/frontend/index.js";
157 wp_register_script(
158 'eb-progress-bar-frontend',
159 plugins_url( $frontend_js, __FILE__ ),
160 isset( $frontend_js_path['dependencies'] ) ? $frontend_js_path['dependencies'] : [],
161 isset( $frontend_js_path['version'] ) ? $frontend_js_path['version'] : PROGRESS_BARS_BLOCKS_VERSION,
162 true
163 );
164 }
165
166 if ( ! WP_Block_Type_Registry::get_instance()->is_registered( 'essential-blocks/progress-bar' ) ) {
167 register_block_type(
168 Progress_Bar_Helper::get_block_register_path( 'progress-bars/progress-bar-block', PROGRESS_BARS_BLOCKS_ADMIN_PATH ),
169 [
170 'editor_script' => 'progress-bars-block-editor-js',
171 'editor_style' => 'progress-bars-block-frontend-style',
172 'style' => 'progress-bars-block-frontend-style',
173 'render_callback' => function ( $attribs, $content ) {
174 if ( ! is_admin() ) {
175 wp_enqueue_script( 'eb-progress-bar-frontend' );
176 wp_enqueue_script( 'essential-blocks-eb-animation' );
177 }
178 return $content;
179 }
180 ]
181 );
182 }
183 }
184 endif;
185
186 add_action( 'init', 'create_block_progress_bar_block_init', 99 );
187