Changeset 1523456
- Timestamp:
- 10/27/2016 11:35:19 PM (9 years ago)
- Location:
- advanced-custom-post-types/trunk
- Files:
-
- 6 edited
-
acpt.php (modified) (1 diff)
-
admin/class-post-type.php (modified) (4 diffs)
-
class-load.php (modified) (2 diffs)
-
class-post-types.php (modified) (3 diffs)
-
class-settings.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
advanced-custom-post-types/trunk/acpt.php
r1506712 r1523456 3 3 Plugin Name: Advanced Custom Post Types 4 4 Description: Customise WordPress with custom post types 5 Version: 0. 2.05 Version: 0.3.0 6 6 Author: iambriansreed 7 7 Author URI: http://iambrian.com/ -
advanced-custom-post-types/trunk/admin/class-post-type.php
r1506712 r1523456 2 2 3 3 namespace Advanced_Custom_Post_Types\Admin; 4 5 use Advanced_Custom_Post_Types\Settings; 4 6 5 7 class Post_Type { … … 7 9 private $fields; 8 10 private $dashicons; 9 10 function __construct( Fields $fields, Dashicons $dashicons ) { 11 private $settings; 12 13 function __construct( Settings $settings, Fields $fields, Dashicons $dashicons ) { 11 14 $this->fields = $fields; 12 15 $this->dashicons = $dashicons; 16 $this->settings = $settings; 13 17 } 14 18 15 19 public function save( $post ) { 16 20 21 if ( ! is_object( $post ) ) { 22 return; 23 } 24 17 25 $post_data = $this->get_post_data( $post->ID ); 18 26 19 if ( $post_data['error'] ) { 20 21 Notices::add( $post_data['error'], 'error', false ); 22 unset( $post_data['error'] ); 23 } 24 25 // $this->test( $post_data ); 26 27 wp_update_post( $post_data ); 27 if ( $post_data->errors ) { 28 Notices::add( $post_data->errors, 'error', false ); 29 } 30 31 wp_update_post( $post_data->post ); 32 33 $save_json = $this->save_json( $post_data ); 34 35 if ( $save_json->errors ) { 36 37 Notices::add( $save_json->errors, 'error', false ); 38 } 39 } 40 41 public function save_json( $post_data ) { 42 43 // vars 44 $path = $this->settings->get( 'save_json' ); 45 $file_name = $post_data->post_type . '.json'; 46 $output = (object) array( 'errors' => false ); 47 48 // remove trailing slash 49 $path = untrailingslashit( $path ); 50 51 // bail early if dir does not exist 52 if ( ! is_writable( $path ) ) { 53 $output->errors = "The ACPT JSON save path '$path' is not writable."; 54 55 return $output; 56 } 57 58 // write file 59 $f = fopen( "{$path}/{$file_name}", 'w' ); 60 fwrite( $f, $this->json_encode( $post_data->data ) ); 61 fclose( $f ); 62 63 // return 64 return $output; 65 28 66 } 29 67 … … 31 69 * @param $post_id 32 70 * 33 * @return array71 * @return object 34 72 * @throws \Exception 35 73 */ … … 198 236 $content->saved = time(); 199 237 200 return array( 201 'ID' => $post_id, 202 'post_title' => $args['plural_name'], 203 'post_name' => 'acpt_post_type_' . $post_type, 204 'post_status' => $content->error ? 'draft' : 'publish', 205 'post_content' => json_encode( $content ), 206 'post_content_data' => $content, 207 'error' => $content->error 208 ); 238 return (object) array( 239 'errors' => $content->error, 240 'post_type' => $post_type, 241 'data' => $content, 242 'post' => array( 243 'ID' => $post_id, 244 'post_type' => $post_type, 245 'post_title' => $args['plural_name'], 246 'post_type' => ACPT_POST_TYPE, 247 'post_name' => 'acpt_post_type_' . $post_type, 248 'post_status' => $content->error ? 'draft' : 'publish', 249 'post_content' => $this->json_encode( $content ), 250 'post_content_data' => $content 251 ) 252 ); 253 } 254 255 function json_encode( $data ) { 256 257 // create json string 258 if ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ) { 259 // PHP at least 5.4 260 return json_encode( $data, JSON_PRETTY_PRINT ); 261 262 } else { 263 // PHP less than 5.4 264 return json_encode( $data ); 265 } 209 266 } 210 267 -
advanced-custom-post-types/trunk/class-load.php
r1506712 r1523456 16 16 17 17 function init() { 18 19 $settings = new Settings(); 18 20 19 $post_types = new Post_Types( );21 $post_types = new Post_Types( $settings ); 20 22 21 23 $post_types->register(); … … 23 25 if ( is_admin() ) { 24 26 25 $settings = new Settings(); 26 $dashicons = new Dashicons(); 27 $fields = new Fields( $settings, $dashicons ); 28 $post_type = new Post_Type( $fields, $dashicons ); 27 $dashicons = new Dashicons(); 28 $fields = new Fields( $settings, $dashicons ); 29 $post_type = new Post_Type( $settings, $fields, $dashicons ); 29 30 30 31 new Admin\Load( $settings, $post_types, $fields, $post_type ); -
advanced-custom-post-types/trunk/class-post-types.php
r1506712 r1523456 4 4 5 5 class Post_Types { 6 7 private $json_path = ''; 8 9 function __construct( Settings $settings ) { 10 11 $this->json_path = $settings->get( 'save_json' ); 12 } 6 13 7 14 private function get_saved_data() { … … 25 32 26 33 foreach ( $posts as $post ) { 27 $post_types[] = json_decode( $post->post_content, true ); 34 35 $post_data = json_decode( $post->post_content, true ); 36 37 $post_types[ $post_data['post_type'] ] = $post_data; 28 38 } 29 39 30 $post_types = apply_filters( 'acpt/post_types', $post_types ); 40 if ( $this->json_path ) { 41 42 $files = scandir( $this->json_path ); 43 44 foreach ( $files as $file ) { 45 46 if ( substr( $file, - 5 ) === '.json' ) { 47 48 $post_type_json = file_get_contents( "$this->json_path/$file" ); 49 50 $post_data = json_decode( $post_type_json, true ); 51 52 $post_types[ $post_data['post_type'] ] = $post_data; 53 } 54 } 55 } 31 56 32 57 return $post_types; 58 59 } 60 61 public function valid_post_type( $post_type ) { 62 return is_string( $post_type ) && strlen( $post_type ) > 0 && strlen( $post_type ) < 21; 33 63 } 34 64 … … 43 73 foreach ( $post_types as $post_type ) { 44 74 45 if ( ! isset( $post_type['post_type'] ) || ! isset( $post_type['args'] ) ) {75 if ( ! isset( $post_type['post_type'] ) || ! $this->valid_post_type( $post_type['post_type'] ) || ! isset( $post_type['args'] ) ) { 46 76 continue; 47 77 } -
advanced-custom-post-types/trunk/class-settings.php
r1506712 r1523456 10 10 11 11 $this->defaults = array( 12 'show_admin' => true, 13 'capability' => 'manage_options' 12 'show_admin' => true, 13 'capability' => 'manage_options', 14 'save_json' => null 14 15 ); 15 16 } -
advanced-custom-post-types/trunk/readme.txt
r1506712 r1523456 17 17 **acpt/settings/show_admin** - Determines whether or not the admin menu is shown. 18 18 19 **acpt/settings/admin_fields** - Determines which field groups may appear in the post type editor.20 21 19 **acpt/settings/capability** - Determines capability is needed to manage custom post types. 22 20 23 **acpt/ post_types** - Alter the post types created21 **acpt/settings/save_json** - The path to save post types locally. 24 22 25 23 == Actions == … … 60 58 = 0.2.0 = 61 59 * Massive refactoring and cleanup, added export 60 61 = 0.3.0 = 62 * Added the Local JSON feature which saves post type settings to files within your theme. The idea is similar to caching and both dramatically speeds up ACPT and allows for version control over your post type settings. Removed unused filters and added the save_json filter to determine where post type setting files are saved. 63 64
Note: See TracChangeset
for help on using the changeset viewer.