PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / trunk
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages vtrunk
3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 All 194 releases
convertkit / includes / class-convertkit-settings-mcp.php

class-convertkit-settings-mcp.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages trunk, at includes/class-convertkit-settings-mcp.php

130 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit MCP Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class to read ConvertKit MCP Settings.
11 *
12 * @since 3.4.0
13 */
14 class ConvertKit_Settings_MCP {
15
16 /**
17 * Holds the Settings Key that stores site wide ConvertKit settings
18 *
19 * @var string
20 *
21 * @since 3.4.0
22 */
23 const SETTINGS_NAME = '_wp_convertkit_settings_mcp';
24
25 /**
26 * Holds the Settings
27 *
28 * @var array
29 *
30 * @since 3.4.0
31 */
32 private $settings = array();
33
34 /**
35 * Constructor. Reads settings from options table, falling back to defaults
36 * if no settings exist.
37 *
38 * @since 3.4.0
39 */
40 public function __construct() {
41
42 // Get Settings.
43 $settings = get_option( self::SETTINGS_NAME );
44
45 // If no Settings exist, falback to default settings.
46 if ( ! $settings ) {
47 $this->settings = $this->get_defaults();
48 } else {
49 $this->settings = array_merge( $this->get_defaults(), $settings );
50 }
51
52 }
53
54 /**
55 * Returns Plugin settings.
56 *
57 * @since 3.4.0
58 *
59 * @return array
60 */
61 public function get() {
62
63 return $this->settings;
64
65 }
66
67 /**
68 * Returns whether the user has access to MCP via a paid plan,
69 * and if so whether the MCP server is enabled in the Plugin's settings.
70 *
71 * @since 3.4.0
72 *
73 * @return bool
74 */
75 public function enabled() {
76
77 // Bail if the connected Kit account isn't on a paid plan.
78 // This queries the cached account details, so no live API call is made.
79 $account = new ConvertKit_Resource_Account();
80 if ( ! $account->is_paid_plan() ) {
81 return false;
82 }
83
84 return ( $this->settings['enabled'] === 'on' ? true : false );
85
86 }
87
88 /**
89 * The default settings, used when the ConvertKit MCP Settings haven't been saved
90 * e.g. on a new installation.
91 *
92 * @since 2.1.0
93 *
94 * @return array
95 */
96 public function get_defaults() {
97
98 $defaults = array(
99 'enabled' => '', // blank|on.
100 );
101
102 /**
103 * The default settings, used when the ConvertKit MCP Settings haven't been saved
104 * e.g. on a new installation.
105 *
106 * @since 3.4.0
107 *
108 * @param array $defaults Default settings.
109 */
110 $defaults = apply_filters( 'convertkit_settings_mcp_get_defaults', $defaults );
111
112 return $defaults;
113
114 }
115
116 /**
117 * Saves the given array of settings to the WordPress options table.
118 *
119 * @since 3.4.0
120 *
121 * @param array $settings Settings.
122 */
123 public function save( $settings ) {
124
125 update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) );
126
127 }
128
129 }
130