VueSettings.php
8.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
namespace AIOSEO\Plugin\Common\Utils;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Vue Settings for the user.
*
* @since 4.0.0
*/
class VueSettings {
/**
* The name to lookup the settings with.
*
* @since 4.0.0
*
* @var string
*/
private $settingsName = '';
/**
* The settings array.
*
* @since 4.0.0
*
* @var array
*/
private $settings = [];
/**
* All the default settings.
*
* @since 4.0.0
*
* @var array
*/
private $defaults = [
'showUpgradeBar' => true,
'showSetupWizard' => true,
'toggledCards' => [
'dashboardOverview' => true,
'dashboardSeoSetup' => true,
'dashboardSeoSiteScore' => true,
'dashboardNotifications' => true,
'dashboardSupport' => true,
'license' => true,
'webmasterTools' => true,
'enableBreadcrumbs' => true,
'breadcrumbSettings' => true,
'breadcrumbTemplates' => true,
'advanced' => true,
'accessControl' => true,
'rssContent' => true,
'generalSitemap' => true,
'generalSitemapSettings' => true,
'imageSitemap' => true,
'videoSitemap' => true,
'newsSitemap' => true,
'rssSitemap' => true,
'rssSitemapSettings' => true,
'rssAdditionalPages' => true,
'rssAdvancedSettings' => true,
'additionalPages' => true,
'advancedSettings' => true,
'videoSitemapSettings' => true,
'videoAdditionalPages' => true,
'videoAdvancedSettings' => true,
'videoEmbedSettings' => true,
'newsSitemapSettings' => true,
'newsAdditionalPages' => true,
'newsAdvancedSettings' => true,
'newsEmbedSettings' => true,
'socialProfiles' => true,
'facebook' => true,
'facebookHomePageSettings' => true,
'facebookAdvancedSettings' => true,
'twitter' => true,
'twitterHomePageSettings' => true,
'pinterest' => true,
'searchTitleSeparator' => true,
'searchHomePage' => true,
'searchSchema' => true,
'searchMediaAttachments' => true,
'searchAdvanced' => true,
'searchAdvancedCrawlCleanup' => true,
'authorArchives' => true,
'dateArchives' => true,
'searchArchives' => true,
'imageSeo' => true,
'completeSeoChecklist' => true,
'localBusinessInfo' => true,
'localBusinessOpeningHours' => true,
'locationsSettings' => true,
'advancedLocationsSettings' => true,
'localBusinessMapsApiKey' => true,
'localBusinessMapsSettings' => true,
'robotsEditor' => true,
'badBotBlocker' => true,
'databaseTools' => true,
'htaccessEditor' => true,
'databaseToolsLogs' => true,
'systemStatusInfo' => true,
'addNewRedirection' => true,
'redirectSettings' => true,
'debug' => true,
'fullSiteRedirectsRelocate' => true,
'fullSiteRedirectsAliases' => true,
'fullSiteRedirectsCanonical' => true,
'fullSiteRedirectsHttpHeaders' => true,
'htmlSitemap' => true,
'htmlSitemapSettings' => true,
'htmlSitemapAdvancedSettings' => true,
'linkAssistantSettings' => true,
'domainActivations' => true,
'404Settings' => true
],
'toggledRadio' => [
'locationsShowOnWebsite' => 'widget',
'breadcrumbsShowOnWebsite' => 'shortcode',
'breadcrumbsShowMoreSeparators' => false,
'searchShowMoreSeparators' => false,
'overviewPostType' => 'post',
],
'internalTabs' => [
'authorArchives' => 'title-description',
'dateArchives' => 'title-description',
'searchArchives' => 'title-description',
'seoAuditChecklist' => 'all-items'
],
'tablePagination' => [
'networkDomains' => 20,
'redirects' => 20,
'redirectLogs' => 20,
'redirect404Logs' => 20,
'sitemapAdditionalPages' => 20,
'linkAssistantLinksReport' => 20,
'linkAssistantPostsReport' => 20,
'linkAssistantDomainsReport' => 20,
'searchStatisticsSeoStatistics' => 20,
'searchStatisticsKeywordRankings' => 20,
'searchStatisticsPostDetailKeywords' => 20
]
];
/**
* The Construct method.
*
* @since 4.0.0
*
* @param string $settings An array of settings.
*/
public function __construct( $settings = '_aioseo_settings' ) {
$this->addDynamicDefaults();
$this->settingsName = $settings;
$this->settings = get_user_meta( get_current_user_id(), $settings, true )
? array_replace_recursive( $this->defaults, get_user_meta( get_current_user_id(), $settings, true ) )
: $this->defaults;
}
/**
* Adds some defaults that are dynamically generated.
*
* @since 4.0.0
*
* @return void
*/
private function addDynamicDefaults() {
$postTypes = aioseo()->helpers->getPublicPostTypes( false, false, true );
foreach ( $postTypes as $postType ) {
$this->defaults['toggledCards'][ $postType['name'] . 'SA' ] = true;
$this->defaults['internalTabs'][ $postType['name'] . 'SA' ] = 'title-description';
}
$taxonomies = aioseo()->helpers->getPublicTaxonomies( false, true );
foreach ( $taxonomies as $taxonomy ) {
$this->defaults['toggledCards'][ $taxonomy['name'] . 'SA' ] = true;
$this->defaults['internalTabs'][ $taxonomy['name'] . 'SA' ] = 'title-description';
}
$postTypes = aioseo()->helpers->getPublicPostTypes( false, true, true );
foreach ( $postTypes as $postType ) {
$this->defaults['toggledCards'][ $postType['name'] . 'ArchiveArchives' ] = true;
$this->defaults['internalTabs'][ $postType['name'] . 'ArchiveArchives' ] = 'title-description';
}
}
/**
* Retrieves all settings.
*
* @since 4.0.0
*
* @return array An array of settings.
*/
public function all() {
return array_replace_recursive( $this->defaults, $this->settings );
}
/**
* Retrieve a setting or null if missing.
*
* @since 4.0.0
*
* @param string $name The name of the property that is missing on the class.
* @param array $arguments The arguments passed into the method.
* @return mixed The value from the settings or default/null.
*/
public function __call( $name, $arguments = [] ) {
$value = isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : ( ! empty( $arguments[0] ) ? $arguments[0] : $this->getDefault( $name ) );
return $value;
}
/**
* Retrieve a setting or null if missing.
*
* @since 4.0.0
*
* @param string $name The name of the property that is missing on the class.
* @return mixed The value from the settings or default/null.
*/
public function __get( $name ) {
$value = isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : $this->getDefault( $name );
return $value;
}
/**
* Sets the settings value and saves to the database.
*
* @since 4.0.0
*
* @param string $name The name of the settings.
* @param mixed $value The value to set.
* @return void
*/
public function __set( $name, $value ) {
$this->settings[ $name ] = $value;
$this->update();
}
/**
* Checks if an settings is set or returns null if not.
*
* @since 4.0.0
*
* @param string $name The name of the settings.
* @return mixed True or null.
*/
public function __isset( $name ) {
return isset( $this->settings[ $name ] ) ? false === empty( $this->settings[ $name ] ) : null;
}
/**
* Unsets the settings value and saves to the database.
*
* @since 4.0.0
*
* @param string $name The name of the settings.
* @return void
*/
public function __unset( $name ) {
if ( ! isset( $this->settings[ $name ] ) ) {
return;
}
unset( $this->settings[ $name ] );
$this->update();
}
/**
* Gets the default value for a setting.
*
* @since 4.0.0
*
* @param string $name The settings name.
* @return mixed The default value.
*/
public function getDefault( $name ) {
return isset( $this->defaults[ $name ] ) ? $this->defaults[ $name ] : null;
}
/**
* Updates the settings in the database.
*
* @since 4.0.0
*
* @return void
*/
public function update() {
update_user_meta( get_current_user_id(), $this->settingsName, $this->settings );
}
}