Skip to content

Commit eab3d3e

Browse files
committed
Updated docs for actions and filters.
1 parent fd41d15 commit eab3d3e

File tree

2 files changed

+60
-63
lines changed

2 files changed

+60
-63
lines changed
Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
11
# Actions & Filters
22

3-
## PHP Actions
3+
## Table of Contents
44

5-
- `hwp_previews_activate` - Plugin activation hook
6-
- `hwp_previews_deactivate` - Plugin deactivation hook
7-
- `hwp_previews_init` - Plugin initialization hook
5+
- [PHP Actions](#php-actions)
6+
- [PHP Filters](#php-filters)
7+
- [Examples](#examples)
8+
- [Actions](#actions)
9+
- [Filters](#filters)
10+
- [Contributing](#contributing)
811

9-
## PHP Filters
12+
---
1013

11-
## Admin
14+
This document lists the available PHP actions and filters provided by the HWP Previews plugin, along with explanations and usage examples. These hooks allow you to customize plugin behavior, settings, and integration with other plugins or your theme.
1215

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
16+
---
1817

18+
## PHP Actions
1919

20+
| Action Name | Description |
21+
|-----------------------------------------------|-----------------------------------------------------------------------------------------------|
22+
| `hwp_previews_init` | Fired after the plugin is initialized. |
23+
| `hwp_previews_activate` | Fired on plugin activation. |
24+
| `hwp_previews_deactivate` | Fired on plugin deactivation. |
25+
| `hwp_previews_settings_init` | Fired after the settings page is initialized. |
26+
| `hwp_previews_settings_form_manager_init` | Fired after the settings form manager is initialized. |
2027

21-
- `hwp_previews_register_parameters` - Allows modification of the URL parameters used for previews for the class `Preview_Parameter_Registry`
22-
- `hwp_previews_template_path` - To use our own template for iframe previews
23-
- `hwp_previews_core` - Register or unregister URL parameters, and adjust types/statuses
24-
- `hwp_previews_filter_available_post_types` - Filter to modify the available post types for Previews.
25-
- `hwp_previews_filter_available_post_statuses` - Filter for post statuses for previews for Previews
26-
- `hwp_previews_filter_available_parent_post_statuses` - Filter for parent post statuses for Previews
27-
- `hwp_previews_settings_group_settings_config` - Filter to modify the settings array. See `Settings_Group`
28-
- `hwp_previews_settings_group_cache_groups` - Filter to modify cache groups for `Settings_Group`
29-
- `hwp_previews_get_post_types_config` - Filter for generating the instance of `Post_Types_Config_Interface`
30-
- `hwp_previews_hooks_post_status_config` - Filter for post status config service for the Hook class
31-
- `hwp_previews_hooks_preview_link_service` - Filter for preview link service for the Hook class
28+
---
3229

33-
## Usage Examples
30+
## PHP Filters
3431

35-
@TODO - Redo
32+
| Filter Name | Description |
33+
|-----------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
34+
| `hwp_previews_settings_fields` | Modify or add settings fields for the settings page. |
35+
| `hwp_previews_settings_group_option_key` | Change the settings group option key (default: `HWP_PREVIEWS_SETTINGS_KEY`). |
36+
| `hwp_previews_settings_group_settings_group` | Change the settings group name (default: `HWP_PREVIEWS_SETTINGS_GROUP`). |
37+
| `hwp_previews_register_parameters` | Allows users to modify or register parameters. |
38+
| `hwp_previews_template_path` | Change the template file path for iframe previews. |
39+
| `hwp_previews_filter_available_post_types` | Filter the available post types for previews (affects settings UI and preview logic). |
40+
| `hwp_previews_filter_available_post_statuses` | Filter the available post statuses for previews. |
3641

42+
---
43+
44+
## Examples
45+
46+
Below is some examples of usage for these actions/filters.
3747

38-
### Filter: Post Types List
3948

40-
Modify which post types appear in the settings UI:
49+
#### `hwp_previews_filter_available_post_types`
50+
**Description:**
51+
Filter the available post types for previews (affects settings UI and preview logic).
4152

4253
```php
4354
// Removes attachment post type from the settings page configuration.
@@ -51,51 +62,32 @@ function hwp_previews_filter_post_type_setting_callback( $post_types ) {
5162
}
5263
```
5364

54-
### Action: Core Registry
5565

56-
Register or unregister URL parameters, and adjust types/statuses:
66+
#### `hwp_previews_template_path`
67+
**Description:**
68+
Change the template file path for iframe previews.
5769

5870
```php
59-
add_action( 'hwp_previews_core', 'modify_preview_url_parameters' );
60-
function modify_preview_url_parameters(
61-
\HWP\Previews\Preview\Parameter\Preview_Parameter_Registry $registry
62-
) {
63-
// Remove default parameter
64-
$registry->unregister( 'author_ID' );
65-
66-
// Add custom parameter
67-
$registry->register( new \HWP\Previews\Preview\Parameter\Preview_Parameter(
68-
'current_time',
69-
static fn( \WP_Post $post ) => (string) time(),
70-
__( 'Current Unix timestamp', 'your-domain' )
71-
) );
72-
}
73-
```
74-
75-
Modify post types and statuses:
76-
77-
```php
78-
add_action( 'hwp_previews_core', 'modify_post_types_and_statuses_configs', 10, 3 );
79-
function modify_post_types_and_statuses_configs(
80-
\HWP\Previews\Preview\Parameter\Preview_Parameter_Registry $registry,
81-
\HWP\Previews\Post\Type\Post_Types_Config $types,
82-
\HWP\Previews\Post\Status\Post_Statuses_Config $statuses
83-
) {
84-
// Limit to pages only
85-
$types->set_post_types( [ 'page' ] );
86-
// Only include drafts
87-
$statuses->set_post_statuses( [ 'draft' ] );
88-
}
71+
add_filter( 'hwp_previews_template_path', function( $default_path ) {
72+
return get_stylesheet_directory() . '/my-preview-template.php';
73+
});
8974
```
9075

91-
### Filter: Iframe Template Path
92-
93-
Use your own template for iframe previews:
76+
#### `hwp_previews_settings_group_option_key` and `hwp_previews_settings_group_settings_group`
77+
**Description:**
78+
Change the settings group option key or group name.
9479

9580
```php
96-
add_filter( 'hwp_previews_template_path', function( $default_path ) {
97-
return get_stylesheet_directory() . '/my-preview-template.php';
81+
add_filter( 'hwp_previews_settings_group_option_key', function( $default_key ) {
82+
return 'my_custom_option_key';
83+
});
84+
add_filter( 'hwp_previews_settings_group_settings_group', function( $default_group ) {
85+
return 'my_custom_settings_group';
9886
});
9987
```
10088

10189
---
90+
91+
## Contributing
92+
93+
If you feel like something is missing or you want to add tests or testing documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.

plugins/hwp-previews/TESTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ We have a few checks which run for a new PR being merged to main
102102
## Setup Tests Locally
103103

104104
@TODO
105+
106+
107+
## Contributing
108+
109+
If you feel like something is missing or you want to add tests or testing documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.

0 commit comments

Comments
 (0)