Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion plugins/hwp-previews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ Post statuses are `publish`, `future`, `draft`, `pending`, `private`, `auto-draf
Navigate in WP Admin to **Settings › HWP Previews**. For each public post type, configure:

* **Enable HWP Previews** – Master switch
* **Unique Post Slugs** – Force unique slugs for all post statuses in the post status config.
* **Allow All Statuses as Parent** – (Hierarchical types only)
* **Preview URL Template** – Custom URL with tokens like `{ID}`, `{slug}`
* **Load Previews in Iframe** – Toggle iframe-based preview rendering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,11 @@ public function post_types_enabled( array $default_value = [] ): array;
public function url_template( string $post_type, string $default_value = '' ): string;

/**
* If the post type post statuses should have unique slug for the post type.
* It the specified post statuses should be allowed to be used as parent post statuses.
*
* @param string $post_type Post type slug.
* @param bool $default_value Default value.
*/
public function unique_post_slugs( string $post_type, bool $default_value = false ): bool;

/**
* It the specified post statuses should be allowed to be used as parent post statuses.
*
* @param string $post_type Post type slug.
* @param bool $default_value Default value.
*/
public function post_statuses_as_parent( string $post_type, bool $default_value = false ): bool;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ public function get_settings_key_enabled(): string {
return 'enabled';
}

/**
* Setting key for unique post slugs.
*/
public function get_settings_key_unique_post_slugs(): string {
return 'unique_post_slugs';
}

/**
* Setting key for post-statuses as parent.
*/
Expand Down Expand Up @@ -100,11 +93,10 @@ public function get_settings_key_in_iframe(): string {
*/
public function get_settings_config(): array {
return apply_filters( 'hwp_previews_settings_group_settings_config', [
$this->get_settings_key_enabled() => 'bool',
$this->get_settings_key_unique_post_slugs() => 'bool',
$this->get_settings_key_enabled() => 'bool',
$this->get_settings_key_post_statuses_as_parent() => 'bool',
$this->get_settings_key_preview_url() => 'string',
$this->get_settings_key_in_iframe() => 'bool',
$this->get_settings_key_preview_url() => 'string',
$this->get_settings_key_in_iframe() => 'bool',
] );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,6 @@ public function post_types_enabled( array $default_value = [] ): array {
return $default_value;
}

/**
* Get Unique Post Slugs setting value for the given post type.
*
* @param string $post_type The post type to get the setting for.
* @param bool $default_value The default value to return if the setting is not set.
*/
public function unique_post_slugs( string $post_type, bool $default_value = false ): bool {

$key = $this->settings_group->get_settings_key_unique_post_slugs();

return $this->settings_group->get_post_type_boolean_value( $key, $post_type, $default_value );
}

/**
* Get Post Statuses as Parent setting value for the given post type.
*
Expand Down
5 changes: 0 additions & 5 deletions plugins/hwp-previews/src/Admin/Settings_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ public static function create_settings_fields( string $post_type, string $label,
sprintf( __( 'Enable HWP Previews for %s', 'hwp-previews' ), $label ),
__( 'Turn preview functionality on or off for this public post type.', 'hwp-previews' )
);
$fields[] = new Checkbox_Field(
'unique_post_slugs',
__( 'Enable unique post slugs for all post statuses', 'hwp-previews' ),
__( 'By default WordPress adds unique post slugs to the published posts. This option enforces unique slugs for all post statuses.', 'hwp-previews' )
);

if ( $is_hierarchical ) {
$fields[] = new Checkbox_Field(
Expand Down
41 changes: 0 additions & 41 deletions plugins/hwp-previews/src/Hooks/Preview_Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
namespace HWP\Previews\Hooks;

use HWP\Previews\Admin\Settings\Helper\Settings_Helper;
use HWP\Previews\Post\Data\Post_Data_Model;
use HWP\Previews\Post\Parent\Post_Parent_Manager;
use HWP\Previews\Post\Slug\Post_Slug_Manager;
use HWP\Previews\Post\Slug\Post_Slug_Repository;
use HWP\Previews\Post\Status\Contracts\Post_Statuses_Config_Interface;
use HWP\Previews\Post\Status\Post_Statuses_Config;
use HWP\Previews\Post\Type\Contracts\Post_Types_Config_Interface;
Expand Down Expand Up @@ -65,9 +62,6 @@ public static function add_hook_actions(): void {
return;
}

// Enable the unique post slug functionality.
add_filter( 'wp_insert_post_data', [ self::class, 'enable_unique_post_slug' ], 10, 2 );

// Enable post statuses as parent for the post types specified in the post-types config.
add_filter( 'page_attributes_dropdown_pages_args', [ self::class, 'enable_post_statuses_as_parent' ], 10, 1 );
add_filter( 'quick_edit_dropdown_pages_args', [ self::class, 'enable_post_statuses_as_parent' ], 10, 1 );
Expand Down Expand Up @@ -145,41 +139,6 @@ public static function get_post_statuses(): array {
return apply_filters( 'hwp_previews_hooks_post_statuses', $post_statuses );
}

/**
* @TODO Remove as part of https://github.com/wpengine/hwptoolkit/issues/226
*
* @link https://developer.wordpress.org/reference/hooks/wp_insert_post_data/
*
* @param array<mixed> $data
* @param array<mixed> $postarr
*
* @return array<mixed>
*/
public static function enable_unique_post_slug( array $data, array $postarr ): array {
$post = new WP_Post( new Post_Data_Model( $data, (int) ( $postarr['ID'] ?? 0 ) ) );

if ( null === self::$settings_helper || null === self::$types_config || null === self::$statuses_config ) {
return $data;
}

// Check if the correspondent setting is enabled.
if ( ! self::$settings_helper->unique_post_slugs( $post->post_type ) ) {
return $data;
}

$post_slug = ( new Post_Slug_Manager(
self::$types_config,
self::$statuses_config,
new Post_Slug_Repository()
) )->force_unique_post_slug( $post );

if ( ! empty( $post_slug ) ) {
$data['post_name'] = $post_slug;
}

return $data;
}

/**
* Enable post statuses as parent for the post types specified in the post types config.
*
Expand Down

This file was deleted.

103 changes: 0 additions & 103 deletions plugins/hwp-previews/src/Post/Slug/Post_Slug_Manager.php

This file was deleted.