PluginProbe
BeyondWords – AI audio for publishers / 4.4.0
BeyondWords – AI audio for publishers v4.4.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 / Component / Settings / SettingsUtils.php

SettingsUtils.php in BeyondWords – AI audio for publishers 4.4.0, at src/Component/Settings/SettingsUtils.php

180 lines 5.3 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\Component\Settings;
6
7 use Beyondwords\Wordpress\Compatibility\Elementor\Elementor;
8 use Beyondwords\Wordpress\Component\Settings\PlayerVersion\PlayerVersion;
9 use Beyondwords\Wordpress\Core\CoreUtils;
10
11 /**
12 * BeyondWords Settings Utilities.
13 *
14 * @package Beyondwords
15 * @subpackage Beyondwords/includes
16 * @author Stuart McAlpine <stu@beyondwords.io>
17 * @since 3.5.0
18 */
19 class SettingsUtils
20 {
21 /**
22 * Get the post types which are forbidden for use with BeyondWords.
23 *
24 * We DO NOT support most of the default WordPress post types. many would not work
25 * correctly with BeyondWords.
26 *
27 * @since 3.7.0
28 *
29 * @static
30 *
31 * @return string[] Array of post type names.
32 **/
33 public static function getForbiddenPostTypes()
34 {
35 return [
36 'attachment',
37 'custom_css',
38 'customize_changeset',
39 'nav_menu_item',
40 'oembed_cache',
41 'revision',
42 'user_request',
43 'wp_block',
44 'wp_template',
45 'wp_template_part',
46 'wp_global_styles',
47 'wp_navigation',
48 ];
49 }
50
51 /**
52 * Get the allowed BeyondWords post types.
53 *
54 * These are the post types which are "allowed" (i.e. not "Forbidden") to be processed
55 * by BeyondWords.
56 *
57 * @since 3.7.0
58 *
59 * @static
60 *
61 * @return string[] Array of post type names.
62 **/
63 public static function getAllowedPostTypes()
64 {
65 $postTypes = get_post_types();
66
67 $forbidden = SettingsUtils::getForbiddenPostTypes();
68
69 // Filter the array, removing unsupported/forbidden post types
70 return array_values(array_diff($postTypes, $forbidden));
71 }
72
73 /**
74 * Get the post types which BeyondWords supports.
75 *
76 * Primarily, any post type which does not have 'custom-fields' in the
77 * 'supports' array will not work with BeyondWords.
78 *
79 * We also DO NOT support most default WordPress post types other than 'post'
80 * and 'page' e.g. we don't support 'attachment', 'revision' and 'wp_template'.
81 *
82 * @since 3.0.0
83 * @since 3.2.0 Removed $output parameter to always output names, never objects.
84 * @since 3.2.0 Added `beyondwords_post_types` filter.
85 * @since 3.5.0 Moved from Core\Utils to Component\Settings\SettingsUtils
86 * @since 3.7.0 Refactored forbidden/allowed/supported post type methods to improve site health debugging info.
87 *
88 * @static
89 *
90 * @return string[] Array of post type names.
91 **/
92 public static function getSupportedPostTypes()
93 {
94 $postTypes = SettingsUtils::getAllowedPostTypes();
95
96 /**
97 * Filters the post types supported by BeyondWords.
98 *
99 * This defaults to all registered post types with 'custom-fields' in their 'supports' array.
100 *
101 * If any of the supplied post types do not support custom fields then they will be removed
102 * from the array.
103 *
104 * Scheduled for removal in plugin version 5.0.0.
105 *
106 * @since 3.3.3
107 *
108 * @deprecated 4.3.0 Replaced with beyondwords_settings_post_types.
109 *
110 * @param string[] The post types supported by BeyondWords.
111 */
112 $postTypes = apply_filters('beyondwords_post_types', $postTypes);
113
114 /**
115 * Filters the post types supported by BeyondWords.
116 *
117 * This defaults to all registered post types with 'custom-fields' in their 'supports' array.
118 *
119 * If any of the supplied post types do not support custom fields then they will be removed
120 * from the array.
121 *
122 * @since 3.3.3 Introduced as beyondwords_post_types
123 * @since 4.3.0 Renamed from beyondwords_post_types to beyondwords_settings_post_types.
124 *
125 * @param string[] The post types supported by BeyondWords.
126 */
127 $postTypes = apply_filters('beyondwords_settings_post_types', $postTypes);
128
129 // Filter the array, removing unsupported post types
130 $postTypes = array_filter($postTypes, function ($postType) {
131 if (! post_type_supports($postType, 'custom-fields')) {
132 return false;
133 }
134
135 return true;
136 });
137
138 return array_values($postTypes);
139 }
140
141 /**
142 * Should we use the Legacy player version?
143 *
144 * @since 4.0.0
145 *
146 * @return boolean
147 */
148 public static function useLegacyPlayer()
149 {
150 // Use "Legacy" player for Elementor
151 if (Elementor::isElementorActivated()) {
152 return true;
153 }
154
155 // Use "Latest" player for all other admin screens
156 if (is_admin()) {
157 return false;
158 }
159
160 $playerVersion = get_option('beyondwords_player_version');
161
162 return $playerVersion === PlayerVersion::LEGACY_VERSION;
163 }
164
165 /**
166 * Do we have both a BeyondWords API key and Project ID?
167 * We need both to call the BeyondWords API.
168 *
169 * @since 3.0.0
170 * @since 4.0.0 Moved from Settings to SettingsUtils
171 * @static
172 *
173 * @return boolean
174 */
175 public static function hasApiSettings()
176 {
177 return boolval(get_option('beyondwords_valid_api_connection'));
178 }
179 }
180