OSDN Git Service

Implemented --raw flag so that one only gets the registration of a taxonomy or post...
authorjmslbam <jmslbam@gmail.com>
Sat, 29 Dec 2012 00:25:46 +0000 (01:25 +0100)
committerjmslbam <jmslbam@gmail.com>
Sat, 29 Dec 2012 00:25:46 +0000 (01:25 +0100)
php/commands/scaffold.php
php/commands/skeletons/post_type_skeleton.php [changed mode: 0755->0644]
php/commands/skeletons/post_type_skeleton_extended.php [new file with mode: 0755]
php/commands/skeletons/taxonomy_skeleton.php [changed mode: 0755->0644]
php/commands/skeletons/taxonomy_skeleton_extended.php [new file with mode: 0755]

index c1b832d..ee11f0c 100755 (executable)
@@ -20,7 +20,7 @@ class Scaffold_Command extends WP_CLI_Command {
    *
    * @alias pt
    *
-   * @synopsis [--description=<description>] [--public=<public>] [--exclude_from_search=<exclude_from_search>] [--show_ui=<show_ui>] [--show_in_nav_menus=<show_in_nav_menus>] [--show_in_menu=<show_in_menu>] [--show_in_admin_bar=<show_in_admin_bar>] [--menu_position=<menu_position>] [--menu_icon=<menu_icon>] [--capability_type=<capability_type>] [--hierarchical=<hierarchical>] [--supports=<supports>] [--has_archive=<has_archive>] [--slug=<slug>] [--feed=<feed>] [--pages=<pages>] [--query_var=<query_var>] [--can_export=<can_export>] [--textdomain=<textdomain>] [--theme] [--plugin_name=<plugin_name>]
+   * @synopsis [--description=<description>] [--public=<public>] [--exclude_from_search=<exclude_from_search>] [--show_ui=<show_ui>] [--show_in_nav_menus=<show_in_nav_menus>] [--show_in_menu=<show_in_menu>] [--show_in_admin_bar=<show_in_admin_bar>] [--menu_position=<menu_position>] [--menu_icon=<menu_icon>] [--capability_type=<capability_type>] [--hierarchical=<hierarchical>] [--supports=<supports>] [--has_archive=<has_archive>] [--slug=<slug>] [--feed=<feed>] [--pages=<pages>] [--query_var=<query_var>] [--can_export=<can_export>] [--textdomain=<textdomain>] [--theme] [--plugin_name=<plugin_name>] [--raw]
    */
   function post_type( $args, $assoc_args ) {
     global $wp_filesystem;
@@ -33,7 +33,7 @@ class Scaffold_Command extends WP_CLI_Command {
     $machine_name_plural      = $this->pluralize( $post_type );
 
     // If no label is given use the slug and prettify it as good as possible
-    if( !isset( $assoc_args['label'] ) ) {
+    if( ! isset( $assoc_args['label'] ) ) {
       $label                  = preg_replace( '/_|-/', ' ', strtolower( $post_type ) );
       $label_ucfirst          = ucfirst( $label );
       $label_plural           = $this->pluralize( $label );
@@ -62,7 +62,8 @@ class Scaffold_Command extends WP_CLI_Command {
       'can_export'          => 'true',
       'textdomain'          => '',
       'theme'               => false,
-      'plugin_name'         => false
+      'plugin_name'         => false,
+      'raw'                 => false,
     );
 
     // Generate the variables from the defaults and associated arguments if they are set
@@ -70,7 +71,13 @@ class Scaffold_Command extends WP_CLI_Command {
 
     $textdomain = $this->get_textdomain( $textdomain, $theme, $plugin_name );
     
-    include 'skeletons/post_type_skeleton.php';
+    if( ! $raw ) {
+      include 'skeletons/post_type_skeleton.php';
+      $output = str_replace( "<?php", "", $output);
+      include 'skeletons/post_type_skeleton_extended.php';
+    } else {
+      include 'skeletons/post_type_skeleton.php';
+    }
 
     if ( $theme || ! empty( $plugin_name ) ) {
       // Write file to theme or given plugin_name
@@ -94,7 +101,7 @@ class Scaffold_Command extends WP_CLI_Command {
    *
    * @alias tax
    *
-   * @synopsis [--public=<public>] [--show_in_nav_menus=<show_in_nav_menus>] [--show_ui=<show_ui>] [--show_tagcloud=<show_tagcloud>] [--hierarchical=<hierarchical>]  [--rewrite=<rewrite>] [--query_var=<query_var>] [--slug=<slug>] [--textdomain=<textdomain>] [--post_types=<post_types>] [--theme] [--plugin_name=<plugin_name>]
+   * @synopsis [--public=<public>] [--show_in_nav_menus=<show_in_nav_menus>] [--show_ui=<show_ui>] [--show_tagcloud=<show_tagcloud>] [--hierarchical=<hierarchical>]  [--rewrite=<rewrite>] [--query_var=<query_var>] [--slug=<slug>] [--textdomain=<textdomain>] [--post_types=<post_types>] [--theme] [--plugin_name=<plugin_name>] [--raw]
    */
   function taxonomy( $args, $assoc_args ) {
     global $wp_filesystem;
@@ -107,7 +114,7 @@ class Scaffold_Command extends WP_CLI_Command {
     $machine_name_plural      = $this->pluralize( $taxonomy );
 
     // If no label is given use the slug and prettify it as good as possible
-    if( !isset( $assoc_args['label'] ) ) {
+    if( ! isset( $assoc_args['label'] ) ) {
       $label                  = preg_replace( '/_|-/', ' ', strtolower( $taxonomy ) );
       $label_ucfirst          = ucfirst( $label );
       $label_plural           = $this->pluralize( $label );
@@ -127,7 +134,8 @@ class Scaffold_Command extends WP_CLI_Command {
       'post_types'          => 'post',
       'textdomain'          => '',
       'theme'               => false,
-      'plugin_name'         => false
+      'plugin_name'         => false,
+      'raw'                 => false,
     );
     
     // Generate the variables from the defaults and associated arguments if they are set
@@ -135,9 +143,15 @@ class Scaffold_Command extends WP_CLI_Command {
 
     $textdomain = $this->get_textdomain( $textdomain, $theme, $plugin_name );
 
-    include 'skeletons/taxonomy_skeleton.php';
+    if( ! $raw ) {
+      include 'skeletons/taxonomy_skeleton.php';
+      $output = str_replace( "<?php", "", $output);
+      include 'skeletons/taxonomy_skeleton_extended.php';
+    } else {
+      include 'skeletons/taxonomy_skeleton.php';
+    }
 
-    if ( $theme || !empty( $plugin_name ) ) {
+    if ( $theme || ! empty( $plugin_name ) ) {
       // Write file to theme or given plugin_name
       $assoc_args = array(
         'type' => 'taxonomy',
old mode 100755 (executable)
new mode 100644 (file)
index e92355d..21253f9
@@ -1,7 +1,5 @@
 <?php
 $output = "<?php
-
-function {$machine_name}_init() {
   register_post_type( '{$post_type}', 
     array(
       'label'               => __( '{$label_plural_ucfirst}', '{$textdomain}' ),
@@ -37,30 +35,4 @@ function {$machine_name}_init() {
         'menu_name'           => __( '{$label_plural_ucfirst}', '{$textdomain}' ),
       ),
     ) 
-  );
-}
-add_action( 'init', '{$machine_name}_init' );
-
-function {$machine_name}_updated_messages( \$messages ) {
-  global \$post, \$post_ID;
-
-  \$messages['{$post_type}'] = array(
-    0 => '', // Unused. Messages start at index 1.
-    1 => sprintf( __('{$label_ucfirst} updated. <a target=\"_blank\" href=\"%s\">View {$label}</a>', '{$textdomain}'), esc_url( get_permalink(\$post_ID) ) ),
-    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( get_permalink(\$post_ID) ) ),
-    7 => __('{$label_ucfirst} saved.', '{$textdomain}'),
-    8 => sprintf( __('{$label_ucfirst} submitted. <a target=\"_blank\" href=\"%s\">Preview {$post_type}</a>', '{$textdomain}'), esc_url( add_query_arg( 'preview', 'true', get_permalink(\$post_ID) ) ) ),
-    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 http://php.net/date
-      date_i18n( __( 'M j, Y @ G:i' ), strtotime( \$post->post_date ) ), esc_url( get_permalink( \$post_ID ) ) ),
-    10 => sprintf( __('{$label_ucfirst} draft updated. <a target=\"_blank\" href=\"%s\">Preview {$post_type}</a>', '{$textdomain}'), esc_url( add_query_arg( 'preview', 'true', get_permalink( \$post_ID ) ) ) ),
-  );
-
-  return \$messages;
-}
-add_filter( 'post_updated_messages', '{$machine_name}_updated_messages' );";
\ No newline at end of file
+  );";
\ No newline at end of file
diff --git a/php/commands/skeletons/post_type_skeleton_extended.php b/php/commands/skeletons/post_type_skeleton_extended.php
new file mode 100755 (executable)
index 0000000..3d541d8
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+$output = "<?php
+
+function {$machine_name}_init() {
+  {$output}
+}
+add_action( 'init', '{$machine_name}_init' );
+
+function {$machine_name}_updated_messages( \$messages ) {
+  global \$post, \$post_ID;
+
+  \$messages['{$post_type}'] = array(
+    0 => '', // Unused. Messages start at index 1.
+    1 => sprintf( __('{$label_ucfirst} updated. <a target=\"_blank\" href=\"%s\">View {$label}</a>', '{$textdomain}'), esc_url( get_permalink(\$post_ID) ) ),
+    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( get_permalink(\$post_ID) ) ),
+    7 => __('{$label_ucfirst} saved.', '{$textdomain}'),
+    8 => sprintf( __('{$label_ucfirst} submitted. <a target=\"_blank\" href=\"%s\">Preview {$post_type}</a>', '{$textdomain}'), esc_url( add_query_arg( 'preview', 'true', get_permalink(\$post_ID) ) ) ),
+    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 http://php.net/date
+      date_i18n( __( 'M j, Y @ G:i' ), strtotime( \$post->post_date ) ), esc_url( get_permalink( \$post_ID ) ) ),
+    10 => sprintf( __('{$label_ucfirst} draft updated. <a target=\"_blank\" href=\"%s\">Preview {$post_type}</a>', '{$textdomain}'), esc_url( add_query_arg( 'preview', 'true', get_permalink( \$post_ID ) ) ) ),
+  );
+
+  return \$messages;
+}
+add_filter( 'post_updated_messages', '{$machine_name}_updated_messages' );";
+?>
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index 1d299b7..e098f77
@@ -1,7 +1,5 @@
 <?php
 $output = "<?php
-
-function {$machine_name}_init() {
   \$labels = array( 
     'name'                        =>  __( '{$label_plural_ucfirst}', '{$textdomain}' ),
     'singular_name'               =>  __( '{$label_ucfirst}', '{$textdomain}' ),
@@ -20,8 +18,8 @@ function {$machine_name}_init() {
     'menu_name'                   =>  __( '{$label_plural_ucfirst}', '{$textdomain}' ),
   );
 
-  \$args = array( 
-    'labels'                  => \$labels,
+  \$args = array(
+       'labels'                  => \$labels,
     'public'                  => {$public},
     'show_in_nav_menus'       => {$show_in_nav_menus},
     'show_ui'                 => {$show_ui},
@@ -42,7 +40,4 @@ function {$machine_name}_init() {
     ),
   );
     
-  register_taxonomy( '{$taxonomy}', array( '{$post_types}' ), \$args );
-
-}
-add_action( 'init', '{$machine_name}_init' );";
\ No newline at end of file
+  register_taxonomy( '{$taxonomy}', array( '{$post_types}' ), \$args );";
\ No newline at end of file
diff --git a/php/commands/skeletons/taxonomy_skeleton_extended.php b/php/commands/skeletons/taxonomy_skeleton_extended.php
new file mode 100755 (executable)
index 0000000..d4015c7
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+$output = "<?php
+
+function {$machine_name}_init() {
+  {$output}
+
+}
+add_action( 'init', '{$machine_name}_init' );";
\ No newline at end of file