← All changes
|
includes/class-convertkit-settings-restrict-content.php
+92
-150
3.4.2
→
2.7.4
View file →
| @@ -77,162 +77,122 @@ | ||
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | - * Returns Restrict Content settings value for the given key. | |
| 81 | + * Returns whether login by email is required for Member Content by Tag functionality. | |
| 82 | 82 | * |
| 83 | - * @since 2.1.0 | |
| 83 | + * @since 2.7.2 | |
| 84 | 84 | * |
| 85 | - * @param string $key Setting Key. | |
| 86 | - * @return string Value | |
| 85 | + * @return bool | |
| 87 | 86 | */ |
| 88 | - public function get_by_key( $key ) { | |
| 87 | + public function require_tag_login() { | |
| 89 | 88 | |
| 90 | - // If the setting doesn't exist, bail. | |
| 91 | - if ( ! array_key_exists( $key, $this->settings ) ) { | |
| 92 | - return ''; | |
| 93 | - } | |
| 89 | + return ( $this->settings['require_tag_login'] === 'on' ? true : false ); | |
| 94 | 90 | |
| 95 | - // If the setting is empty, fallback to the default. | |
| 96 | - if ( empty( $this->settings[ $key ] ) ) { | |
| 97 | - $defaults = $this->get_defaults(); | |
| 98 | - return $defaults[ $key ]; | |
| 99 | - } | |
| 91 | + } | |
| 100 | 92 | |
| 101 | - return $this->settings[ $key ]; | |
| 93 | + /** | |
| 94 | + * Returns the reCAPTCHA Site Key Plugin setting. | |
| 95 | + * | |
| 96 | + * @since 2.6.8 | |
| 97 | + * | |
| 98 | + * @return string | |
| 99 | + */ | |
| 100 | + public function get_recaptcha_site_key() { | |
| 102 | 101 | |
| 102 | + return $this->settings['recaptcha_site_key']; | |
| 103 | + | |
| 103 | 104 | } |
| 104 | 105 | |
| 105 | 106 | /** |
| 106 | - * Returns this settings group's programmatic name. | |
| 107 | + * Returns whether the reCAPTCHA Site Key has been set in the Plugin settings. | |
| 107 | 108 | * |
| 108 | - * @since 3.4.0 | |
| 109 | + * @since 2.6.8 | |
| 109 | 110 | * |
| 111 | + * @return bool | |
| 112 | + */ | |
| 113 | + public function has_recaptcha_site_key() { | |
| 114 | + | |
| 115 | + return ! empty( $this->get_recaptcha_site_key() ); | |
| 116 | + | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 120 | + * Returns the reCAPTCHA Secret Key Plugin setting. | |
| 121 | + * | |
| 122 | + * @since 2.6.8 | |
| 123 | + * | |
| 110 | 124 | * @return string |
| 111 | 125 | */ |
| 112 | - public function get_name() { | |
| 126 | + public function get_recaptcha_secret_key() { | |
| 113 | 127 | |
| 114 | - return 'restrict-content'; | |
| 128 | + return $this->settings['recaptcha_secret_key']; | |
| 115 | 129 | |
| 116 | 130 | } |
| 117 | 131 | |
| 118 | 132 | /** |
| 119 | - * Returns the title of this settings group. | |
| 133 | + * Returns whether the reCAPTCHA Secret Key has been set in the Plugin settings. | |
| 120 | 134 | * |
| 121 | - * @since 3.4.0 | |
| 135 | + * @since 2.6.8 | |
| 122 | 136 | * |
| 123 | - * @return string | |
| 137 | + * @return bool | |
| 124 | 138 | */ |
| 125 | - public function get_title() { | |
| 139 | + public function has_recaptcha_secret_key() { | |
| 126 | 140 | |
| 127 | - return __( 'Member Content Settings', 'convertkit' ); | |
| 141 | + return ! empty( $this->get_recaptcha_secret_key() ); | |
| 128 | 142 | |
| 129 | 143 | } |
| 130 | 144 | |
| 131 | 145 | /** |
| 132 | - * Returns the keys in this settings group that hold credentials or other | |
| 133 | - * sensitive values. | |
| 146 | + * Returns whether the reCAPTCH Site Key and Secret Key are defined | |
| 147 | + * in the Plugin settings. | |
| 134 | 148 | * |
| 135 | - * Member Content settings hold no secrets; returned for interface | |
| 136 | - * consistency. | |
| 149 | + * @since 2.6.8 | |
| 137 | 150 | * |
| 138 | - * @since 3.4.0 | |
| 151 | + * @return bool | |
| 152 | + */ | |
| 153 | + public function has_recaptcha_site_and_secret_keys() { | |
| 154 | + | |
| 155 | + return $this->get_recaptcha_site_key() && $this->has_recaptcha_secret_key(); | |
| 156 | + | |
| 157 | + } | |
| 158 | + | |
| 159 | + /** | |
| 160 | + * Returns the reCAPTCHA minimum score Plugin setting. | |
| 139 | 161 | * |
| 140 | - * @return string[] | |
| 162 | + * @since 2.6.8 | |
| 163 | + * | |
| 164 | + * @return float | |
| 141 | 165 | */ |
| 142 | - public function get_secret_keys() { | |
| 166 | + public function get_recaptcha_minimum_score() { | |
| 143 | 167 | |
| 144 | - return array(); | |
| 168 | + return (float) $this->settings['recaptcha_minimum_score']; | |
| 145 | 169 | |
| 146 | 170 | } |
| 147 | 171 | |
| 148 | 172 | /** |
| 149 | - * Returns the JSON Schema describing this settings group, in the shape | |
| 150 | - * stored by save() / returned by get(), excluding secret keys. | |
| 173 | + * Returns Restrict Content settings value for the given key. | |
| 151 | 174 | * |
| 152 | - * @since 3.4.0 | |
| 175 | + * @since 2.1.0 | |
| 153 | 176 | * |
| 154 | - * @return array | |
| 177 | + * @param string $key Setting Key. | |
| 178 | + * @return string Value | |
| 155 | 179 | */ |
| 156 | - public function get_schema() { | |
| 180 | + public function get_by_key( $key ) { | |
| 157 | 181 | |
| 158 | - return array( | |
| 159 | - 'type' => 'object', | |
| 160 | - 'additionalProperties' => false, | |
| 161 | - 'properties' => array( | |
| 162 | - 'permit_crawlers' => array( | |
| 163 | - 'type' => 'string', | |
| 164 | - 'enum' => array( '', 'on' ), | |
| 165 | - 'description' => __( 'Whether search engine crawlers are permitted to index Member Content.', 'convertkit' ), | |
| 166 | - ), | |
| 167 | - 'no_access_text_form' => array( | |
| 168 | - 'type' => 'string', | |
| 169 | - 'description' => __( 'Message shown to a visitor without access when content is restricted by Form.', 'convertkit' ), | |
| 170 | - ), | |
| 171 | - 'subscribe_heading' => array( | |
| 172 | - 'type' => 'string', | |
| 173 | - 'description' => __( 'Heading shown above the subscribe call-to-action when content is restricted by Product.', 'convertkit' ), | |
| 174 | - ), | |
| 175 | - 'subscribe_text' => array( | |
| 176 | - 'type' => 'string', | |
| 177 | - 'description' => __( 'Body text shown alongside the subscribe call-to-action when content is restricted by Product.', 'convertkit' ), | |
| 178 | - ), | |
| 179 | - 'no_access_text' => array( | |
| 180 | - 'type' => 'string', | |
| 181 | - 'description' => __( 'Message shown to a visitor without access when content is restricted by Product.', 'convertkit' ), | |
| 182 | - ), | |
| 183 | - 'subscribe_heading_tag' => array( | |
| 184 | - 'type' => 'string', | |
| 185 | - 'description' => __( 'Heading shown above the subscribe call-to-action when content is restricted by Tag.', 'convertkit' ), | |
| 186 | - ), | |
| 187 | - 'subscribe_text_tag' => array( | |
| 188 | - 'type' => 'string', | |
| 189 | - 'description' => __( 'Body text shown alongside the subscribe call-to-action when content is restricted by Tag.', 'convertkit' ), | |
| 190 | - ), | |
| 191 | - 'require_tag_login' => array( | |
| 192 | - 'type' => 'string', | |
| 193 | - 'enum' => array( '', 'on' ), | |
| 194 | - 'description' => __( 'Whether visitors must log in by email to access Member Content restricted by Tag.', 'convertkit' ), | |
| 195 | - ), | |
| 196 | - 'no_access_text_tag' => array( | |
| 197 | - 'type' => 'string', | |
| 198 | - 'description' => __( 'Message shown to a visitor without access when content is restricted by Tag.', 'convertkit' ), | |
| 199 | - ), | |
| 200 | - 'subscribe_button_label' => array( | |
| 201 | - 'type' => 'string', | |
| 202 | - 'description' => __( 'Label for the Subscribe button.', 'convertkit' ), | |
| 203 | - ), | |
| 204 | - 'email_text' => array( | |
| 205 | - 'type' => 'string', | |
| 206 | - 'description' => __( 'Body text shown above the email log-in form.', 'convertkit' ), | |
| 207 | - ), | |
| 208 | - 'email_button_label' => array( | |
| 209 | - 'type' => 'string', | |
| 210 | - 'description' => __( 'Label for the email log-in button.', 'convertkit' ), | |
| 211 | - ), | |
| 212 | - 'email_heading' => array( | |
| 213 | - 'type' => 'string', | |
| 214 | - 'description' => __( 'Heading shown above the email log-in form.', 'convertkit' ), | |
| 215 | - ), | |
| 216 | - 'email_description_text' => array( | |
| 217 | - 'type' => 'string', | |
| 218 | - 'description' => __( 'Description shown beneath the email log-in heading.', 'convertkit' ), | |
| 219 | - ), | |
| 220 | - 'email_check_heading' => array( | |
| 221 | - 'type' => 'string', | |
| 222 | - 'description' => __( 'Heading shown after the visitor requests a magic log-in code.', 'convertkit' ), | |
| 223 | - ), | |
| 224 | - 'email_check_text' => array( | |
| 225 | - 'type' => 'string', | |
| 226 | - 'description' => __( 'Body text shown after the visitor requests a magic log-in code.', 'convertkit' ), | |
| 227 | - ), | |
| 228 | - 'container_css_classes' => array( | |
| 229 | - 'type' => 'string', | |
| 230 | - 'description' => __( 'Additional CSS classes appended to the Restrict Content container element.', 'convertkit' ), | |
| 231 | - ), | |
| 232 | - ), | |
| 233 | - ); | |
| 182 | + // If the setting doesn't exist, bail. | |
| 183 | + if ( ! array_key_exists( $key, $this->settings ) ) { | |
| 184 | + return ''; | |
| 185 | + } | |
| 234 | 186 | |
| 187 | + // If the setting is empty, fallback to the default. | |
| 188 | + if ( empty( $this->settings[ $key ] ) ) { | |
| 189 | + $defaults = $this->get_defaults(); | |
| 190 | + return $defaults[ $key ]; | |
| 191 | + } | |
| 192 | + | |
| 193 | + return $this->settings[ $key ]; | |
| 194 | + | |
| 235 | 195 | } |
| 236 | 196 | |
| 237 | 197 | /** |
| 238 | 198 | * The default settings, used when the ConvertKit Restrict Content Settings haven't been saved |
| @@ -245,32 +205,35 @@ | ||
| 245 | 205 | public function get_defaults() { |
| 246 | 206 | |
| 247 | 207 | $defaults = array( |
| 248 | 208 | // Permit Crawlers. |
| 249 | - 'permit_crawlers' => '', | |
| 209 | + 'permit_crawlers' => '', | |
| 250 | 210 | |
| 251 | 211 | // Restrict by Form. |
| 252 | - 'no_access_text_form' => __( 'Your account does not have access to this content. Please use the form above to subscribe.', 'convertkit' ), | |
| 212 | + 'no_access_text_form' => __( 'Your account does not have access to this content. Please use the form above to subscribe.', 'convertkit' ), | |
| 253 | 213 | |
| 254 | 214 | // Restrict by Product. |
| 255 | - 'subscribe_heading' => __( 'Read this post with a premium subscription', 'convertkit' ), | |
| 256 | - 'subscribe_text' => __( 'This post is only available to premium subscribers. Join today to get access to all posts.', 'convertkit' ), | |
| 257 | - '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' ), | |
| 215 | + 'subscribe_heading' => __( 'Read this post with a premium subscription', 'convertkit' ), | |
| 216 | + 'subscribe_text' => __( 'This post is only available to premium subscribers. Join today to get access to all posts.', 'convertkit' ), | |
| 217 | + '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' ), | |
| 258 | 218 | |
| 259 | 219 | // Restrict by Tag. |
| 260 | - 'subscribe_heading_tag' => __( 'Subscribe to keep reading', 'convertkit' ), | |
| 261 | - 'subscribe_text_tag' => __( 'This post is free to read but only available to subscribers. Join today to get access to all posts.', 'convertkit' ), | |
| 262 | - 'no_access_text_tag' => __( 'Your account does not have access to this content. Please use the form above to subscribe.', 'convertkit' ), | |
| 220 | + 'subscribe_heading_tag' => __( 'Subscribe to keep reading', 'convertkit' ), | |
| 221 | + 'subscribe_text_tag' => __( 'This post is free to read but only available to subscribers. Join today to get access to all posts.', 'convertkit' ), | |
| 222 | + 'require_tag_login' => '', // blank|on. | |
| 223 | + 'recaptcha_site_key' => '', | |
| 224 | + 'recaptcha_secret_key' => '', | |
| 225 | + 'recaptcha_minimum_score' => '0.5', | |
| 226 | + 'no_access_text_tag' => __( 'Your account does not have access to this content. Please use the form above to subscribe.', 'convertkit' ), | |
| 263 | 227 | |
| 264 | 228 | // All. |
| 265 | - 'subscribe_button_label' => __( 'Subscribe', 'convertkit' ), | |
| 266 | - 'email_text' => __( 'Already subscribed?', 'convertkit' ), | |
| 267 | - 'email_button_label' => __( 'Log in', 'convertkit' ), | |
| 268 | - 'email_heading' => __( 'Log in to read this post', 'convertkit' ), | |
| 269 | - 'email_description_text' => __( 'We\'ll email you a magic code to log you in without a password.', 'convertkit' ), | |
| 270 | - 'email_check_heading' => __( 'We just emailed you a log in code', 'convertkit' ), | |
| 271 | - 'email_check_text' => __( 'Enter the code below to finish logging in', 'convertkit' ), | |
| 272 | - 'container_css_classes' => '', | |
| 229 | + 'subscribe_button_label' => __( 'Subscribe', 'convertkit' ), | |
| 230 | + 'email_text' => __( 'Already subscribed?', 'convertkit' ), | |
| 231 | + 'email_button_label' => __( 'Log in', 'convertkit' ), | |
| 232 | + 'email_heading' => __( 'Log in to read this post', 'convertkit' ), | |
| 233 | + 'email_description_text' => __( 'We\'ll email you a magic code to log you in without a password.', 'convertkit' ), | |
| 234 | + 'email_check_heading' => __( 'We just emailed you a log in code', 'convertkit' ), | |
| 235 | + 'email_check_text' => __( 'Enter the code below to finish logging in', 'convertkit' ), | |
| 273 | 236 | ); |
| 274 | 237 | |
| 275 | 238 | /** |
| 276 | 239 | * The default settings, used when the ConvertKit Restrict Content Settings haven't been saved |
| @@ -295,29 +258,8 @@ | ||
| 295 | 258 | */ |
| 296 | 259 | public function save( $settings ) { |
| 297 | 260 | |
| 298 | 261 | update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) ); |
| 299 | - | |
| 300 | - // Reload settings in class, to reflect changes. | |
| 301 | - $this->refresh_settings(); | |
| 302 | - | |
| 303 | - } | |
| 304 | - | |
| 305 | - /** | |
| 306 | - * Reloads settings from the options table so this instance has the latest values. | |
| 307 | - * | |
| 308 | - * @since 3.3.5 | |
| 309 | - */ | |
| 310 | - private function refresh_settings() { | |
| 311 | - | |
| 312 | - $settings = get_option( self::SETTINGS_NAME ); | |
| 313 | - | |
| 314 | - if ( ! $settings ) { | |
| 315 | - $this->settings = $this->get_defaults(); | |
| 316 | - return; | |
| 317 | - } | |
| 318 | - | |
| 319 | - $this->settings = array_merge( $this->get_defaults(), $settings ); | |
| 320 | 262 | |
| 321 | 263 | } |
| 322 | 264 | |
| 323 | 265 | } |