Skip to content

Commit

Permalink
Admin: Generate classic editor URL by removed edit filter
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Sep 6, 2017
1 parent 547d038 commit 54df7bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,16 @@ function gutenberg_add_edit_links( $actions, $post ) {
return $actions;
}

if ( gutenberg_post_has_blocks( $post->ID ) ) {
remove_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10 );
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 );
}
remove_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10 );
$classic_url = get_edit_post_link( $post->ID, 'raw' );
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 );

// Build the new edit actions. See also: WP_Posts_List_Table::handle_row_actions().
$title = _draft_or_post_title( $post->ID );
$edit_actions = array(
'classic hide-if-no-js' => sprintf(
'<a href="%s" aria-label="%s">%s</a>',
esc_url( get_edit_post_link( $post->ID, 'raw' ) ),
esc_url( $classic_url ),
esc_attr( sprintf(
/* translators: %s: post title */
__( 'Edit &#8220;%s&#8221; in the classic editor', 'gutenberg' ),
Expand Down
2 changes: 2 additions & 0 deletions phpunit/class-admin-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ function test_gutenberg_add_edit_links() {
$actions = apply_filters( 'post_row_actions', $original_actions, get_post( self::$post_with_blocks ) );
$this->assertArrayHasKey( 'gutenberg hide-if-no-js', $actions );
$this->assertArrayHasKey( 'classic hide-if-no-js', $actions );
$this->assertContains( 'post.php', $actions['classic hide-if-no-js'] );

$actions = apply_filters( 'post_row_actions', $original_actions, get_post( self::$post_without_blocks ) );
$this->assertArrayHasKey( 'gutenberg hide-if-no-js', $actions );
$this->assertArrayHasKey( 'classic hide-if-no-js', $actions );
$this->assertContains( 'post.php', $actions['classic hide-if-no-js'] );

$trashed_post = $this->factory()->post->create( array(
'post_status' => 'trash',
Expand Down

0 comments on commit 54df7bc

Please sign in to comment.