Export.php
2 years ago
GetFields.php
4 months ago
Import.php
2 years ago
Options.php
1 week ago
Pages.php
2 years ago
Posts.php
4 months ago
Services.php
1 year ago
Export.php
78 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Export services. |
| 4 | * |
| 5 | * @package ShopPress |
| 6 | */ |
| 7 | |
| 8 | namespace ShopPress\Admin\API; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | class Export { |
| 13 | /** |
| 14 | * Instance of this class. |
| 15 | * |
| 16 | * @since 1.0.0 |
| 17 | */ |
| 18 | public static $instance; |
| 19 | |
| 20 | /** |
| 21 | * File content. |
| 22 | * |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | private $content; |
| 26 | |
| 27 | /** |
| 28 | * Provides access to a single instance of a module using the singleton pattern. |
| 29 | * |
| 30 | * @since 1.0.0 |
| 31 | * |
| 32 | * @return object |
| 33 | */ |
| 34 | public static function instance() { |
| 35 | if ( self::$instance === null ) { |
| 36 | self::$instance = new self(); |
| 37 | } |
| 38 | return self::$instance; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Set content. |
| 43 | * |
| 44 | * @since 1.0.0 |
| 45 | * |
| 46 | * @param $content |
| 47 | */ |
| 48 | private function set_file_content( $content ) { |
| 49 | $this->content = $content; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Export. |
| 54 | * |
| 55 | * @since 1.0.0 |
| 56 | * |
| 57 | * @param object $request |
| 58 | */ |
| 59 | public function export( $request ) { |
| 60 | $action = $request->get_param( 'action' ); |
| 61 | |
| 62 | switch ( $action ) { |
| 63 | case 'exportOptions': { |
| 64 | $options = get_option( 'sp_admin' ); |
| 65 | |
| 66 | $this->set_file_content( $options ); |
| 67 | break; |
| 68 | } |
| 69 | |
| 70 | default: { |
| 71 | break; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | return wp_send_json( $this->content ); |
| 76 | } |
| 77 | } |
| 78 |