| @@ 72-102 (lines=31) @@ | ||
| 69 | * |
|
| 70 | * @subcommand save-pod |
|
| 71 | */ |
|
| 72 | public function save_pod( $args, $assoc_args ) { |
|
| 73 | ||
| 74 | // Don't allow id to be set. |
|
| 75 | if ( isset( $assoc_args['id'] ) ) { |
|
| 76 | unset( $assoc_args['id'] ); |
|
| 77 | } |
|
| 78 | ||
| 79 | $api = pods_api(); |
|
| 80 | ||
| 81 | $id = 0; |
|
| 82 | ||
| 83 | try { |
|
| 84 | $pod = $api->load_pod( $assoc_args['name'] ); |
|
| 85 | ||
| 86 | if ( ! $pod ) { |
|
| 87 | WP_CLI::error( sprintf( __( 'Pod "%s" does not exist.', 'pods' ), $assoc_args['name'] ) ); |
|
| 88 | } |
|
| 89 | ||
| 90 | $id = $api->save_pod( $assoc_args ); |
|
| 91 | } catch ( Exception $e ) { |
|
| 92 | WP_CLI::error( sprintf( __( 'Error saving pod: %s', 'pods' ), $e->getMessage() ) ); |
|
| 93 | } |
|
| 94 | ||
| 95 | if ( 0 < $id ) { |
|
| 96 | WP_CLI::success( __( 'Pod saved.', 'pods' ) ); |
|
| 97 | WP_CLI::line( sprintf( __( 'ID: %s', 'pods' ), $id ) ); |
|
| 98 | } else { |
|
| 99 | WP_CLI::error( __( 'Pod not saved.', 'pods' ) ); |
|
| 100 | } |
|
| 101 | ||
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * Duplicate a pod. |
|
| @@ 126-156 (lines=31) @@ | ||
| 123 | * |
|
| 124 | * @subcommand duplicate-pod |
|
| 125 | */ |
|
| 126 | public function duplicate_pod( $args, $assoc_args ) { |
|
| 127 | ||
| 128 | // Don't allow id to be set. |
|
| 129 | if ( isset( $assoc_args['id'] ) ) { |
|
| 130 | unset( $assoc_args['id'] ); |
|
| 131 | } |
|
| 132 | ||
| 133 | $api = pods_api(); |
|
| 134 | ||
| 135 | $id = 0; |
|
| 136 | ||
| 137 | try { |
|
| 138 | $pod = $api->load_pod( $assoc_args['name'] ); |
|
| 139 | ||
| 140 | if ( ! $pod ) { |
|
| 141 | WP_CLI::error( sprintf( __( 'Pod "%s" does not exist.', 'pods' ), $assoc_args['name'] ) ); |
|
| 142 | } |
|
| 143 | ||
| 144 | $id = $api->duplicate_pod( $assoc_args ); |
|
| 145 | } catch ( Exception $e ) { |
|
| 146 | WP_CLI::error( sprintf( __( 'Error duplicating pod: %s', 'pods' ), $e->getMessage() ) ); |
|
| 147 | } |
|
| 148 | ||
| 149 | if ( 0 < $id ) { |
|
| 150 | WP_CLI::success( __( 'Pod duplicated.', 'pods' ) ); |
|
| 151 | WP_CLI::line( sprintf( __( 'New ID: %s', 'pods' ), $id ) ); |
|
| 152 | } else { |
|
| 153 | WP_CLI::error( __( 'Pod not duplicated.', 'pods' ) ); |
|
| 154 | } |
|
| 155 | ||
| 156 | } |
|
| 157 | ||
| 158 | /** |
|
| 159 | * Reset a pod which will delete all pod items. |
|