class-email-encoder-bundle-ajax.php
6 years ago
class-email-encoder-bundle-helpers.php
6 years ago
class-email-encoder-bundle-run-admin.php
6 years ago
class-email-encoder-bundle-run.php
6 years ago
class-email-encoder-bundle-settings.php
6 years ago
class-email-encoder-bundle-validate.php
6 years ago
index.php
6 years ago
class-email-encoder-bundle-settings.php
807 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class Email_Encoder_Settings |
| 5 | * |
| 6 | * This class contains all of our important settings |
| 7 | * Here you can configure the whole plugin behavior. |
| 8 | * |
| 9 | * @since 2.0.0 |
| 10 | * @package EEB |
| 11 | * @author Ironikus <info@ironikus.com> |
| 12 | */ |
| 13 | class Email_Encoder_Settings{ |
| 14 | |
| 15 | /** |
| 16 | * Our globally used capability |
| 17 | * |
| 18 | * @var string |
| 19 | * @since 2.0.0 |
| 20 | */ |
| 21 | private $admin_cap; |
| 22 | |
| 23 | /** |
| 24 | * The main page name |
| 25 | * |
| 26 | * @var string |
| 27 | * @since 2.0.0 |
| 28 | */ |
| 29 | private $page_name; |
| 30 | |
| 31 | /** |
| 32 | * Email_Encoder_Settings constructor. |
| 33 | * |
| 34 | * We define all of our necessary settings in here. |
| 35 | * If you need to do plugin related changes, everything will |
| 36 | * be available in this file. |
| 37 | */ |
| 38 | function __construct(){ |
| 39 | $this->admin_cap = 'manage_options'; |
| 40 | $this->page_name = 'email-encoder-bundle-option-page'; |
| 41 | $this->page_title = EEB_NAME; |
| 42 | $this->final_outout_buffer_hook = 'final_output'; |
| 43 | $this->widget_callback_hook = 'widget_output'; |
| 44 | $this->template_tags = array( 'eeb_filter' => 'template_tag_eeb_filter', 'eeb_mailto' => 'template_tag_eeb_mailto' ); |
| 45 | $this->settings_key = 'WP_Email_Encoder_Bundle_options'; |
| 46 | $this->version_key = 'email-encoder-bundle-version'; |
| 47 | $this->image_secret_key = 'email-encoder-bundle-img-key'; |
| 48 | $this->at_identifier = '##eebAddIdent##'; |
| 49 | $this->previous_version = null; |
| 50 | $this->hook_priorities = array( |
| 51 | 'buffer_final_output' => 1000, |
| 52 | 'setup_single_filter_hooks' => 100, |
| 53 | 'add_custom_template_tags' => 10, |
| 54 | 'load_frontend_header_styling' => 10, |
| 55 | 'eeb_dynamic_sidebar_params' => 100, |
| 56 | 'filter_rss' => 100, |
| 57 | 'filter_page' => 100, |
| 58 | 'filter_content' => 100, |
| 59 | 'first_version_init' => 100, |
| 60 | 'version_update' => 100, |
| 61 | 'display_email_image' => 10, |
| 62 | 'callback_rss_remove_shortcodes' => 10, |
| 63 | 'load_ajax_scripts_styles' => 10, |
| 64 | 'load_ajax_scripts_styles_admin' => 10, |
| 65 | ); |
| 66 | |
| 67 | //Regex |
| 68 | $this->email_regex = '([_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,}))'; |
| 69 | $this->soft_attribute_regex = array( |
| 70 | 'woocommerce_variation_attribute_tag' => '/data-product_variations="([^"]*)"/i', |
| 71 | 'jetpack_carousel_image_attribute_tag' => '/data-image-meta="([^"]*)"/i', |
| 72 | 'html_placeholder_tag' => '/placeholder="([^"]*)"/i', |
| 73 | ); |
| 74 | |
| 75 | //Load data |
| 76 | $this->settings = $this->load_settings(); |
| 77 | $this->version = $this->load_version(); |
| 78 | $this->email_image_secret = $this->load_email_image_secret(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * ###################### |
| 83 | * ### |
| 84 | * #### MAIN SETTINGS |
| 85 | * ### |
| 86 | * ###################### |
| 87 | */ |
| 88 | |
| 89 | /** |
| 90 | * Load the settings for our admin settings page |
| 91 | * |
| 92 | * @return array - An array with all available settings and filled values |
| 93 | */ |
| 94 | private function load_settings(){ |
| 95 | $fields = array( |
| 96 | |
| 97 | 'protect' => array( |
| 98 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 99 | 'id' => 'protect', |
| 100 | 'type' => 'multi-input', |
| 101 | 'input-type' => 'radio', |
| 102 | 'title' => __( 'Protect emails', 'email-encoder-bundle' ), |
| 103 | 'inputs' => array( |
| 104 | 1 => array( |
| 105 | 'label' => __( 'Full-page scan', 'email-encoder-bundle' ), |
| 106 | 'description' => __('This will check the whole page against any mails and secures them.', 'email-encoder-bundle' ) |
| 107 | ), |
| 108 | 2 => array( |
| 109 | 'label' => __( 'Wordpress filters', 'email-encoder-bundle' ), |
| 110 | 'description' => __('Secure only mails that occur within WordPress filters. (Not recommended)', 'email-encoder-bundle' ), |
| 111 | 'advanced' => true, |
| 112 | ), |
| 113 | 3 => array( |
| 114 | 'label' => __( 'Don\'t do anything.', 'email-encoder-bundle' ), |
| 115 | 'description' => __('This turns off the protection for emails. (Not recommended)', 'email-encoder-bundle') |
| 116 | ), |
| 117 | ), |
| 118 | 'required' => false |
| 119 | ), |
| 120 | |
| 121 | 'protect_using' => array( |
| 122 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 123 | 'id' => 'protect_using', |
| 124 | 'type' => 'multi-input', |
| 125 | 'input-type' => 'radio', |
| 126 | 'title' => __( 'Protect emails using', 'email-encoder-bundle' ), |
| 127 | 'inputs' => array( |
| 128 | 'with_javascript' => array( |
| 129 | 'label' => __( 'automatically the best method (including javascript)', 'email-encoder-bundle' ) |
| 130 | ), |
| 131 | 'without_javascript' => array( |
| 132 | 'label' => __( 'automatically the best method (excluding javascript)', 'email-encoder-bundle' ), |
| 133 | ), |
| 134 | 'strong_method' => array( |
| 135 | 'label' => __( 'a strong method that replaces all emails with a "*protection text*".', 'email-encoder-bundle' ), |
| 136 | 'description' => __('You can configure the protection text within the advanced settings.', 'email-encoder-bundle') |
| 137 | ), |
| 138 | 'char_encode' => array( |
| 139 | 'label' => __( 'simple HTML character encoding.', 'email-encoder-bundle' ), |
| 140 | 'description' => __('Offers good (but not the best) protection, which saves you in most scenarios.', 'email-encoder-bundle') |
| 141 | ), |
| 142 | ), |
| 143 | 'required' => false |
| 144 | ), |
| 145 | |
| 146 | 'filter_body' => array( |
| 147 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 148 | 'id' => 'filter_body', |
| 149 | 'type' => 'multi-input', |
| 150 | 'input-type' => 'checkbox', |
| 151 | 'advanced' => true, |
| 152 | 'title' => __( 'Protect...', 'email-encoder-bundle' ), |
| 153 | 'label' => __( 'Customize what this plugin protects.', 'email-encoder-bundle' ), |
| 154 | 'inputs' => array( |
| 155 | 'filter_rss' => array( |
| 156 | 'advanced' => true, |
| 157 | 'label' => __( 'RSS feed', 'email-encoder-bundle' ), |
| 158 | 'description' => __( 'Activating this option results in protecting the rss feed based on the given protection method.', 'email-encoder-bundle' ) |
| 159 | ), |
| 160 | 'remove_shortcodes_rss' => array( |
| 161 | 'advanced' => true, |
| 162 | 'label' => __( 'Remove all shortcodes from the RSS feeds', 'email-encoder-bundle' ), |
| 163 | 'description' => __( 'Activating this option results in protecting the rss feed based on the given protection method.', 'email-encoder-bundle' ) |
| 164 | ), |
| 165 | 'input_strong_protection' => array( |
| 166 | 'advanced' => true, |
| 167 | 'label' => __( 'input form email fields using strong protection.', 'email-encoder-bundle' ), |
| 168 | 'description' => __( 'Warning: this option could conflict with certain form plugins. Test it first. (Requires javascript)', 'email-encoder-bundle' ) |
| 169 | ), |
| 170 | 'encode_mailtos' => array( |
| 171 | 'advanced' => true, |
| 172 | 'label' => __( 'plain emails by converting them to mailto links', 'email-encoder-bundle' ), |
| 173 | 'description' => __( 'Plain emails will be automatically converted to mailto links where possible.', 'email-encoder-bundle' ) |
| 174 | ), |
| 175 | 'convert_plain_to_image' => array( |
| 176 | 'advanced' => true, |
| 177 | 'label' => __( 'plain emails by converting them to png images', 'email-encoder-bundle' ), |
| 178 | 'description' => __( 'Plain emails will be automatically converted to png images where possible.', 'email-encoder-bundle' ) |
| 179 | ), |
| 180 | 'protect_shortcode_tags' => array( |
| 181 | 'advanced' => true, |
| 182 | 'label' => __( 'shortcode content', 'email-encoder-bundle' ), |
| 183 | 'description' => __( 'Protect every shortcode content separately. (This may slows down your site)', 'email-encoder-bundle' ) |
| 184 | ), |
| 185 | 'filter_hook' => array( |
| 186 | 'advanced' => true, |
| 187 | 'label' => __( 'emails from "init" hook', 'email-encoder-bundle' ), |
| 188 | 'description' => __( 'Check this option if you want to register the email filters on the "init" hook instead of the "wp" hook.', 'email-encoder-bundle' ) |
| 189 | ), |
| 190 | 'deactivate_rtl' => array( |
| 191 | 'advanced' => true, |
| 192 | 'label' => __( 'mailto links without CSS direction', 'email-encoder-bundle' ), |
| 193 | 'description' => __( 'Check this option if your site does not support CSS directions.', 'email-encoder-bundle' ) |
| 194 | ), |
| 195 | 'no_script_tags' => array( |
| 196 | 'advanced' => true, |
| 197 | 'label' => __( 'no script tags', 'email-encoder-bundle' ), |
| 198 | 'description' => __( 'Check this option if you face issues with encoded script tags. This will deactivate protection for script tags.', 'email-encoder-bundle' ) |
| 199 | ), |
| 200 | 'no_attribute_validation' => array( |
| 201 | 'advanced' => true, |
| 202 | 'label' => __( 'html attributes without soft encoding.', 'email-encoder-bundle' ), |
| 203 | 'description' => __( 'Do not soft-filter all html attributes. This might optimizes the performance, but can break the site if other plugins use your email in attribute tags.', 'email-encoder-bundle' ) |
| 204 | ), |
| 205 | ), |
| 206 | 'required' => false, |
| 207 | ), |
| 208 | |
| 209 | 'image_settings' => array( |
| 210 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 211 | 'id' => 'image_settings', |
| 212 | 'type' => 'multi-input', |
| 213 | 'input-type' => 'text', |
| 214 | 'advanced' => true, |
| 215 | 'title' => __( 'Image settings', 'email-encoder-bundle' ), |
| 216 | 'label' => __( 'Customize the settings for dynamically created images.', 'email-encoder-bundle' ), |
| 217 | 'inputs' => array( |
| 218 | 'image_color' => array( |
| 219 | 'advanced' => true, |
| 220 | 'label' => __( 'Image Colors', 'email-encoder-bundle' ), |
| 221 | 'description' => __( 'Please include RGB colors, comme saparated. E.g.: 0,0,255', 'email-encoder-bundle' ) |
| 222 | ), |
| 223 | 'image_background_color' => array( |
| 224 | 'advanced' => true, |
| 225 | 'label' => __( 'Image Background Colors', 'email-encoder-bundle' ), |
| 226 | 'description' => __( 'Please include RGB colors, comme saparated. E.g.: 0,0,255', 'email-encoder-bundle' ) |
| 227 | ), |
| 228 | 'image_text_opacity' => array( |
| 229 | 'advanced' => true, |
| 230 | 'label' => __( 'Text Opacity', 'email-encoder-bundle' ), |
| 231 | 'description' => __( 'Change the text opacity for the created images. 0 = not transparent - 127 = completely transprent', 'email-encoder-bundle' ) |
| 232 | ), |
| 233 | 'image_background_opacity' => array( |
| 234 | 'advanced' => true, |
| 235 | 'label' => __( 'Background Opacity', 'email-encoder-bundle' ), |
| 236 | 'description' => __( 'Change the background opacity for the created images. 0 = not transparent - 127 = completely transprent', 'email-encoder-bundle' ) |
| 237 | ), |
| 238 | 'image_font_size' => array( |
| 239 | 'advanced' => true, |
| 240 | 'label' => __( 'Font Size', 'email-encoder-bundle' ), |
| 241 | 'description' => __( 'Change the font size of the image text. Default: 4 - You can choose from 1 - 5', 'email-encoder-bundle' ) |
| 242 | ), |
| 243 | ), |
| 244 | 'required' => false, |
| 245 | ), |
| 246 | |
| 247 | 'skip_posts' => array( |
| 248 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 249 | 'id' => 'skip_posts', |
| 250 | 'type' => 'text', |
| 251 | 'advanced' => true, |
| 252 | 'title' => __('Exclude post id\'s from protection', 'email-encoder-bundle'), |
| 253 | 'placeholder' => '', |
| 254 | 'required' => false, |
| 255 | 'description' => __('By comma separating post id\'s ( e.g. 123,4535,643), you are able to exclude these posts from the logic protection.', 'email-encoder-bundle') |
| 256 | ), |
| 257 | |
| 258 | 'protection_text' => array( |
| 259 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 260 | 'id' => 'protection_text', |
| 261 | 'type' => 'text', |
| 262 | 'advanced' => true, |
| 263 | 'title' => __('Set protection text *', 'email-encoder-bundle'), |
| 264 | 'placeholder' => '', |
| 265 | 'required' => false, |
| 266 | 'description' => __('This text will be shown for protected email addresses and within noscript tags.', 'email-encoder-bundle') |
| 267 | ), |
| 268 | |
| 269 | 'class_name' => array( |
| 270 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 271 | 'id' => 'class_name', |
| 272 | 'type' => 'text', |
| 273 | 'advanced' => true, |
| 274 | 'title' => __('Additional classes', 'email-encoder-bundle'), |
| 275 | 'label' => __('Add extra classes to mailto links.', 'email-encoder-bundle'), |
| 276 | 'placeholder' => '', |
| 277 | 'required' => false, |
| 278 | 'description' => __('Leave blank for none', 'email-encoder-bundle') |
| 279 | ), |
| 280 | |
| 281 | 'footer_scripts' => array( |
| 282 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 283 | 'id' => 'footer_scripts', |
| 284 | 'type' => 'checkbox', |
| 285 | 'advanced' => true, |
| 286 | 'title' => __('Load scripts in footer', 'email-encoder-bundle'), |
| 287 | 'label' => __('Check this button if you want to load all frontend scripts within the footer.', 'email-encoder-bundle'), |
| 288 | 'placeholder' => '', |
| 289 | 'required' => false, |
| 290 | 'description' => __('This forces every script to be enqueued within the footer.', 'email-encoder-bundle') |
| 291 | ), |
| 292 | |
| 293 | 'disable_marketing' => array( |
| 294 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 295 | 'id' => 'disable_marketing', |
| 296 | 'type' => 'checkbox', |
| 297 | 'advanced' => true, |
| 298 | 'title' => __('Disable Marketing', 'email-encoder-bundle'), |
| 299 | 'label' => __('Disable all marketing notifications', 'email-encoder-bundle'), |
| 300 | 'placeholder' => '', |
| 301 | 'required' => false, |
| 302 | 'description' => __('If you are not satisfied with our marketing recommendations, check this box.', 'email-encoder-bundle') |
| 303 | ), |
| 304 | |
| 305 | 'show_encoded_check' => array( |
| 306 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 307 | 'id' => 'show_encoded_check', |
| 308 | 'type' => 'checkbox', |
| 309 | 'title' => __('Security Check', 'email-encoder-bundle'), |
| 310 | 'label' => __('Mark emails on the site as successfully encoded', 'email-encoder-bundle') . '<i class="dashicons-before dashicons-lock" style="color:green;"></i>', |
| 311 | 'placeholder' => '', |
| 312 | 'required' => false, |
| 313 | 'description' => __('Only visible for admin users. If your emails look broken, simply deactivate this feature.', 'email-encoder-bundle') |
| 314 | ), |
| 315 | |
| 316 | 'own_admin_menu' => array( |
| 317 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 318 | 'id' => 'own_admin_menu', |
| 319 | 'type' => 'checkbox', |
| 320 | 'advanced' => true, |
| 321 | 'title' => __('Admin Menu', 'email-encoder-bundle'), |
| 322 | 'label' => __('Show this page in the main menu item', 'email-encoder-bundle'), |
| 323 | 'placeholder' => '', |
| 324 | 'required' => false, |
| 325 | 'description' => __('Otherwise it will be shown in "Settings"-menu.', 'email-encoder-bundle') |
| 326 | ), |
| 327 | |
| 328 | 'encoder_form' => array( |
| 329 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 330 | 'id' => 'encoder_form', |
| 331 | 'type' => 'multi-input', |
| 332 | 'input-type' => 'checkbox', |
| 333 | 'advanced' => true, |
| 334 | 'title' => __( 'Encoder form settings', 'email-encoder-bundle' ), |
| 335 | 'inputs' => array( |
| 336 | 'display_encoder_form' => array( |
| 337 | 'label' => __( 'Activate the encoder form.', 'email-encoder-bundle' ), |
| 338 | 'description' => __( 'This allows you to use the email encoder form, as well as the shortcode and template tag.', 'email-encoder-bundle' ) |
| 339 | ), |
| 340 | 'powered_by' => array( |
| 341 | 'label' => __( 'Show a "powered by" link on bottom of the encoder form', 'email-encoder-bundle' ), |
| 342 | ), |
| 343 | ), |
| 344 | 'required' => false |
| 345 | ), |
| 346 | |
| 347 | 'advanced_settings' => array( |
| 348 | 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ), |
| 349 | 'id' => 'advanced_settings', |
| 350 | 'type' => 'checkbox', |
| 351 | 'title' => __('Advanced Settings', 'email-encoder-bundle'), |
| 352 | 'label' => __('Show advanced settings for more configuration possibilities.', 'email-encoder-bundle'), |
| 353 | 'placeholder' => '', |
| 354 | 'required' => false, |
| 355 | 'description' => __('Activate the advanced settings in case you want to customize the default logic or you want to troubleshoot the plugin.', 'email-encoder-bundle') |
| 356 | ), |
| 357 | |
| 358 | ); |
| 359 | |
| 360 | //End Migrate Old Plugin |
| 361 | |
| 362 | $default_values = array( |
| 363 | 'protect' => 1, |
| 364 | 'filter_rss' => 1, |
| 365 | 'display_encoder_form' => 1, |
| 366 | 'powered_by' => 1, |
| 367 | 'protect_using' => 'with_javascript', |
| 368 | 'class_name' => 'mail-link', |
| 369 | 'protection_text' => '*protected email*', |
| 370 | 'image_color' => '0,0,0', |
| 371 | 'image_background_color'=> '0,0,0', |
| 372 | 'image_text_opacity' => '0', |
| 373 | 'image_background_opacity' => '127', |
| 374 | 'image_font_size' => '4', |
| 375 | ); |
| 376 | $values = get_option( $this->settings_key ); |
| 377 | |
| 378 | if( empty( $values ) && ! is_array( $values ) ){ |
| 379 | update_option( $this->settings_key, $default_values ); |
| 380 | $values = $default_values; |
| 381 | } |
| 382 | |
| 383 | //Bakwards compatibility |
| 384 | if( ! isset( $values['protect_using'] ) ){ |
| 385 | $values['protect_using'] = 'with_javascript'; |
| 386 | $values['display_encoder_form'] = 1; |
| 387 | } |
| 388 | |
| 389 | //In case the mailto functiinality was deactivated, we will set it do "Do nothing" as well. |
| 390 | if( ! isset( $values['protect'] ) ){ |
| 391 | $values['protect'] = 1; |
| 392 | } |
| 393 | ///Backwards compatibility |
| 394 | |
| 395 | //Value corrections |
| 396 | if( ! isset( $values['image_color'] ) ){ |
| 397 | $values['image_color'] = $default_values['image_color']; |
| 398 | } |
| 399 | $image_color = explode( ',', $values['image_color'] ); |
| 400 | if( count( $image_color ) != 3 ){ |
| 401 | $values['image_color'] = $default_values['image_color']; |
| 402 | } |
| 403 | foreach( explode( ',', $values['image_color'] ) as $image_color_key => $image_color_single ){ |
| 404 | if( ! is_numeric( trim( $image_color_single ) ) ){ |
| 405 | $values['image_color'] = $default_values['image_color']; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | if( ! isset( $values['image_background_color'] ) ){ |
| 410 | $values['image_background_color'] = $default_values['image_background_color']; |
| 411 | } |
| 412 | $image_background_color = explode( ',', $values['image_background_color'] ); |
| 413 | if( count( $image_background_color ) != 3 ){ |
| 414 | $values['image_background_color'] = $default_values['image_background_color']; |
| 415 | } |
| 416 | foreach( explode( ',', $values['image_background_color'] ) as $image_background_color_key => $image_background_color_single ){ |
| 417 | if( ! is_numeric( trim( $image_background_color_single ) ) ){ |
| 418 | $values['image_background_color'] = $default_values['image_background_color']; |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if( ! isset( $values['image_text_opacity'] ) || ! is_numeric( $values['image_text_opacity'] ) ){ |
| 423 | $values['image_text_opacity'] = $default_values['image_text_opacity']; |
| 424 | } |
| 425 | if( ! isset( $values['image_background_opacity'] ) || ! is_numeric( $values['image_background_opacity'] ) ){ |
| 426 | $values['image_background_opacity'] = $default_values['image_background_opacity']; |
| 427 | } |
| 428 | if( ! isset( $values['image_font_size'] ) || ! is_numeric( $values['image_font_size'] ) ){ |
| 429 | $values['image_font_size'] = $default_values['image_font_size']; |
| 430 | } |
| 431 | ///Value corrections |
| 432 | |
| 433 | foreach( $fields as $key => $field ){ |
| 434 | if( $field['type'] === 'multi-input' ){ |
| 435 | foreach( $field['inputs'] as $smi_key => $smi_data ){ |
| 436 | |
| 437 | if( $field['input-type'] === 'radio' ){ |
| 438 | if( isset( $values[ $key ] ) && (string) $values[ $key ] === (string) $smi_key ){ |
| 439 | $fields[ $key ]['value'] = $values[ $key ]; |
| 440 | } |
| 441 | } else { |
| 442 | if( isset( $values[ $smi_key ] ) ){ |
| 443 | $fields[ $key ]['inputs'][ $smi_key ]['value'] = $values[ $smi_key ]; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | } |
| 448 | } else { |
| 449 | if( isset( $values[ $key ] ) ){ |
| 450 | $fields[ $key ]['value'] = $values[ $key ]; |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | return apply_filters( 'eeb/settings/fields', $fields ); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * ###################### |
| 460 | * ### |
| 461 | * #### VERSIONING |
| 462 | * ### |
| 463 | * ###################### |
| 464 | */ |
| 465 | |
| 466 | public function load_version(){ |
| 467 | |
| 468 | $current_version = get_option( $this->get_version_key() ); |
| 469 | |
| 470 | if( empty( $current_version ) ){ |
| 471 | $current_version = EEB_VERSION; |
| 472 | update_option( $this->get_version_key(), $current_version ); |
| 473 | |
| 474 | add_action( 'init', array( $this, 'first_version_init' ), $this->get_hook_priorities( 'first_version_init' ) ); |
| 475 | } else { |
| 476 | if( $current_version !== EEB_VERSION ){ |
| 477 | $this->previous_version = $current_version; |
| 478 | $current_version = EEB_VERSION; |
| 479 | update_option( $this->get_version_key(), $current_version ); |
| 480 | |
| 481 | add_action( 'init', array( $this, 'version_update' ), $this->get_hook_priorities( 'version_update' ) ); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | return $current_version; |
| 486 | } |
| 487 | |
| 488 | public function load_email_image_secret(){ |
| 489 | |
| 490 | if( ! (bool) $this->get_setting( 'convert_plain_to_image', true, 'filter_body' ) ){ |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | $image_descret = get_option( $this->get_image_secret_key() ); |
| 495 | |
| 496 | if( ! empty( $image_descret ) ){ |
| 497 | return $image_descret; |
| 498 | } |
| 499 | |
| 500 | $key = ''; |
| 501 | |
| 502 | for ($i = 0; $i < 265; $i++) { |
| 503 | $key .= chr(mt_rand(33, 126)); |
| 504 | } |
| 505 | |
| 506 | update_option( $this->get_image_secret_key(), $key ); |
| 507 | |
| 508 | return $key; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Fires an action after our settings key was initially set |
| 513 | * the very first time. |
| 514 | * |
| 515 | * @return void |
| 516 | */ |
| 517 | public function first_version_init(){ |
| 518 | do_action( 'eeb/settings/first_version_init', EEB_VERSION ); |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Fires after the version of the plugin is initially updated |
| 523 | * |
| 524 | * @return void |
| 525 | */ |
| 526 | public function version_update(){ |
| 527 | do_action( 'eeb/settings/version_update', EEB_VERSION, $this->previous_version ); |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * ###################### |
| 532 | * ### |
| 533 | * #### CALLABLE FUNCTIONS |
| 534 | * ### |
| 535 | * ###################### |
| 536 | */ |
| 537 | |
| 538 | /** |
| 539 | * Our admin cap handler function |
| 540 | * |
| 541 | * This function handles the admin capability throughout |
| 542 | * the whole plugin. |
| 543 | * |
| 544 | * $target - With the target function you can make a more precised filtering |
| 545 | * by changing it for specific actions. |
| 546 | * |
| 547 | * @param string $target - A identifier where the call comes from |
| 548 | * @return mixed |
| 549 | */ |
| 550 | public function get_admin_cap( $target = 'main' ){ |
| 551 | /** |
| 552 | * Customize the globally used capability for this plugin |
| 553 | * |
| 554 | * This filter is called every time the capability is needed. |
| 555 | */ |
| 556 | return apply_filters( 'eeb/settings/capability', $this->admin_cap, $target ); |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Return the page name for our admin page |
| 561 | * |
| 562 | * @return string - the page name |
| 563 | */ |
| 564 | public function get_page_name(){ |
| 565 | /* |
| 566 | * Filter the page name based on your needs |
| 567 | */ |
| 568 | return apply_filters( 'eeb/settings/page_name', $this->page_name ); |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Return the page title for our admin page |
| 573 | * |
| 574 | * @return string - the page title |
| 575 | */ |
| 576 | public function get_page_title(){ |
| 577 | /* |
| 578 | * Filter the page title based on your needs. |
| 579 | */ |
| 580 | return apply_filters( 'eeb/settings/page_title', $this->page_title ); |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * Return the settings_key |
| 585 | * |
| 586 | * @return string - the settings key |
| 587 | */ |
| 588 | public function get_settings_key(){ |
| 589 | return $this->settings_key; |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Return the version_key |
| 594 | * |
| 595 | * @return string - the version_key |
| 596 | */ |
| 597 | public function get_version_key(){ |
| 598 | return $this->version_key; |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Return the image_secret_key |
| 603 | * |
| 604 | * @return string - the image_secret_key |
| 605 | */ |
| 606 | public function get_image_secret_key(){ |
| 607 | return $this->image_secret_key; |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Return the email_image_secret |
| 612 | * |
| 613 | * @return string - the email_image_secret |
| 614 | */ |
| 615 | public function get_email_image_secret(){ |
| 616 | return $this->email_image_secret; |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Return the version |
| 621 | * |
| 622 | * @return string - the version |
| 623 | */ |
| 624 | public function get_version(){ |
| 625 | return apply_filters( 'eeb/settings/get_version', $this->version ); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * Return the default template tags |
| 630 | * |
| 631 | * @return array - the template tags |
| 632 | */ |
| 633 | public function get_template_tags(){ |
| 634 | return apply_filters( 'eeb/settings/get_template_tags', $this->template_tags ); |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Return the widget callback hook name |
| 639 | * |
| 640 | * @return string - the final widget callback hook name |
| 641 | */ |
| 642 | public function get_widget_callback_hook(){ |
| 643 | return apply_filters( 'eeb/settings/widget_callback_hook', $this->widget_callback_hook ); |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * Return the final output buffer hook name |
| 648 | * |
| 649 | * @return string - the final output buffer hook name |
| 650 | */ |
| 651 | public function get_final_outout_buffer_hook(){ |
| 652 | return apply_filters( 'eeb/settings/final_outout_buffer_hook', $this->final_outout_buffer_hook ); |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Return the @ symbol identifier |
| 657 | * |
| 658 | * @return string - the @ symbol identifier |
| 659 | */ |
| 660 | public function get_at_identifier(){ |
| 661 | return apply_filters( 'eeb/settings/at_identifier', $this->at_identifier ); |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * @link http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/ |
| 666 | * @param boolean $include |
| 667 | * @return string |
| 668 | */ |
| 669 | public function get_email_regex( $include = false ){ |
| 670 | |
| 671 | if ($include === true) { |
| 672 | $return = $this->email_regex; |
| 673 | } else { |
| 674 | $return = '/' . $this->email_regex . '/i'; |
| 675 | } |
| 676 | |
| 677 | return apply_filters( 'eeb/settings/get_email_regex', $return, $include ); |
| 678 | } |
| 679 | |
| 680 | /** |
| 681 | * Get Woocommerce variation attribute regex |
| 682 | * |
| 683 | * @param boolean $include |
| 684 | * @return string |
| 685 | */ |
| 686 | public function get_soft_attribute_regex( $single = null ){ |
| 687 | |
| 688 | $return = $this->soft_attribute_regex; |
| 689 | |
| 690 | if( $single !== null ){ |
| 691 | if( isset( $this->soft_attribute_regex[ $single ] ) ){ |
| 692 | $return = $this->soft_attribute_regex[ $single ]; |
| 693 | } else { |
| 694 | $return = false; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | return apply_filters( 'eeb/settings/get_soft_attribute_regex', $return, $single ); |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Get hook priorities |
| 703 | * |
| 704 | * @param boolean $single - wether you want to return only a single hook priority or not |
| 705 | * @return mixed - An array or string of hook priority(-ies) |
| 706 | */ |
| 707 | public function get_hook_priorities( $single = false ){ |
| 708 | |
| 709 | $return = $this->hook_priorities; |
| 710 | $default = false; |
| 711 | |
| 712 | if( $single ){ |
| 713 | if( isset( $this->hook_priorities[ $single ] ) ){ |
| 714 | $return = $this->hook_priorities[ $single ]; |
| 715 | } else { |
| 716 | $return = 10; |
| 717 | $default = true; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | return apply_filters( 'eeb/settings/get_hook_priorities', $return, $default, $single ); |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * ###################### |
| 726 | * ### |
| 727 | * #### Settings helper |
| 728 | * ### |
| 729 | * ###################### |
| 730 | */ |
| 731 | |
| 732 | /** |
| 733 | * Get the admin page url |
| 734 | * |
| 735 | * @return string - The admin page url |
| 736 | */ |
| 737 | public function get_admin_page_url(){ |
| 738 | |
| 739 | $url = admin_url( "options-general.php?page=" . $this->get_page_name() ); |
| 740 | |
| 741 | return apply_filters( 'eeb/settings/get_admin_page_url', $url ); |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * Helper function to reload the settings |
| 746 | * |
| 747 | * @return array - An array of all available settings |
| 748 | */ |
| 749 | public function reload_settings(){ |
| 750 | |
| 751 | $this->settings = $this->load_settings(); |
| 752 | |
| 753 | return $this->settings; |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Return the default strings that are available |
| 758 | * for this plugin. |
| 759 | * |
| 760 | * @param $slug - the identifier for your specified setting |
| 761 | * @param $single - wether you only want to return the value or the whole settings element |
| 762 | * @param $group - in case you call a multi-input that contains multiple values (e.g. checkbox), you can set a sub-slug to grab the sub value |
| 763 | * @return string - the default string |
| 764 | */ |
| 765 | public function get_setting( $slug = '', $single = false, $group = '' ){ |
| 766 | $return = $this->settings; |
| 767 | |
| 768 | if( empty( $slug ) ){ |
| 769 | return $return; |
| 770 | } |
| 771 | |
| 772 | if( isset( $this->settings[ $slug ] ) || ( ! empty( $group ) && isset( $this->settings[ $group ] ) ) ){ |
| 773 | if( $single ){ |
| 774 | $return = false; // Default false |
| 775 | |
| 776 | //Set default to the main valie if available given with radio buttons) |
| 777 | if( isset( $this->settings[ $slug ]['value'] ) ){ |
| 778 | $return = $this->settings[ $slug ]['value']; |
| 779 | } |
| 780 | |
| 781 | if( |
| 782 | ! empty( $group ) |
| 783 | && isset( $this->settings[ $group ]['type'] ) |
| 784 | && $this->settings[ $group ]['type'] === 'multi-input' |
| 785 | ) |
| 786 | { |
| 787 | if( isset( $this->settings[ $group ]['inputs'][ $slug ] ) && isset( $this->settings[ $group ]['inputs'][ $slug ]['value'] ) ){ |
| 788 | $return = $this->settings[ $group ]['inputs'][ $slug ]['value']; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | } else { |
| 793 | |
| 794 | if( ! empty( $group ) && isset( $this->settings[ $group ] ) ){ |
| 795 | $return = $this->settings[ $group ]; |
| 796 | } else { |
| 797 | $return = $this->settings[ $slug ]; |
| 798 | } |
| 799 | |
| 800 | } |
| 801 | |
| 802 | } |
| 803 | |
| 804 | return $return; |
| 805 | } |
| 806 | |
| 807 | } |