PluginProbe
BeyondWords – AI audio for publishers / 4.5.0
BeyondWords – AI audio for publishers v4.5.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.5.0, at src/Component/Settings/SettingsUtils.php

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