{
  "generator": "Code Snippets v3.6.2",
  "date_created": "2023-12-28 15:42",
  "snippets": [
    {
      "id": 31,
      "name": "MA Oxygen Colors Gutenberg",
      "desc": "<p>Oxygen Global Colors in Gutenberg</p>\n<p>Version 1.0.3, 2023-12-28 <br />© 2020-2023, Matthias Altmann</p>\n<p>Info: <br />en: <a href=\"https://www.altmann.de/en/blog-en/code-snippet-oxygen-colors-in-gutenberg/\">https://www.altmann.de/en/blog-en/code-snippet-oxygen-colors-in-gutenberg/</a> <br />de: <a href=\"https://www.altmann.de/blog/code-snippet-oxygen-farben-in-gutenberg/\">https://www.altmann.de/blog/code-snippet-oxygen-farben-in-gutenberg/</a></p>",
      "code": "\n/*\nPlugin Name:  MA Oxygen Colors Gutenberg\nDescription:  Provide Oxygen colors in Gutenberg\nAuthor:       <a href=\"https://www.altmann.de/\">Matthias Altmann</a>\nVersion:      1.0.3\nPlugin URI:   https://www.altmann.de/en/blog-en/code-snippet-oxygen-colors-in-gutenberg/\nDescription:  en: https://www.altmann.de/en/blog-en/code-snippet-oxygen-colors-in-gutenberg/\n              de: https://www.altmann.de/blog/code-snippet-oxygen-farben-in-gutenberg/\nCopyright:    © 2020-2023, Matthias Altmann\n\nVersion History:\nDate\t\tVersion\t\tDescription\n---------------------------------------------------------------------------------------------------------------------\n2023-12-28\t1.0.3\t\tTest\n\t\t\t\t\t\t- WordPress 6.4.2, Oxygen 4.8\n2023-01-02\t1.0.2\t\tTest:\n\t\t\t\t\t\t- WordPress 6.1.1, Oxygen 4.3\n\t\t\t\t\t\tChanges:\n\t\t\t\t\t\t- Initialization\n\t\t\t\t\t\t- Increase specificity for CSS rules for WP 6.1.1\n2022-02-11\t\t\t\tTest:\n\t\t\t\t\t\t- PHP 8.0, WordPress 5.9, Oxygen 4.0 beta 1\n\t\t\t\t\t\tChanges:\n\t\t\t\t\t\t- Black & white not added by default\n2021-03-21  1.0.1       Bug Fix: Only initialize if Oxygen plugin is active\n                        (Thanks to Adrien Robert for reporting!)\n2020-12-29 \t1.0.0\t\tInitial Release \n2020-12-29\t\t\t\tDevelopment start\n*/\n\nclass MA_Oxygen_Colors_Gutenberg {\n\tconst TITLE\t\t\t= 'MA Oxygen Colors Gutenberg';\n\tconst SLUG\t\t\t= 'ma_oxygen_colors_gutenberg';\n\tconst VERSION\t\t= '1.0.3';\n\n\t// Configuration\n\tprivate static $debug\t\t\t\t= false;\t// caution! may produce a lot of output\n\tprivate static $timing\t\t\t\t= false;\t// caution! may produce a lot of output\n\tprivate static $add_black_white     = false;\t// automatically add black and white colors\n\tprivate static $allow_custom_color  = true;\t\t// allow custom color settings in Gutenberg\n\n\t//-------------------------------------------------------------------------------------------------------------------\n\tstatic function init() {\n\t\tadd_action('after_setup_theme', [__CLASS__, 'palette_backend']);\n\t\tadd_action('enqueue_block_assets', [__CLASS__, 'palette_frontend']);\n\t}\n\t//-------------------------------------------------------------------------------------------------------------------\n\t// Add Oxygen's global colors to Gutenberg's backend editor palette\n\tstatic function palette_backend() {\n\t\t$st = microtime(true);\n\n\t\t$gutenberg_colors = [];\n\t\tif (self::$add_black_white) {\n\t\t\t// add black and white\n\t\t\t$gutenberg_colors[] = [ 'name' => 'black', 'slug' => 'color-black', 'color' => '#000000' ];\n\t\t\t$gutenberg_colors[] = [ 'name' => 'white', 'slug' => 'color-white', 'color' => '#ffffff' ];\n\t\t}\n\t\t// add oxygen global colors\n\t\t$oxy_colors = oxy_get_global_colors();\n\t\tforeach($oxy_colors['colors'] as $oxy_color) {\n\t\t\t$gutenberg_colors[] = [ 'name' => $oxy_color['name'], 'slug' => 'color-'.$oxy_color['id'], 'color' => $oxy_color['value'] ];\n\t\t}\n\t\tadd_theme_support( 'editor-color-palette', $gutenberg_colors );\n\t\tif (!self::$allow_custom_color) {\n\t\t\tadd_theme_support( 'disable-custom-colors' );\n\t\t}\n\n\t\tif (WP_DEBUG && self::$debug) {error_log(sprintf('%s::%s() gutenberg_colors: %s',self::TITLE,__FUNCTION__,print_r($gutenberg_colors,true)));}\n\t\t$et = microtime(true);\n\t\tif (WP_DEBUG && self::$timing) {error_log(sprintf('%s::%s() Timing: %.5f sec.',self::TITLE,__FUNCTION__,$et-$st));}\n\t}\n\n\t//-------------------------------------------------------------------------------------------------------------------\n\t// Add corresponding CSS to frontend Gutenberg blocks\n\tstatic function palette_frontend(){\n\t\t$st = microtime(true);\n\n\t\t$gutenberg_colors_frontend_css = '';\n\t\tif (self::$add_black_white) {\n\t\t\t// add black and white\n\t\t\t$gutenberg_colors_frontend_css .= 'body.oxygen-body .has-color-black-color{color:#000000;}';\n\t\t\t$gutenberg_colors_frontend_css .= 'body.oxygen-body .has-color-black-background-color{background-color:#000000;}';\n\t\t\t$gutenberg_colors_frontend_css .= 'body.oxygen-body .has-color-white-color{color:#ffffff;}';\n\t\t\t$gutenberg_colors_frontend_css .= 'body.oxygen-body .has-color-white-background-color{background-color:#ffffff;}';\n\t\t}\n\t\t// add oxygen global colors\n\t\t$oxy_colors = oxy_get_global_colors();\n\t\tforeach( $oxy_colors['colors'] as $oxy_color) {\n\t\t\t$gutenberg_colors_frontend_css .= 'body.oxygen-body .has-color-'.$oxy_color['id'].'-color {color:'.$oxy_color['value'].'}';\n\t\t\t$gutenberg_colors_frontend_css .= 'body.oxygen-body .has-color-'.$oxy_color['id'].'-background-color{background-color:'.$oxy_color['value'].'}';\n\t\t}\n\t\twp_register_style('gutenberg-oxygen-colors', false );\n\t\twp_enqueue_style('gutenberg-oxygen-colors');\n\t\twp_add_inline_style('gutenberg-oxygen-colors', $gutenberg_colors_frontend_css );\n\n\t\tif (WP_DEBUG && self::$debug) {error_log(sprintf('%s::%s() gutenberg_colors_frontend_css: %s',self::TITLE,__FUNCTION__,print_r($gutenberg_colors_frontend_css,true)));}\n\t\t$et = microtime(true);\n\t\tif (WP_DEBUG && self::$timing) {error_log(sprintf('%s::%s() Timing: %.5f sec.',self::TITLE,__FUNCTION__,$et-$st));}\n\n\t}\n\n}\n\n\n\n//===================================================================================================================\n// Initialize\nadd_action('setup_theme',function(){\n\tif (!defined('CT_VERSION'))\treturn;\t// only initialize if Oxygen plugin is active\n\tif (wp_doing_ajax()) \t\treturn;\t// don't run for AJAX requests\n\tif (wp_doing_cron()) \t\treturn;\t// don't run for CRON requests\n\tif (wp_is_json_request()) \treturn;\t// don't run for JSON requests\n\tMA_Oxygen_Colors_Gutenberg::init();\n},1005); \n",
      "tags": [
        "Oxygen"
      ],
      "active": true,
      "modified": "2023-12-28 15:42:30",
      "revision": "7"
    }
  ]
}