Skip to content

Commit 2916d1f

Browse files
committed
Reviewing admin functionality. Tidy up of docs etc.
1 parent 31501f8 commit 2916d1f

19 files changed

+185
-65
lines changed

plugins/hwp-previews/ACTIONS_AND_FILTERS.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@
88

99
## PHP Filters
1010

11+
## Admin
12+
13+
- `hwp_previews_settings_init` - Allows a user to modify the `Settings` instance
14+
- `hwp_previews_settings_form_manager_init` - Allows a user to modify the `Settings_Form_Manager` instance and update fields and post types
15+
- `hwp_previews_settings_fields` - Allows a user to register, modify, or remove settings fields for the settings page
16+
- `hwp_previews_settings_group_option_key` - Filter to modify the settings group option key. Default is HWP_PREVIEWS_SETTINGS_KEY
17+
- `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP
18+
19+
20+
1121
- `hwp_previews_register_parameters` - Allows modification of the URL parameters used for previews for the class `Preview_Parameter_Registry`
1222
- `hwp_previews_template_path` - To use our own template for iframe previews
1323
- `hwp_previews_core` - Register or unregister URL parameters, and adjust types/statuses
1424
- `hwp_previews_filter_available_post_types` - Filter to modify the available post types for Previews.
1525
- `hwp_previews_filter_available_post_statuses` - Filter for post statuses for previews for Previews
1626
- `hwp_previews_filter_available_parent_post_statuses` - Filter for parent post statuses for Previews
17-
- `hwp_previews_settings_group_option_key` - Filter to modify the settings group option key. Default is HWP_PREVIEWS_SETTINGS_KEY
18-
- `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP
1927
- `hwp_previews_settings_group_settings_config` - Filter to modify the settings array. See `Settings_Group`
2028
- `hwp_previews_settings_group_cache_groups` - Filter to modify cache groups for `Settings_Group`
2129
- `hwp_previews_get_post_types_config` - Filter for generating the instance of `Post_Types_Config_Interface`
2230
- `hwp_previews_hooks_post_status_config` - Filter for post status config service for the Hook class
2331
- `hwp_previews_hooks_preview_link_service` - Filter for preview link service for the Hook class
24-
- `hwp_previews_settings_fields` - Allows a user to register, modify, or remove settings fields for the settings page
2532

2633
## Usage Examples
2734

plugins/hwp-previews/activation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Activation Hook
44
*
55
* @package HWP\Previews
6+
*
7+
* @since 0.0.1
68
*/
79

810
declare(strict_types=1);

plugins/hwp-previews/deactivation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Deactivation Hook
77
*
88
* @package HWP\Previews
9+
*
10+
* @since 0.0.1
911
*/
1012

1113
/**

plugins/hwp-previews/hwp-previews.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ function hwp_previews_init(): void {
6464
if ( ! function_exists( 'hwp_previews_constants' ) ) {
6565
/**
6666
* Define plugin constants.
67-
*
68-
* phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
69-
* phpcs:disable SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
7067
*/
7168
function hwp_previews_constants(): void {
7269
if ( ! defined( 'HWP_PREVIEWS_VERSION' ) ) {
@@ -81,25 +78,13 @@ function hwp_previews_constants(): void {
8178
define( 'HWP_PREVIEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
8279
}
8380

84-
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_FILE' ) ) {
85-
define( 'HWP_PREVIEWS_PLUGIN_FILE', __FILE__ );
86-
}
87-
88-
if ( ! defined( 'HWP_PREVIEWS_AUTOLOAD' ) ) {
89-
define( 'HWP_PREVIEWS_AUTOLOAD', true );
90-
}
91-
9281
if ( ! defined( 'HWP_PREVIEWS_SETTINGS_GROUP' ) ) {
9382
define( 'HWP_PREVIEWS_SETTINGS_GROUP', 'hwp_previews_settings_group' );
9483
}
9584

9685
if ( ! defined( 'HWP_PREVIEWS_SETTINGS_KEY' ) ) {
9786
define( 'HWP_PREVIEWS_SETTINGS_KEY', 'hwp_previews_settings' );
9887
}
99-
100-
if ( ! defined( 'HWP_PREVIEWS_TEXT_DOMAIN' ) ) {
101-
define( 'HWP_PREVIEWS_TEXT_DOMAIN', 'hwp-previews' );
102-
}
10388
}
10489
}
10590

@@ -112,7 +97,7 @@ function hwp_previews_plugin_init(): ?Plugin {
11297
return null;
11398
}
11499
require_once HWP_PREVIEWS_PLUGIN_DIR . 'src/Plugin.php';
115-
return Plugin::instance();
100+
return Plugin::init();
116101
}
117102
}
118103

@@ -146,7 +131,7 @@ static function (): void {
146131
}
147132

148133
/**
149-
* Load plugin textdomain.
134+
* Load plugin text domain.
150135
*/
151136
function hwp_previews_load_textdomain(): void {
152137
load_plugin_textdomain( 'hwp-previews', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace HWP\Previews\Admin\Settings\Fields\Field;
66

77
use HWP\Previews\Admin\Settings\Fields\Settings_Field_Interface;
8+
use HWP\Previews\Preview\Post\Post_Settings_Service;
89

910
abstract class Abstract_Settings_Field implements Settings_Field_Interface {
1011
/**
@@ -121,7 +122,7 @@ public function add_settings_field( string $section, string $page, array $args )
121122
public function settings_field_callback( array $args ): void {
122123

123124
$post_type = $args['post_type'] ?? 'post';
124-
$settings_key = $args['settings_key'] ?? HWP_PREVIEWS_SETTINGS_KEY;
125+
$settings_key = $args['settings_key'] ?? Post_Settings_Service::get_option_key();
125126

126127
printf(
127128
'<div tabindex="0" aria-describedby="%2$s-tooltip" class="hwp-previews-tooltip">

plugins/hwp-previews/src/Admin/Settings/Fields/Field/Checkbox_Field.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
namespace HWP\Previews\Admin\Settings\Fields\Field;
66

7+
/**
8+
* Checkbox field class
9+
*
10+
* This class represents a checkbox field in the settings of the HWP Previews plugin.
11+
*
12+
* @package HWP\Previews
13+
*
14+
* @since 0.0.1
15+
*/
716
class Checkbox_Field extends Abstract_Settings_Field {
817
/**
918
* The default value for the field.

plugins/hwp-previews/src/Admin/Settings/Fields/Field/Text_Input_Field.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
namespace HWP\Previews\Admin\Settings\Fields\Field;
66

7+
/**
8+
* Text input class
9+
*
10+
* This class represents a text input field in the settings of the HWP Previews plugin.
11+
*
12+
* @package HWP\Previews
13+
*
14+
* @since 0.0.1
15+
*/
716
class Text_Input_Field extends Abstract_Settings_Field {
817
/**
918
* The default value for the field.

plugins/hwp-previews/src/Admin/Settings/Fields/Field/URL_Input_Field.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
namespace HWP\Previews\Admin\Settings\Fields\Field;
66

7+
/**
8+
* URL input class
9+
*
10+
* This class represents a url input field in the settings of the HWP Previews plugin.
11+
*
12+
* @package HWP\Previews
13+
*
14+
* @since 0.0.1
15+
*/
716
class URL_Input_Field extends Text_Input_Field {
817
/**
918
* @param mixed $value
@@ -64,8 +73,8 @@ private function fix_url( string $value ): string {
6473
return '';
6574
}
6675

67-
$has_prootocol = preg_match( '/^https?:\/\//i', $value ) === 1;
68-
if ( $has_prootocol ) {
76+
$has_protocol = preg_match( '/^https?:\/\//i', $value ) === 1;
77+
if ( $has_protocol ) {
6978
return $value;
7079
}
7180
$protocol = is_ssl() ? 'https://' : 'http://';

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
use HWP\Previews\Admin\Settings\Fields\Field\Checkbox_Field;
88
use HWP\Previews\Admin\Settings\Fields\Field\URL_Input_Field;
99

10+
/**
11+
* Class Settings_Field_Collection
12+
*
13+
* This class manages a collection of settings fields for the HWP Previews plugin.
14+
* It provides methods to add, remove, and retrieve fields, as well as to initialize them.
15+
*
16+
* @package HWP\Previews
17+
*
18+
* @since 0.0.1
19+
*/
1020
class Settings_Field_Collection {
1121
/**
1222
* The ID of the field that enables or disables the previews.

plugins/hwp-previews/src/Admin/Settings/Menu/Menu_Page.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
namespace HWP\Previews\Admin\Settings\Menu;
66

7+
/**
8+
* Menu class for WordPress admin settings page.
9+
*
10+
* This class is responsible for creating a menu page in the WordPress admin area.
11+
*
12+
* @package HWP\Previews
13+
*
14+
* @since 0.0.1
15+
*/
716
class Menu_Page {
817
/**
918
* The title of the page.

0 commit comments

Comments
 (0)