Skip to content

Commit

Permalink
Merge pull request #40 from studiopress/fix/cpt-menus-do-not-appear
Browse files Browse the repository at this point in the history
Fix the issue of submenus not appearing
  • Loading branch information
kienstra authored Oct 19, 2020
2 parents 60295cb + fb9f6d0 commit 8c08a37
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 57 deletions.
39 changes: 9 additions & 30 deletions php/Admin/Onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,15 @@ 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>
<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>
<?php
edit_post_link(
__( 'Let\'s get started!', 'genesis-custom-blocks' ),
'<p>',
'</p>',
$example_post_id,
'button button--white button_cta'
);
?>
<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 @@ -169,31 +173,6 @@ 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
6 changes: 5 additions & 1 deletion php/PostTypes/BlockPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct() {
*/
public function register_hooks() {
add_action( 'init', [ $this, 'register_post_type' ] );
add_action( 'admin_init', [ $this, 'add_caps' ] );
add_action( 'plugins_loaded', [ $this, 'add_caps' ] );
add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] );
add_action( 'add_meta_boxes', [ $this, 'remove_meta_boxes' ] );
add_action( 'edit_form_before_permalink', [ $this, 'template_location' ] );
Expand Down Expand Up @@ -218,6 +218,10 @@ public function register_post_type() {
* @return void
*/
public function add_caps() {
if ( ! is_admin() ) {
return;
}

$admin = get_role( 'administrator' );
if ( ! $admin ) {
return;
Expand Down
2 changes: 2 additions & 0 deletions tests/php/Integration/TestPostCapabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public function get_users() {
* @param bool $expected The expected result for those capability and roles.
*/
public function test_user_capability( $user_role, $capability, $expected ) {
set_current_screen( 'edit-post' );
wp_set_current_user( $this->factory()->user->create( [ 'role' => $user_role ] ) );

$this->assertEquals( $expected, current_user_can( $capability, $this->post_id ) );
}
}
26 changes: 1 addition & 25 deletions tests/php/Unit/Admin/TestOnboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,10 @@ public function test_show_welcome_notice_should_display() {

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 )
ob_get_clean()
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/Unit/PostTypes/TestBlockPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function test_register_hooks() {
$this->instance->register_hooks();

$this->assertEquals( 10, has_action( 'init', [ $this->instance, 'register_post_type' ] ) );
$this->assertEquals( 10, has_action( 'admin_init', [ $this->instance, 'add_caps' ] ) );
$this->assertEquals( 10, has_action( 'plugins_loaded', [ $this->instance, 'add_caps' ] ) );
$this->assertEquals( 10, has_action( 'add_meta_boxes', [ $this->instance, 'add_meta_boxes' ] ) );
$this->assertEquals( 10, has_action( 'add_meta_boxes', [ $this->instance, 'remove_meta_boxes' ] ) );
$this->assertEquals( 10, has_action( 'post_submitbox_start', [ $this->instance, 'save_draft_button' ] ) );
Expand Down

0 comments on commit 8c08a37

Please sign in to comment.