PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.0
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.0
2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 2.7.1 All 27 releases
insert-php / includes / class.license.php

class.license.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.7.0, at includes/class.license.php

135 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * License management class
4 *
5 * Handles premium license activation, deactivation, and validation.
6 */
7
8 // Exit if accessed directly
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Class WINP_License
15 *
16 * Standalone license provider with dummy methods for initial implementation.
17 * All methods return hardcoded values to be replaced with real API calls later.
18 */
19 class WINP_License {
20
21 /**
22 * Get the license data.
23 *
24 * @return bool|\stdClass
25 */
26 public static function get_data() {
27 if ( ! defined( 'WASP_PLUGIN_NAMESPACE' ) ) {
28 return false;
29 }
30
31 return get_option( WASP_PLUGIN_NAMESPACE . '_license_data' );
32 }
33
34 /**
35 * Check if Pro is available
36 *
37 * @return bool
38 */
39 public function is_pro_active() {
40 return defined( 'WASP_PLUGIN_VERSION' );
41 }
42
43 /**
44 * Get license key
45 *
46 * @return string License key
47 */
48 public function get_key() {
49 $license = self::get_data();
50
51 if ( false === $license ) {
52 return '';
53 }
54
55 if ( ! isset( $license->key ) ) {
56 return '';
57 }
58
59 return $license->key;
60 }
61
62 /**
63 * Check if license is currently active and valid
64 *
65 * @return bool True if active
66 */
67 public function is_active() {
68 $status = self::get_data();
69
70 if ( ! $status ) {
71 return false;
72 }
73
74 if ( ! isset( $status->license ) ) {
75 return false;
76 }
77
78 if ( 'valid' !== $status->license ) {
79 return false;
80 }
81
82 return true;
83 }
84
85 /**
86 * Get a setting value
87 *
88 * @param string $key Setting key
89 *
90 * @return mixed Setting value or null
91 */
92 public function get_setting( $key ) {
93 $data = self::get_data();
94
95 if ( false === $data ) {
96 return null;
97 }
98
99 if ( 'plugin_id' === $key ) {
100 return $data->download_id ?? null;
101 }
102
103 return null;
104 }
105
106 /**
107 * Toggle license.
108 *
109 * @param string $action License action.
110 * @param string $key License Key.
111 *
112 * @return array<string, mixed>|\WP_Error Response.
113 */
114 public function toggle_license( $action, $key ) {
115 if ( 'deactivate' === $action ) {
116 $key = apply_filters( 'product_woody_license_key', 'free' );
117 }
118
119 $response = apply_filters( 'themeisle_sdk_license_process_woody', $key, $action );
120
121 if ( is_wp_error( $response ) ) {
122 return $response;
123 }
124
125 return [
126 'success' => true,
127 'message' => 'activate' === $action ? __( 'Activated', 'insert-php' ) : __( 'Deactivated', 'insert-php' ),
128 'license' => [
129 'key' => apply_filters( 'product_woody_license_key', 'free' ),
130 'status' => apply_filters( 'product_woody_license_status', false ),
131 ],
132 ];
133 }
134 }
135