PluginProbe
BeyondWords – AI audio for publishers / 4.7.0
BeyondWords – AI audio for publishers v4.7.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 4.7.0 All 43 releases
speechkit / src / Core / CoreUtils.php

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

149 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 <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
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 if ($screen->parent_base === 'edit' || $screen->base === 'post') {
74 return true;
75 }
76
77 return false;
78 }
79
80 /**
81 * Get the BeyondWords post meta keys.
82 *
83 * @since 4.1.0
84 *
85 * @param string $type Type (current|deprecated|all).
86 *
87 * @throws Exception
88 *
89 * @return string[] Post meta keys.
90 **/
91 public static function getPostMetaKeys($type = 'current')
92 {
93 $current = [
94 'beyondwords_generate_audio',
95 'beyondwords_project_id',
96 'beyondwords_content_id',
97 'beyondwords_preview_token',
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_status',
124 'speechkit_updated_at',
125 '_speechkit_link',
126 '_speechkit_text',
127 ];
128
129 $keys = [];
130
131 switch ($type) {
132 case 'current':
133 $keys = $current;
134 break;
135 case 'deprecated':
136 $keys = $deprecated;
137 break;
138 case 'all':
139 $keys = array_merge($current, $deprecated);
140 break;
141 default:
142 throw \Exception('Unexpected $type param for CoreUtils::getPostMetaKeys()');
143 break;
144 }
145
146 return $keys;
147 }
148 }
149