. */ /* Stop direct call */ defined('ABSPATH') OR exit; if (!defined('ACC_PATH')) define( 'ACC_PATH', plugin_dir_path(__FILE__) ); if (!defined('ACC_BASE')) define( 'ACC_BASE', plugin_basename(__FILE__) ); # loading the framework if (!class_exists('A5_Image')) require_once ACC_PATH.'class-lib/A5_ImageClass.php'; if (!class_exists('A5_Excerpt')) require_once ACC_PATH.'class-lib/A5_ExcerptClass.php'; if (!class_exists('A5_FormField')) require_once ACC_PATH.'class-lib/A5_FormFieldClass.php'; if (!class_exists('A5_OptionPage')) require_once ACC_PATH.'class-lib/A5_OptionPageClass.php'; if (!class_exists('A5_DynamicFiles')) require_once ACC_PATH.'class-lib/A5_DynamicFileClass.php'; if (!class_exists('A5_Widget')) require_once ACC_PATH.'class-lib/A5_WidgetClass.php'; #loading plugin specific classes if (!class_exists('ACC_Admin')) require_once ACC_PATH.'class-lib/ACC_AdminClass.php'; if (!class_exists('ACC_DynamicCSS')) require_once ACC_PATH.'class-lib/ACC_DynamicCSSClass.php'; if (!class_exists('Advanced_Category_Column_Widget')) require_once ACC_PATH.'class-lib/ACC_WidgetClass.php'; class AdvancedCategoryColumn { const version = 3.4; private static $options; function __construct() { self::$options = get_option('acc_options'); if (self::version != self::$options['version']) $this->_update_options(); if (@!array_key_exists('flushed', self::$options)) add_action('init', array ($this, 'update_rewrite_rules')); if (true == WP_DEBUG): add_action('wp_before_admin_bar_render', array($this, 'admin_bar_menu')); endif; // Load language files load_plugin_textdomain('advanced-cc', false , basename(dirname(__FILE__)).'/languages'); add_action('save_post', array($this, 'flush_widget_cache')); add_action('deleted_post', array($this, 'flush_widget_cache')); add_action('switch_theme', array($this, 'flush_widget_cache')); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); add_filter('plugin_row_meta', array($this, 'register_links'), 10, 2); add_filter( 'plugin_action_links', array($this, 'plugin_action_links'), 10, 2 ); register_activation_hook( __FILE__, array($this, '_install') ); register_deactivation_hook( __FILE__, array($this, '_uninstall') ); $ACC_DynamicCSS = new ACC_DynamicCSS; $ACC_Admin = new ACC_Admin; } // attach JavaScript file for textarea resizing function enqueue_scripts($hook) { if ($hook != 'post.php' && $hook != 'widgets.php' && $hook != 'settings_page_advanced-cc-settings') return; $min = (SCRIPT_DEBUG == false) ? '.min.' : '.'; wp_register_script('ta-expander-script', plugins_url('ta-expander'.$min.'js', __FILE__), array('jquery'), '3.0', true); wp_enqueue_script('ta-expander-script'); } //Additional links on the plugin page function register_links($links, $file) { if ($file == ACC_BASE) : $links[] = ''.__('FAQ', 'advanced-cc').''; $links[] = ''.__('Donate', 'advanced-cc').''; endif; return $links; } function plugin_action_links( $links, $file ) { if ($file == ACC_BASE) array_unshift($links, ''.__('Settings', 'advanced-cc').''); return $links; } // Creating default options on activation function _install() { $compress = (SCRIPT_DEBUG) ? false : true; $default = array( 'version' => self::version, 'cache' => array(), 'inline' => false, 'compress' => $compress, 'css' => "-moz-hyphens: auto;\n-o-hyphens: auto;\n-webkit-hyphens: auto;\n-ms-hyphens: auto;\nhyphens: auto;", 'css_cache' => '' ); add_option('acc_options', $default); add_rewrite_rule('a5-framework-frontend.css', 'index.php?A5_file=wp_css', 'top'); add_rewrite_rule('a5-framework-frontend.js', 'index.php?A5_file=wp_js', 'top'); add_rewrite_rule('a5-framework-backend.css', 'index.php?A5_file=admin_css', 'top'); add_rewrite_rule('a5-framework-backend.js', 'index.php?A5_file=admin_js', 'top'); add_rewrite_rule('a5-framework-login.css', 'index.php?A5_file=login_css', 'top'); add_rewrite_rule('a5-framework-login.js', 'index.php?A5_file=login_js', 'top'); add_rewrite_rule('a5-export-settings', 'index.php?A5_file=export', 'top'); flush_rewrite_rules(); } // Cleaning on deactivation function _uninstall() { delete_option('acc_options'); flush_rewrite_rules(); } // updating options in case they are outdated function _update_options() { $compress = (SCRIPT_DEBUG) ? false : true; $options_old = get_option('acc_options'); $options_new['css'] = (isset($options_old['acc_css'])) ? $options_old['acc_css'] : @$options_old['css']; $options_new['cache'] = array(); $options_new['inline'] = (isset($options_old['inline'])) ? $options_old['inline'] : false; $options_new['compress'] = (isset($options_old['compress'])) ? $options_old['compress'] : $compress; $options_new['version'] = self::version; if (!strstr($options_new['css'], 'hyphens')) $options_new['css'] .= "-moz-hyphens: auto;\n-o-hyphens: auto;\n-webkit-hyphens: auto;\n-ms-hyphens: auto;\nhyphens: auto;".$options_old['css']; update_option('acc_options', $options_new); } function update_rewrite_rules() { add_rewrite_rule('a5-framework-frontend.css', 'index.php?A5_file=wp_css', 'top'); add_rewrite_rule('a5-framework-frontend.js', 'index.php?A5_file=wp_js', 'top'); add_rewrite_rule('a5-framework-backend.css', 'index.php?A5_file=admin_css', 'top'); add_rewrite_rule('a5-framework-backend.js', 'index.php?A5_file=admin_js', 'top'); add_rewrite_rule('a5-framework-login.css', 'index.php?A5_file=login_css', 'top'); add_rewrite_rule('a5-framework-login.js', 'index.php?A5_file=login_js', 'top'); add_rewrite_rule('a5-export-settings', 'index.php?A5_file=export', 'top'); flush_rewrite_rules(); self::$options['flushed'] = true; update_option('acc_options', self::$options); } function flush_widget_cache() { global $wpdb; self::$options['cache'] = array(); $update_args = array('option_value' => serialize(self::$options)); $result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => 'acc_options' ) ); } /** * * Adds a link to the settings to the admin bar in case WP_DEBUG is true * */ function admin_bar_menu() { global $wp_admin_bar; if (!is_super_admin() || !is_admin_bar_showing()) return; $wp_admin_bar->add_node(array('parent' => '', 'id' => 'a5-framework', 'title' => 'A5 Framework')); $wp_admin_bar->add_node(array('parent' => 'a5-framework', 'id' => 'a5-advanced-cc', 'title' => 'Advanced Category Column', 'href' => admin_url('options-general.php?page=advanced-cc-settings'))); } } $AdvancedCategoryColumn = new AdvancedCategoryColumn; ?>