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
36 changes: 36 additions & 0 deletions includes/class-spacefast-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ public static function register_simply_static(): void {
require_once dirname( __DIR__ ) . '/includes/class-spacefast-simply-static-task.php';
add_filter( 'simplystatic.archive_creation_job.task_list', array( __CLASS__, 'simply_static_tasks' ), 20, 2 );
add_filter( 'simply_static_class_name', array( __CLASS__, 'simply_static_task_class' ), 20, 2 );
add_filter( 'ss_additional_urls', array( __CLASS__, 'simply_static_archive_urls' ), 20 );
add_action( 'ss_archive_creation_job_after_start_queue', array( __CLASS__, 'static_export_started' ), 20 );
}

Expand Down Expand Up @@ -891,6 +892,41 @@ public static function simply_static_task_class( string $class_name, string $tas
: $class_name;
}

/**
* Simply Static discovers custom post entries but not every custom post type
* archive. Include those archive routes so navigation links cannot publish as
* broken pages.
*
* @param array<int,string> $urls Additional source URLs.
* @return array<int,string>
*/
public static function simply_static_archive_urls( array $urls ): array {
if ( Spacefast_Settings::MODE_STATIC !== Spacefast_Settings::mode() ) {
return $urls;
}
$options = get_option( 'simply-static', array() );
$options = is_array( $options ) ? $options : array();
$selected = isset( $options['post_types'] ) && is_array( $options['post_types'] )
? $options['post_types']
: array();
$configured = ! empty( $options['post_types_configured'] ) || array() !== $selected;
$post_types = get_post_types( array( 'public' => true ), 'objects' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Filter archives by front-end viewability

When a post type is registered with public => false, publicly_queryable => true, and has_archive => true, WordPress can expose a working front-end archive, but this query omits it because it checks only public. Conversely, a type can be public while explicitly not publicly queryable and will be added even though its archive route is not viewable. Determine eligibility using the post type's front-end viewability so valid archive links are exported without queueing inaccessible routes.

Useful? React with 👍 / 👎.

foreach ( $post_types as $name => $post_type ) {
if (
'attachment' === $name
|| empty( $post_type->has_archive )
|| ( $configured && ! in_array( $name, $selected, true ) )
) {
continue;
}
$archive_url = get_post_type_archive_link( $name );
if ( is_string( $archive_url ) && '' !== $archive_url ) {
$urls[] = $archive_url;
}
}
return array_values( array_unique( $urls ) );
}

public static function static_export_started( int $blog_id = 0 ): void {
unset( $blog_id );
if (
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: spacefast
Tags: static site, headless cms, simply static, deployment
Requires at least: 6.5
Requires PHP: 8.1
Stable tag: 0.5.6
Stable tag: 0.5.7
License: GPLv2 or later

Publish a Simply Static export to Spacefast, or rebuild a headless site when WordPress content changes.
Expand Down Expand Up @@ -31,6 +31,9 @@ OAuth access is limited to the Team you authorize and the mode you choose. WordP

== Changelog ==

= 0.5.7 =
* Include public custom post type archive routes in Simply Static exports.

= 0.5.6 =
* Make static WordPress exports publicly readable by default while preserving an explicit sf.jsonc access policy.

Expand Down
4 changes: 2 additions & 2 deletions spacefast-wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Spacefast
* Plugin URI: https://spacefast.com/
* Description: Publishes static WordPress exports or rebuilds a headless Spacefast site.
* Version: 0.5.6
* Version: 0.5.7
* Update URI: https://github.com/spacefast/wordpress
* Requires at least: 6.5
* Requires PHP: 8.1
Expand All @@ -14,7 +14,7 @@

defined( 'ABSPATH' ) || exit;

define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.6' );
define( 'SPACEFAST_WORDPRESS_VERSION', '0.5.7' );
define( 'SPACEFAST_WORDPRESS_FILE', __FILE__ );

require_once __DIR__ . '/includes/class-spacefast-settings.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function spacefast_accept( bool $condition, string $message ): void {
);

$plugin = get_plugin_data( WP_PLUGIN_DIR . '/spacefast-wordpress/spacefast-wordpress.php', false, false );
spacefast_accept( '0.5.6' === $plugin['Version'], 'Unexpected plugin version.' );
spacefast_accept( '0.5.7' === $plugin['Version'], 'Unexpected plugin version.' );
spacefast_accept( 'https://github.com/spacefast/wordpress' === $plugin['UpdateURI'], 'Update URI is missing.' );

Spacefast_Settings::disconnect();
Expand Down
37 changes: 37 additions & 0 deletions tests/behavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ function wp_json_encode( $value ): string {
function get_post_type_object( string $post_type ) {
return $GLOBALS['spacefast_post_types'][ $post_type ] ?? null;
}
function get_post_types( array $args = array(), string $output = 'names' ): array {
$post_types = array_filter(
$GLOBALS['spacefast_post_types'],
static fn( object $post_type ): bool => ! isset( $args['public'] ) || $post_type->public === $args['public']
);
return 'objects' === $output ? $post_types : array_keys( $post_types );
}
function get_post_type_archive_link( string $post_type ) {
return $GLOBALS['spacefast_post_types'][ $post_type ]->archive_link ?? false;
}
function wp_generate_uuid4(): string {
return '00000000-0000-4000-8000-000000000001';
}
Expand Down Expand Up @@ -839,6 +849,33 @@ static function ( string $url ) use ( &$invalid_receipt_requests ): array {
),
'publishes after export delivery and before cleanup'
);
$GLOBALS['spacefast_post_types']['case_study'] = (object) array(
'public' => true,
'has_archive' => 'case-studies',
'archive_link' => 'https://wp.example.test/case-studies/',
);
$GLOBALS['spacefast_post_types']['private_story'] = (object) array(
'public' => false,
'has_archive' => 'private-stories',
'archive_link' => 'https://wp.example.test/private-stories/',
);
check(
array( 'https://wp.example.test/manual/', 'https://wp.example.test/case-studies/' )
=== Spacefast_Plugin::simply_static_archive_urls(
array( 'https://wp.example.test/manual/', 'https://wp.example.test/case-studies/' )
),
'includes public custom post archives once in static exports'
);
$GLOBALS['spacefast_options']['simply-static'] = array(
'post_types' => array( 'post' ),
'post_types_configured' => true,
);
check(
array( 'https://wp.example.test/manual/' )
=== Spacefast_Plugin::simply_static_archive_urls( array( 'https://wp.example.test/manual/' ) ),
'respects the Simply Static post type selection for archives'
);
unset( $GLOBALS['spacefast_options']['simply-static'] );

$archive = sys_get_temp_dir() . '/spacefast-wordpress-static-' . uniqid();
mkdir( $archive );
Expand Down
Loading