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
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions includes/AMP/Output_Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ public static function is_needed(): bool {

$has_old_amp_version = ! \defined( '\AMP__VERSION' ) || ( \defined( '\AMP__VERSION' ) && version_compare( \AMP__VERSION, WEBSTORIES_AMP_VERSION, '<' ) );
$amp_available = \function_exists( 'amp_is_available' ) && amp_is_available();
$amp_enabled = \function_exists( 'amp_is_enabled' ) && amp_is_enabled(); // Technically an internal method.
$amp_initialized = did_action( 'amp_init' ) > 0;
$amp_supported_post = \function_exists( 'amp_is_post_supported' ) && amp_is_post_supported( $current_post->ID ?? 0 );

// @phpstan-ignore function.internal
$amp_enabled = \function_exists( 'amp_is_enabled' ) && amp_is_enabled();
$amp_initialized = did_action( 'amp_init' ) > 0;
$amp_supported_post = \function_exists( 'amp_is_post_supported' ) && amp_is_post_supported( $current_post->ID ?? 0 );

return $has_old_amp_version || ! $amp_available || ! $amp_enabled || ! $amp_initialized || ! $amp_supported_post;
}
Expand Down
1 change: 1 addition & 0 deletions includes/Media/Media_Source_Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public function filter_rest_generated_media_attachments( $args ) {
* @since 1.29.0
*/
private function add_missing_terms(): void {
// @phpstan-ignore function.internal (false positive)
$existing_terms = get_terms(
[
'taxonomy' => $this->get_taxonomy_slug(),
Expand Down
1 change: 0 additions & 1 deletion includes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class Plugin extends ServiceBasedPlugin {
'rest.products' => REST_API\Products_Controller::class,
'rest.publisher_logos' => REST_API\Publisher_Logos_Controller::class,
'rest.status_check_controller' => REST_API\Status_Check_Controller::class,
'rest.stories_autosave' => REST_API\Stories_Autosaves_Controller::class,
'rest.stories_lock' => REST_API\Stories_Lock_Controller::class,
'rest.media' => REST_API\Stories_Media_Controller::class,
'rest.settings' => REST_API\Stories_Settings_Controller::class,
Expand Down
1 change: 1 addition & 0 deletions includes/REST_API/Font_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public function prepare_item_for_response( $item, $request ): WP_REST_Response {
$self = $links['self']['href'];

foreach ( $actions as $rel ) {
// @phpstan-ignore method.internal (false positive)
$response->add_link( $rel, $self );
}
}
Expand Down
76 changes: 20 additions & 56 deletions includes/REST_API/Stories_Autosaves_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@

namespace Google\Web_Stories\REST_API;

use Google\Web_Stories\Infrastructure\Delayed;
use Google\Web_Stories\Infrastructure\HasRequirements;
use Google\Web_Stories\Infrastructure\Registerable;
use Google\Web_Stories\Infrastructure\Service;
use Google\Web_Stories\Story_Post_Type;
use WP_Post;
use WP_REST_Autosaves_Controller;
use WP_REST_Controller;
Expand All @@ -43,11 +38,9 @@
/**
* Stories_Autosaves_Controller class.
*
* Register using register_post_type once https://core.trac.wordpress.org/ticket/56922 is committed.
*
* @phpstan-import-type Schema from \Google\Web_Stories\REST_API\Stories_Base_Controller
*/
class Stories_Autosaves_Controller extends WP_REST_Autosaves_Controller implements Service, Delayed, Registerable, HasRequirements {
class Stories_Autosaves_Controller extends WP_REST_Autosaves_Controller {

/**
* Parent post controller.
Expand All @@ -64,58 +57,28 @@ class Stories_Autosaves_Controller extends WP_REST_Autosaves_Controller implemen
*
* @since 1.0.0
*
* @param Story_Post_Type $story_post_type Story_Post_Type instance.
*/
public function __construct( Story_Post_Type $story_post_type ) {
parent::__construct( $story_post_type->get_slug() );

$this->parent_controller = $story_post_type->get_parent_controller();
$this->parent_base = $story_post_type->get_rest_base();
$this->namespace = $story_post_type->get_rest_namespace();
}

/**
* Register the service.
*
* @since 1.7.0
* @param string $parent_post_type Post type of the parent.
*/
public function register(): void {
$this->register_routes();
}
public function __construct( string $parent_post_type ) {
parent::__construct( $parent_post_type );

/**
* Get the action to use for registering the service.
*
* @since 1.7.0
*
* @return string Registration action to use.
*/
public static function get_registration_action(): string {
return 'rest_api_init';
}
/**
* Post type instance.
*
* @var \WP_Post_Type $post_type_object
*/
$post_type_object = get_post_type_object( $parent_post_type );

/**
* Get the action priority to use for registering the service.
*
* @since 1.7.0
*
* @return int Registration action priority to use.
*/
public static function get_registration_action_priority(): int {
return 100;
}
/**
* Parent controller instance.
*
* @var WP_REST_Controller $parent_controller
*/
$parent_controller = $post_type_object->get_rest_controller();

/**
* Get the list of service IDs required for this service to be registered.
*
* Needed because the story post type needs to be registered first.
*
* @since 1.13.0
*
* @return string[] List of required services.
*/
public static function get_requirements(): array {
return [ 'story_post_type' ];
$this->parent_controller = $parent_controller;
$this->parent_base = ! empty( $post_type_object->rest_base ) ? (string) $post_type_object->rest_base : $post_type_object->name;
$this->namespace = ! empty( $post_type_object->rest_namespace ) ? (string) $post_type_object->rest_namespace : 'wp/v2';
}

/**
Expand Down Expand Up @@ -195,6 +158,7 @@ public function prepare_item_for_response( $post, $request ): WP_REST_Response {
$response = new WP_REST_Response( $data );
foreach ( $links as $rel => $rel_links ) {
foreach ( $rel_links as $link ) {
// @phpstan-ignore method.internal (false positive)
$response->add_link( $rel, $link['href'], $link['attributes'] );
}
}
Expand Down
1 change: 1 addition & 0 deletions includes/REST_API/Stories_Base_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function prepare_item_for_response( $post, $request ): WP_REST_Response {
$response = new WP_REST_Response( $data );
foreach ( $links as $rel => $rel_links ) {
foreach ( $rel_links as $link ) {
// @phpstan-ignore method.internal (false positive)
$response->add_link( $rel, $link['href'], $link['attributes'] );
}
}
Expand Down
1 change: 1 addition & 0 deletions includes/REST_API/Stories_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public function prepare_item_for_response( $post, $request ): WP_REST_Response {
$response = new WP_REST_Response( $data );
foreach ( $links as $rel => $rel_links ) {
foreach ( $rel_links as $link ) {
// @phpstan-ignore method.internal (false positive)
$response->add_link( $rel, $link['href'], $link['attributes'] );
}
}
Expand Down
28 changes: 15 additions & 13 deletions includes/Story_Post_Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use Google\Web_Stories\Infrastructure\HasMeta;
use Google\Web_Stories\Infrastructure\HasRequirements;
use Google\Web_Stories\REST_API\Stories_Autosaves_Controller;
use Google\Web_Stories\REST_API\Stories_Controller;
use WP_Post;

Expand Down Expand Up @@ -331,7 +332,7 @@ public function on_plugin_uninstall(): void {
*/
protected function get_args(): array {
return [
'labels' => [
'labels' => [
'name' => _x( 'Stories', 'post type general name', 'web-stories' ),
'singular_name' => _x( 'Story', 'post type singular name', 'web-stories' ),
'add_new' => __( 'Add New Story', 'web-stories' ),
Expand Down Expand Up @@ -367,8 +368,8 @@ protected function get_args(): array {
'item_link_description' => _x( 'A link to a story.', 'navigation link block description', 'web-stories' ),
'item_trashed' => __( 'Story trashed.', 'web-stories' ),
],
'menu_icon' => $this->get_post_type_icon(),
'supports' => [
'menu_icon' => $this->get_post_type_icon(),
'supports' => [
'title', // Used for amp-story[title].
'author',
'editor',
Expand All @@ -377,20 +378,21 @@ protected function get_args(): array {
'revisions', // Without this, the REST API will return 404 for an autosave request.
'custom-fields',
],
'rewrite' => [
'rewrite' => [
'slug' => self::REWRITE_SLUG,
'with_front' => false,
'feeds' => true,
],
'public' => true,
'has_archive' => $this->get_has_archive(),
'exclude_from_search' => true,
'show_ui' => true,
'show_in_rest' => true,
'rest_namespace' => self::REST_NAMESPACE,
'rest_controller_class' => Stories_Controller::class,
'capability_type' => [ 'web-story', 'web-stories' ],
'map_meta_cap' => true,
'public' => true,
'has_archive' => $this->get_has_archive(),
'exclude_from_search' => true,
'show_ui' => true,
'show_in_rest' => true,
'rest_namespace' => self::REST_NAMESPACE,
'rest_controller_class' => Stories_Controller::class,
'autosave_rest_controller_class' => Stories_Autosaves_Controller::class,
'capability_type' => [ 'web-story', 'web-stories' ],
'map_meta_cap' => true,
];
}

Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ parameters:
identifier: requireOnce.fileNotFound
-
identifier: require.fileNotFound
-
identifier: function.internal
path: tests/phpunit/integration/tests
-
identifier: staticMethod.internalClass
path: tests/phpunit/unit/tests
-
message: '/^Parameter #2 \$args of method WP_Customize_Manager::add_setting\(\)/'
path: includes/Admin/Customizer.php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class Stories_Autosaves_Controller extends DependencyInjectedRestTestCase {
*/
protected static int $author_id;

/**
* Test instance.
*/
private \Google\Web_Stories\REST_API\Stories_Autosaves_Controller $controller;

public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ): void {
self::$author_id = $factory->user->create(
[
Expand All @@ -50,14 +45,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ): void
);
}

public function set_up(): void {
parent::set_up();

$this->controller = $this->injector->make( \Google\Web_Stories\REST_API\Stories_Autosaves_Controller::class );
}

public function test_create_item_as_author_should_not_strip_markup(): void {
$this->controller->register();

wp_set_current_user( self::$author_id );

Expand Down