Acme Demo Setup - Version 2.0.1

Version Description

Download this release

Release Info

Developer acmethemes
Plugin Icon 128x128 Acme Demo Setup
Version 2.0.1
Comparing to
See all releases

Code changes from version 2.0.0 to 2.0.1

acme-demo-setup.php CHANGED
@@ -16,7 +16,7 @@ if ( ! defined( 'WPINC' ) ) {
16
  * Plugin Name: Acme Demo Setup
17
  * Plugin URI:
18
  * Description: Install Template Demo Library for Acme Themes
19
- * Version: 2.0.0
20
  * Author: acmethemes
21
  * Author URI: https://www.acmethemes.com/
22
  * License: GPL-2.0+
@@ -26,7 +26,7 @@ if ( ! defined( 'WPINC' ) ) {
26
  */
27
 
28
  /*Define Constants for this plugin*/
29
- define( 'ACME_DEMO_SETUP_VERSION', '2.0.0' );
30
  define( 'ACME_DEMO_SETUP_PLUGIN_NAME', 'acme-demo-setup' );
31
  define( 'ACME_DEMO_SETUP_PATH', plugin_dir_path( __FILE__ ) );
32
  define( 'ACME_DEMO_SETUP_URL', plugin_dir_url( __FILE__ ) );
16
  * Plugin Name: Acme Demo Setup
17
  * Plugin URI:
18
  * Description: Install Template Demo Library for Acme Themes
19
+ * Version: 2.0.1
20
  * Author: acmethemes
21
  * Author URI: https://www.acmethemes.com/
22
  * License: GPL-2.0+
26
  */
27
 
28
  /*Define Constants for this plugin*/
29
+ define( 'ACME_DEMO_SETUP_VERSION', '2.0.1' );
30
  define( 'ACME_DEMO_SETUP_PLUGIN_NAME', 'acme-demo-setup' );
31
  define( 'ACME_DEMO_SETUP_PATH', plugin_dir_path( __FILE__ ) );
32
  define( 'ACME_DEMO_SETUP_URL', plugin_dir_url( __FILE__ ) );
includes/api.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+ if ( ! class_exists( 'Acme_Demo_Setup_Template_Library_Api' ) ) {
6
+ /**
7
+ * @package Acme Themes
8
+ * @subpackage Acme Demo Setup Template Library Api
9
+ * @since 2.0.1
10
+ *
11
+ * Call like this
12
+ * SITEURL/wp-json/acmethemes-demo-api/v1/fetch_templates/
13
+ *
14
+ */
15
+ class Acme_Demo_Setup_Template_Library_Api extends WP_Rest_Controller {
16
+
17
+ /**
18
+ * Rest route namespace.
19
+ *
20
+ * @var Acme_Demo_Setup_Template_Library_Api
21
+ */
22
+ public $namespace = 'acmethemes-demo-api/';
23
+
24
+ /**
25
+ * Rest route version.
26
+ *
27
+ * @var Acme_Demo_Setup_Template_Library_Api
28
+ */
29
+ public $version = 'v1';
30
+
31
+ /**
32
+ * Initialize the class
33
+ */
34
+ public function run() {
35
+ add_action( 'rest_api_init', array( $this, 'register_routes' ) );
36
+ }
37
+
38
+ /**
39
+ * Register REST API route
40
+ */
41
+ public function register_routes() {
42
+ $namespace = $this->namespace . $this->version;
43
+
44
+ register_rest_route(
45
+ $namespace,
46
+ '/fetch_templates',
47
+ array(
48
+ array(
49
+ 'methods' => \WP_REST_Server::READABLE,
50
+ 'callback' => array( $this, 'fetch_templates' ),
51
+ 'args' => array(
52
+ 'theme-slug' => array(
53
+ 'type' => 'string',
54
+ 'required' => true,
55
+ 'description' => __( 'Theme Slug', 'acme-demo-setup' ),
56
+ ),
57
+ ),
58
+ ),
59
+ )
60
+ );
61
+ }
62
+
63
+ /**
64
+ * Function to fetch templates.
65
+ *
66
+ * @return array|bool|\WP_Error
67
+ */
68
+ public function fetch_templates( \WP_REST_Request $request ) {
69
+ if ( ! $request->get_param( 'theme-slug' ) ) {
70
+ return false;
71
+ }
72
+ $theme_slug = $request->get_param( 'theme-slug' );
73
+
74
+ $templates = acme_demo_setup_get_templates_lists( $theme_slug );
75
+ return rest_ensure_response( $templates );
76
+ }
77
+
78
+ /**
79
+ * Gets an instance of this object.
80
+ * Prevents duplicate instances which avoid artefacts and improves performance.
81
+ *
82
+ * @static
83
+ * @access public
84
+ * @since 1.0.1
85
+ * @return object
86
+ */
87
+ public static function get_instance() {
88
+ // Store the instance locally to avoid private static replication
89
+ static $instance = null;
90
+
91
+ // Only run these methods if they haven't been ran previously
92
+ if ( null === $instance ) {
93
+ $instance = new self();
94
+ }
95
+
96
+ // Always return the instance
97
+ return $instance;
98
+ }
99
+
100
+ /**
101
+ * Throw error on object clone
102
+ *
103
+ * The whole idea of the singleton design pattern is that there is a single
104
+ * object therefore, we don't want the object to be cloned.
105
+ *
106
+ * @access public
107
+ * @since 1.0.0
108
+ * @return void
109
+ */
110
+ public function __clone() {
111
+ // Cloning instances of the class is forbidden.
112
+ _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'acme-demo-setup' ), '1.0.0' );
113
+ }
114
+
115
+ /**
116
+ * Disable unserializing of the class
117
+ *
118
+ * @access public
119
+ * @since 1.0.0
120
+ * @return void
121
+ */
122
+ public function __wakeup() {
123
+ // Unserializing instances of the class is forbidden.
124
+ _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'acme-demo-setup' ), '1.0.0' );
125
+ }
126
+ }
127
+
128
+ }
129
+ Acme_Demo_Setup_Template_Library_Api::get_instance()->run();
includes/functions.php CHANGED
@@ -14,4 +14,3209 @@ function acme_demo_setup_get_theme_screenshot(){
14
  function acme_demo_setup_get_theme_name(){
15
  $current_theme = wp_get_theme();
16
  return $current_theme->get('Name');