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

161 lines 4.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 <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 $allowedPostTypes = 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 * @since 3.3.3
105 *
106 * @param string[] The post types supported by BeyondWords.
107 */
108 $supportedPostTypes = apply_filters('beyondwords_post_types', $allowedPostTypes);
109
110 // Filter the array, removing unsupported post types
111 $supportedPostTypes = array_filter($supportedPostTypes, function ($postType) {
112 if (! post_type_supports($postType, 'custom-fields')) {
113 return false;
114 }
115
116 return true;
117 });
118
119 return array_values($supportedPostTypes);
120 }
121
122 /**
123 * Should we use the Legacy player version?
124 *
125 * @since 4.0.0
126 *
127 * @return boolean
128 */
129 public static function useLegacyPlayer()
130 {
131 // Use "Legacy" player for Elementor
132 if (Elementor::isElementorActivated()) {
133 return true;
134 }
135
136 // Use "Latest" player for all other admin screens
137 if (is_admin()) {
138 return false;
139 }
140
141 $playerVersion = get_option('beyondwords_player_version');
142
143 return $playerVersion === PlayerVersion::LEGACY_VERSION;
144 }
145
146 /**
147 * Do we have both a BeyondWords API key and Project ID?
148 * We need both to call the BeyondWords API.
149 *
150 * @since 3.0.0
151 * @since 4.0.0 Moved from Settings to SettingsUtils
152 * @static
153 *
154 * @return boolean
155 */
156 public static function hasApiSettings()
157 {
158 return boolval(get_option('beyondwords_valid_api_connection'));
159 }
160 }
161