Skip to content

Commit 9ceb025

Browse files
committed
refactor: rename settings 'options' key to 'default' for consistency
1 parent ee5768b commit 9ceb025

File tree

9 files changed

+1510
-121
lines changed

9 files changed

+1510
-121
lines changed

includes/admin/class-settings.php

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ public function get_translation_strings() {
236236
'reset_settings' => esc_html__( 'Reset all settings', 'knowledgebase' ),
237237
'reset_button_confirm' => esc_html__( 'Do you really want to reset all these settings to their default values?', 'knowledgebase' ),
238238
'checkbox_modified' => esc_html__( 'Modified from default setting', 'knowledgebase' ),
239+
'button_label' => esc_html__( 'Choose File', 'knowledgebase' ),
240+
'previous_saved' => esc_html__( 'Previously saved', 'knowledgebase' ),
239241
);
240242

241243
/**
@@ -336,7 +338,7 @@ public static function settings_general() {
336338
'name' => '<h3>' . esc_html__( 'Multi-Product Mode', 'knowledgebase' ) . '</h3>',
337339
'desc' => '',
338340
'type' => 'header',
339-
'options' => '',
341+
'default' => '',
340342
),
341343
'multi_product' => array(
342344
'id' => 'multi_product',
@@ -346,91 +348,128 @@ public static function settings_general() {
346348
'knowledgebase'
347349
),
348350
'type' => 'checkbox',
349-
'options' => false,
351+
'default' => false,
350352
),
351-
'slug_header' => array(
352-
'id' => 'slug_header',
353-
'name' => '<h3>' . esc_html__( 'Knowledge Base Permalink', 'knowledgebase' ) . '</h3>',
354-
'desc' => '',
353+
'permalink_header' => array(
354+
'id' => 'permalink_header',
355+
'name' => '<h3>' . esc_html__( 'Permalinks', 'knowledgebase' ) . '</h3>',
356+
'desc' => esc_html__( 'The following settings affect the permalinks of the knowledge base. These are set when registering the custom post type and taxonomy. Please visit the Permalinks page in the Settings menu to refresh permalinks if you get 404 errors.', 'knowledgebase' ),
355357
'type' => 'header',
356358
),
357359
'kb_slug' => array(
358360
'id' => 'kb_slug',
359361
'name' => esc_html__( 'Knowledge Base slug', 'knowledgebase' ),
360362
'desc' => esc_html__( 'This will set the opening path of the URL of the knowledge base and is set when registering the custom post type', 'knowledgebase' ),
361363
'type' => 'text',
362-
'options' => 'knowledgebase',
364+
'default' => 'knowledgebase',
363365
),
364366
'product_slug' => array(
365367
'id' => 'product_slug',
366368
'name' => esc_html__( 'Product slug', 'knowledgebase' ),
367369
'desc' => esc_html__( 'This slug forms part of the URL for product pages when Multi-Product Mode is enabled. The value is used when registering the custom taxonomy.', 'knowledgebase' ),
368370
'type' => 'text',
369-
'options' => 'kb/product',
371+
'default' => 'kb/product',
370372
),
371373
'category_slug' => array(
372374
'id' => 'category_slug',
373375
'name' => esc_html__( 'Section slug', 'knowledgebase' ),
374376
'desc' => esc_html__( 'Each section is a section of the knowledge base. This setting is used when registering the custom section and forms a part of the URL when browsing section archives', 'knowledgebase' ),
375377
'type' => 'text',
376-
'options' => 'kb/section',
378+
'default' => 'kb/section',
377379
),
378380
'tag_slug' => array(
379381
'id' => 'tag_slug',
380382
'name' => esc_html__( 'Tags slug', 'knowledgebase' ),
381383
'desc' => esc_html__( 'Each article can have multiple tags. This setting is used when registering the custom tag and forms a part of the URL when browsing tag archives', 'knowledgebase' ),
382384
'type' => 'text',
383-
'options' => 'kb/tags',
385+
'default' => 'kb/tags',
386+
),
387+
'article_permalink' => array(
388+
'id' => 'article_permalink',
389+
'name' => esc_html__( 'Article Permalink Structure', 'knowledgebase' ),
390+
'desc' => esc_html__( 'Structure for article URLs. Default: %postname%', 'knowledgebase' ),
391+
'type' => 'text',
392+
'default' => '%postname%',
393+
'field_class' => 'large-text',
394+
'pro' => true,
395+
),
396+
'performance_header' => array(
397+
'id' => 'performance_header',
398+
'name' => '<h3>' . esc_html__( 'Performance', 'knowledgebase' ) . '</h3>',
399+
'desc' => '',
400+
'type' => 'header',
384401
),
385402
'cache' => array(
386403
'id' => 'cache',
387404
'name' => esc_html__( 'Enable cache', 'knowledgebase' ),
388405
'desc' => esc_html__( 'Cache the output of the queries to speed up retrieval of the knowledgebase. Recommended for large knowledge bases', 'knowledgebase' ),
389406
'type' => 'checkbox',
390-
'options' => false,
407+
'default' => false,
408+
),
409+
'cache_expiry' => array(
410+
'id' => 'cache_expiry',
411+
'name' => esc_html__( 'Cache Time', 'knowledgebase' ),
412+
'desc' => esc_html__( 'How long should the knowledge base be cached for. Default is 1 day.', 'knowledgebase' ),
413+
'type' => 'select',
414+
'default' => DAY_IN_SECONDS,
415+
'options' => array(
416+
0 => esc_html__( 'No expiry', 'knowledgebase' ),
417+
HOUR_IN_SECONDS => esc_html__( '1 Hour', 'knowledgebase' ),
418+
6 * HOUR_IN_SECONDS => esc_html__( '6 Hours', 'knowledgebase' ),
419+
12 * HOUR_IN_SECONDS => esc_html__( '12 Hours', 'knowledgebase' ),
420+
DAY_IN_SECONDS => esc_html__( '1 Day', 'knowledgebase' ),
421+
3 * DAY_IN_SECONDS => esc_html__( '3 Days', 'knowledgebase' ),
422+
WEEK_IN_SECONDS => esc_html__( '1 Week', 'knowledgebase' ),
423+
2 * WEEK_IN_SECONDS => esc_html__( '2 Weeks', 'knowledgebase' ),
424+
MONTH_IN_SECONDS => esc_html__( '30 Days', 'knowledgebase' ),
425+
2 * MONTH_IN_SECONDS => esc_html__( '60 Days', 'knowledgebase' ),
426+
3 * MONTH_IN_SECONDS => esc_html__( '90 Days', 'knowledgebase' ),
427+
YEAR_IN_SECONDS => esc_html__( '1 Year', 'knowledgebase' ),
428+
),
429+
'pro' => true,
391430
),
392431
'uninstall_header' => array(
393432
'id' => 'uninstall_header',
394433
'name' => '<h3>' . esc_html__( 'Uninstall options', 'knowledgebase' ) . '</h3>',
395434
'desc' => '',
396435
'type' => 'header',
397-
'options' => '',
436+
'default' => '',
398437
),
399438
'uninstall_options' => array(
400439
'id' => 'uninstall_options',
401440
'name' => esc_html__( 'Delete options on uninstall', 'knowledgebase' ),
402441
'desc' => esc_html__( 'Check this box to delete the settings on this page when the plugin is deleted via the Plugins page in your WordPress Admin', 'knowledgebase' ),
403442
'type' => 'checkbox',
404-
'options' => true,
443+
'default' => true,
405444
),
406445
'uninstall_data' => array(
407446
'id' => 'uninstall_data',
408447
'name' => esc_html__( 'Delete all content on uninstall', 'knowledgebase' ),
409448
'desc' => esc_html__( 'Check this box to delete all the posts, categories and tags created by the plugin. There is no way to restore the data if you choose this option', 'knowledgebase' ),
410449
'type' => 'checkbox',
411-
'options' => false,
450+
'default' => false,
412451
),
413452
'feed_header' => array(
414453
'id' => 'feed_header',
415454
'name' => '<h3>' . esc_html__( 'Feed options', 'knowledgebase' ) . '</h3>',
416455
'desc' => '',
417456
'type' => 'header',
418-
'options' => '',
457+
'default' => '',
419458
),
420459
'include_in_feed' => array(
421460
'id' => 'include_in_feed',
422461
'name' => esc_html__( 'Include in feed', 'knowledgebase' ),
423462
'desc' => esc_html__( 'Adds the knowledge base articles to the main RSS feed for your site', 'knowledgebase' ),
424463
'type' => 'checkbox',
425-
'options' => true,
464+
'default' => true,
426465
),
427466
'disable_kb_feed' => array(
428467
'id' => 'disable_kb_feed',
429468
'name' => esc_html__( 'Disable KB feed', 'knowledgebase' ),
430469
/* translators: 1: Opening link tag, 2: Closing link tag. */
431470
'desc' => sprintf( esc_html__( 'The knowledge base articles have a default feed. This option will disable the feed. You might need to %1$srefresh your permalinks%2$s when changing this option.', 'knowledgebase' ), '<a href="' . admin_url( 'options-permalink.php' ) . '" target="_blank">', '</a>' ),
432471
'type' => 'checkbox',
433-
'options' => false,
472+
'default' => false,
434473
),
435474
);
436475

@@ -468,7 +507,7 @@ public static function settings_output() {
468507
'name' => esc_html__( 'First section level', 'knowledgebase' ),
469508
'desc' => esc_html__( 'This option allows you to create multi-level knowledge bases. This works in conjunction with the inbuilt styles. Set to 1 to lay out the top level sections in a grid. Set to 2 to lay out the second level categories in the grid. This is great if you have multiple products and want to create separate knowledge bases for each of them. The default option is 2 and was the behaviour of this plugin before v1.5.0.', 'knowledgebase' ),
470509
'type' => 'number',
471-
'options' => '2',
510+
'default' => '2',
472511
'size' => 'small',
473512
'min' => '1',
474513
'max' => '5',
@@ -478,35 +517,35 @@ public static function settings_output() {
478517
'name' => esc_html__( 'Show article count', 'knowledgebase' ),
479518
'desc' => esc_html__( 'If selected, the number of articles will be displayed in an orange circle next to the header. You can override the color by styling wzkb_section_count', 'knowledgebase' ),
480519
'type' => 'checkbox',
481-
'options' => true,
520+
'default' => true,
482521
),
483522
'show_excerpt' => array(
484523
'id' => 'show_excerpt',
485524
'name' => esc_html__( 'Show excerpt', 'knowledgebase' ),
486525
'desc' => esc_html__( 'Select to include the post excerpt after the article link', 'knowledgebase' ),
487526
'type' => 'checkbox',
488-
'options' => false,
527+
'default' => false,
489528
),
490529
'clickable_section' => array(
491530
'id' => 'clickable_section',
492531
'name' => esc_html__( 'Link section title', 'knowledgebase' ),
493532
'desc' => esc_html__( 'If selected, the title of each section of the knowledgebase will be linked to its own page', 'knowledgebase' ),
494533
'type' => 'checkbox',
495-
'options' => true,
534+
'default' => true,
496535
),
497536
'show_empty_sections' => array(
498537
'id' => 'show_empty_sections',
499538
'name' => esc_html__( 'Show empty sections', 'knowledgebase' ),
500539
'desc' => esc_html__( 'If selected, sections with no articles will also be displayed', 'knowledgebase' ),
501540
'type' => 'checkbox',
502-
'options' => false,
541+
'default' => false,
503542
),
504543
'limit' => array(
505544
'id' => 'limit',
506545
'name' => esc_html__( 'Max articles per section', 'knowledgebase' ),
507546
'desc' => esc_html__( 'Enter the number of articles that should be displayed in each section when viewing the knowledge base. After this limit is reached, the footer is displayed with the more link to view the category.', 'knowledgebase' ),
508547
'type' => 'number',
509-
'options' => '5',
548+
'default' => '5',
510549
'size' => 'small',
511550
'min' => '1',
512551
'max' => '500',
@@ -516,14 +555,14 @@ public static function settings_output() {
516555
'name' => esc_html__( 'Show sidebar', 'knowledgebase' ),
517556
'desc' => esc_html__( 'Add the sidebar of your theme into the inbuilt templates for archive, sections and search. Activate this option if your theme does not already include this.', 'knowledgebase' ),
518557
'type' => 'checkbox',
519-
'options' => false,
558+
'default' => false,
520559
),
521560
'show_related_articles' => array(
522561
'id' => 'show_related_articles',
523562
'name' => esc_html__( 'Show related articles', 'knowledgebase' ),
524563
'desc' => esc_html__( 'Add related articles at the bottom of the knowledge base article. Only works when using the inbuilt template.', 'knowledgebase' ),
525564
'type' => 'checkbox',
526-
'options' => true,
565+
'default' => true,
527566
),
528567
);
529568

includes/admin/settings/class-metabox-api.php

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/**
33
* Class to display and save a Metabox.
44
*
5-
* @since 2.3.0
6-
*
75
* @package WebberZone\Knowledge_Base
86
*/
97

@@ -15,7 +13,7 @@
1513
}
1614

1715
/**
18-
* ATA Metabox class to register the metabox for ata_snippets post type.
16+
* Metabox API class.
1917
*/
2018
#[\AllowDynamicProperties]
2119
class Metabox_API {
@@ -56,11 +54,11 @@ class Metabox_API {
5654
protected $title;
5755

5856
/**
59-
* Text to show to indicate a checkbox has been modified from its default value.
57+
* Translation strings.
6058
*
61-
* @var string Checkbox Modified Text.
59+
* @var array Translation strings.
6260
*/
63-
public $checkbox_modified_text;
61+
public $translation_strings;
6462

6563
/**
6664
* Array containing the settings' fields.
@@ -76,20 +74,20 @@ class Metabox_API {
7674
* Array or string of arguments. Default is blank array.
7775
*
7876
* @type string $settings_key Settings key - is used to prepare the form fields. It is not the meta key.
79-
* @type string $prefix Used to create the meta keys. The meta key format is _{$prefix}_{$setting_id}.
80-
* @type string|array|\WP_Screen $post_type The post type(s) on which to show the box.
81-
* @type array $registered_settings Settings fields array.
82-
* @type string $checkbox_modified_text Text to show to indicate a checkbox has been modified from its default value.
77+
* @type string $prefix Used to create the meta keys. The meta key format is _{$prefix}_{$setting_id}.
78+
* @type string|array|\WP_Screen $post_type The post type(s) on which to show the box.
79+
* @type array $registered_settings Settings fields array.
80+
* @type array $translation_strings Translation strings.
8381
* }
8482
*/
8583
public function __construct( $args ) {
8684
$defaults = array(
87-
'settings_key' => '',
88-
'prefix' => '',
89-
'post_type' => '',
90-
'title' => '',
91-
'registered_settings' => array(),
92-
'checkbox_modified_text' => '',
85+
'settings_key' => '',
86+
'prefix' => '',
87+
'post_type' => '',
88+
'title' => '',
89+
'registered_settings' => array(),
90+
'translation_strings' => array(),
9391
);
9492

9593
$args = wp_parse_args( $args, $defaults );
@@ -124,14 +122,14 @@ public function add_meta_boxes() {
124122
*/
125123
public function admin_enqueue_scripts( $hook ) {
126124
if ( in_array( $hook, array( 'post.php', 'post-new.php' ), true ) || get_current_screen()->post_type === $this->post_type ) {
127-
$this->enqueue_scripts_styles();
125+
self::enqueue_scripts_styles();
128126
}
129127
}
130128

131129
/**
132130
* Enqueues all scripts, styles, settings, and templates necessary to use the Settings API.
133131
*/
134-
public function enqueue_scripts_styles() {
132+
public static function enqueue_scripts_styles() {
135133

136134
$minimize = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
137135

@@ -154,10 +152,10 @@ public function enqueue_scripts_styles() {
154152
);
155153

156154
// Enqueue WZ Admin JS.
157-
wp_enqueue_script( 'wz-' . $this->prefix . '-admin' );
158-
wp_enqueue_script( 'wz-' . $this->prefix . '-codemirror' );
159-
wp_enqueue_script( 'wz-' . $this->prefix . '-taxonomy-suggest' );
160-
wp_enqueue_script( 'wz-' . $this->prefix . '-media-selector' );
155+
wp_enqueue_script( 'wz-admin-js' );
156+
wp_enqueue_script( 'wz-codemirror-js' );
157+
wp_enqueue_script( 'wz-taxonomy-suggest-js' );
158+
wp_enqueue_script( 'wz-media-selector-js' );
161159
}
162160

163161
/**
@@ -199,7 +197,7 @@ public function save( $post_id ) {
199197

200198
foreach ( $this->registered_settings as $setting ) {
201199
$id = $setting['id'];
202-
$type = isset( $setting['type'] ) ? $setting['type'] : 'text';
200+
$type = $setting['type'] ?? 'text';
203201

204202
/**
205203
* Skip settings that are not really settings.
@@ -225,7 +223,7 @@ public function save( $post_id ) {
225223
/**
226224
* Filter the post meta array which contains post-specific settings.
227225
*
228-
* @param array $post_meta Array of ATA metabox settings.
226+
* @param array $post_meta Array of metabox settings.
229227
* @param int $post_id Post ID
230228
*/
231229
$post_meta = apply_filters( "{$this->prefix}_meta_key", $post_meta, $post_id );
@@ -257,9 +255,9 @@ public function html( $post ) {
257255

258256
$settings_form = new Settings_Form(
259257
array(
260-
'settings_key' => $this->settings_key,
261-
'prefix' => $this->prefix,
262-
'checkbox_modified_text' => $this->checkbox_modified_text,
258+
'settings_key' => $this->settings_key,
259+
'prefix' => $this->prefix,
260+
'translation_strings' => $this->translation_strings,
263261
)
264262
);
265263

@@ -287,8 +285,8 @@ public function html( $post ) {
287285

288286
$id = $args['id'];
289287
$value = get_post_meta( $post->ID, "_{$this->prefix}_{$id}", true );
290-
$args['value'] = ! empty( $value ) ? $value : ( isset( $args['default'] ) ? $args['default'] : $args['options'] );
291-
$type = isset( $args['type'] ) ? $args['type'] : 'text';
288+
$args['value'] = ! empty( $value ) ? $value : ( $args['default'] ?? '' );
289+
$type = $args['type'] ?? 'text';
292290
$callback = method_exists( $settings_form, "callback_{$type}" ) ? array( $settings_form, "callback_{$type}" ) : array( $settings_form, 'callback_missing' );
293291

294292
echo '<tr>';
@@ -301,7 +299,7 @@ public function html( $post ) {
301299
echo '</table>';
302300

303301
/**
304-
* Action triggered when displaying the metabox.
302+
* Action triggered when displaying the meta box.
305303
*
306304
* @param object $post Post object.
307305
*/

0 commit comments

Comments
 (0)