/** * Init singleton instance and add actions */ public function __construct() { parent::__construct(); self::$instance = $this; add_action('admin_menu', array($this, 'hook_admin_menu_swifty_admin_licenses_page'), 10500); }
/** * Check if swiftylib classes are needed and find newest version of lib before instantiating * * @param $class_name */ function swifty_autoload_function($class_name) { if ($class_name === 'LibSwiftyPlugin') { swifty_autoload_lib_helper_main('/php/lib_swifty_plugin.php'); if (is_null(LibSwiftyPlugin::get_instance())) { new LibSwiftyPlugin(); } } if ($class_name === 'LibSwiftyPluginView') { swifty_autoload_lib_helper_main('/php/lib_swifty_plugin_view.php'); if (is_null(LibSwiftyPluginView::get_instance())) { new LibSwiftyPluginView(); } } }
/** * echo some js script needed in the head */ public static function echo_include_head_script() { if (!self::$included_head_script) { self::$included_head_script = true; ?> <script> var ssd_status_onload = 0; var ssd_list_loadCss = []; var ssd_add_loadCss = function( s ) { ssd_list_loadCss.push(s); if( typeof swifty_do_loadCSS === 'function' ) { swifty_do_loadCSS(); } }; var ssd_list_loadJs = []; var ssd_add_loadJs = function( s ) { ssd_list_loadJs.push(s); if( typeof swifty_do_loadJs === 'function' ) { swifty_do_loadJs(); } }; var ssd_list_loadFont = []; var ssd_add_loadFont = function( s ) { ssd_list_loadFont.push(s); if( typeof swifty_do_loadFont === 'function' ) { swifty_do_loadFont(); } }; var swifty_list_exec = [ { 'status': 'hold', 'for': 'page_loaded' } ]; var swifty_add_exec = function( s ) { swifty_list_exec.push(s); if( typeof swifty_do_exec === 'function' ) { swifty_do_exec(); } }; </script> <?php } }
/** * @param integer $post_id * @param string $post_status */ protected function _update_post_status($post_id, $post_status) { if ($this->is_swifty && $post_status === 'publish') { // use autosave content when publishing, remove autosave (no newer autosave record) $autosave_content = LibSwiftyPluginView::get_instance()->get_autosave_version_if_newer($post_id); $post_data = array('ID' => $post_id, 'post_status' => $post_status); if ($autosave_content) { $post_data['post_content'] = $autosave_content; } wp_update_post($post_data); } else { // remember current autosave LibSwiftyPlugin::get_instance()->wp_update_post_keep_autosave($post_id, array('ID' => $post_id, 'post_status' => $post_status)); } }
/** * set the ss_mode cookie, use ss_mode Get attribute * defaults to ss */ public static function set_ss_mode() { // reset the ss_mode, after setting cookies the value might change self::$_ss_mode = null; $mode = ''; if (!empty($_COOKIE['ss_mode']) && in_array($_COOKIE['ss_mode'], self::$_valid_modes)) { $mode = $_COOKIE['ss_mode']; } if (!empty($_GET['ss_mode']) && in_array($_GET['ss_mode'], self::$_valid_modes)) { $mode = $_GET['ss_mode']; } if (!$mode) { $mode = self::$_default_mode; } setcookie('ss_mode', $mode, 0, '/'); $_COOKIE['ss_mode'] = $mode; }