sprintf( '%s', admin_url( 'options-general.php?page=authorbiobox' ), __( 'Settings', 'authorbiobox' ) ) ); return array_merge( $settings, $links ); } /** * Custom contact methods. * * @param array $methods Old contact methods. * * @return array New contact methods. */ public function contact_methods( $methods ) { // Add new methods. $methods['facebook'] = __( 'Facebook', 'authorbiobox' ); $methods['twitter'] = __( 'Twitter', 'authorbiobox' ); $methods['googleplus'] = __( 'Google Plus', 'authorbiobox' ); $methods['linkedin'] = __( 'LinkedIn', 'authorbiobox' ); // Remove old methods. unset( $methods['aim'] ); unset( $methods['yim'] ); unset( $methods['jabber'] ); return $methods; } /** * Register admin scripts. */ public function scripts() { wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_style( 'wp-color-picker' ); wp_register_script( 'authorbiobox-admin', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery', 'wp-color-picker' ), null, true ); wp_enqueue_script( 'authorbiobox-admin' ); } /** * Sets default settings * * @return array Plugin default settings. */ protected function default_settings() { $settings = array( 'settings' => array( 'title' => __( 'Settings', 'authorbiobox' ), 'type' => 'section', 'menu' => 'authorbiobox_settings' ), 'display' => array( 'title' => __( 'Display in', 'authorbiobox' ), 'default' => 'posts', 'type' => 'select', 'description' => sprintf( __( 'You can display the box directly into your theme using: %s', 'authorbiobox' ), '
<?php if ( function_exists( \'get_author_bio_box\' ) ) echo get_author_bio_box(); ?>' ), 'section' => 'settings', 'menu' => 'authorbiobox_settings', 'options' => array( 'posts' => __( 'Only in Posts', 'authorbiobox' ), 'home_posts' => __( 'Homepage and Posts', 'authorbiobox' ), 'none' => __( 'None', 'authorbiobox' ), ) ), 'design' => array( 'title' => __( 'Design', 'authorbiobox' ), 'type' => 'section', 'menu' => 'authorbiobox_settings' ), 'gravatar' => array( 'title' => __( 'Gravatar size', 'authorbiobox' ), 'default' => 70, 'type' => 'text', 'description' => sprintf( __( 'Set the Gravatar size (only integers). To configure the profile picture of the author you need to register in %s.', 'authorbiobox' ), 'gravatar.com' ), 'section' => 'design', 'menu' => 'authorbiobox_settings' ), 'background_color' => array( 'title' => __( 'Background color', 'authorbiobox' ), 'default' => '#f8f8f8', 'type' => 'color', 'section' => 'design', 'menu' => 'authorbiobox_settings' ), 'text_color' => array( 'title' => __( 'Text color', 'authorbiobox' ), 'default' => '#333333', 'type' => 'color', 'section' => 'design', 'menu' => 'authorbiobox_settings' ), 'title_color' => array( 'title' => __( 'Title color', 'authorbiobox' ), 'default' => '#555555', 'type' => 'color', 'section' => 'design', 'menu' => 'authorbiobox_settings' ), 'border_size' => array( 'title' => __( 'Border size', 'authorbiobox' ), 'default' => 2, 'type' => 'text', 'section' => 'design', 'description' => __( 'Thickness of the top and bottom edge of the box (only integers).', 'authorbiobox' ), 'menu' => 'authorbiobox_settings' ), 'border_style' => array( 'title' => __( 'Border style', 'authorbiobox' ), 'default' => 'solid', 'type' => 'select', 'section' => 'design', 'menu' => 'authorbiobox_settings', 'options' => array( 'none' => __( 'None', 'authorbiobox' ), 'solid' => __( 'Solid', 'authorbiobox' ), 'dotted' => __( 'Dotted', 'authorbiobox' ), 'dashed' => __( 'Dashed', 'authorbiobox' ) ) ), 'border_color' => array( 'title' => __( 'Border color', 'authorbiobox' ), 'default' => '#cccccc', 'type' => 'color', 'section' => 'design', 'menu' => 'authorbiobox_settings' ), ); return $settings; } /** * Installs default settings on plugin activation. */ public function install() { $settings = array(); foreach ( $this->default_settings() as $key => $value ) { if ( 'section' != $value['type'] ) { if ( 'authorbiobox_design' == $value['menu'] ) { $design[ $key ] = $value['default']; } else { $settings[ $key ] = $value['default']; } } } add_option( 'authorbiobox_settings', $settings ); } /** * Update plugin settings. */ public function update() { if ( get_option( 'authorbbox_img' ) ) { $settings = array( 'gravatar' => get_option( 'authorbbox_img' ), 'background_color' => get_option( 'authorbbox_bg' ), 'border_size' => get_option( 'authorbbox_bwidth' ), 'border_color' => get_option( 'authorbbox_bcolor' ), 'text_color' => '#333333', 'title_color' => '#555555' ); switch ( get_option( 'authorbbox_bstyle' ) ) { case 'Solida': $settings['border_style'] = 'solid'; break; case 'Pontilhada': $settings['border_style'] = 'dotted'; break; case 'Tracejada': $settings['border_style'] = 'dashed'; break; default: $settings['border_style'] = 'none'; break; } if ( 2 == get_option( 'authorbbox_function' ) ) { $settings['display'] = 'none'; } else { if ( 'posts' == get_option( 'authorbbox_show' ) ) $settings['display'] = 'posts'; else $settings['display'] = 'home_posts'; } // Updates options update_option( 'authorbiobox_settings', $settings ); // Removes old options. delete_option('authorbbox_img'); delete_option('authorbbox_bg'); delete_option('authorbbox_bwidth'); delete_option('authorbbox_bstyle'); delete_option('authorbbox_bcolor'); delete_option('authorbbox_show'); delete_option('authorbbox_function'); } else { // Install default options. $this->install(); } } /** * Add plugin settings menu. */ public function menu() { add_options_page( __( 'Author Bio Box', 'authorbiobox' ), __( 'Author Bio Box', 'authorbiobox' ), 'manage_options', 'authorbiobox', array( &$this, 'settings_page' ) ); } /** * Plugin settings page. */ public function settings_page() { $settings = get_option( 'authorbiobox_settings' ); // Create tabs current class. $current_tab = ''; if ( isset( $_GET['tab'] ) ) $current_tab = $_GET['tab']; else $current_tab = 'settings'; ?>

update(); foreach ( $this->default_settings() as $key => $value ) { switch ( $value['type'] ) { case 'section': add_settings_section( $key, $value['title'], '__return_false', $value['menu'] ); break; case 'text': add_settings_field( $key, $value['title'], array( &$this , 'text_element_callback' ), $value['menu'], $value['section'], array( 'menu' => $value['menu'], 'id' => $key, 'class' => 'small-text', 'description' => isset( $value['description'] ) ? $value['description'] : '' ) ); break; case 'select': add_settings_field( $key, $value['title'], array( &$this , 'select_element_callback' ), $value['menu'], $value['section'], array( 'menu' => $value['menu'], 'id' => $key, 'description' => isset( $value['description'] ) ? $value['description'] : '', 'options' => $value['options'] ) ); break; case 'color': add_settings_field( $key, $value['title'], array( &$this , 'color_element_callback' ), $value['menu'], $value['section'], array( 'menu' => $value['menu'], 'id' => $key, 'description' => isset( $value['description'] ) ? $value['description'] : '' ) ); break; default: break; } } // Register settings. register_setting( $settings, $settings, array( &$this, 'validate_options' ) ); } /** * Text element fallback. * * @param array $args Field arguments. * * @return string Text field. */ public function text_element_callback( $args ) { $menu = $args['menu']; $id = $args['id']; $class = isset( $args['class'] ) ? $args['class'] : 'small-text'; $options = get_option( $menu ); if ( isset( $options[$id] ) ) $current = $options[$id]; else $current = isset( $args['default'] ) ? $args['default'] : ''; $html = sprintf( '', $id, $menu, $current, $class ); // Displays option description. if ( isset( $args['description'] ) ) $html .= sprintf( '

%s

', $args['description'] ); echo $html; } /** * Select field fallback. * * @param array $args Field arguments. * * @return string Select field. */ public function select_element_callback( $args ) { $menu = $args['menu']; $id = $args['id']; $options = get_option( $menu ); // Sets current option. if ( isset( $options[$id] ) ) $current = $options[$id]; else $current = isset( $args['default'] ) ? $args['default'] : ''; $html = sprintf( ''; // Displays the description. if ( $args['description'] ) $html .= sprintf( '

%s

', $args['description'] ); echo $html; } /** * Color element fallback. * * @param array $args Field arguments. * * @return string Color field. */ public function color_element_callback( $args ) { $menu = $args['menu']; $id = $args['id']; $options = get_option( $menu ); if ( isset( $options[$id] ) ) $current = $options[$id]; else $current = isset( $args['default'] ) ? $args['default'] : '#333333'; $html = sprintf( '', $id, $menu, $current ); // Displays option description. if ( isset( $args['description'] ) ) $html .= sprintf( '

%s

', $args['description'] ); echo $html; } /** * Valid options. * * @param array $input options to valid. * * @return array validated options. */ public function validate_options( $input ) { // Create our array for storing the validated options. $output = array(); // Loop through each of the incoming options. foreach ( $input as $key => $value ) { // Check to see if the current option has a value. If so, process it. if ( isset( $input[ $key ] ) ) { // Strip all HTML and PHP tags and properly handle quoted strings. $output[ $key ] = sanitize_text_field( $input[ $key ] ); } } // Return the array processing any additional functions filtered by this action. return apply_filters( 'authorbiobox_validate_input', $output, $input ); } } // Close Author_Bio_Box class.