forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'WordPress:trunk' into trunk
- Loading branch information
Showing
77 changed files
with
1,324 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,7 +172,7 @@ _Parameters_ | |
|
||
_Returns_ | ||
|
||
- `Object?`: Block Type. | ||
- `?Object`: Block Type. | ||
|
||
### getBlockTypes | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
lib/compat/wordpress-6.8/class-gutenberg-hierarchical-sort.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.