PluginProbe ʕ •ᴥ•ʔ
Custom Post Type UI / 1.19.2
Custom Post Type UI v1.19.2
1.19.2 1.19.1 1.19.0 trunk 0.7.0.0 0.7.1.0 0.7.2.0 0.8.0.0 0.8.1 0.8.2 0.8.3 0.8.4 0.8.5 0.9.0 0.9.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.2 1.11.0 1.11.1 1.11.2 1.12.0 1.12.1 1.13.0 1.13.1 1.13.2 1.13.3 1.13.4 1.13.5 1.13.6 1.13.7 1.14.0 1.15.0 1.15.1 1.16.0 1.17.0 1.17.1 1.17.2 1.17.3 1.18.0 1.18.1 1.18.2 1.18.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.8.0 1.8.1 1.8.2 1.9.0 1.9.1 1.9.2
custom-post-type-ui / inc / wp-cli.php
custom-post-type-ui / inc Last commit date
tools-sections 1 month ago about.php 1 month ago listings.php 1 month ago post-types.php 1 month ago support.php 1 month ago taxonomies.php 1 month ago tools.php 1 month ago utility.php 1 month ago wp-cli.php 1 month ago
wp-cli.php
125 lines
1 <?php
2 /**
3 * Custom Post Type UI WP-CLI.
4 *
5 * @package CPTUI
6 * @subpackage WP-CLI
7 * @author WebDevStudios
8 * @since 1.6.0
9 * @license GPL-2.0+
10 */
11
12 // phpcs:disable WebDevStudios.All.RequireAuthor
13
14 /**
15 * Imports and exports Custom Post Type UI setting data.
16 */
17 class CPTUI_Import_JSON extends WP_CLI_Command {
18
19 public $args;
20
21 public $assoc_args;
22
23 public $type;
24
25 public $data = [];
26
27 /**
28 * Imports and parses JSON into CPTUI settings.
29 *
30 * ## Options
31 *
32 * [--type=<type>]
33 * : What type of import this is. Available options are `post_type` and `taxonomy`.
34 *
35 * [--data-path=<path>]
36 * : The server path to the file holding JSON data to import. Relative to PWD.
37 */
38 public function import( $args, $assoc_args ) {
39 $this->args = $args;
40 $this->assoc_args = $assoc_args;
41
42 if ( ! isset( $this->assoc_args['type'] ) ) {
43 WP_CLI::error( esc_html__( 'Please provide whether you are importing post types or taxonomies', 'custom-post-type-ui' ) );
44 }
45
46 if ( ! isset( $this->assoc_args['data-path'] ) ) {
47 WP_CLI::error( esc_html__( 'Please provide a path to the file holding your CPTUI JSON data.', 'custom-post-type-ui' ) );
48 }
49
50 $this->type = $assoc_args['type'];
51
52 $json = file_get_contents( $this->assoc_args['data-path'] );
53
54 if ( empty( $json ) ) {
55 WP_CLI::error( esc_html__( 'No JSON data found', 'custom-post-type-ui' ) );
56 }
57
58 if ( 'post_type' === $this->type ) {
59 $this->data['cptui_post_import'] = json_decode( stripslashes_deep( trim( $json ) ), true );
60 }
61
62 if ( 'taxonomy' === $this->type ) {
63 $this->data['cptui_tax_import'] = json_decode( stripslashes_deep( trim( $json ) ), true );
64 }
65
66 $result = cptui_import_types_taxes_settings( $this->data );
67
68 if ( false === $result || 'import_fail' === $result ) {
69 WP_CLI::error( sprintf( esc_html__( 'An error on import occurred', 'custom-post-type-ui' ) ) );
70 } else {
71 WP_CLI::success(
72 sprintf(
73 /* translators: Placeholders are just for HTML markup that doesn't need translated */
74 esc_html__( 'Imported %s successfully', 'custom-post-type-ui' ),
75 $this->type
76 )
77 );
78 }
79 }
80
81 /**
82 * Export CPTUI settings to file.
83 *
84 * ## Options
85 *
86 * [--type=<type>]
87 * : Which settings to export. Available options are `post_type` and `taxonomy`.
88 *
89 * [--dest-path=<path>]
90 * : The path and file to export to. Relative to PWD.
91 */
92 public function export( $args, $assoc_args ) {
93 $this->args = $args;
94 $this->assoc_args = $assoc_args;
95
96 if ( ! isset( $this->assoc_args['type'] ) ) {
97 WP_CLI::error( esc_html__( 'Please provide whether you are exporting your post types or taxonomies', 'custom-post-type-ui' ) );
98 }
99
100 if ( ! isset( $this->assoc_args['dest-path'] ) ) {
101 WP_CLI::error( esc_html__( 'Please provide a path to export your data to.', 'custom-post-type-ui' ) );
102 }
103
104 $this->type = $assoc_args['type'];
105
106 if ( 'post_type' === $this->type ) {
107 $content = cptui_get_post_type_data();
108 }
109
110 if ( 'taxonomy' === $this->type ) {
111 $content = cptui_get_taxonomy_data();
112 }
113
114 $content = wp_json_encode( $content );
115 $result = file_put_contents( $this->assoc_args['dest-path'], $content );
116
117 if ( false === $result ) {
118 WP_CLI::error( esc_html__( 'Error saving data.', 'custom-post-type-ui' ) );
119 }
120
121 WP_CLI::success( esc_html__( 'Successfully saved data to file.', 'custom-post-type-ui' ) );
122 }
123 }
124 WP_CLI::add_command( 'cptui', 'CPTUI_Import_JSON' );
125