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' ) ); 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', 'only_frontpage' => 'off', 'title' => 'Your title', 'content' => 'Your content', 'only_once' => 'off', 'only_once_days' => 30, 'icon_type' => 'empty', ); if ( is_multisite() ) { if ( ! get_site_option( 'aspexisweetpopups_options' ) ) add_site_option( 'aspexisweetpopups_options', $config_default, '', 'yes' ); } else { if ( ! get_option( 'aspexisweetpopups_options' ) ) add_option( 'aspexisweetpopups_options', $config_default, '', 'yes' ); } if ( is_multisite() ) $this->config = get_site_option( 'aspexisweetpopups_options' ); else $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() { if( $this->config['status'] != 'enabled' || ( $this->config['only_frontpage'] == 'on' && ! is_front_page() ) ) 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.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' ) ); } 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() { if ( ! is_multisite() ) delete_option( 'aspexisweetpopups_options' ); else { global $wpdb; $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); $original_blog_id = get_current_blog_id(); foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); delete_option( 'aspexisweetpopups_options' ); } switch_to_blog( $original_blog_id ); delete_site_option( 'aspexisweetpopups_options' ); } } public function display_admin_notices( $echo = false ) { $ret = ''; foreach( (array)$this->errors as $error ) $ret .= '
'.$error.'
'.$message.'