| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Beyondwords\Wordpress\Core; |
| 6 |
|
| 7 |
/** |
| 8 |
* BeyondWords Core Utilities. |
| 9 |
* |
| 10 |
* @package Beyondwords |
| 11 |
* @subpackage Beyondwords/includes |
| 12 |
* @author Stuart McAlpine <stu@beyondwords.io> |
| 13 |
* @since 3.5.0 |
| 14 |
*/ |
| 15 |
class CoreUtils |
| 16 |
{ |
| 17 |
/** |
| 18 |
* Check to see if the Gutenberg Editor is being used. |
| 19 |
* |
| 20 |
* @link https://wordpress.stackexchange.com/a/324866 |
| 21 |
* |
| 22 |
* @since 3.0.0 |
| 23 |
* @since 3.5.0 Moved from Core\Utils to Core\CoreUtils |
| 24 |
*/ |
| 25 |
public static function isGutenbergPage() |
| 26 |
{ |
| 27 |
if (function_exists('is_gutenberg_page') && is_gutenberg_page()) { |
| 28 |
// The Gutenberg plugin is on. |
| 29 |
return true; |
| 30 |
} |
| 31 |
|
| 32 |
$currentScreen = null; |
| 33 |
|
| 34 |
if (function_exists('get_current_screen')) { |
| 35 |
$currentScreen = get_current_screen(); |
| 36 |
} |
| 37 |
|
| 38 |
if ($currentScreen === null) { |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
if (method_exists($currentScreen, 'is_block_editor') && $currentScreen->is_block_editor()) { |
| 43 |
// Gutenberg page on 5+. |
| 44 |
return true; |
| 45 |
} |
| 46 |
|
| 47 |
return false; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Check to see if current screen is an edit screen (this includes the screen |
| 52 |
* that lists the posts). |
| 53 |
* |
| 54 |
* @since 4.0.0 |
| 55 |
*/ |
| 56 |
public static function isEditScreen() |
| 57 |
{ |
| 58 |
if (! function_exists('get_current_screen')) { |
| 59 |
return false; |
| 60 |
} |
| 61 |
|
| 62 |
$screen = get_current_screen(); |
| 63 |
|
| 64 |
// TODO improve this check? |
| 65 |
if ($screen->parent_base === 'edit' || $screen->base === 'post') { |
| 66 |
return true; |
| 67 |
} |
| 68 |
|
| 69 |
return false; |
| 70 |
} |
| 71 |
} |
| 72 |
|