Skip to content

Commit

Permalink
Merge pull request #110 from thrijith/GH-109
Browse files Browse the repository at this point in the history
fix wpcs in cpt generation
  • Loading branch information
gitlost authored Jan 8, 2018
2 parents 13b3ccb + 01a7975 commit f4a7eac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
8 changes: 4 additions & 4 deletions features/scaffold.feature
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Feature: WordPress code scaffolding
"""
And STDOUT should contain:
"""
'menu_icon' => 'dashicons-admin-post',
'menu_icon' => 'dashicons-admin-post',
"""

Scenario: CPT slug is too long
Expand All @@ -176,23 +176,23 @@ Feature: WordPress code scaffolding
When I run `wp scaffold post-type zombie --dashicon="art"`
Then STDOUT should contain:
"""
'menu_icon' => 'dashicons-art',
'menu_icon' => 'dashicons-art',
"""

Scenario: Scaffold a Custom Post Type with dashicon in the case of passing "dashicon-info"
Given a WP install
When I run `wp scaffold post-type zombie --dashicon="dashicon-info"`
Then STDOUT should contain:
"""
'menu_icon' => 'dashicons-info',
'menu_icon' => 'dashicons-info',
"""

Scenario: Scaffold a Custom Post Type with dashicon in the case of passing "dashicons-info"
Given a WP install
When I run `wp scaffold post-type zombie --dashicon="dashicons-info"`
Then STDOUT should contain:
"""
'menu_icon' => 'dashicons-info',
'menu_icon' => 'dashicons-info',
"""

Scenario: Scaffold a plugin
Expand Down
24 changes: 12 additions & 12 deletions templates/post_type.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
register_post_type( '{{slug}}', array(
'labels' => array(
'labels' => array(
'name' => __( '{{label_plural_ucfirst}}', '{{textdomain}}' ),
'singular_name' => __( '{{label_ucfirst}}', '{{textdomain}}' ),
'all_items' => __( 'All {{label_plural_ucfirst}}', '{{textdomain}}' ),
Expand All @@ -26,16 +26,16 @@
'parent_item_colon' => __( 'Parent {{label_ucfirst}}:', '{{textdomain}}' ),
'menu_name' => __( '{{label_plural_ucfirst}}', '{{textdomain}}' ),
),
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_nav_menus' => true,
'supports' => array( 'title', 'editor' ),
'has_archive' => true,
'rewrite' => true,
'query_var' => true,
'menu_icon' => 'dashicons-{{dashicon}}',
'show_in_rest' => true,
'rest_base' => '{{slug}}',
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_nav_menus' => true,
'supports' => array( 'title', 'editor' ),
'has_archive' => true,
'rewrite' => true,
'query_var' => true,
'menu_icon' => 'dashicons-{{dashicon}}',
'show_in_rest' => true,
'rest_base' => '{{slug}}',
'rest_controller_class' => 'WP_REST_Posts_Controller',
) );
37 changes: 25 additions & 12 deletions templates/post_type_extended.mustache
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
<?php

/**
* Registers the `{{machine_name}}` post type.
*/
function {{machine_name}}_init() {
{{output}}
}
add_action( 'init', '{{machine_name}}_init' );

/**
* Sets the post updated messages for the `{{machine_name}}` post type.
*
* @param array $messages Post updated messages.
* @return array Messages for the `{{machine_name}}` post type.
*/
function {{machine_name}}_updated_messages( $messages ) {
global $post;
$permalink = get_permalink( $post );
$messages['{{slug}}'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __('{{label_ucfirst}} updated. <a target="_blank" href="%s">View {{label}}</a>', '{{textdomain}}'), esc_url( $permalink ) ),
2 => __('Custom field updated.', '{{textdomain}}'),
3 => __('Custom field deleted.', '{{textdomain}}'),
4 => __('{{label_ucfirst}} updated.', '{{textdomain}}'),
0 => '', // Unused. Messages start at index 1.
/* translators: %s: post permalink */
1 => sprintf( __( '{{label_ucfirst}} updated. <a target="_blank" href="%s">View {{label}}</a>', '{{textdomain}}' ), esc_url( $permalink ) ),
2 => __( 'Custom field updated.', '{{textdomain}}' ),
3 => __( 'Custom field deleted.', '{{textdomain}}' ),
4 => __( '{{label_ucfirst}} updated.', '{{textdomain}}' ),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __('{{label_ucfirst}} restored to revision from %s', '{{textdomain}}'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('{{label_ucfirst}} published. <a href="%s">View {{label}}</a>', '{{textdomain}}'), esc_url( $permalink ) ),
7 => __('{{label_ucfirst}} saved.', '{{textdomain}}'),
8 => sprintf( __('{{label_ucfirst}} submitted. <a target="_blank" href="%s">Preview {{label}}</a>', '{{textdomain}}'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
9 => sprintf( __('{{label_ucfirst}} scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview {{label}}</a>', '{{textdomain}}'),
// translators: Publish box date format, see https://secure.php.net/manual/en/function.date.php
5 => isset( $_GET['revision'] ) ? sprintf( __( '{{label_ucfirst}} restored to revision from %s', '{{textdomain}}' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
/* translators: %s: post permalink */
6 => sprintf( __( '{{label_ucfirst}} published. <a href="%s">View {{label}}</a>', '{{textdomain}}' ), esc_url( $permalink ) ),
7 => __( '{{label_ucfirst}} saved.', '{{textdomain}}' ),
/* translators: %s: post permalink */
8 => sprintf( __( '{{label_ucfirst}} submitted. <a target="_blank" href="%s">Preview {{label}}</a>', '{{textdomain}}' ), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
/* translators: 1: Publish box date format, see https://secure.php.net/date 2: Post permalink */
9 => sprintf( __( '{{label_ucfirst}} scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview {{label}}</a>', '{{textdomain}}' ),
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ),
10 => sprintf( __('{{label_ucfirst}} draft updated. <a target="_blank" href="%s">Preview {{label}}</a>', '{{textdomain}}'), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
/* translators: %s: post permalink */
10 => sprintf( __( '{{label_ucfirst}} draft updated. <a target="_blank" href="%s">Preview {{label}}</a>', '{{textdomain}}' ), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
);
return $messages;
Expand Down

0 comments on commit f4a7eac

Please sign in to comment.