class-do-css.php
6 years ago
class-enqueue-css.php
6 years ago
class-settings.php
6 years ago
dashboard.php
6 years ago
defaults.php
6 years ago
functions.php
6 years ago
general.php
6 years ago
generate-css.php
6 years ago
general.php
194 lines
| 1 | <?php |
| 2 | /** |
| 3 | * General actions and filters. |
| 4 | * |
| 5 | * @package GenerateBlocks |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | add_action( 'enqueue_block_editor_assets', 'generateblocks_do_block_editor_assets' ); |
| 13 | /** |
| 14 | * Enqueue Gutenberg block assets for backend editor. |
| 15 | * |
| 16 | * @uses {wp-blocks} for block type registration & related functions. |
| 17 | * @uses {wp-element} for WP Element abstraction — structure of blocks. |
| 18 | * @uses {wp-i18n} to internationalize the block's text. |
| 19 | * @uses {wp-editor} for WP editor styles. |
| 20 | * @since 0.1 |
| 21 | */ |
| 22 | function generateblocks_do_block_editor_assets() { |
| 23 | wp_enqueue_script( |
| 24 | 'generateblocks', |
| 25 | GENERATEBLOCKS_DIR_URL . 'dist/blocks.build.js', |
| 26 | array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), |
| 27 | filemtime( GENERATEBLOCKS_DIR . 'dist/blocks.build.js' ), |
| 28 | true |
| 29 | ); |
| 30 | |
| 31 | wp_enqueue_script( |
| 32 | 'generateblocks-dompurify', |
| 33 | GENERATEBLOCKS_DIR_URL . 'assets/js/purify.min.js', |
| 34 | array( 'generateblocks' ), |
| 35 | filemtime( GENERATEBLOCKS_DIR . 'assets/js/purify.min.js' ), |
| 36 | true |
| 37 | ); |
| 38 | |
| 39 | wp_enqueue_style( |
| 40 | 'generateblocks', |
| 41 | GENERATEBLOCKS_DIR_URL . 'dist/blocks.editor.build.css', |
| 42 | array( 'wp-edit-blocks' ), |
| 43 | filemtime( GENERATEBLOCKS_DIR . 'dist/blocks.editor.build.css' ) |
| 44 | ); |
| 45 | |
| 46 | wp_localize_script( |
| 47 | 'generateblocks', |
| 48 | 'generateBlocksInfo', |
| 49 | array( |
| 50 | 'isGeneratePress' => defined( 'GENERATE_VERSION' ), |
| 51 | 'hasCustomFields' => post_type_supports( get_post_type(), 'custom-fields' ), |
| 52 | ) |
| 53 | ); |
| 54 | |
| 55 | if ( function_exists( 'generate_get_color_defaults' ) ) { |
| 56 | $color_settings = wp_parse_args( |
| 57 | get_option( 'generate_settings', array() ), |
| 58 | generate_get_color_defaults() |
| 59 | ); |
| 60 | |
| 61 | $generatepressDefaultStyling = apply_filters( |
| 62 | 'generateblocks_gp_default_styling', |
| 63 | array( |
| 64 | 'buttonBackground' => $color_settings['form_button_background_color'], |
| 65 | 'buttonBackgroundHover' => $color_settings['form_button_background_color_hover'], |
| 66 | 'buttonText' => $color_settings['form_button_text_color'], |
| 67 | 'buttonTextHover' => $color_settings['form_button_text_color_hover'], |
| 68 | 'buttonPaddingTop' => '10px', |
| 69 | 'buttonPaddingRight' => '20px', |
| 70 | 'buttonPaddingBottom' => '10px', |
| 71 | 'buttonPaddingLeft' => '20px', |
| 72 | ) |
| 73 | ); |
| 74 | |
| 75 | $css = sprintf( |
| 76 | '.gb-button.button { |
| 77 | background-color: %1$s; |
| 78 | color: %2$s; |
| 79 | padding-top: %3$s; |
| 80 | padding-right: %4$s; |
| 81 | padding-bottom: %5$s; |
| 82 | padding-left: %6$s; |
| 83 | }', |
| 84 | $generatepressDefaultStyling['buttonBackground'], |
| 85 | $generatepressDefaultStyling['buttonText'], |
| 86 | $generatepressDefaultStyling['buttonPaddingTop'], |
| 87 | $generatepressDefaultStyling['buttonPaddingRight'], |
| 88 | $generatepressDefaultStyling['buttonPaddingBottom'], |
| 89 | $generatepressDefaultStyling['buttonPaddingLeft'] |
| 90 | ); |
| 91 | |
| 92 | $css .= sprintf( |
| 93 | '.gb-button.button:active, .gb-button.button:hover, .gb-button.button:focus { |
| 94 | background-color: %1$s; |
| 95 | color: %2$s; |
| 96 | }', |
| 97 | $generatepressDefaultStyling['buttonBackgroundHover'], |
| 98 | $generatepressDefaultStyling['buttonTextHover'] |
| 99 | ); |
| 100 | |
| 101 | wp_add_inline_style( 'generateblocks', $css ); |
| 102 | } |
| 103 | |
| 104 | $defaults = generateblocks_get_block_defaults(); |
| 105 | |
| 106 | wp_localize_script( |
| 107 | 'generateblocks', |
| 108 | 'generateBlocksDefaults', |
| 109 | $defaults |
| 110 | ); |
| 111 | |
| 112 | wp_localize_script( |
| 113 | 'generateblocks', |
| 114 | 'generateBlocksStyling', |
| 115 | generateblocks_get_default_styles() |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | add_filter( 'block_categories', 'generateblocks_do_category' ); |
| 120 | /** |
| 121 | * Add GeneratePress category to Gutenberg. |
| 122 | * |
| 123 | * @param array $categories Existing categories. |
| 124 | * @since 0.1 |
| 125 | */ |
| 126 | function generateblocks_do_category( $categories ) { |
| 127 | return array_merge( |
| 128 | array( |
| 129 | array( |
| 130 | 'slug' => 'generateblocks', |
| 131 | 'title' => __( 'GenerateBlocks', 'generateblocks' ), |
| 132 | ), |
| 133 | ), |
| 134 | $categories |
| 135 | ); |
| 136 | } |
| 137 | |
| 138 | add_action( 'wp_enqueue_scripts', 'generateblocks_do_google_fonts' ); |
| 139 | add_action( 'enqueue_block_editor_assets', 'generateblocks_do_google_fonts' ); |
| 140 | /** |
| 141 | * Do Google Fonts. |
| 142 | * |
| 143 | * @since 0.1 |
| 144 | */ |
| 145 | function generateblocks_do_google_fonts() { |
| 146 | $fonts_url = generateblocks_get_google_fonts_uri(); |
| 147 | |
| 148 | if ( $fonts_url ) { |
| 149 | wp_enqueue_style( 'generateblocks-google-fonts', $fonts_url, array(), null, 'all' ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | add_action( 'init', 'generateblocks_register_meta' ); |
| 154 | /** |
| 155 | * Register our post meta. |
| 156 | * |
| 157 | * @since 0.1 |
| 158 | */ |
| 159 | function generateblocks_register_meta() { |
| 160 | register_meta( |
| 161 | 'post', |
| 162 | '_generate-full-width-content', |
| 163 | array( |
| 164 | 'show_in_rest' => true, |
| 165 | 'auth_callback' => '__return_true', |
| 166 | 'single' => true, |
| 167 | ) |
| 168 | ); |
| 169 | } |
| 170 | |
| 171 | add_filter( 'generateblocks_css_print_method', 'generateblocks_set_css_print_method' ); |
| 172 | /** |
| 173 | * Set our CSS print method. |
| 174 | * |
| 175 | * @param string $method Existing method. |
| 176 | */ |
| 177 | function generateblocks_set_css_print_method( $method ) { |
| 178 | return generateblocks_get_option( 'css_print_method' ); |
| 179 | } |
| 180 | |
| 181 | add_filter( 'excerpt_allowed_blocks', 'generateblocks_set_excerpt_allowed_blocks' ); |
| 182 | /** |
| 183 | * Add blocks that can be displayed in post excerpts. |
| 184 | * |
| 185 | * @param array $allowed Existing allowed blocks. |
| 186 | * @since 1.0 |
| 187 | */ |
| 188 | function generateblocks_set_excerpt_allowed_blocks( $allowed ) { |
| 189 | $allowed[] = 'generateblocks/headline'; |
| 190 | $allowed[] = 'generateblocks/container'; |
| 191 | |
| 192 | return $allowed; |
| 193 | } |
| 194 |