GENERATEBLOCKS_DIR_URL . 'assets/images/placeholder1280x720.png', 'squarePlaceholder' => GENERATEBLOCKS_DIR_URL . 'assets/images/placeholder800x.png', ] ); wp_localize_script( 'generateblocks-text-editor-script', 'generateblocksBlockText', [ 'defaultButtonAttributes' => apply_filters( 'generateblocks_default_button_attributes', [ 'styles' => [ 'display' => 'inline-flex', 'alignItems' => 'center', 'backgroundColor' => '#215bc2', 'color' => '#ffffff', 'paddingTop' => '1rem', 'paddingRight' => '2rem', 'paddingBottom' => '1rem', 'paddingLeft' => '2rem', 'textDecoration' => 'none', '&:is(:hover, :focus)' => [ 'backgroundColor' => '#1a4a9b', 'color' => '#ffffff', ], ], ] ), ] ); global $pagenow; $generateblocks_deps = array( 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', 'wp-compose', 'wp-data' ); if ( 'widgets.php' === $pagenow ) { unset( $generateblocks_deps[2] ); } $assets_file = GENERATEBLOCKS_DIR . 'dist/blocks.asset.php'; $compiled_assets = file_exists( $assets_file ) ? require $assets_file : false; $assets = isset( $compiled_assets['dependencies'] ) && isset( $compiled_assets['version'] ) ? $compiled_assets : [ 'dependencies' => $generateblocks_deps, 'version' => filemtime( GENERATEBLOCKS_DIR . 'dist/blocks.js' ), ]; wp_enqueue_script( 'generateblocks', GENERATEBLOCKS_DIR_URL . 'dist/blocks.js', $assets['dependencies'], $assets['version'], true ); if ( function_exists( 'wp_set_script_translations' ) ) { wp_set_script_translations( 'generateblocks', 'generateblocks' ); } wp_enqueue_style( 'generateblocks', GENERATEBLOCKS_DIR_URL . 'dist/blocks.css', array( 'wp-edit-blocks', 'generateblocks-packages' ), filemtime( GENERATEBLOCKS_DIR . 'dist/blocks.css' ) ); $image_sizes = get_intermediate_image_sizes(); $image_sizes = array_diff( $image_sizes, array( '1536x1536', '2048x2048' ) ); $image_sizes[] = 'full'; wp_localize_script( 'generateblocks', 'generateBlocksInfo', array( 'imageSizes' => $image_sizes, 'svgShapes' => generateblocks_get_svg_shapes(), 'syncResponsivePreviews' => generateblocks_get_option( 'sync_responsive_previews' ), 'excerptLength' => apply_filters( 'excerpt_length', 55 ), // phpcs:ignore -- Core filter. 'excerptMore' => apply_filters( 'excerpt_more', ' ' . '[…]' ), // phpcs:ignore -- Core filter. 'imagePlaceholders' => array( 'standard' => GENERATEBLOCKS_DIR_URL . 'assets/images/image-placeholder.png', 'square' => GENERATEBLOCKS_DIR_URL . 'assets/images/square-image-placeholder.png', ), 'globalContainerWidth' => generateblocks_get_global_container_width(), 'queryLoopEditorPostsCap' => apply_filters( 'generateblocks_query_loop_editor_posts_cap', 50 ), 'disableGoogleFonts' => generateblocks_get_option( 'disable_google_fonts' ), 'typographyFontFamilyList' => generateblocks_get_font_family_list(), 'useV1Blocks' => generateblocks_use_v1_blocks(), ) ); if ( function_exists( 'generate_get_color_defaults' ) ) { $color_settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_color_defaults() ); $generatepressDefaultStyling = apply_filters( 'generateblocks_gp_default_styling', array( 'buttonBackground' => $color_settings['form_button_background_color'], 'buttonBackgroundHover' => $color_settings['form_button_background_color_hover'], 'buttonText' => $color_settings['form_button_text_color'], 'buttonTextHover' => $color_settings['form_button_text_color_hover'], 'buttonPaddingTop' => '10px', 'buttonPaddingRight' => '20px', 'buttonPaddingBottom' => '10px', 'buttonPaddingLeft' => '20px', ) ); $css = sprintf( '.gb-button.button { background-color: %1$s; color: %2$s; padding-top: %3$s; padding-right: %4$s; padding-bottom: %5$s; padding-left: %6$s; }', $generatepressDefaultStyling['buttonBackground'], $generatepressDefaultStyling['buttonText'], $generatepressDefaultStyling['buttonPaddingTop'], $generatepressDefaultStyling['buttonPaddingRight'], $generatepressDefaultStyling['buttonPaddingBottom'], $generatepressDefaultStyling['buttonPaddingLeft'] ); $css .= sprintf( '.gb-button.button:active, .gb-button.button:hover, .gb-button.button:focus { background-color: %1$s; color: %2$s; }', $generatepressDefaultStyling['buttonBackgroundHover'], $generatepressDefaultStyling['buttonTextHover'] ); wp_add_inline_style( 'generateblocks', $css ); } $defaults = generateblocks_get_block_defaults(); wp_localize_script( 'generateblocks', 'generateBlocksDefaults', $defaults ); wp_localize_script( 'generateblocks', 'generateBlocksStyling', generateblocks_get_default_styles() ); wp_localize_script( 'generateblocks', 'generateBlocksLegacyDefaults', array( 'v_1_4_0' => GenerateBlocks_Legacy_Attributes::get_defaults( '1.4.0' ), ) ); $editor_sidebar_assets = generateblocks_get_enqueue_assets( 'editor-sidebar' ); wp_enqueue_script( 'generateblocks-editor-sidebar', GENERATEBLOCKS_DIR_URL . 'dist/editor-sidebar.js', $editor_sidebar_assets['dependencies'], $editor_sidebar_assets['version'], true ); if ( function_exists( 'wp_set_script_translations' ) ) { wp_set_script_translations( 'generateblocks-editor-sidebar', 'generateblocks' ); } wp_enqueue_style( 'generateblocks-editor-sidebar', GENERATEBLOCKS_DIR_URL . 'dist/editor-sidebar.css', array( 'wp-components' ), filemtime( GENERATEBLOCKS_DIR . 'dist/editor-sidebar.css' ) ); $packages_asset_info = generateblocks_get_enqueue_assets( 'packages' ); wp_register_style( 'generateblocks-packages', GENERATEBLOCKS_DIR_URL . 'dist/packages.css', '', $packages_asset_info['version'] ); // Enqueue scripts for all edge22 packages in the plugin. $package_json = GENERATEBLOCKS_DIR . 'package.json'; if ( file_exists( $package_json ) ) { $package_json_parsed = json_decode( file_get_contents( $package_json ), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents true ); $edge22_packages = array_filter( $package_json_parsed['dependencies'], function( $package_name ) { return 0 === strpos( $package_name, '@edge22/' ); }, ARRAY_FILTER_USE_KEY ); foreach ( $edge22_packages as $name => $version ) { $name = str_replace( '@edge22/', '', $name ); $path = GENERATEBLOCKS_DIR . "dist/{$name}-imported.asset.php"; if ( ! file_exists( $path ) ) { continue; } $package_info = require $path; wp_register_script( "generateblocks-$name", GENERATEBLOCKS_DIR_URL . 'dist/' . $name . '.js', $package_info['dependencies'], $version, true ); wp_register_style( "generateblocks-$name", GENERATEBLOCKS_DIR_URL . 'dist/' . $name . '.css', [], $version ); } } $editor_assets = generateblocks_get_enqueue_assets( 'editor' ); wp_enqueue_script( 'generateblocks-editor', GENERATEBLOCKS_DIR_URL . 'dist/editor.js', $editor_assets['dependencies'], $editor_assets['version'], true ); $tags = GenerateBlocks_Register_Dynamic_Tag::get_tags(); $tag_list = []; foreach ( $tags as $tag => $data ) { $relevant_data = $data; unset( $relevant_data['return'] ); if ( $data ) { $tag_list[] = $relevant_data; } } wp_localize_script( 'generateblocks-editor', 'generateBlocksEditor', [ 'useV1Blocks' => generateblocks_use_v1_blocks(), 'dynamicTags' => $tag_list, 'hasGPFontLibrary' => function_exists( 'generatepress_is_module_active' ) ? generatepress_is_module_active( 'generate_package_font_library', 'GENERATE_FONT_LIBRARY' ) : false, 'dateFormat' => get_option( 'date_format' ), 'wpContentUrl' => content_url(), 'typographyFontFamilyList' => generateblocks_get_font_family_list(), 'dynamicTagsPreview' => apply_filters( 'generateblocks_dynamic_tags_preview', true ) ? 'enabled' : 'disabled', ] ); wp_enqueue_style( 'generateblocks-editor', GENERATEBLOCKS_DIR_URL . 'dist/editor.css', array( 'wp-edit-blocks', 'generateblocks-packages' ), filemtime( GENERATEBLOCKS_DIR . 'dist/editor.css' ) ); } add_filter( 'block_categories_all', 'generateblocks_do_category' ); /** * Add GeneratePress category to Gutenberg. * * @param array $categories Existing categories. * @since 0.1 */ function generateblocks_do_category( $categories ) { array_unshift( $categories, [ 'slug' => 'generateblocks', 'title' => __( 'GenerateBlocks', 'generateblocks' ), ] ); return $categories; } add_action( 'wp_enqueue_scripts', 'generateblocks_do_google_fonts' ); add_action( 'enqueue_block_editor_assets', 'generateblocks_do_google_fonts' ); /** * Do Google Fonts. * * @since 0.1 */ function generateblocks_do_google_fonts() { if ( generateblocks_get_option( 'disable_google_fonts' ) ) { return; } $fonts_url = generateblocks_get_google_fonts_uri(); if ( $fonts_url ) { wp_enqueue_style( 'generateblocks-google-fonts', $fonts_url, array(), null, 'all' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion } } add_filter( 'generateblocks_css_print_method', 'generateblocks_set_css_print_method' ); /** * Set our CSS print method. * * @param string $method Existing method. */ function generateblocks_set_css_print_method( $method ) { $method = generateblocks_get_option( 'css_print_method' ); if ( is_single() ) { $method = 'inline'; } return $method; } add_filter( 'excerpt_allowed_blocks', 'generateblocks_set_excerpt_allowed_blocks' ); /** * Add blocks that can be displayed in post excerpts. * * @param array $allowed Existing allowed blocks. * @since 1.0 */ function generateblocks_set_excerpt_allowed_blocks( $allowed ) { $allowed[] = 'generateblocks/headline'; $allowed[] = 'generateblocks/container'; $allowed[] = 'generateblocks/text'; $allowed[] = 'generateblocks/element'; return $allowed; } add_filter( 'excerpt_allowed_wrapper_blocks', 'generateblocks_set_excerpt_allowed_wrapper_blocks' ); /** * Allows excerpts to be generated from the `innerBlocks` of these wrappers. * * @param array $allowed Existing allowed wrapper blocks. * @since 1.5.0 */ function generateblocks_set_excerpt_allowed_wrapper_blocks( $allowed ) { $allowed[] = 'generateblocks/container'; $allowed[] = 'generateblocks/element'; return $allowed; } add_filter( 'generateblocks_before_container_close', 'generateblocks_do_shape_divider', 10, 2 ); /** * Add shape divider to Container. * * @since 1.2.0 * @param string $output The current block output. * @param array $attributes The current block attributes. */ function generateblocks_do_shape_divider( $output, $attributes ) { $defaults = generateblocks_get_block_defaults(); $settings = wp_parse_args( $attributes, $defaults['container'] ); if ( ! empty( $settings['shapeDividers'] ) ) { $shapes = generateblocks_get_svg_shapes(); $shape_values = array(); foreach ( $shapes as $group => $data ) { if ( ! empty( $data['svgs'] ) && is_array( $data['svgs'] ) ) { foreach ( $data['svgs'] as $key => $shape ) { $shape_values[ $key ] = $shape['icon']; } } } $output .= '