DemoPartsRepository.php
3 years ago
DemoSites.php
3 years ago
DemoSitesHelpers.php
4 years ago
DemoSitesImportBlockMap.php
4 years ago
DemoSitesImporter.php
3 years ago
DemoSitesLogger.php
4 years ago
DemoSitesRepository.php
3 years ago
WXRExporter.php
4 years ago
WXRImporter.php
3 years ago
WpCliCommand.php
3 years ago
DemoPartsRepository.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\DemoSites; |
| 4 | |
| 5 | class DemoPartsRepository { |
| 6 | |
| 7 | private static $demoParts = null; |
| 8 | const DEMO_PARTS_TRANSIENT = 'kubio-demo-parts-repository'; |
| 9 | private static $instance = null; |
| 10 | |
| 11 | public function __construct() { |
| 12 | $this->addRestEndPoints(); |
| 13 | $this->loadData(); |
| 14 | } |
| 15 | |
| 16 | public function loadData() { |
| 17 | $data = get_transient( self::DEMO_PARTS_TRANSIENT ); |
| 18 | if ( $data !== false ) { |
| 19 | static::$demoParts = $data; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | public function getDemoParts() { |
| 24 | return static::$demoParts; |
| 25 | } |
| 26 | |
| 27 | public function saveDemoParts( \WP_REST_Request $request ) { |
| 28 | $demoParts = $request->get_param('demoParts'); |
| 29 | if(isset($demoParts) && !empty($demoParts)) { |
| 30 | set_transient( static::DEMO_PARTS_TRANSIENT, $demoParts ); |
| 31 | } |
| 32 | |
| 33 | } |
| 34 | public function addRestEndPoints() { |
| 35 | add_action( |
| 36 | 'rest_api_init', |
| 37 | function () { |
| 38 | $namespace = 'kubio/v1'; |
| 39 | |
| 40 | register_rest_route( |
| 41 | $namespace, |
| 42 | '/demo-sites/demo-parts', |
| 43 | array( |
| 44 | 'methods' => 'POST', |
| 45 | 'callback' => array( $this, 'saveDemoParts' ), |
| 46 | 'permission_callback' => function () { |
| 47 | return current_user_can( 'edit_theme_options' ); |
| 48 | }, |
| 49 | |
| 50 | ) |
| 51 | ); |
| 52 | } |
| 53 | ); |
| 54 | |
| 55 | } |
| 56 | |
| 57 | public static function getInstance() { |
| 58 | if ( ! self::$instance ) { |
| 59 | |
| 60 | self::$instance = new self(); |
| 61 | } |
| 62 | |
| 63 | return self::$instance; |
| 64 | } |
| 65 | |
| 66 | public static function load() { |
| 67 | return self::getInstance(); |
| 68 | } |
| 69 | |
| 70 | } |
| 71 |