| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package Tag Groups |
| 5 |
* @author Christoph Amthor |
| 6 |
* @copyright 2020 Christoph Amthor (@ Chatty Mango, chattymango.com) |
| 7 |
* @license GPL-3.0+ |
| 8 |
*/ |
| 9 |
|
| 10 |
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps, PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
| 11 |
if (! class_exists('TagGroups_Gutenberg')) { |
| 12 |
/** |
| 13 |
* |
| 14 |
*/ |
| 15 |
class TagGroups_Gutenberg |
| 16 |
{ |
| 17 |
/** |
| 18 |
* Check if Gutenberg is active. |
| 19 |
* Must be used not earlier than plugins_loaded action fired. |
| 20 |
* from https://gist.github.com/mihdan/8ba1a70d8598460421177c7d31202908 |
| 21 |
* |
| 22 |
* @return bool |
| 23 |
*/ |
| 24 |
public static function is_gutenberg_active() |
| 25 |
{ |
| 26 |
$gutenberg = false; |
| 27 |
$block_editor = false; |
| 28 |
if (has_filter('replace_editor', 'gutenberg_init')) { |
| 29 |
// Gutenberg is installed and activated. |
| 30 |
$gutenberg = true; |
| 31 |
} |
| 32 |
|
| 33 |
if (version_compare($GLOBALS['wp_version'], '5.0-beta', '>')) { |
| 34 |
// Block editor. |
| 35 |
$block_editor = true; |
| 36 |
} |
| 37 |
|
| 38 |
if (! $gutenberg && ! $block_editor) { |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 43 |
if (! is_plugin_active('classic-editor/classic-editor.php')) { |
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
$use_block_editor = ( get_option('classic-editor-replace') === 'no-replace' ); |
| 48 |
return $use_block_editor; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
/** |
| 53 |
* Create a new block category |
| 54 |
* |
| 55 |
* @param array $categories |
| 56 |
* @return array |
| 57 |
*/ |
| 58 |
public static function block_categories($categories) |
| 59 |
{ |
| 60 |
|
| 61 |
$category_slugs = wp_list_pluck($categories, 'slug'); |
| 62 |
return in_array('chatty-mango', $category_slugs, true) ? $categories : array_merge($categories, array( |
| 63 |
array( |
| 64 |
'slug' => 'chatty-mango', |
| 65 |
'title' => 'Tag Groups', |
| 66 |
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
| 67 |
'icon' => null, //'admin-plugins', // icons might be removed in future |
| 68 |
), |
| 69 |
)); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
} |
| 75 |
|