admin_url( 'admin-ajax.php' ), 'debug' => ( self::is_js_debug_mode() || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ), 'home_url' => home_url(), 'mobile_browser_theme_switch' => appp_get_setting( 'mobile_browser_theme_switch' ), 'admin_theme_switch' => appp_get_setting( 'admin_theme_switch' ), 'app_offline_toggle' => ( appp_get_setting( 'app_offline_toggle' ) == 'on' ) ? '' : '1', // on mean it's disabled 'is_appp_true' => self::is_app(), 'noGoBackFlags' => array(), 'ver' => self::get_apv(), 'alert_pop_title' => apply_filters('alert_pop_title', get_bloginfo( 'name' ) ) ); // Load translations add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); // Setup our activation and deactivation hooks register_activation_hook( __FILE__, array( $this, 'activate' ) ); register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); // Welcom activation add_action( 'admin_init', array( $this, 'welcome_screen_do_activation_redirect' ) ); add_action( 'admin_menu', array( $this, 'welcome_screen_pages' ) ); add_action( 'admin_head', array( $this, 'welcome_screen_remove_menus' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'welcome_screen_assets' ) ); // Hook in all our important pieces add_action( 'plugins_loaded', array( $this, 'includes' ) ); add_action( 'admin_init', array( $this, 'check_appp_licenses' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ), 8 ); add_action( 'wp_head', array( $this, 'do_appp_script' ), 1 ); add_action( 'wp_enqueue_scripts', array( $this, 'ajax_login_init' ) ); add_action( 'wp_ajax_nopriv_apppajaxlogin', array( $this, 'appp_ajax_login' ) ); // @since WP 4.7 add_filter( 'stylesheet', array( $this, 'use_appp_theme_in_customizer') ); add_filter( 'template', array( $this, 'use_appp_theme_in_customizer') ); // remove wp version param from cordova enqueued scripts (so script loading doesn't break) // This will mean that it's harder to break caching on the cordova script add_filter( 'script_loader_src', array( $this, 'remove_query_arg' ), 9999 ); require_once( self::$inc_path . 'AppPresser_Admin_Settings.php' ); require_once( self::$inc_path . 'plugin-updater.php' ); // require_once( self::$inc_path . 'AppPresser_Theme_Customizer.php' ); require_once( self::$inc_path . 'AppPresser_Ajax_Extras.php' ); require_once( self::$inc_path . 'AppPresser_Remote_Scripts.php' ); if( ! is_multisite() ) { require_once( self::$inc_path . 'AppPresser_Log_Admin.php' ); require_once( self::$inc_path . 'AppPresser_Logger.php' ); } // $this->theme_customizer = new AppPresser_Theme_Customizer(); } /** * AppPresser licenses admin notification * @since 2.0.0 */ public function check_appp_licenses() { require_once( self::$inc_path . 'AppPresser_License_Check.php' ); AppPresser_License_Check::run(); } /** * Manually add some vars and our script tag so that we can head off the page if need be * @since 1.0.3 */ function do_appp_script() { if( self::is_min_ver( 2 ) ) { // v2 or higher wp_localize_script( 'jquery', 'apppCore', self::$l10n ); return; } // Only use minified files if not debugging scripts $min = self::is_js_debug_mode() ? '' : '.min'; // If PHP can read the cookie, we'll enqueue the standard way if ( is_user_logged_in() || self::is_app() ) { wp_enqueue_script( 'appp-core', self::$js_url ."appp$min.js", null, self::VERSION ); wp_localize_script( 'appp-core', 'apppCore', self::$l10n ); return; } if ( ! self::$l10n['mobile_browser_theme_switch'] && ! self::$l10n['admin_theme_switch'] ) return; // Otherwise we want to include the script ASAP to redirect the page if need be. foreach ( self::$l10n as $key => $value ) { if (is_array($value)) { $value = implode(',', $value); if( class_exists('AppPresser_Logger') ) { AppPresser_Logger::log( 'array to string conversion', $value, __FILE__, __METHOD__, __LINE__ ); } } $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8'); } ?> theme_switcher = new AppPresser_Theme_Switcher(); } /** * Activation hook for the plugin. * @since 1.0.0 */ function activate() { // code to execute when plugin is activated // @TODO: Define default settings upon activation set_transient( '_welcome_screen_activation_redirect', true, 30 ); } function welcome_screen_do_activation_redirect() { // Bail if no activation redirect if ( ! get_transient( '_welcome_screen_activation_redirect' ) ) { return; } // Delete the redirect transient delete_transient( '_welcome_screen_activation_redirect' ); // Bail if activating from network, or bulk if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { return; } // Redirect to Apppresser about page wp_safe_redirect( add_query_arg( array( 'page' => 'welcome-to-apppresser' ), admin_url( 'index.php' ) ) ); } /** * * @since 2.1.2 */ public function welcome_screen_pages() { add_dashboard_page( 'Welcome To Apppresser', 'Welcome To Apppresser', 'read', 'welcome-to-apppresser', array( $this, 'welcome_screen_content' ) ); } /** * * @since 2.1.2 */ public function welcome_screen_content() { ?>
' ) || is_plugin_active( 'mp6/mp6.php' ); } /** * A wrapper for get_apv which returns an integer of the current version number or zero if not found, * this converts it to a boolean; updated in 2.0 for backwards compatiblity. * @since 1.0.0 * @return boolean Variable value */ public static function is_app() { return (self::get_apv()); } /** * Gets the appp=1 value whether set by url param or cookie * @since 2.0.0 * @return boolean value */ public static function read_app_version() { if ( self::$is_apppv !== null ) return self::$is_apppv; if( isset( $_GET['appp_bypass'] ) && $_GET['appp_bypass'] == 'false' ) { self::set_bypass_cookie(false); } else if( ( isset( $_GET['appp_bypass'] ) && $_GET['appp_bypass'] == 'true' ) || ( isset( $_COOKIE['AppPresser_Bypass'] ) && $_COOKIE['AppPresser_Bypass'] == 'true' ) ) { if( isset( $_GET['appp_bypass'] ) ) self::set_bypass_cookie(); return self::$is_apppv = 0; } if( isset( $_GET['appp'] ) && $_GET['appp'] == 2 || isset( $_COOKIE['AppPresser_Appp2'] ) && $_COOKIE['AppPresser_Appp2'] === 'true' ) { self::$is_apppv = 2; } else if( ( isset( $_GET['appp'] ) && $_GET['appp'] == 1 ) || isset( $_COOKIE['AppPresser_Appp'] ) && $_COOKIE['AppPresser_Appp'] === 'true' ) { self::$is_apppv = 1; } else { self::$is_apppv = 0; } return self::$is_apppv; } /** * Gets or compares the app version from the appp=X url param or cookie * get_apv() will return an integer of the exact version * get_apv(2) will return boolean if it's an exact match * get_apv(1, true) will return boolean if app is x >= * @since 2.0.0 * @param int $is_ver the version to check against * @param boolean $min_ver to check if the current version is >= $is_ver * @return int|boolean Variable value */ public static function get_apv( $is_ver = 0, $min_ver = false ) { if( $is_ver && $min_ver ) { // Compare a minimum version return ( self::read_app_version() >= $is_ver ); } else if( $is_ver ) { // Compare exact version in $is_ver if( self::read_app_version() == $is_ver ) { return true; } else { return false; } } else { // Return the exact version return self::read_app_version(); } } /** * A wrapper for get_apv when getting the minimum version */ public static function is_min_ver( $is_ver ) { return self::get_apv( $is_ver, true ); } /** * Checks for debug settings either by * - defined constant 'SCRIPT_DEBUG' or * - url parameter 'apppdebug' or * - cookie 'AppPresser_Debug_Scripts' * @since 2.0 * @return boolean value */ public static function is_js_debug_mode() { if( self::$debug === null) { if( isset( $_GET['apppdebug'] ) ) { self::set_debug_cookie(); } self::$debug = (( isset( $_GET['apppdebug'] ) ) || ( isset( $_COOKIE['AppPresser_Debug_Scripts'] ) && $_COOKIE['AppPresser_Debug_Scripts'] === 'true' ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )); } return self::$debug; } /** * Adds ajax for form#loginform modal in apptheme 2.1.3 and ion 1.0.1 * @since 2.0.1 */ public function appp_ajax_login() { // check_ajax_referer( 'ajax-login-nonce', 'security' ); $info = array(); $info['user_login'] = $_POST['username']; $info['user_password'] = $_POST['password']; $info['remember'] = true; $user_signon = wp_signon( $info, false ); if( is_wp_error( $user_signon ) ) { $return = array( 'message' => __('The log in you have entered is not valid.', 'apppresser'), 'line' => __LINE__, 'success' => false ); wp_send_json_error( $return ); } else { $return = array( 'message' => sprintf( __('Welcome %s, you are now logged in.', 'apppresser'), $user_signon->display_name), ); wp_send_json_success( $return ); } } /** * Adds language textdomain options for form#loginform modal in apptheme 2.1.3 and ion 1.0.1 * @since 2.0.1 */ public function ajax_login_init() { $l10n = array( 'processing' => __('Logging in....', 'apppresser'), 'required' => __('Fields are required', 'apppresser'), 'error' => __('Error Logging in', 'apppresser'), ); $l10n = $this->custom_login_redirect( $l10n ); wp_localize_script( 'jquery', 'appp_ajax_login', $l10n ); } /** * Adds custom login redirect for form#loginform modal in apptheme 2.5.0 and ion 1.4.0 * @since 2.7.0 * @param array $l10n * @return array $l10n */ public function custom_login_redirect( $l10n ) { if( has_filter( 'appp_login_redirect' ) ) { $l10n['login_redirect'] = apply_filters( 'appp_login_redirect', '' ); } return $l10n; } // @since WP 4.7 public function use_appp_theme_in_customizer( $theme ) { if( strpos( $_SERVER['REQUEST_URI'], 'customize.php' ) && isset( $_GET['theme'] ) ) { $appp_theme = appp_get_setting( 'appp_theme' ); if( $appp_theme ) { return $appp_theme; } } return $theme; } public static function get_theme_mod( $key, $default = '' ) { $appp_theme = self::settings( 'appp_theme' ); $theme_settings = self::settings('theme_mods_' . $appp_theme ); if( isset( $theme_settings, $theme_settings[$key] ) && ! empty( $theme_settings[$key] ) ) { return $theme_settings[$key]; } return $default; } } // Singleton rather than a global.. If they want access, they can use: AppPresser::get(); /** * Function wrapper for AppPresser::settings() * @since 1.0.0 * @param string $key Optional key to get a specific option * @param string $fallback Fallback option if none is found. * @return mixed Array of all options, a specific option, or false if specific option not found. */ function appp_get_setting( $key = false, $fallback = false ) { return AppPresser::settings( $key, $fallback ); } function appp_get_theme_mod( $key, $default = '' ) { return AppPresser::get_theme_mod( $key, $default ); }