get_options(); } /** * Load text domain */ public function load_text_domain() { load_plugin_textdomain( self::$textdomain, null, str_replace( 'lib', 'languages', dirname( plugin_basename( __FILE__ ) ) ) ); } /** * Get option * * @return mixed */ public function get_options() { $this->options = get_option( self::$prefix . '_options' ); return $this->options; } /** * @return AN_MC_Plugin */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } /** * Init action */ public function init_action() { // Set up the settings. add_action( 'admin_init', array( &$this, 'register_settings' ) ); // Set up the administration page. add_action( 'admin_menu', array( &$this, 'set_up_admin_page' ) ); add_action( 'widgets_init', array( $this, 'widgets_init' ) ); add_action( 'admin_notices', array( $this, 'admin_notice' ), 10, 1 ); } public function widgets_init() { register_widget("AN_Widget_MailChimp"); } /** * Admin notice * */ public function admin_notice() { $screen = get_current_screen(); /* * notice-error – error message displayed with a red border * notice-warning – warning message displayed with a yellow border * notice-success – success message displayed with a green border * notice-info – info message displayed with a blue border */ if ( ! is_wp_error( $screen ) && ! empty( $screen ) && ( $screen->id === 'settings_page_another-mailchimp-widget/lib/an_mc_plugin.class' ) ) { $last_query = get_transient( 'mp-am-last-action-data' ); if ( ! empty( $last_query ) && $last_query[ 'mpam_sync' ] ) { if ( ! empty( $last_query[ 'errorMessage' ] ) ) { $class = 'notice-error'; } else { $class = 'notice-success'; } AN_MC_View::get_instance()->get_template( '/admin/notice', array( 'class' => $class, 'data' => $last_query ) ); delete_transient( 'mp-am-last-action-data' ); } } } /** * Get prefix * * @return string */ public function get_prefix() { return self::$prefix; } /** * Dismiss admin Notice */ public function dismiss_admin_notice() { global $current_user; $userid = $current_user->ID; if ( isset( $_GET[ 'dismiss_another-mailchimp' ] ) && 'yes' == $_GET[ 'dismiss_another-mailchimp' ] ) { add_user_meta( $userid, 'ignore_error_notice', 'yes', true ); } } /** * Admin notice */ public function admin_notices() { global $current_user; $userid = $current_user->ID; if ( ! get_user_meta( $userid, 'ignore_error_notice' ) ) { echo '
' . $this->get_admin_notices() . '

' . __( 'Dismiss this notice', 'another-mailchimp-widget' ) . '

'; } } /** * Get admin notices * * @return string */ public function get_admin_notices() { $notice = AN_MC_View::get_instance()->get_template_html( '/notice/change-settings' ); return $notice; } /** * Add admin page * * @return bool|void */ public function admin_page() { $api_key = ( is_array( $this->options ) ) ? $this->options[ 'api-key' ] : ''; if ( isset( $_POST[ self::$prefix . '_nonce' ] ) ) { $nonce = $_POST[ self::$prefix . '_nonce' ]; $nonce_key = self::$prefix . '_update_options'; if ( ! wp_verify_nonce( $nonce, $nonce_key ) ) { ?>

update_options( $new_options ); $api_key = $this->options[ 'api-key' ]; } } ?>

MailChimp API key here to get started. You will need to have at least one MailChimp list set up.', 'another-mailchimp-widget' ) ?>

errorMessage ) ) { ?> get_account_subscribe_lists(); if ( !empty($lists) ) {?>
get_mcapi(); $mcapi->get_lists(); $HTTP_Code = $mcapi->HTTP_Code; endif; ?>
get_response_message() ?>

    ' . __( 'List', 'another-mailchimp-widget' ) .' ' . $list['title'] . ' - ' . $list['id'] . ''; if ( !empty ($list['categories']) ) { foreach ($list['categories'] as $category) { //echo '  ' . $category['title'] . ' - ' . $category['id'] . '
    '; if ( !empty($category['interests']) ) {?>
    • ' . __( 'Group', 'another-mailchimp-widget' ) .' ' . $interests['title'] . ' - ' . $interests['id'] . ''; } ?>

[mp-mc-form list="list_id/group_id" button="Subscribe" email_text="Your E-mail" first_name_text="First Name" last_name_text="Last Name" placeholder="true" firstname="false" lastname="false" success="Thank you for joining our mailing list." failure="There was a problem processing your submission." ]


★★★★★ rating.', 'another-mailchimp-widget' ), 'https://wordpress.org/plugins/another-mailchimp-widget/'); ?>

get_options(); } /** * Get MailChimp API3 * * @return bool|MailChimp_API */ public function get_mcapi() { $api_key = $this->get_api_key(); if ( false == $api_key ) { return false; } else { if ( empty( self::$mcapi ) ) { self::$mcapi = new MailChimp_API( $api_key ); } return self::$mcapi; } } /** * Get MailChimp api Key * * @return bool|mixed */ private function get_api_key() { if ( is_array( $this->options ) && ! empty( $this->options[ 'api-key' ] ) ) { return $this->options[ 'api-key' ]; } else { return false; } } /** * Check exists api key * @return bool */ public function is_have_api_key() { $api_key = $this->get_api_key(); return (bool) $api_key; } /** * Get admin error notices * * @param $mcapi * * @return string */ public function get_admin_error_notices( $mcapi ) { global $blog_id; $error = $mcapi->HTTP_Code; if ( $error === 104 || $error == 106 ) { $notice = AN_MC_View::get_instance()->get_template_html( '/notice/invalid-api-key' ); } else { $notice = '

' . $mcapi->errorMessage . '

'; } return $notice; } /** * Register setting */ public function register_settings() { register_setting( self::$prefix . '_options', self::$prefix . '_options', array( $this, 'save_settings' ) ); } /** * Remove option */ public function remove_options() { delete_option( self::$prefix . '_options' ); } /** * Add submenu page */ public function set_up_admin_page() { add_submenu_page( 'options-general.php', __( 'Another MailChimp', 'another-mailchimp-widget' ), __( 'Another MailChimp', 'another-mailchimp-widget' ), 'activate_plugins', __FILE__, array( &$this, 'admin_page' ) ); } /** * Set option */ public function set_up_options() { add_option( self::$prefix . '_options', '', '', self::$public_option ); } /** * Add script */ public function add_scripts() { if ( ! is_admin() ) { wp_enqueue_script( 'ns-mc-widget', AN_MC_PLUGIN_URL . 'assets/js/another-mailchimp.min.js', array( 'jquery' ), null ); } } public function add_style() { wp_enqueue_style( 'mp-am-widget', AN_MC_PLUGIN_URL . 'assets/css/style.css', array(), null ); } /** * Save settings * * @param $settings * * @return mixed */ public function save_settings( $settings ) { if ( isset( $settings[ 'mpam_sync' ] ) && $settings[ 'mpam_sync' ] ) { $data = array( 'mpam_sync' => true ); $mcapi = $this->get_mcapi(); if ( is_object( $mcapi ) ) { $request_api_key = isset( $_POST[ 'ns_mc_options' ][ 'api-key' ] ) ? $_POST[ 'ns_mc_options' ][ 'api-key' ] : false; $api_key = $this->get_api_key(); if ( $api_key !== $request_api_key && $request_api_key ) { $mcapi->set_apikey( $request_api_key ); } $lists = $mcapi->get_lists(); $data[ 'HTTP_Code' ] = $mcapi->HTTP_Code; if ( ! empty( $lists ) && empty( $lists[ 'error' ] ) ) { $account_subscribe_lists = $mcapi->get_account_subscribe_lists( true ); } if ( ! empty( $account_subscribe_lists ) ) { update_option( self::$prefix . '_account_subscribe_lists', $account_subscribe_lists ); $data[ 'list_count' ] = count( $account_subscribe_lists ); $data[ 'message' ] = sprintf( _n( '%s list updated.', '%s lists updated.', $data[ 'list_count' ], 'another-mailchimp-widget' ), $data[ 'list_count' ] ); } } $data[ 'errorMessage' ] = $mcapi->errorMessage; set_transient( 'mp-am-last-action-data', $data, 5 * MINUTE_IN_SECONDS ); } return $settings; } }