Skip to content

Commit

Permalink
Another refactor is done
Browse files Browse the repository at this point in the history
  • Loading branch information
sohelamin committed Jun 29, 2016
1 parent 40757fc commit bfac67e
Show file tree
Hide file tree
Showing 9 changed files with 331 additions and 334 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WP Generator

Inspired by [https://github.com/tareq1988/wp-generators](https://github.com/tareq1988/wp-generators)

## Supported
## Features
- WP List Table Generator

## Installation
Expand Down
41 changes: 24 additions & 17 deletions process.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ function process($post_data, $download = true, $delete = true)
$plugin_main_file = file_get_contents(dirname(__FILE__) . '/stubs/plugin-name.stub');
$plugin_uninstall_file = file_get_contents(dirname(__FILE__) . '/stubs/uninstall.stub');

$crud_admin_menu_file = file_get_contents(dirname(__FILE__) . '/stubs/class-crud-name-admin-menu.stub');
$admin_menu_file = file_get_contents(dirname(__FILE__) . '/stubs/class-admin-menu.stub');
$form_handler_file = file_get_contents(dirname(__FILE__) . '/stubs/class-form-handler.stub');
$crud_functions_file = file_get_contents(dirname(__FILE__) . '/stubs/crud-name-functions.stub');
$crud_functions_file = file_get_contents(dirname(__FILE__) . '/stubs/crud-name-functions.stub');
$crud_wp_list_table_file = file_get_contents(dirname(__FILE__) . '/stubs/class-crud-name-list-table.stub');
$crud_list_view_file = file_get_contents(dirname(__FILE__) . '/stubs/views/crud-name.stub');
Expand All @@ -305,10 +307,11 @@ function process($post_data, $download = true, $delete = true)
$crud_wp_list_table_file = str_replace("%%column_default%%", $column_default, $crud_wp_list_table_file);
$crud_wp_list_table_file = str_replace("%%columns%%", $columns, $crud_wp_list_table_file);
$crud_wp_list_table_file = str_replace("%%sortable_columns%%", $sortable_columns, $crud_wp_list_table_file);
$crud_wp_list_table_file = str_replace("%%form_submit_fields%%", $form_submit_fields, $crud_wp_list_table_file);
$crud_wp_list_table_file = str_replace("%%form_fields%%", $form_fields, $crud_wp_list_table_file);

$crud_functions_file = str_replace("%%form_single_default%%", $form_single_default, $crud_functions_file);
$crud_wp_list_table_file = str_replace("%%form_validation%%", $form_validation, $crud_wp_list_table_file);

$form_handler_file = str_replace("%%form_submit_fields%%", $form_submit_fields, $form_handler_file);
$form_handler_file = str_replace("%%form_fields%%", $form_fields, $form_handler_file);

// Repacing form html
$crud_new_view_file = str_replace("%%new_view_form%%", $new_view_form, $crud_new_view_file);
Expand All @@ -319,7 +322,8 @@ function process($post_data, $download = true, $delete = true)
$plugin_main_file = str_replace("%%$key%%", $value, $plugin_main_file);
$plugin_uninstall_file = str_replace("%%$key%%", $value, $plugin_uninstall_file);
$crud_functions_file = str_replace("%%$key%%", $value, $crud_functions_file);
$crud_admin_menu_file = str_replace("%%$key%%", $value, $crud_admin_menu_file);
$admin_menu_file = str_replace("%%$key%%", $value, $admin_menu_file);
$form_handler_file = str_replace("%%$key%%", $value, $form_handler_file);
$crud_wp_list_table_file = str_replace("%%$key%%", $value, $crud_wp_list_table_file);
$crud_list_view_file = str_replace("%%$key%%", $value, $crud_list_view_file);
$crud_new_view_file = str_replace("%%$key%%", $value, $crud_new_view_file);
Expand All @@ -344,34 +348,37 @@ function process($post_data, $download = true, $delete = true)
mkdir($plugin_dir . 'includes/', 0777);
}

$crud_dir = $plugin_dir . 'includes/' . $data['crud_name'] . '/';
if (!is_dir($crud_dir)) {
mkdir($crud_dir, 0777);
$admin_dir = $plugin_dir . 'includes/admin/';
if (!is_dir($admin_dir)) {
mkdir($admin_dir, 0777);
}

// Creating admin menu file
file_put_contents($crud_dir . 'class-' . $data['crud_name'] . '-admin-menu.php', $crud_admin_menu_file);
file_put_contents($admin_dir . 'class-admin-menu.php', $admin_menu_file);

// Creating form handler file
file_put_contents($admin_dir . 'class-form-handler.php', $form_handler_file);

// Creating functions file
file_put_contents($crud_dir . $data['crud_name'] . '-functions.php', $crud_functions_file);
file_put_contents($plugin_dir . 'includes/' . $data['crud_name'] . '-functions.php', $crud_functions_file);

// Creating plugin main file
file_put_contents($crud_dir . 'class-' . $data['crud_name'] . '-list-table.php', $crud_wp_list_table_file);
file_put_contents($plugin_dir . 'includes/' . 'class-' . $data['crud_name'] . '-list-table.php', $crud_wp_list_table_file);

if (!is_dir($crud_dir . 'views/')) {
mkdir($crud_dir . 'views/', 0777);
if (!is_dir($admin_dir . 'views/')) {
mkdir($admin_dir . 'views/', 0777);
}
// Creating plugin main file
file_put_contents($crud_dir . 'views/' . $data['crud_name'] . '.php', $crud_list_view_file);
file_put_contents($admin_dir . 'views/' . $data['crud_name'] . '.php', $crud_list_view_file);

// Creating plugin main file
file_put_contents($crud_dir . 'views/' . $data['crud_name_singular'] . '-new.php', $crud_new_view_file);
file_put_contents($admin_dir . 'views/' . $data['crud_name_singular'] . '-new.php', $crud_new_view_file);

// Creating plugin main file
file_put_contents($crud_dir . 'views/' . $data['crud_name_singular'] . '-edit.php', $crud_edit_view_file);
file_put_contents($admin_dir . 'views/' . $data['crud_name_singular'] . '-edit.php', $crud_edit_view_file);

// Creating plugin main file
file_put_contents($crud_dir . 'views/' . $data['crud_name_singular'] . '-single.php', $crud_single_view_file);
file_put_contents($admin_dir . 'views/' . $data['crud_name_singular'] . '-single.php', $crud_single_view_file);

zipDir($plugin_dir, $data['plugin_name_dash'] . '.zip', $download);

Expand Down
72 changes: 72 additions & 0 deletions stubs/class-admin-menu.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Admin Menu
*/
class Admin_Menu {
/**
* Constructor.
*
* @param void
*/
public function __construct() {
add_action( 'admin_menu', array( $this, 'plugin_menu' ) );

include dirname( __FILE__ ) . '/../class-%%crud_name%%-list-table.php';
include dirname( __FILE__ ) . '/class-form-handler.php';
new Form_Handler();
}

/**
* Registering plugin menu.
*
* @return void
*/
public function plugin_menu() {
$hook = add_menu_page(
'%%plugin_name_cap%%',
'%%plugin_name_cap%%',
'manage_options',
'%%plugin_page%%',
array( $this, 'plugin_settings_page' ),
'dashicons-groups', null
);
}

/**
* Plugin settings page.
*
* @return void
*/
public function plugin_settings_page() {
$action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
$id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
$template = '';

switch ($action) {
case 'view':
$template = dirname( __FILE__ ) . '/views/%%crud_name_singular%%-single.php';
break;

case 'edit':
$template = dirname( __FILE__ ) . '/views/%%crud_name_singular%%-edit.php';
break;

case 'new':
$template = dirname( __FILE__ ) . '/views/%%crud_name_singular%%-new.php';
break;

default:
$template = dirname( __FILE__ ) . '/views/%%crud_name%%.php';
break;
}

if ( file_exists( $template ) ) {
include( $template );
}
}
}
128 changes: 0 additions & 128 deletions stubs/class-crud-name-admin-menu.stub

This file was deleted.

Loading

0 comments on commit bfac67e

Please sign in to comment.