Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/8.4 #23410

Closed
wants to merge 9 commits into from
Closed
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
180 changes: 180 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Printing since 1440. This is the development plugin for the new block editor in core.
* Requires at least: 5.3
* Requires PHP: 5.6
* Version: 8.3.0
* Version: 8.4.0-rc.2
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
19 changes: 12 additions & 7 deletions lib/block-directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

if (
gutenberg_is_experiment_enabled( 'gutenberg-block-directory' ) &&
! has_action( 'admin_enqueue_scripts', 'enqueue_block_editor_assets_block_directory' )
) {
/**
Expand All @@ -22,18 +21,24 @@ function gutenberg_enqueue_block_editor_assets_block_directory() {
/**
* Add data attribute of handle to all script tags output in the wp-admin.
*
* @param string $tag The `<script>` tag for the enqueued script.
* @param string $handle The script's registered handle.
* @param string $tag The `<script>` tag for the enqueued script.
* @param string $handle The script's registered handle.
* @param string $esc_src The script's pre-escaped registered src.
*
* @return string Filter script tag.
* @return string Filtered script tag.
*/
function gutenberg_change_script_tag( $tag, $handle ) {
function gutenberg_change_script_tag( $tag, $handle, $esc_src ) {
if ( ! is_admin() ) {
return $tag;
}
$tag = str_replace( '<script ', sprintf( '<script data-handle="%s" ', esc_attr( $handle ) ), $tag );

$tag = str_replace(
sprintf( "<script src='%s'></script>", $esc_src ),
sprintf( "<script data-handle='%s' src='%s'></script>", esc_attr( $handle ), $esc_src ),
$tag
);

return $tag;
}
add_filter( 'script_loader_tag', 'gutenberg_change_script_tag', 10, 2 );
add_filter( 'script_loader_tag', 'gutenberg_change_script_tag', 1, 3 );
}
143 changes: 1 addition & 142 deletions lib/class-wp-rest-block-directory-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,6 @@ public function register_routes() {
'schema' => array( $this, 'get_public_item_schema' ),
)
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/install',
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'create_item' ),
'permission_callback' => array( $this, 'create_item_permissions_check' ),
'args' => array(
'slug' => array(
'required' => true,
),
),
)
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/uninstall',
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_item' ),
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
'args' => array(
'slug' => array(
'required' => true,
),
),
)
);
}

/**
Expand Down Expand Up @@ -136,117 +106,6 @@ public function get_items( $request ) {
return rest_ensure_response( $result );
}

/**
* Checks whether a given request has permission to install and activate plugins.
*
* @since 5.5.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
*/
public function create_item_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
if ( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'activate_plugins' ) ) {
return new WP_Error(
'rest_block_directory_cannot_create',
__( 'Sorry, you are not allowed to install blocks.', 'gutenberg' ),
array( 'status' => rest_authorization_required_code() )
);
}

return true;
}

/**
* Installs and activates a plugin
*
* @since 5.5.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';

$existing = $this->find_plugin_for_slug( $request['slug'] );

if ( $existing ) {
$activate = new WP_REST_Request( 'PUT', '/__experimental/plugins/' . substr( $existing, 0, - 4 ) );
$activate->set_body_params( array( 'status' => 'active' ) );

return rest_do_request( $activate );
}

$inner_request = new WP_REST_Request( 'POST', '/__experimental/plugins' );
$inner_request->set_body_params(
array(
'slug' => $request['slug'],
'status' => 'active',
)
);

return rest_do_request( $inner_request );
}

/**
* Checks whether a given request has permission to remove/deactivate plugins.
*
* @since 5.5.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
*/
public function delete_item_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
if ( ! current_user_can( 'delete_plugins' ) || ! current_user_can( 'deactivate_plugins' ) ) {
return new WP_Error(
'rest_block_directory_cannot_delete',
__( 'Sorry, you are not allowed to uninstall blocks.', 'gutenberg' ),
array( 'status' => rest_authorization_required_code() )
);
}

return true;
}

/**
* Deactivates and deletes a plugin
*
* @since 5.5.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
*/
public function delete_item( $request ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';

$slug = trim( $request->get_param( 'slug' ) );

if ( ! $slug ) {
return new WP_Error( 'slug_not_provided', 'Valid slug not provided.', array( 'status' => 400 ) );
}

$plugin_file = $this->find_plugin_for_slug( $slug );

if ( ! $plugin_file ) {
return new WP_Error( 'block_not_found', 'Valid slug not provided.', array( 'status' => 400 ) );
}

$route = '/__experimental/plugins/' . substr( $plugin_file, 0, - 4 );
$deactivate = new WP_REST_Request( 'PUT', $route );
$deactivate->set_body_params( array( 'status' => 'inactive' ) );

$deactivated = rest_do_request( $deactivate );

if ( $deactivated->is_error() ) {
return $deactivated->as_error();
}

return rest_do_request( new WP_REST_Request( 'DELETE', $route ) );
}

/**
* Parse block metadata for a block, and prepare it for an API repsonse.
*
Expand Down Expand Up @@ -277,7 +136,7 @@ public function prepare_item_for_response( $plugin, $request ) {
'assets' => array(),
'last_updated' => $plugin['last_updated'],
'humanized_updated' => sprintf(
/* translators: %s: Human-readable time difference. */
/* translators: %s: Human-readable time difference. */
__( '%s ago', 'gutenberg' ),
human_time_diff( strtotime( $plugin['last_updated'] ) )
),
Expand Down
8 changes: 4 additions & 4 deletions lib/class-wp-rest-image-editor-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public function apply_edits( $request ) {
return new WP_Error( 'fileload', 'Unable to load original media file' );
}

if ( isset( $params['rotation'] ) ) {
$image_editor->rotate( 0 - $params['rotation'] );
}

$size = $image_editor->get_size();

// Finally apply the modifications.
Expand All @@ -139,10 +143,6 @@ public function apply_edits( $request ) {
$height = round( ( $size['height'] * floatval( $params['height'] ) ) / 100.0 );
$image_editor->crop( $crop_x, $crop_y, $width, $height );

if ( isset( $params['rotation'] ) ) {
$image_editor->rotate( 0 - $params['rotation'] );
}

// TODO: Generate filename based on edits.
$target_file = 'edited-' . $meta['original_name'];

Expand Down
12 changes: 0 additions & 12 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-navigation',
)
);
add_settings_field(
'gutenberg-block-directory',
__( 'Block Directory', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable block directory search', 'gutenberg' ),
'id' => 'gutenberg-block-directory',
)
);
add_settings_field(
'gutenberg-full-site-editing',
__( 'Full Site Editing', 'gutenberg' ),
Expand Down Expand Up @@ -143,7 +132,6 @@ function gutenberg_display_experiment_section() {
function gutenberg_experiments_editor_settings( $settings ) {
$experiments_settings = array(
'__experimentalEnableLegacyWidgetBlock' => gutenberg_is_experiment_enabled( 'gutenberg-widget-experiments' ),
'__experimentalBlockDirectory' => gutenberg_is_experiment_enabled( 'gutenberg-block-directory' ),
'__experimentalEnableFullSiteEditing' => gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing' ),
'__experimentalEnableFullSiteEditingDemo' => gutenberg_is_experiment_enabled( 'gutenberg-full-site-editing-demo' ),
);
Expand Down
8 changes: 0 additions & 8 deletions lib/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ function gutenberg_register_rest_widget_areas() {
* @since 6.5.0
*/
function gutenberg_register_rest_block_directory() {
if ( ! gutenberg_is_experiment_enabled( 'gutenberg-block-directory' ) ) {
return;
}

$block_directory_controller = new WP_REST_Block_Directory_Controller();
$block_directory_controller->register_routes();
}
Expand Down Expand Up @@ -159,10 +155,6 @@ function gutenberg_register_rest_customizer_nonces() {
* Registers the Plugins REST API routes.
*/
function gutenberg_register_plugins_endpoint() {
if ( ! gutenberg_is_experiment_enabled( 'gutenberg-block-directory' ) ) {
return;
}

$plugins = new WP_REST_Plugins_Controller();
$plugins->register_routes();
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gutenberg",
"version": "8.3.0",
"version": "8.4.0-rc.2",
"private": true,
"description": "A new WordPress editor experience.",
"author": "The WordPress Contributors",
Expand Down
22 changes: 12 additions & 10 deletions packages/block-directory/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ export function* installBlockType( block ) {
throw new Error( __( 'Block has no assets.' ) );
}
yield setIsInstalling( block.id, true );
yield apiFetch( {
path: '__experimental/block-directory/install',
const response = yield apiFetch( {
path: '__experimental/plugins',
data: {
slug: block.id,
status: 'active',
},
method: 'POST',
} );
yield addInstalledBlockType( block );
const endpoint = response?._links?.self[ 0 ]?.href;
yield addInstalledBlockType( { ...block, endpoint } );

yield loadAssets( assets );
const registeredBlocks = yield select( 'core/blocks', 'getBlockTypes' );
Expand All @@ -94,18 +96,18 @@ export function* installBlockType( block ) {
* @param {Object} block The blockType object.
*/
export function* uninstallBlockType( block ) {
const { id } = block;
try {
const response = yield apiFetch( {
path: '__experimental/block-directory/uninstall',
yield apiFetch( {
url: block.endpoint,
data: {
slug: id,
status: 'inactive',
},
method: 'PUT',
} );
yield apiFetch( {
url: block.endpoint,
method: 'DELETE',
} );
if ( response !== true ) {
throw new Error( __( 'Unable to uninstall this block.' ) );
}
yield removeInstalledBlockType( block );
} catch ( error ) {
yield dispatch(
Expand Down
Loading