Skip to content

Commit

Permalink
Merge branch 'WordPress:trunk' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
karthick-murugan authored Dec 19, 2024
2 parents 301d70f + 319cab0 commit c80640f
Show file tree
Hide file tree
Showing 77 changed files with 1,324 additions and 344 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/sync-assets-to-plugin-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Sync Gutenberg plugin assets to WordPress.org plugin repo

on:
push:
branches:
- trunk
paths:
- assets/**

jobs:
sync-assets:
name: Sync assets to WordPress.org plugin repo
runs-on: ubuntu-latest
environment: wp.org plugin
env:
PLUGIN_REPO_URL: 'https://plugins.svn.wordpress.org/gutenberg'
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}

steps:
- name: Check out Gutenberg assets folder from WP.org plugin repo
run: |
svn checkout "$PLUGIN_REPO_URL/assets" \
--username "$SVN_USERNAME" --password "$SVN_PASSWORD"
- name: Delete everything
run: find assets -type f -not -path 'assets/.svn/*' -delete

- name: Checkout assets from current release
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
sparse-checkout: |
assets
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
path: git

- name: Copy files from git checkout to svn working copy
run: cp -R git/assets/* assets

- name: Commit the updated assets
working-directory: ./assets
run: |
svn st | awk '/^?/ {print $2}' | xargs -r svn add
svn st | awk '/^!/ {print $2}' | xargs -r svn rm
svn commit . \
-m "Sync assets for commit $GITHUB_SHA" \
--no-auth-cache --non-interactive --username "$SVN_USERNAME" --password "$SVN_PASSWORD" \
--config-option=servers:global:http-timeout=600
Binary file added assets/banner-1544x500.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/banner-772x250.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-128x128.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-256x256.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions backport-changelog/6.8/8014.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/8014

* https://github.com/WordPress/gutenberg/pull/66479
8 changes: 4 additions & 4 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ _Parameters_

_Returns_

- `Object?`: Block attributes.
- `?Object`: Block attributes.

### getBlockCount

Expand Down Expand Up @@ -448,7 +448,7 @@ Determines the items that appear in the available block transforms list.

Each item object contains what's necessary to display a menu item in the transform list and handle its selection.

The 'frecency' property is a heuristic (<https://en.wikipedia.org/wiki/Frecency>) that combines block usage frequenty and recency.
The 'frecency' property is a heuristic (<https://en.wikipedia.org/wiki/Frecency>) that combines block usage frequency and recency.

Items are returned ordered descendingly by their 'frecency'.

Expand Down Expand Up @@ -521,7 +521,7 @@ _Properties_

- _name_ `string`: The type of block.
- _attributes_ `?Object`: Attributes to pass to the newly created block.
- _attributesToCopy_ `?Array<string>`: Attributes to be copied from adjecent blocks when inserted.
- _attributesToCopy_ `?Array<string>`: Attributes to be copied from adjacent blocks when inserted.

### getDraggedBlockClientIds

Expand Down Expand Up @@ -580,7 +580,7 @@ Determines the items that appear in the inserter. Includes both static items (e.

Each item object contains what's necessary to display a button in the inserter and handle its selection.

The 'frecency' property is a heuristic (<https://en.wikipedia.org/wiki/Frecency>) that combines block usage frequenty and recency.
The 'frecency' property is a heuristic (<https://en.wikipedia.org/wiki/Frecency>) that combines block usage frequency and recency.

Items are returned ordered descendingly by their 'utility' and 'frecency'.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ _Parameters_

_Returns_

- `Object?`: Block Type.
- `?Object`: Block Type.

### getBlockTypes

Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core-edit-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Retrieves the template of the currently edited post.

_Returns_

- `Object?`: Post Template.
- `?Object`: Post Template.

### getEditorMode

Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core-rich-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ _Parameters_
_Returns_
- `Object?`: Format type.
- `?Object`: Format type.
### getFormatTypeForBareElement
Expand Down
205 changes: 205 additions & 0 deletions lib/compat/wordpress-6.8/class-gutenberg-hierarchical-sort.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<?php

/**
* Modifies the Post controller endpoint to support orderby_hierarchy.
*
* @package gutenberg
* @since 6.8.0
*/

class Gutenberg_Hierarchical_Sort {
private static $post_ids = array();
private static $levels = array();
private static $instance;

public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}

return self::$instance;
}

public function run( $args ) {
$new_args = array_merge(
$args,
array(
'fields' => 'id=>parent',
'posts_per_page' => -1,
)
);
$query = new WP_Query( $new_args );
$posts = $query->posts;
$result = self::sort( $posts );

self::$post_ids = $result['post_ids'];
self::$levels = $result['levels'];
}

/**
* Check if the request is eligible for hierarchical sorting.
*
* @param array $request The request data.
*
* @return bool Return true if the request is eligible for hierarchical sorting.
*/
public static function is_eligible( $request ) {
if ( ! isset( $request['orderby_hierarchy'] ) || true !== $request['orderby_hierarchy'] ) {
return false;
}

return true;
}

public static function get_ancestor( $post_id ) {
return get_post( $post_id )->post_parent ?? 0;
}

/**
* Sort posts by hierarchy.
*
* Takes an array of posts and sorts them based on their parent-child relationships.
* It also tracks the level depth of each post in the hierarchy.
*
* Example input:
* ```
* [
* ['ID' => 4, 'post_parent' => 2],
* ['ID' => 2, 'post_parent' => 0],
* ['ID' => 3, 'post_parent' => 2],
* ]
* ```
*
* Example output:
* ```
* [
* 'post_ids' => [2, 4, 3],
* 'levels' => [0, 1, 1]
* ]
* ```
*
* @param array $posts Array of post objects containing ID and post_parent properties.
*
* @return array {
* Sorted post IDs and their hierarchical levels
*
* @type array $post_ids Array of post IDs
* @type array $levels Array of levels for the corresponding post ID in the same index
* }
*/
public static function sort( $posts ) {
/*
* Arrange pages in two arrays:
*
* - $top_level: posts whose parent is 0
* - $children: post ID as the key and an array of children post IDs as the value.
* Example: $children[10][] contains all sub-pages whose parent is 10.
*
* Additionally, keep track of the levels of each post in $levels.
* Example: $levels[10] = 0 means the post ID is a top-level page.
*
*/
$top_level = array();
$children = array();
foreach ( $posts as $post ) {
if ( empty( $post->post_parent ) ) {
$top_level[] = $post->ID;
} else {
$children[ $post->post_parent ][] = $post->ID;
}
}

$ids = array();
$levels = array();
self::add_hierarchical_ids( $ids, $levels, 0, $top_level, $children );

// Process remaining children.
if ( ! empty( $children ) ) {
foreach ( $children as $parent_id => $child_ids ) {
$level = 0;
$ancestor = $parent_id;
while ( 0 !== $ancestor ) {
++$level;
$ancestor = self::get_ancestor( $ancestor );
}
self::add_hierarchical_ids( $ids, $levels, $level, $child_ids, $children );
}
}

return array(
'post_ids' => $ids,
'levels' => $levels,
);
}

private static function add_hierarchical_ids( &$ids, &$levels, $level, $to_process, $children ) {
foreach ( $to_process as $id ) {
if ( in_array( $id, $ids, true ) ) {
continue;
}
$ids[] = $id;
$levels[ $id ] = $level;

if ( isset( $children[ $id ] ) ) {
self::add_hierarchical_ids( $ids, $levels, $level + 1, $children[ $id ], $children );
unset( $children[ $id ] );
}
}
}

public static function get_post_ids() {
return self::$post_ids;
}

public static function get_levels() {
return self::$levels;
}
}

add_filter(
'rest_page_collection_params',
function ( $params ) {
$params['orderby_hierarchy'] = array(
'description' => 'Sort pages by hierarchy.',
'type' => 'boolean',
'default' => false,
);
return $params;
}
);

add_filter(
'rest_page_query',
function ( $args, $request ) {
if ( ! Gutenberg_Hierarchical_Sort::is_eligible( $request ) ) {
return $args;
}

$hs = Gutenberg_Hierarchical_Sort::get_instance();
$hs->run( $args );

// Reconfigure the args to display only the ids in the list.
$args['post__in'] = $hs->get_post_ids();
$args['orderby'] = 'post__in';

return $args;
},
10,
2
);

add_filter(
'rest_prepare_page',
function ( $response, $post, $request ) {
if ( ! Gutenberg_Hierarchical_Sort::is_eligible( $request ) ) {
return $response;
}

$hs = Gutenberg_Hierarchical_Sort::get_instance();
$response->data['level'] = $hs->get_levels()[ $post->ID ];

return $response;
},
10,
3
);
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.8/block-comments.php';
require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php';
require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php';
require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-hierarchical-sort.php';
require __DIR__ . '/compat/wordpress-6.8/rest-api.php';

// Plugin specific code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,36 @@ const controls = (
/>
</BlockControls>
</>
}
);
```

### Props

| Name | Type | Default | Description |
| ---------- | ---------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `label` | `string` | `Change matrix alignment` | concise description of tool's functionality. |
| `onChange` | `function` | `noop` | the function to execute upon a user's change of the matrix state |
| `value` | `string` | `center` | describes the content alignment location and can be `top`, `right`, `bottom`, `left`, `topRight`, `bottomRight`, `bottomLeft`, `topLeft` |
### `label`

- **Type:** `string`
- **Default:** `'Change matrix alignment'`

Label for the control.

### `onChange`

- **Type:** `Function`
- **Default:** `noop`

Function to execute upon a user's change of the matrix state.

### `value`

- **Type:** `string`
- **Default:** `'center'`
- **Options:** `'center'`, `'center center'`, `'center left'`, `'center right'`, `'top center'`, `'top left'`, `'top right'`, `'bottom center'`, `'bottom left'`, `'bottom right'`

Content alignment location.

### `isDisabled`

- **Type:** `boolean`
- **Default:** `false`

Whether the control should be disabled.
Loading

0 comments on commit c80640f

Please sign in to comment.