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
class-plugin.php
132 lines
| 1 | <?php |
| 2 | |
| 3 | class MC4WP_Lite { |
| 4 | private static $instance; |
| 5 | |
| 6 | public static function instance() { |
| 7 | return self::$instance; |
| 8 | } |
| 9 | |
| 10 | public static function init() { |
| 11 | if(self::$instance) { |
| 12 | throw new Exception("ALready initialized."); |
| 13 | } else { |
| 14 | self::$instance = new self; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | private function __construct() { |
| 19 | $this->backwards_compatibility(); |
| 20 | |
| 21 | // checkbox |
| 22 | require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-checkbox.php'; |
| 23 | MC4WP_Lite_Checkbox::init(); |
| 24 | |
| 25 | // form |
| 26 | require_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-form.php'; |
| 27 | MC4WP_Lite_Form::init(); |
| 28 | |
| 29 | // widget |
| 30 | add_action( 'widgets_init', array($this, 'register_widget') ); |
| 31 | |
| 32 | if (!is_admin()) { |
| 33 | // frontend only |
| 34 | include_once MC4WP_LITE_PLUGIN_DIR . 'includes/template-functions.php'; |
| 35 | |
| 36 | // load css |
| 37 | add_action( 'wp_enqueue_scripts', array($this, 'load_stylesheets'), 90); |
| 38 | add_action( 'login_enqueue_scripts', array($this, 'load_stylesheets') ); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | private function backwards_compatibility() { |
| 43 | $options = get_option( 'mc4wp_lite' ); |
| 44 | |
| 45 | // transfer widget to new id? |
| 46 | if(get_option('mc4wp_transfered_old_widgets', false) == false) { |
| 47 | $sidebars_widgets = get_option('sidebars_widgets'); |
| 48 | |
| 49 | if($sidebars_widgets && is_array($sidebars_widgets)) { |
| 50 | foreach($sidebars_widgets as $key => $widgets) |
| 51 | { |
| 52 | if(!is_array($widgets)) { continue; } |
| 53 | foreach($widgets as $subkey => $widget_name) { |
| 54 | |
| 55 | if(substr($widget_name, 0, 17) == 'mc4wp_lite_widget') { |
| 56 | |
| 57 | $new_widget_name = str_replace('mc4wp_lite_widget', 'mc4wp_widget', $widget_name); |
| 58 | // active widget found, just change name? |
| 59 | $sidebars_widgets[$key][$subkey] = $new_widget_name; |
| 60 | update_option('sidebars_widgets', $sidebars_widgets); |
| 61 | update_option('widget_mc4wp_widget', get_option('widget_mc4wp_lite_widget') ); |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | update_option('mc4wp_transfered_old_widgets', true); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | // transfer old options to new options format |
| 75 | if (isset( $options['mailchimp_api_key'] )) { |
| 76 | |
| 77 | $new_options = array( |
| 78 | 'general' => array(), |
| 79 | 'checkbox' => array(), |
| 80 | 'form' => array() |
| 81 | ); |
| 82 | |
| 83 | $new_options['general']['api_key'] = $options['mailchimp_api_key']; |
| 84 | |
| 85 | foreach ( $options as $key => $value ) { |
| 86 | $_pos = strpos( $key, '_' ); |
| 87 | |
| 88 | $first_key = substr( $key, 0, $_pos ); |
| 89 | $second_key = substr( $key, $_pos + 1 ); |
| 90 | |
| 91 | if ( isset( $new_options[$first_key] ) ) { |
| 92 | |
| 93 | // change option name |
| 94 | if ( $second_key == 'show_at_bp_form' ) { |
| 95 | $second_key = 'show_at_buddypress_form'; |
| 96 | } |
| 97 | |
| 98 | // change option name |
| 99 | if ( $second_key == 'show_at_ms_form' ) { |
| 100 | $second_key = 'show_at_multisite_form'; |
| 101 | } |
| 102 | |
| 103 | // set value into new option name |
| 104 | $new_options[$first_key][$second_key] = $value; |
| 105 | } |
| 106 | |
| 107 | } |
| 108 | |
| 109 | update_option( 'mc4wp_lite', $new_options['general'] ); |
| 110 | update_option( 'mc4wp_lite_checkbox', $new_options['checkbox'] ); |
| 111 | update_option( 'mc4wp_lite_form', $new_options['form'] ); |
| 112 | } // end transfer options |
| 113 | } |
| 114 | |
| 115 | public function register_widget() |
| 116 | { |
| 117 | include_once MC4WP_LITE_PLUGIN_DIR . 'includes/class-widget.php'; |
| 118 | register_widget( 'MC4WP_Lite_Widget' ); |
| 119 | } |
| 120 | |
| 121 | public function load_stylesheets() |
| 122 | { |
| 123 | $stylesheets = apply_filters('mc4wp_stylesheets', array()); |
| 124 | |
| 125 | if(!empty($stylesheets)) { |
| 126 | $stylesheet_url = add_query_arg($stylesheets, plugins_url('mailchimp-for-wp/assets/css/css.php')); |
| 127 | wp_enqueue_style( 'mailchimp-for-wp', $stylesheet_url, array(), MC4WP_LITE_VERSION); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | } |
| 132 |