* @version 05/22/2014 * @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 { /** * string for translation * @var string */ static public $textdomain; /** * string for options in table options * @var string */ static private $option_string; /** * string for plugin file * @var string */ static private $plugin; /** * post types for the settings * @var Array */ static private $post_types_for_js; /** * string for nonce fields * @var string */ static public $nonce_string; /** * @var */ protected $page_hook; /** * Handler for the action 'init'. Instantiates this class. * @access public * @since 2.0.0 * @return \Add_Quicktag|\Add_Quicktag_Settings $instance */ public static function get_object() { static $instance; if ( NULL === $instance ) { $instance = new self(); } return $instance; } /** * 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 \Add_Quicktag_Settings */ private 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 remove core quicktags require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-remove-quicktags.php'; // include class for add enhanced code quicktags // @TODO Solution for special code tags in quicktags //require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-code-quicktags.php'; // include class for im/export require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class-imexport.php'; } /** * Return 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 * @param 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 * @since 2.0.0 * * @param array $links , string $file * @param $file * * @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_textdomain() ); ?>

get_post_types_for_js() as $post_type ) { $pt_title .= '' . $post_type . '' . "\n"; $pt_colgroup .= '' . "\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"; } 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() ); ?>

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 ) { // Save core buttons changes if ( isset( $value[ 'core_buttons' ] ) ) { $core_buttons = $value[ 'core_buttons' ]; } // Save Code buttons if ( isset( $value[ 'code_buttons' ] ) ) { $code_buttons = $value[ 'code_buttons' ]; } // set allowed 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' ) ); $buttons = ''; // filter for allowed values foreach ( $value[ 'buttons' ] as $key => $button ) { foreach ( $button as $label => $val ) { if ( ! in_array( $label, $allowed_settings ) ) { unset( $button[ $label ] ); } } $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 ( ! empty( $b[ 'text' ] ) && ! empty( $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; } } // Check for wrong empty values and kill foreach ( $value[ 'buttons' ] as $key => $b ) { if ( empty( $b[ 'text' ] ) && empty( $b[ 'start' ] ) ) { unset( $value[ 'buttons' ][ $key ] ); } } // reorder the array $value[ 'buttons' ] = array_values( $value[ 'buttons' ] ); // Add core buttons to array of options if ( ! empty( $core_buttons ) ) { foreach ( $core_buttons as $key => $var ) { $core_buttons[ $key ] = (int) $var; } $value[ 'core_buttons' ] = $core_buttons; } // Add code buttons to array of options if ( ! empty( $code_buttons ) ) { foreach ( $code_buttons as $key => $var ) { $code_buttons[ $key ] = (int) $var; } $value[ 'code_buttons' ] = $code_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 ); } /** * Enqueue scripts and stylesheets * @since 0.0.2 * * @param $where */ 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' ); wp_register_style( self::$option_string . '_admin_style', plugins_url( '/css/settings' . $suffix . '.css', parent::get_plugin_string() ), array(), FALSE, 'screen' ); wp_enqueue_style( self::$option_string . '_admin_style' ); } /** * 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();