PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
← All changes | includes/assets.php +125 -5 2.11.1 → 2.14.0 View file →
@@ -8,13 +8,19 @@
8 8 use ABlocks\Classes\FileUpload;
9 9 use ABlocks\Classes\AssetsGenerator;
10 10 use ABlocks\Classes\RegisterScripts;
11 11 use ABlocks\Classes\GlobalCssGenerator;
12 +use ABlocks\Classes\GlobalClasses;
13 +use ABlocks\Classes\AtomicStyles;
12 14 use ABlocks\Classes\FontLoadLocally;
13 15 use ABlocks\Admin\Menu;
14 16 use ABlocks\Helper;
15 17
16 18 class Assets {
19 +
20 + /** Records which plugin version last generated the page stylesheets. */
21 + const BUILD_OPTION = 'ablocks_assets_build';
22 +
17 23 public $current_page_template_part = [];
18 24 public $current_page_blocks = [];
19 25 private $FileUpload;
20 26 private $current_page_slug = '';
@@ -106,18 +112,32 @@
106 112 'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
107 113 'is_pro' => (bool) Helper::is_active_ablocks_pro(),
108 114 'is_archive' => (bool) is_archive(),
109 115 'archive_post_type' => $this->get_current_archive_post_type(),
116 + // Responsive breakpoint widths (px) shared with the JS CSS generators
117 + // and the block editor so media queries match the frontend.
118 + 'breakpoints' => Helper::get_breakpoints(),
119 + // Ordered device list (Desktop + built-ins + custom breakpoints) for
120 + // the atomic block's responsive device switcher. Widest-first, so
121 + // the editor and the frontend agree on breakpoint precedence.
122 + 'responsive_devices' => Helper::get_responsive_devices(),
123 + // Whether breakpoint queries overlap (cascade) or are exclusive
124 + // bands (strict). The editor preview builds matching queries.
125 + 'breakpoint_mode' => Helper::get_breakpoint_mode(),
110 126 ];
111 127 }
112 128
113 129 public function get_localize_dashboard_data() {
114 - if ( ! current_user_can( 'manage_options' ) ) {
130 + // Anyone permitted to reach an aBlocks screen needs the nonce, or the
131 + // dashboard loads and then 403s on every request it makes.
132 + if ( ! current_user_can( Permissions::ACCESS ) ) {
115 133 return $this->get_localize_script_data();
116 134 }
117 135 return array_merge($this->get_localize_script_data(), [
118 136 'nonce' => wp_create_nonce( 'wp_rest' ),
119 137 'ablocks_nonce' => wp_create_nonce( 'ablocks_nonce' ),
138 + 'permissions' => Permissions::for_user(),
139 + 'is_admin_user' => Permissions::is_real_admin(),
120 140 ]);
121 141 }
122 142 public function get_localize_editor_data() {
123 143 if ( ! current_user_can( 'edit_posts' ) ) {
@@ -196,8 +216,11 @@
196 216 'academy_lms' => Helper::is_active_academy(),
197 217 'storeengine' => Helper::is_active_storeengine(),
198 218 'wp_map_block' => Helper::is_active_wp_map_block(),
199 219 'easy_content_manager' => Helper::is_active_easy_content_manager(),
220 + 'zencommunity' => Helper::is_active_zencommunity(),
221 + 'gemboards' => Helper::is_active_gemboards(),
222 + 'quizpress' => Helper::is_active_quizpress(),
200 223 ]
201 224 );
202 225 return apply_filters(
203 226 'ablocks/assets/dashboard_scripts_data',
@@ -229,8 +252,11 @@
229 252 'global_color' => (array) Helper::get_settings( 'global_color', [] ),
230 253 'global_typography' => (array) Helper::get_settings( 'global_typography', [] ),
231 254 'global_typography_list' => wp_list_pluck( Helper::get_settings( 'global_typography', [] ), 'value', 'id' ),
232 255 'global_font_family_fallback' => (string) Helper::get_settings( 'global_font_family_fallback', 'Sans-serif' ),
256 + // Editor paste — see includes/api/paste-controller.php.
257 + 'paste_google_docs' => (bool) Helper::get_settings( 'paste_google_docs', true ),
258 + 'paste_convert_webp' => (bool) Helper::get_settings( 'paste_convert_webp', true ),
233 259 // Theme.json + Font Library families, so uploaded/theme fonts are
234 260 // selectable next to the Google catalog.
235 261 'theme_fonts' => \ABlocks\Classes\FontStack::get_theme_font_families(),
236 262 ],
@@ -243,9 +269,13 @@
243 269 'quizpress' => Helper::is_active_quizpress(),
244 270 'easy_content_manager' => Helper::is_active_easy_content_manager(),
245 271 ],
246 272 'blocks_status' => $ablocks_blocks,
247 - 'post_types' => $post_types
273 + 'post_types' => $post_types,
274 + // What this user may do inside the editor. Read by
275 + // src/utils/permissions.js to hide controls they cannot use.
276 + 'permissions' => Permissions::for_user(),
277 + 'is_admin_user' => Permissions::is_real_admin(),
248 278 );
249 279 return apply_filters(
250 280 'ablocks/assets/editor_scripts_data',
251 281 array_merge(
@@ -807,23 +837,113 @@
807 837
808 838 public function is_assets_generated() {
809 839 $file_name = $this->current_page_slug;
810 840 $css_file_path = $this->FileUpload->get_file_path( $file_name . '.min.css' );
811 - return file_exists( $css_file_path );
841 +
842 + if ( ! file_exists( $css_file_path ) ) {
843 + return false;
844 + }
845 +
846 + // The file embeds the global-class CSS this page needs, so editing a
847 + // class has to make every generated stylesheet stale. Comparing the
848 + // file's mtime against the library's change stamp rebuilds them lazily,
849 + // one page at a time on next visit, without stamping a revision into
850 + // every file name (which the per-post delete in Blocks relies on).
851 + //
852 + // Strictly greater, not >=: mtime has one-second resolution, so a file
853 + // written in the same second as a class edit is indistinguishable from
854 + // one written just after it. Treating that tie as stale costs one extra
855 + // regeneration; treating it as fresh would serve the old CSS until the
856 + // next edit.
857 + return filemtime( $css_file_path ) > max(
858 + GlobalClasses::get_revision(),
859 + self::build_revision()
860 + );
812 861 }
813 862
863 + /**
864 + * When this plugin's own CSS last changed, as a timestamp.
865 + *
866 + * The generated file bakes in each block's static stylesheet (see
867 + * AssetsGenerator, which concatenates get_static_css() into it), so a CSS
868 + * fix shipped in an update reached nobody whose pages were generated before
869 + * it: the file still existed, still parsed, and nothing about it looked
870 + * stale, so it was served unchanged forever. Verified by planting a
871 + * stylesheet carrying the previous release's rules — it survived every
872 + * subsequent page load untouched. That is why a fix could land in the
873 + * editor, which loads each block's style.css directly, and never appear on
874 + * the front end.
875 + *
876 + * Keyed on the version rather than a file scan: it is one option read on
877 + * the common path, and every shipped CSS change comes with a version bump.
878 + * Each page then rebuilds once, on its next visit, exactly the way a
879 + * global-class edit already makes them rebuild.
880 + *
881 + * @return int Timestamp of the running version's first request.
882 + */
883 + public static function build_revision() {
884 + $stamp = get_option( self::BUILD_OPTION );
885 +
886 + // The compiler's output revision is part of the key, so an emission
887 + // change stales every baked page even without a version bump. See
888 + // AtomicStyles::OUTPUT_REVISION.
889 + $build = ABLOCKS_VERSION . '+' . AtomicStyles::OUTPUT_REVISION;
890 +
891 + if (
892 + is_array( $stamp ) &&
893 + isset( $stamp['version'], $stamp['time'] ) &&
894 + $build === $stamp['version']
895 + ) {
896 + return (int) $stamp['time'];
897 + }
898 +
899 + $now = time();
900 + update_option(
901 + self::BUILD_OPTION,
902 + [
903 + 'version' => $build,
904 + 'time' => $now,
905 + ],
906 + true
907 + );
908 +
909 + return $now;
910 + }
911 +
814 912 public function set_current_page_template_part( $content, $block ) {
815 913 if ( ! isset( $block['blockName'] ) && is_array( $block ) ) {
816 914 foreach ( $block as $block_item ) {
817 - if ( ! empty( $block_item['blockName'] ) && strpos( $block_item['blockName'], 'ablocks/' ) !== false ) {
915 + if ( $this->is_page_asset_block( $block_item ) ) {
818 916 $this->current_page_blocks[] = $block_item;
819 917 }
820 918 }
821 919 }
822 - if ( ! empty( $block['blockName'] ) && strpos( $block['blockName'], 'ablocks/' ) !== false ) {
920 + if ( $this->is_page_asset_block( $block ) ) {
823 921 $this->current_page_blocks[] = $block;
824 922 }
825 923 return $content;
924 + }
925 +
926 + /**
927 + * Whether a top-level block contributes to the page's generated assets.
928 + *
929 + * A synced pattern counts too: AssetsGenerator::recursive_block_parser()
930 + * already expands its reference. Collecting only `ablocks/*` names left a
931 + * page whose content is just a pattern with no combined CSS/JS at all — so a
932 + * Loop Filter placed from a pattern rendered unstyled and did nothing when
933 + * clicked.
934 + *
935 + * @param mixed $block Parsed block.
936 + * @return bool
937 + */
938 + private function is_page_asset_block( $block ) {
939 + if ( ! is_array( $block ) || empty( $block['blockName'] ) ) {
940 + return false;
941 + }
942 + if ( 'core/block' === $block['blockName'] ) {
943 + return ! empty( $block['attrs']['ref'] );
944 + }
945 + return strpos( $block['blockName'], 'ablocks/' ) !== false;
826 946 }
827 947
828 948 public function set_theme_builder_locations( $args ) {
829 949 $this->theme_builder_locations = $args;