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 '
' . __( 'Dismiss this notice', 'another-mailchimp-widget' ) . '
MailChimp API key here to get started. You will need to have at least one MailChimp list set up.', 'another-mailchimp-widget' ) ?>
[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." ]
list' ) ?>★★★★★ rating.', 'another-mailchimp-widget' ), 'https://wordpress.org/plugins/another-mailchimp-widget/'); ?>
' . $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; } }