Skip to content

Commit 920735e

Browse files
committed
Refactor settings to make it easier to test.
1 parent df45c0a commit 920735e

31 files changed

+701
-708
lines changed

plugins/hwp-previews/ACTIONS_AND_FILTERS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
## PHP Filters
1010

1111
- `hwp_previews_register_parameters` - Allows modification of the URL parameters used for previews for the class `Preview_Parameter_Registry`
12-
- `hwp_previews_filter_post_type_setting` - Filter or modify what post types appear in the settings UI
1312
- `hwp_previews_template_path` - To use our own template for iframe previews
1413
- `hwp_previews_core` - Register or unregister URL parameters, and adjust types/statuses
14+
- `hwp_previews_filter_available_post_types` - Filter to modify the available post types for Previews.
1515
- `hwp_previews_settings_group_option_key` - Filter to modify the settings group option key. Default is HWP_PREVIEWS_SETTINGS_KEY
1616
- `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP
1717
- `hwp_previews_settings_group_settings_config` - Filter to modify the settings array. See `Settings_Group`
@@ -21,7 +21,7 @@
2121
- `hwp_previews_hooks_post_status_config` - Filter for post status config service for the Hook class
2222
- `hwp_previews_hooks_preview_link_service` - Filter for preview link service for the Hook class
2323
- `hwp_previews_hooks_post_statuses` - Filter for post statuses for previews for the Hook Class
24-
24+
- `hwp_previews_settings_fields` - Allows a user to register, modify, or remove settings fields for the settings page
2525

2626
## Usage Examples
2727

plugins/hwp-previews/activation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @package HWP\Previews
66
*/
77

8-
declare( strict_types = 1 );
8+
declare(strict_types=1);
99

1010
/**
1111
* Runs when the plugin is activated.

plugins/hwp-previews/bin/run-qa.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
# Running PHP Code Quality Analysis locally
4+
composer run check-cs
5+
composer run phpstan
6+
composer run php:psalm

plugins/hwp-previews/codeception.dist.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ modules:
9494
adminEmail: "%WORDPRESS_ADMIN_EMAIL%"
9595
title: 'Test'
9696
plugins:
97-
- wp-graphql/wp-graphql.php
9897
- hwp-previews/hwp-previews.php
9998
activatePlugins:
100-
- wp-graphql/wp-graphql.php
10199
- hwp-previews/hwp-previews.php
102100
configFile: 'tests/_data/config.php'

plugins/hwp-previews/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"autoload-dev": {
102102
"psr-4": {
103103
"HWP\\Previews\\Unit\\": "tests/unit/",
104+
"HWP\\Previews\\Functional\\": "tests/functional/",
104105
"HWP\\Previews\\Integration\\": "tests/integration/",
105106
"HWP\\Previews\\PHPStan\\": "phpstan/",
106107
"HWPStandard\\": "phpcs/HWPStandard"
@@ -130,8 +131,6 @@
130131
"php:psalm:info": "psalm --show-info=true",
131132
"php:psalm:fix": "psalm --alter"
132133
},
133-
"scripts-descriptions": {
134-
},
135134
"support": {
136135
"docs": "https://github.com/wpengine/hwptoolkit/tree/main/docs",
137136
"email": "[email protected]",

plugins/hwp-previews/hwp-previews.php

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,41 @@
4848

4949
/**
5050
* Define plugin constants.
51+
*
52+
* phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
53+
* phpcs:disable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
5154
*/
5255
function hwp_previews_constants(): void {
53-
$constants = [
54-
'HWP_PREVIEWS_VERSION' => '0.0.1',
55-
'HWP_PREVIEWS_PLUGIN_DIR' => plugin_dir_path( __FILE__ ),
56-
'HWP_PREVIEWS_PLUGIN_URL' => plugin_dir_url( __FILE__ ),
57-
'HWP_PREVIEWS_PLUGIN_FILE' => __FILE__,
58-
'HWP_PREVIEWS_AUTOLOAD' => true,
59-
'HWP_PREVIEWS_SETTINGS_GROUP' => 'hwp_previews_settings_group',
60-
'HWP_PREVIEWS_SETTINGS_KEY' => 'hwp_previews_settings',
61-
'HWP_PREVIEWS_TEXT_DOMAIN' => 'hwp-previews',
62-
];
63-
64-
foreach ( $constants as $name => $value ) {
65-
if ( ! defined( $name ) ) {
66-
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
67-
define( $name, $value );
68-
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
69-
}
56+
if ( ! defined( 'HWP_PREVIEWS_VERSION' ) ) {
57+
define( 'HWP_PREVIEWS_VERSION', '0.0.1' );
58+
}
59+
60+
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) {
61+
define( 'HWP_PREVIEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
62+
}
63+
64+
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_URL' ) ) {
65+
define( 'HWP_PREVIEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
66+
}
67+
68+
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_FILE' ) ) {
69+
define( 'HWP_PREVIEWS_PLUGIN_FILE', __FILE__ );
70+
}
71+
72+
if ( ! defined( 'HWP_PREVIEWS_AUTOLOAD' ) ) {
73+
define( 'HWP_PREVIEWS_AUTOLOAD', true );
74+
}
75+
76+
if ( ! defined( 'HWP_PREVIEWS_SETTINGS_GROUP' ) ) {
77+
define( 'HWP_PREVIEWS_SETTINGS_GROUP', 'hwp_previews_settings_group' );
78+
}
79+
80+
if ( ! defined( 'HWP_PREVIEWS_SETTINGS_KEY' ) ) {
81+
define( 'HWP_PREVIEWS_SETTINGS_KEY', 'hwp_previews_settings' );
82+
}
83+
84+
if ( ! defined( 'HWP_PREVIEWS_TEXT_DOMAIN' ) ) {
85+
define( 'HWP_PREVIEWS_TEXT_DOMAIN', 'hwp-previews' );
7086
}
7187

7288
// Plugin Template Directory.
@@ -75,6 +91,9 @@ function hwp_previews_constants(): void {
7591
}
7692
}
7793

94+
// phpcs:enable Generic.Metrics.CyclomaticComplexity.TooHigh
95+
// phpcs:enable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
96+
7897
/**
7998
* Initializes plugin.
8099
*/

plugins/hwp-previews/phpcs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
<description>Coding standards for the HWP Previews plugin</description>
99
<file>./hwp-previews.php</file>
10+
<file>./activation.php</file>
11+
<file>./deactivation.php</file>
1012
<file>./vendor/autoload.php</file>
1113
<file>./src/</file>
1214
<exclude-pattern>*/languages/*</exclude-pattern>

plugins/hwp-previews/src/Admin/Settings/Contracts/Menu_Page_Interface.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

plugins/hwp-previews/src/Admin/Settings/Contracts/Post_Types_Settings_Interface.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

plugins/hwp-previews/src/Admin/Settings/Fields/Abstract_Settings_Field.php

Lines changed: 0 additions & 162 deletions
This file was deleted.

0 commit comments

Comments
 (0)