-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLANET-7177 Move Default P4 Post Type setting under Settings > Writing (
#2094) This is to simplify our settings and improve UX
- Loading branch information
Showing
6 changed files
with
100 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace P4\MasterTheme\Migrations; | ||
|
||
use P4\MasterTheme\MigrationRecord; | ||
use P4\MasterTheme\MigrationScript; | ||
use P4\MasterTheme\Settings\DefaultPostType; | ||
|
||
class M021MigrateDefaultPostType extends MigrationScript | ||
{ | ||
/** | ||
* Perform the actual migration. | ||
* | ||
* @param MigrationRecord $record Information on the execution, can be used to add logs. | ||
* phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter -- interface implementation | ||
*/ | ||
public static function execute(MigrationRecord $record): void | ||
{ | ||
$value = planet4_get_option('default_p4_pagetype'); | ||
|
||
$options = get_option('planet4_options'); | ||
unset($options['default_p4_pagetype']); | ||
update_option('planet4_options', $options); | ||
|
||
if (!$value) { | ||
return; | ||
} | ||
|
||
update_option(DefaultPostType::KEY, $value); | ||
} | ||
// phpcs:enable SlevomatCodingStandard.Functions.UnusedParameter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace P4\MasterTheme\Settings; | ||
|
||
class DefaultPostType | ||
{ | ||
public const KEY = 'planet4_default_post_type'; | ||
|
||
public function __construct() | ||
{ | ||
$this->hooks(); | ||
} | ||
|
||
public function hooks(): void | ||
{ | ||
add_action('admin_init', [self::class, 'register_settings']); | ||
} | ||
|
||
public static function register_settings(): void | ||
{ | ||
register_setting( | ||
'writing', | ||
self::KEY, | ||
['type' => 'integer'], | ||
); | ||
|
||
add_settings_field( | ||
self::KEY, | ||
__('Default P4 Post Type', 'planet4-master-theme-backend'), | ||
[self::class, 'settings_field'], | ||
'writing', | ||
); | ||
} | ||
|
||
public static function settings_field(): void | ||
{ | ||
wp_dropdown_categories( | ||
[ | ||
'show_option_none' => __('Select Post Type', 'planet4-master-theme-backend'), | ||
'hide_empty' => 0, | ||
'orderby' => 'name', | ||
'selected' => self::get_option(), | ||
'name' => self::KEY, | ||
'taxonomy' => 'p4-page-type', | ||
] | ||
); | ||
} | ||
|
||
public static function get_option(): int | ||
{ | ||
return get_option(self::KEY); | ||
} | ||
} |