PluginProbe
BeyondWords – AI audio for publishers / 4.4.0
BeyondWords – AI audio for publishers v4.4.0
7.2.0 7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 All 44 releases
speechkit / src / Core / CoreUtils.php

CoreUtils.php in BeyondWords – AI audio for publishers 4.4.0, at src/Core/CoreUtils.php

148 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 <[email protected]>
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
52 * (this includes the screen that lists the posts).
53 *
54 * @since 4.0.0
55 * @since 4.0.5 Ensure is_admin() and $screen
56 */
57 public static function isEditScreen()
58 {
59 if (! is_admin()) {
60 return false;
61 }
62
63 if (! function_exists('get_current_screen')) {
64 return false;
65 }
66
67 $screen = get_current_screen();
68
69 if (! $screen || ! ($screen instanceof \WP_Screen)) {
70 return false;
71 }
72
73 // TODO improve this check?
74 if ($screen->parent_base === 'edit' || $screen->base === 'post') {
75 return true;
76 }
77
78 return false;
79 }
80
81 /**
82 * Get the BeyondWords post meta keys.
83 *
84 * @since 4.1.0
85 *
86 * @param string $type Type (current|deprecated|all).
87 *
88 * @throws Exception
89 *
90 * @return string[] Post meta keys.
91 **/
92 public static function getPostMetaKeys($type = 'current')
93 {
94 $current = [
95 'beyondwords_generate_audio',
96 'beyondwords_project_id',
97 'beyondwords_content_id',
98 'beyondwords_player_style',
99 'beyondwords_language_id',
100 'beyondwords_title_voice_id',
101 'beyondwords_body_voice_id',
102 'beyondwords_summary_voice_id',
103 'beyondwords_error_message',
104 'beyondwords_disabled',
105 'beyondwords_delete_content',
106 ];
107
108 $deprecated = [
109 'beyondwords_podcast_id',
110 'beyondwords_hash',
111 'publish_post_to_speechkit',
112 'speechkit_hash',
113 'speechkit_generate_audio',
114 'speechkit_project_id',
115 'speechkit_podcast_id',
116 'speechkit_error_message',
117 'speechkit_disabled',
118 'speechkit_access_key',
119 'speechkit_error',
120 'speechkit_info',
121 'speechkit_response',
122 'speechkit_retries',
123 'speechkit_updated_at',
124 '_speechkit_link',
125 '_speechkit_text',
126 ];
127
128 $keys = [];
129
130 switch ($type) {
131 case 'current':
132 $keys = $current;
133 break;
134 case 'deprecated':
135 $keys = $deprecated;
136 break;
137 case 'all':
138 $keys = array_merge($current, $deprecated);
139 break;
140 default:
141 throw \Exception('Unexpected $type param for CoreUtils::getPostMetaKeys()');
142 break;
143 }
144
145 return $keys;
146 }
147 }
148