settings(); add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); add_action( 'init', array( &$this, 'init' ), 10 ); add_action( 'wp_enqueue_scripts', array( &$this, 'init_scripts' ), 11 ); add_action( 'admin_enqueue_scripts',array( &$this, 'admin_scripts' ) ); add_filter( 'plugin_action_links', array( &$this, 'settings_link' ), 10, 2); register_uninstall_hook( __FILE__, array( 'AspexiSweetPopups', 'uninstall' ) ); } /* WP init action */ public function init() { /* Internationalization */ load_plugin_textdomain( 'aspexisweetpopups', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } public function admin_menu() { add_submenu_page( 'themes.php', __( 'Aspexi Sweet Popups', 'aspexisweetpopups' ), __( 'Aspexi Sweet Popups', 'aspexisweetpopups' ), 'manage_options', 'aspexi-sweet-popups.php', array( &$this, 'admin_page' ) ); } public function settings() { $config_default = array( 'aspexisweetpopups_version' => ASPEXISWEETPOPUPS_VERSION, 'status' => 'disabled', 'theme' => 'none', 'only_frontpage' => 'off', 'title' => 'Your title', 'content' => 'Your content', 'only_once' => 'off', 'only_once_days' => 30, 'icon_type' => 'empty', ); if ( ! get_option( 'aspexisweetpopups_options' ) ) add_option( 'aspexisweetpopups_options', $config_default, '', 'yes' ); $this->config = get_option( 'aspexisweetpopups_options' ); } public function get_content_with_shortcodes() { $content = nl2br( $this->config['content'] ); $matches = array(); preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches ); if ( ! empty( $matches[2] ) ) foreach ( $matches[2] as $key => $shortcode ) $content = str_replace( $matches[0][$key], do_shortcode( $matches[0][$key] ), $content ); return $content; } public function init_scripts() { $disable_maybe = apply_filters( 'aspexisweetpopups_disablemaybe', false ); if( $this->config['status'] != 'enabled' || ( $this->config['only_frontpage'] == 'on' && ! is_front_page() ) || $disable_maybe ) return; wp_enqueue_style( 'sweet-alert', ASPEXISWEETPOPUPS_URL . 'css/sweetalert.css' ); switch ( $this->config['theme'] ) { case 'facebook': wp_enqueue_style( 'sweet-alert-facebook-theme', ASPEXISWEETPOPUPS_URL . 'css/sweetalert-facebook.css' ); break; case 'google': wp_enqueue_style( 'sweet-alert-google-theme', ASPEXISWEETPOPUPS_URL . 'css/sweetalert-google.css' ); break; case 'twitter': wp_enqueue_style( 'sweet-alert-twitter-theme', ASPEXISWEETPOPUPS_URL . 'css/sweetalert-twitter.css' ); break; } wp_enqueue_script( 'sweet-alert', ASPEXISWEETPOPUPS_URL . 'js/sweetalert.min.js' ); wp_enqueue_script( 'aspexi-sweet-popups', ASPEXISWEETPOPUPS_URL . 'js/asp.js', array( 'sweet-alert', 'jquery') ); wp_localize_script( 'aspexi-sweet-popups', 'asp', array( 'show' => ( isset( $_COOKIE[$this->cookie_name] ) && 'on' == $this->config['only_once'] ) ? false : true, 'title' => $this->config['title'], 'content' => $this->get_content_with_shortcodes(), 'icon_type' => $this->config['icon_type'], 'html' => 'true' ) ); $_expire = 0; if ( $this->config['only_once_days'] != '' ) $_expire = absint( (int)$this->config['only_once_days'] ); if( ! isset( $_COOKIE[$this->cookie_name] ) && 'on' == $this->config['only_once'] ) { if( 0 == $_expire ) $expire = 0; else $expire = time() + ( 60 * 60 * 24 * $_expire ); setcookie( $this->cookie_name, 'false', $expire ); } elseif( isset( $_COOKIE[$this->cookie_name] ) && 'on' != $this->config['only_once'] ) // remove cookie setcookie( $this->cookie_name, '', time() - 360 ); } public function admin_scripts( $hook_suffix ) { if( 'appearance_page_aspexi-sweet-popups' != $hook_suffix ) return; wp_enqueue_style( 'sweet-alert', ASPEXISWEETPOPUPS_URL . 'css/sweetalert.css' ); wp_enqueue_script( 'sweet-alert', ASPEXISWEETPOPUPS_URL . 'js/sweetalert.min.js' ); wp_enqueue_script( 'aspexi-sweet-popups', ASPEXISWEETPOPUPS_URL . 'js/asp-admin.js', array( 'sweet-alert', 'jquery') ); wp_localize_script( 'aspexi-sweet-popups', 'asp', array( 'show' => ( isset( $_COOKIE[$this->cookie_name] ) && 'on' == $this->config['only_once'] ) ? false : true, 'title' => $this->config['title'], 'content' => nl2br( $this->config['content'] ), 'icon_type' => $this->config['icon_type'], 'html' => 'true', 'aspexisweetpopups_url' => ASPEXISWEETPOPUPS_URL ) ); } public function get_pro_url() { return 'http://aspexi.com/downloads/aspexi-sweet-popups/?src=free_plugin'; } public function get_pro_link() { return ''.__( 'Get PRO version', 'aspexisweetpopups' ).''; } public function settings_link( $action_links, $plugin_file ) { if( $plugin_file == plugin_basename(__FILE__) ) { $pro_link = $this->get_pro_link(); array_unshift( $action_links, $pro_link ); $settings_link = '' . __("Settings") . ''; array_unshift( $action_links, $settings_link ); } return $action_links; } public static function uninstall() { delete_option( 'aspexisweetpopups_options' ); } public function display_admin_notices( $echo = false ) { $ret = ''; foreach( (array)$this->errors as $error ) $ret .= '

'.$error.'

'; foreach( (array)$this->messages as $message ) $ret .= '

'.$message.'

'; if( $echo ) echo $ret; else return $ret; } public function admin_page() { if ( ! current_user_can('manage_options') ) wp_die( __('You do not have sufficient permissions to access this page.') ); if ( isset( $_REQUEST['asp_form_submit'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'asp_nonce_name' ) ) { if ( ! in_array( $_REQUEST['asp_status'], array( 'enabled', 'disabled' ) ) ) $this->add_error( __( 'Wrong or missing status. Available statuses: enabled and disabled. Settings not saved.' ) ); if ( ! in_array( $_REQUEST['asp_theme'], array( 'none', 'facebook', 'google', 'twitter' ) ) ) $this->add_error( __( 'Wrong or missing theme. Available themes: Default, Facebook, Google, Twitter. Settings not saved.' ) ); if ( ! in_array( $_REQUEST['asp_icon_type'], array( 'empty', 'warning', 'error', 'success', 'info' ) ) ) $this->add_error( __( 'Wrong icon type. Available types: empty, warning, error, success, info. Settings not saved.' ) ); if( isset( $_REQUEST['asp_content'] ) ) { $_asp_content = stripslashes( wp_kses_post( balanceTags( $_REQUEST['asp_content'], true ) ) ); if( ! strlen( $_asp_content ) ) $this->add_error( __( 'Missing Popup content. Settings not saved.') ); } else $this->add_error( __( 'Missing Popup content. Settings not saved.') ); if ( ! $this->has_errors() ) { $aspexisweetpopups_request_options = array(); $aspexisweetpopups_request_options['status'] = isset( $_REQUEST['asp_status'] ) ? sanitize_text_field( $_REQUEST['asp_status'] ) : ''; $aspexisweetpopups_request_options['theme'] = isset( $_REQUEST['asp_theme'] ) ? sanitize_text_field( $_REQUEST['asp_theme'] ) : ''; $aspexisweetpopups_request_options['only_frontpage'] = isset( $_REQUEST['asp_only_frontpage'] ) ? sanitize_text_field( $_REQUEST['asp_only_frontpage'] ) : ''; $aspexisweetpopups_request_options['title'] = isset( $_REQUEST['asp_title'] ) ? sanitize_text_field( $_REQUEST['asp_title'] ) : ''; $aspexisweetpopups_request_options['content'] = $_asp_content; $aspexisweetpopups_request_options['only_once'] = isset( $_REQUEST['asp_only_once'] ) ? sanitize_text_field( $_REQUEST['asp_only_once'] ) : ''; if( 'on' == $aspexisweetpopups_request_options['only_once'] ) $aspexisweetpopups_request_options['only_once_days'] = isset( $_REQUEST['asp_only_once_days'] ) ? absint( (int) $_REQUEST['asp_only_once_days'] ) : ''; $aspexisweetpopups_request_options['icon_type'] = isset( $_REQUEST['asp_icon_type'] ) ? sanitize_text_field( $_REQUEST['asp_icon_type'] ) : ''; $this->config = array_merge( $this->config, $aspexisweetpopups_request_options ); update_option( 'aspexisweetpopups_options', $this->config, 'yes' ); $this->add_message( __( 'Settings saved.', 'aspexisweetpopups' ) ); } } ?>
display_admin_notices( true ); ?>

config['only_frontpage'] == 'on') ? 'checked' : ''; ?>>

config['only_once'] ) ? 'checked' : ''; ?> value="on">
config['only_once'] ) ? 'disabled' : ''; ?>>  


Made by

messages[] = $message; } public function has_errors() { return count( $this->errors ); } private function add_error( $error ) { $error = trim( $error ); if( strlen( $error ) ) $this->errors[] = $error; } } global $aspexi_sweet_popups; $aspexi_sweet_popups = new AspexiSweetPopups(); }