* @version 02/09/2013 * @since 2.0.0 */ if ( ! function_exists( 'add_action' ) ) { echo "Hi there! I'm just a part of plugin, not much I can do when called directly."; exit; } class Add_Quicktag_Settings extends Add_Quicktag { protected static $classobj = NULL; // string for translation static public $textdomain; // string for options in table options static private $option_string; // string for plugin file static private $plugin; // post types for the settings static private $post_types_for_js; // string for nonce fields static public $nonce_string; protected $page_hook; /** * Handler for the action 'init'. Instantiates this class. * * @access public * @since 2.0.0 * @return $classobj */ public static function get_object() { if ( NULL === self :: $classobj ) { self :: $classobj = new self; } return self :: $classobj; } /** * Constructor, init on defined hooks of WP and include second class * * @access public * @since 0.0.2 * @uses register_activation_hook, register_uninstall_hook, add_action * @return void */ public function __construct() { if ( ! is_admin() ) return NULL; // textdomain from parent class self::$textdomain = parent::get_textdomain(); self::$option_string = parent::get_option_string(); self::$plugin = parent::get_plugin_string(); self::$post_types_for_js = parent::get_post_types_for_js(); self::$nonce_string = 'addquicktag_nonce'; register_uninstall_hook( __FILE__, array( 'Add_Quicktag_Settings', 'unregister_settings' ) ); // settings for an active multisite if ( is_multisite() && is_plugin_active_for_network( self::$plugin ) ) { add_action( 'network_admin_menu', array( $this, 'add_settings_page' ) ); // add settings link add_filter( 'network_admin_plugin_action_links', array( $this, 'network_admin_plugin_action_links' ), 10, 2 ); // save settings on network add_action( 'network_admin_edit_' . self::$option_string, array( $this, 'save_network_settings_page' ) ); // return message for update settings add_action( 'network_admin_notices', array( $this, 'get_network_admin_notices' ) ); // add script on settings page } else { add_action( 'admin_menu', array( $this, 'add_settings_page' ) ); // add settings link add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); // use settings API add_action( 'admin_init', array( $this, 'register_settings' ) ); } // include js add_action( 'admin_print_scripts-settings_page_' . str_replace( '.php', '', plugin_basename( __FILE__ ) ), array( $this, 'print_scripts' ) ); // add meta boxes on settings pages add_action( 'addquicktag_settings_page_sidebar', array( $this, 'get_plugin_infos' ) ); add_action( 'addquicktag_settings_page_sidebar', array( $this, 'get_about_plugin' ) ); // include class for im/export require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-imexport.php'; } /** * Retrun allowed post types for include scripts * * @since 2.1.1 * @access public * @return Array */ public function get_post_types_for_js() { return self::$post_types_for_js; } /** * Return Textdomain string * * @access public * @since 2.0.0 * @return string */ public function get_textdomain() { return self :: $textdomain; } /** * Add settings link on plugins.php in backend * * @uses * @access public * @param array $links, string $file * @since 2.0.0 * @return string $links */ public function plugin_action_links( $links, $file ) { if ( parent :: get_plugin_string() == $file ) $links[] = '' . __('Settings') . ''; return $links; } /** * Add settings link on plugins.php on network admin in backend * * @uses * @access public * @param array $links, string $file * @since 2.0.0 * @return string $links */ public function network_admin_plugin_action_links( $links, $file ) { if ( parent :: get_plugin_string() == $file ) $links[] = '' . __('Settings') . ''; return $links; } /** * Add settings page in WP backend * * @uses add_options_page * @access public * @since 2.0.0 * @return void */ public function add_settings_page () { if ( is_multisite() && is_plugin_active_for_network( self::$plugin ) ) { add_submenu_page( 'settings.php', parent :: get_plugin_data( 'Name' ) . ' ' . __( 'Settings', $this->get_textdomain() ), parent :: get_plugin_data( 'Name' ), 'manage_options', plugin_basename(__FILE__), array( $this, 'get_settings_page' ) ); } else { add_options_page( parent :: get_plugin_data( 'Name' ) . ' ' . __( 'Settings', $this->get_textdomain() ), parent :: get_plugin_data( 'Name' ), 'manage_options', plugin_basename(__FILE__), array( $this, 'get_settings_page' ) ); add_action( 'contextual_help', array( $this, 'contextual_help' ), 10, 3 ); } } /** * Return form and markup on settings page * * @uses settings_fields, normalize_whitespace, is_plugin_active_for_network, get_site_option, get_option * @access public * @since 0.0.2 * @return void */ public function get_settings_page() { ?>

get_textdomain() ); ?>

get_post_types_for_js() as $post_type ) { $pt_title .= '' . $post_type . '' . "\n"; } ?> get_post_types_for_js() as $post_type ) { if ( ! isset( $b[$post_type] ) ) $b[$post_type] = 0; $b[$post_type] = intval( $b[$post_type] ); if ( 1 == $b[$post_type] ) $pt_checked = ' checked="checked"'; else $pt_checked = ''; $pt_checkboxes .= '' . "\n"; } $nr = $i + 1; echo ' ' . $pt_checkboxes . ' ' . ' '; } // loop about the post types, create html an values for empty new checkboxes $pt_new_boxes = ''; foreach ( $this->get_post_types_for_js() as $post_type ) { if ( ! isset( $b[$post_type] ) ) $b[$post_type] = 0; $b[$post_type] = intval( $b[$post_type] ); if ( 1 == $b[$post_type] ) $pt_checked = ' checked="checked"'; else $pt_checked = ''; $pt_new_boxes .= '' . "\n"; } ?>
get_textdomain() ); ?> get_textdomain() ); ?> get_textdomain() ); ?> get_textdomain() ); ?> get_textdomain() ); ?> get_textdomain() ); ?> get_textdomain() ); ?>

get_textdomain() ); ?>

get_textdomain() ); ?>

get_textdomain() ); ?>

get_textdomain() ); ?>

get_textdomain() ); ?>

get_textdomain() ); ?>

validate_settings( $_POST[self::$option_string] ); // update options update_site_option( self::$option_string, $value ); // redirect to settings page in network wp_redirect( add_query_arg( array( 'page' => plugin_basename( __FILE__ ), 'updated' => 'true' ), network_admin_url( 'settings.php' ) ) ); exit(); } /* * Retrun string vor update message * * @uses * @access public * @since 2.0.0 * @return string $notice */ public function get_network_admin_notices() { // if updated and the right page if ( isset( $_GET['updated'] ) && 'settings_page_addquicktag/inc/class-settings-network' === $GLOBALS['current_screen'] -> id ) { $message = __( 'Options saved.', $this->get_textdomain() ); $notice = '

' .$message . '

'; echo $notice; } } /** * Validate settings for options * * @uses normalize_whitespace * @access public * @param array $value * @since 2.0.0 * @return string $value */ public function validate_settings( $value ) { // set allowd values for import, only the defaults of plugin and custom post types $allowed_settings = (array) array_merge( $this->get_post_types_for_js(), array( 'text', 'title', 'start', 'end', 'access', 'order', 'visual' ) ); // filter for allowed values foreach ( $value['buttons'] as $key => $button ) { foreach ($button as $key => $val) { if ( ! in_array( $key, $allowed_settings) ) unset( $button[$key] ); } $buttons[] = $button; } // return filtered array $filtered_values['buttons'] = $buttons; $value = $filtered_values; $buttons = array(); for ( $i = 0; $i < count( $value['buttons']); $i++ ) { $b = $value['buttons'][$i]; if ($b['text'] != '' && $b['start'] != '') { $b['text'] = esc_html( $b['text'] ); $b['title'] = esc_html( $b['title'] ); $b['start'] = stripslashes( $b['start'] ); $b['end'] = stripslashes( $b['end'] ); if ( isset( $b['access'] ) ) $b['access'] = esc_html( $b['access'] ); if ( isset( $b['order'] ) ) $b['order'] = intval( $b['order'] ); // visual settings if ( isset( $b['visual'] ) ) $b['visual'] = intval( $b['visual'] ); else $b['visual'] = 0; // post types foreach ( $this->get_post_types_for_js() as $post_type ) { if ( isset( $b[$post_type] ) ) $b[$post_type] = intval( $b[$post_type] ); else $b[$post_type] = 0; } $buttons[] = $b; } } $value['buttons'] = $buttons; return $value; } /** * Register settings for options * * @uses register_setting * @access public * @since 2.0.0 * @return void */ public function register_settings() { register_setting( self::$option_string . '_group', self::$option_string, array( $this, 'validate_settings' ) ); } /** * Unregister and delete settings; clean database * * @uses unregister_setting, delete_option * @access public * @since 0.0.2 * @return void */ public function unregister_settings() { unregister_setting( self::$option_string . '_group', self::$option_string ); delete_option( self::$option_string ); } public function print_scripts( $where ) { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : ''; wp_register_script( self::$option_string . '_admin_script', plugins_url( '/js/settings' . $suffix. '.js', parent::get_plugin_string() ), array( 'jquery', 'quicktags' ), '', TRUE ); wp_enqueue_script( self::$option_string . '_admin_script' ); } /** * Add help text * * @uses normalize_whitespace * @param string $contextual_help * @param string $screen_id * @param string $screen * @since 2.0.0 * @return string $contextual_help */ public function contextual_help( $contextual_help, $screen_id, $screen ) { if ( 'settings_page_' . self::$option_string . '_group' !== $screen_id ) return $contextual_help; $contextual_help = '

' . __( '' ) . '

'; return normalize_whitespace( $contextual_help ); } } $add_quicktag_settings = Add_Quicktag_Settings :: get_object();