Skip to content

Commit

Permalink
Merge pull request #23 from studiopress/fix/lets-get-started-link
Browse files Browse the repository at this point in the history
Ensure the "Let's get started" link appears
  • Loading branch information
kienstra committed Aug 27, 2020
2 parents 86c0d6c + d879a9c commit 7b75647
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 9 deletions.
39 changes: 30 additions & 9 deletions php/Admin/Onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,11 @@ public function show_welcome_notice() {
<h2><span role="image" aria-label="<?php esc_attr_e( 'Waving hand emoji', 'genesis-custom-blocks' ); ?>">👋</span> <?php esc_html_e( 'Hi, and welcome!', 'genesis-custom-blocks' ); ?></h2>
<p class="intro"><?php esc_html_e( 'Genesis Custom Blocks makes it easy to build your own blocks for the WordPress editor.', 'genesis-custom-blocks' ); ?></p>
<p><strong><?php esc_html_e( 'Want to see how it\'s done?', 'genesis-custom-blocks' ); ?></strong> <?php esc_html_e( 'Here\'s one we prepared earlier.', 'genesis-custom-blocks' ); ?></p>
<?php
edit_post_link(
__( 'Let\'s get started!', 'genesis-custom-blocks' ),
'<p>',
'</p>',
$example_post_id,
'button button--white button_cta'
);
?>
<p>
<a class="button button--white button_cta" href="<?php echo esc_url( $this->get_edit_link( $example_post_id ) ); ?>">
<?php esc_html_e( 'Let\'s get started!', 'genesis-custom-blocks' ); ?>
</a>
</p>
<p class="ps"><?php esc_html_e( 'P.S. We don\'t like to nag. This message won\'t be shown again.', 'genesis-custom-blocks' ); ?></p>
<p class="ps">
<?php
Expand All @@ -173,6 +169,31 @@ public function show_welcome_notice() {
<?php
}

/**
* Gets the link to edit a post.
*
* A forked and simplified version of get_edit_post_link().
*
* @param string|int $post_id The ID of the post.
* @return string|null The URL to edit the post.
*/
public function get_edit_link( $post_id ) {
$post = get_post( $post_id );
if ( ! $post ) {
return null;
}

$post_type_object = get_post_type_object( $post->post_type );
if ( empty( $post_type_object->_edit_link ) ) {
return null;
}

$link = admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=edit', $post->ID ) );

/** This filter is documented in wp-includes/link-template.php */
return apply_filters( 'get_edit_post_link', $link, $post->ID, 'display' );
}

/**
* Render the Edit Your First Block message.
*/
Expand Down
56 changes: 56 additions & 0 deletions tests/php/Unit/Admin/TestOnboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,62 @@ public function test_register_hooks() {
$this->assertEquals( 10, has_action( 'current_screen', [ $this->instance, 'admin_notices' ] ) );
}

/**
* Test show_welcome_notice when it should not display.
*
* @covers \Genesis\CustomBlocks\Admin\Onboarding::show_welcome_notice()
*/
public function test_show_welcome_notice_does_not_display() {
ob_start();
$this->instance->show_welcome_notice();
$this->assertEmpty( ob_get_clean() );
}

/**
* Test show_welcome_notice when it should display.
*
* @covers \Genesis\CustomBlocks\Admin\Onboarding::show_welcome_notice()
*/
public function test_show_welcome_notice_should_display() {
$post_id = $this->factory()->post->create( [ 'post_type' => 'genesis_custom_block' ] );
update_option(
Onboarding::OPTION_NAME,
$post_id
);

ob_start();
$this->instance->show_welcome_notice();
$output = ob_get_clean();

$this->assertContains(
'<div class="genesis-custom-blocks-welcome genesis-custom-blocks-notice notice is-dismissible">',
$output
);
$this->assertContains( strval( $post_id ), $output );
}

/**
* Test get_edit_link when the post ID is not for a post.
*
* @covers \Genesis\CustomBlocks\Admin\Onboarding::get_edit_link()
*/
public function test_get_edit_link_no_post() {
$this->assertEmpty( $this->instance->get_edit_link( 123456789 ) );
}

/**
* Test get_edit_link when there is a valid post.
*
* @covers \Genesis\CustomBlocks\Admin\Onboarding::get_edit_link()
*/
public function test_get_edit_link_with_post() {
$post_id = $this->factory()->post->create( [ 'post_type' => 'genesis_custom_block' ] );
$this->assertContains(
"post.php?post={$post_id}&amp;action=edit",
$this->instance->get_edit_link( $post_id )
);
}

/**
* Test plugin_activation.
*
Expand Down

0 comments on commit 7b75647

Please sign in to comment.