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

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

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