views
12 years ago
class-admin.php
12 years ago
class-api.php
12 years ago
class-checkbox.php
12 years ago
class-form.php
12 years ago
class-plugin.php
12 years ago
class-widget.php
12 years ago
functions.php
12 years ago
index.php
12 years ago
template-functions.php
12 years ago
functions.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | if( ! defined("MC4WP_LITE_VERSION") ) { |
| 4 | header( 'Status: 403 Forbidden' ); |
| 5 | header( 'HTTP/1.1 403 Forbidden' ); |
| 6 | exit; |
| 7 | } |
| 8 | |
| 9 | function mc4wp_get_options($key = null) { |
| 10 | static $options; |
| 11 | |
| 12 | if(!$options) { |
| 13 | $defaults = array( |
| 14 | 'general' => array( |
| 15 | 'api_key' => '' |
| 16 | ), |
| 17 | 'checkbox' => array( |
| 18 | 'label' => 'Sign me up for the newsletter!', |
| 19 | 'precheck' => 1, |
| 20 | 'css' => 1, |
| 21 | 'show_at_comment_form' => 0, |
| 22 | 'show_at_registration_form' => 0, |
| 23 | 'show_at_multisite_form' => 0, |
| 24 | 'show_at_buddypress_form' => 0, |
| 25 | 'show_at_bbpress_forms' => 0, |
| 26 | 'lists' => array(), |
| 27 | 'double_optin' => 1 |
| 28 | ), |
| 29 | 'form' => array( |
| 30 | 'css' => 'default', |
| 31 | 'markup' => "<p>\n\t<label for=\"mc4wp_email\">Email address: </label>\n\t<input type=\"email\" id=\"mc4wp_email\" name=\"EMAIL\" required placeholder=\"Your email address\" />\n</p>\n\n<p>\n\t<input type=\"submit\" value=\"Sign up\" />\n</p>", |
| 32 | 'text_success' => 'Thank you, your sign-up request was successful! Please check your e-mail inbox.', |
| 33 | 'text_error' => 'Oops. Something went wrong. Please try again later.', |
| 34 | 'text_invalid_email' => 'Please provide a valid email address.', |
| 35 | 'text_already_subscribed' => "Given email address is already subscribed, thank you!", |
| 36 | 'redirect' => '', |
| 37 | 'lists' => array(), |
| 38 | 'double_optin' => 1, |
| 39 | 'hide_after_success' => 0 |
| 40 | ) |
| 41 | ); |
| 42 | |
| 43 | $db_keys_option_keys = array( |
| 44 | 'mc4wp_lite' => 'general', |
| 45 | 'mc4wp_lite_checkbox' => 'checkbox', |
| 46 | 'mc4wp_lite_form' => 'form' |
| 47 | ); |
| 48 | |
| 49 | $options = array(); |
| 50 | foreach ( $db_keys_option_keys as $db_key => $option_key ) { |
| 51 | $option = get_option( $db_key ); |
| 52 | |
| 53 | // add option to database to prevent query on every pageload |
| 54 | if ( $option == false ) { add_option( $db_key, $defaults[$option_key] ); } |
| 55 | |
| 56 | $options[$option_key] = array_merge( $defaults[$option_key], (array) $option ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if($key) { |
| 61 | return $options[$key]; |
| 62 | } |
| 63 | |
| 64 | return $options; |
| 65 | } |
| 66 | |
| 67 | function mc4wp_get_api() { |
| 68 | static $api; |
| 69 | |
| 70 | if(!$api) { |
| 71 | require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-api.php'; |
| 72 | $opts = mc4wp_get_options(); |
| 73 | $api = new MC4WP_Lite_API( $opts['general']['api_key'] ); |
| 74 | } |
| 75 | |
| 76 | return $api; |
| 77 | } |