PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.3.1
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.3.1
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-restrict-content.php

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

185 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Restrict Content Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class to read ConvertKit Restrict Content Settings.
11 *
12 * @since 2.1.0
13 */
14 class ConvertKit_Settings_Restrict_Content {
15
16 /**
17 * Holds the Settings Key that stores site wide ConvertKit settings
18 *
19 * @var string
20 *
21 * @since 2.1.0
22 */
23 const SETTINGS_NAME = '_wp_convertkit_settings_restrict_content';
24
25 /**
26 * Holds the Settings
27 *
28 * @var array
29 *
30 * @since 2.1.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 2.1.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 2.1.0
58 *
59 * @return array
60 */
61 public function get() {
62
63 return $this->settings;
64
65 }
66
67 /**
68 * Returns whether crawlers are permitted to index Member Content in the Plugin settings.
69 *
70 * @since 2.4.1
71 *
72 * @return bool
73 */
74 public function permit_crawlers() {
75
76 return ( $this->settings['permit_crawlers'] === 'on' ? true : false );
77
78 }
79
80 /**
81 * Returns whether login by email is required for Member Content by Tag functionality.
82 *
83 * @since 2.7.2
84 *
85 * @return bool
86 */
87 public function require_tag_login() {
88
89 return ( $this->settings['require_tag_login'] === 'on' ? true : false );
90
91 }
92
93 /**
94 * Returns Restrict Content settings value for the given key.
95 *
96 * @since 2.1.0
97 *
98 * @param string $key Setting Key.
99 * @return string Value
100 */
101 public function get_by_key( $key ) {
102
103 // If the setting doesn't exist, bail.
104 if ( ! array_key_exists( $key, $this->settings ) ) {
105 return '';
106 }
107
108 // If the setting is empty, fallback to the default.
109 if ( empty( $this->settings[ $key ] ) ) {
110 $defaults = $this->get_defaults();
111 return $defaults[ $key ];
112 }
113
114 return $this->settings[ $key ];
115
116 }
117
118 /**
119 * The default settings, used when the ConvertKit Restrict Content Settings haven't been saved
120 * e.g. on a new installation.
121 *
122 * @since 2.1.0
123 *
124 * @return array
125 */
126 public function get_defaults() {
127
128 $defaults = array(
129 // Permit Crawlers.
130 'permit_crawlers' => '',
131
132 // Restrict by Form.
133 'no_access_text_form' => __( 'Your account does not have access to this content. Please use the form above to subscribe.', 'convertkit' ),
134
135 // Restrict by Product.
136 'subscribe_heading' => __( 'Read this post with a premium subscription', 'convertkit' ),
137 'subscribe_text' => __( 'This post is only available to premium subscribers. Join today to get access to all posts.', 'convertkit' ),
138 'no_access_text' => __( 'Your account does not have access to this content. Please use the button above to purchase, or enter the email address you used to purchase the product.', 'convertkit' ),
139
140 // Restrict by Tag.
141 'subscribe_heading_tag' => __( 'Subscribe to keep reading', 'convertkit' ),
142 'subscribe_text_tag' => __( 'This post is free to read but only available to subscribers. Join today to get access to all posts.', 'convertkit' ),
143 'require_tag_login' => '', // blank|on.
144 'no_access_text_tag' => __( 'Your account does not have access to this content. Please use the form above to subscribe.', 'convertkit' ),
145
146 // All.
147 'subscribe_button_label' => __( 'Subscribe', 'convertkit' ),
148 'email_text' => __( 'Already subscribed?', 'convertkit' ),
149 'email_button_label' => __( 'Log in', 'convertkit' ),
150 'email_heading' => __( 'Log in to read this post', 'convertkit' ),
151 'email_description_text' => __( 'We\'ll email you a magic code to log you in without a password.', 'convertkit' ),
152 'email_check_heading' => __( 'We just emailed you a log in code', 'convertkit' ),
153 'email_check_text' => __( 'Enter the code below to finish logging in', 'convertkit' ),
154 'container_css_classes' => '',
155 );
156
157 /**
158 * The default settings, used when the ConvertKit Restrict Content Settings haven't been saved
159 * e.g. on a new installation.
160 *
161 * @since 2.1.0
162 *
163 * @param array $defaults Default settings.
164 */
165 $defaults = apply_filters( 'convertkit_settings_restrict_content_get_defaults', $defaults );
166
167 return $defaults;
168
169 }
170
171 /**
172 * Saves the given array of settings to the WordPress options table.
173 *
174 * @since 2.1.0
175 *
176 * @param array $settings Settings.
177 */
178 public function save( $settings ) {
179
180 update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) );
181
182 }
183
184 }
185