| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: Gallery Styles |
| 4 |
* Plugin URI: https://github.com/DanielFloeter/gallery-styles |
| 5 |
* Description: Additional Styles for the WordPress core/gallery |
| 6 |
* Version: 1.3.5 |
| 7 |
* Author: TipTopPress |
| 8 |
* Author URI: https://tiptoppress.com |
| 9 |
* License: GPL-2.0-or-later |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 |
* Text Domain: gallery-styles-block |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
namespace galleryStyleBlock; |
| 16 |
|
| 17 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 18 |
|
| 19 |
/** |
| 20 |
* Write the color and accessing |
| 21 |
* css variable "--line-color" |
| 22 |
*/ |
| 23 |
function custom_block_wrapper( $block_content, $block ) { |
| 24 |
if ( $block['blockName'] === 'core/gallery' ) { |
| 25 |
|
| 26 |
$line_color_styles = (isset( $block['attrs']['lineColor'] ) && $block['attrs']['lineColor'] !== '') ? '--line-color:' . $block['attrs']['lineColor'] : ''; |
| 27 |
$foreground_styles = (isset( $block['attrs']['foreground'] ) && $block['attrs']['foreground'] !== '') ? '--foreground:' . $block['attrs']['foreground'] : ''; |
| 28 |
$background_styles = (isset( $block['attrs']['background'] ) && $block['attrs']['background'] !== '') ? '--background:' . $block['attrs']['background'] : ''; |
| 29 |
$blend_mode_styles = (isset( $block['attrs']['blendMode'] ) && $block['attrs']['blendMode'] !== '') ? '--blend-mode:' . $block['attrs']['blendMode'] : '--blend-mode:multiply'; |
| 30 |
$text_blend_mode_styles = (isset( $block['attrs']['textBlendMode'] ) && $block['attrs']['textBlendMode'] !== '') ? '--text-blend-mode:color-dodge' : '--text-blend-mode:normal'; |
| 31 |
$font_size = (isset( $block['attrs']['fontSize'] ) && $block['attrs']['fontSize'] !== '') ? '--font-size:' . $block['attrs']['fontSize'] : ''; |
| 32 |
$disable_caption = (isset( $block['attrs']['disableCaption'] ) && $block['attrs']['disableCaption'] !== '') ? '--disable-caption:hidden' : ''; |
| 33 |
|
| 34 |
$styles = $line_color_styles . '; ' . $foreground_styles . '; ' . $background_styles . '; ' . $disable_caption . '; ' . $blend_mode_styles . '; ' . $text_blend_mode_styles . '; ' . $font_size; |
| 35 |
|
| 36 |
$content = '<div style="' . esc_attr($styles) . '">'; |
| 37 |
$content .= $block_content; |
| 38 |
$content .= '</div>'; |
| 39 |
return $content; |
| 40 |
} |
| 41 |
return $block_content; |
| 42 |
} |
| 43 |
|
| 44 |
add_filter( 'render_block', __NAMESPACE__ . '\custom_block_wrapper', 10, 2 ); |
| 45 |
|
| 46 |
/** |
| 47 |
* Enqueue Block Styles Javascript and Styles Stylesheet for editing |
| 48 |
*/ |
| 49 |
function custom_gutenberg_scripts() { |
| 50 |
|
| 51 |
// wp_enqueue_style( 'editor-style-index-css', |
| 52 |
// plugins_url( '/build/index.css', __FILE__ ), |
| 53 |
// array(), |
| 54 |
// filemtime( plugin_dir_path( __FILE__ ) . 'build/index.css' ) |
| 55 |
// ); |
| 56 |
|
| 57 |
wp_enqueue_script( |
| 58 |
'block-styles-script', |
| 59 |
plugins_url( 'build/index.js', __FILE__ ), |
| 60 |
array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ), |
| 61 |
filemtime( plugin_dir_path( __FILE__ ) . './build/index.js' ) |
| 62 |
); |
| 63 |
} |
| 64 |
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\custom_gutenberg_scripts' ); |
| 65 |
|
| 66 |
/** |
| 67 |
* Enqueue Block Styles Stylesheet for editor and front-end |
| 68 |
*/ |
| 69 |
function custom_gutenberg_styles() { |
| 70 |
|
| 71 |
wp_enqueue_style( 'style-index-css', |
| 72 |
plugins_url( 'build/style-index.css', __FILE__ ), |
| 73 |
array(), |
| 74 |
filemtime( plugin_dir_path( __FILE__ ) . 'build/style-index.css' ) |
| 75 |
); |
| 76 |
|
| 77 |
} |
| 78 |
add_action( 'enqueue_block_assets', __NAMESPACE__ . '\custom_gutenberg_styles' ); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|