existing_options = $options; else $this->existing_options = array(); } /** * Reference the social plugin by name. * * @since 1.1 * * @return string social plugin name */ public static function social_plugin_name() { return __( 'Follow Button', 'facebook' ); } /** * Evaluate the Facebook_Follow_Button class file if it is not already loaded. * * @since 1.1 * * @return void */ public static function require_follow_button_builder() { if ( ! class_exists( 'Facebook_Follow_Button' ) ) require_once( dirname( dirname(__FILE__) ) . '/social-plugins/class-facebook-follow-button.php' ); } /** * Navigate to the settings page through the Facebook top-level menu item. * * @since 1.1 * * @uses add_submenu_page() * @param string $parent_slug Facebook top-level menu item slug * @return string submenu hook suffix */ public static function add_submenu_item( $parent_slug ) { $follow_button_settings = new Facebook_Follow_Button_Settings(); $hook_suffix = add_submenu_page( $parent_slug, self::social_plugin_name(), self::social_plugin_name(), 'manage_options', self::PAGE_SLUG, array( &$follow_button_settings, 'settings_page' ) ); if ( $hook_suffix ) { $follow_button_settings->hook_suffix = $hook_suffix; register_setting( $hook_suffix, self::OPTION_NAME, array( 'Facebook_Follow_Button_Settings', 'sanitize_options' ) ); add_action( 'load-' . $hook_suffix, array( &$follow_button_settings, 'onload' ) ); } return $hook_suffix; } /** * Load stored options and scripts on settings page view. * * @since 1.1 * * @return void */ public function onload() { $options = get_option( self::OPTION_NAME ); if ( ! is_array( $options ) ) $options = array(); $this->existing_options = $options; $this->settings_api_init(); } /** * Load the page. * * @since 1.1 * * @return void */ public function settings_page() { if ( ! isset( $this->hook_suffix ) ) return; Facebook_Settings::settings_page_template( $this->hook_suffix, sprintf( __( '%s Settings', 'facebook' ), self::social_plugin_name() ) ); } /** * Hook into the settings API. * * @since 1.1 * * @uses add_settings_section() * @uses add_settings_field() * @return void */ private function settings_api_init() { if ( ! isset( $this->hook_suffix ) ) return; $section = 'facebook-follow-button'; add_settings_section( $section, '', // no title for main section array( &$this, 'section_header' ), $this->hook_suffix ); // when, where add_settings_field( 'facebook-follow-show-on', _x( 'Show on', 'Display the social plugin in specific areas of a website', 'facebook' ), array( &$this, 'display_show_on' ), $this->hook_suffix, $section ); add_settings_field( 'facebook-follow-position', _x( 'Position', 'Desired position of a Facebook social plugin relative to main post content.', 'facebook' ), array( &$this, 'display_position' ), $this->hook_suffix, $section, array( 'label_for' => 'facebook-follow-position' ) ); // follow button options add_settings_field( 'facebook-follow-layout', _x( 'Layout', 'Positioning of components of a Facebook social plugin relative to each other. Example layouts include button before interaction count or interaction count above button.', 'facebook' ), array( &$this, 'display_layout' ), $this->hook_suffix, $section ); add_settings_field( 'facebook-follow-show-faces', _x( 'Show faces', 'Show the faces of Facebook friends who have interacted with this object.', 'facebook' ), array( &$this, 'display_show_faces' ), $this->hook_suffix, $section, array( 'label_for' => 'facebook-follow-show-faces' ) ); add_settings_field( 'facebook-follow-width', __( 'Width', 'facebook' ), array( &$this, 'display_width' ), $this->hook_suffix, $section, array( 'label_for' => 'facebook-follow-width' ) ); add_settings_field( 'facebook-follow-font', __( 'Font', 'facebook' ), array( &$this, 'display_font' ), $this->hook_suffix, $section, array( 'label_for' => 'facebook-follow-font' ) ); add_settings_field( 'facebook-follow-colorscheme', __( 'Color scheme', 'facebook' ), array( &$this, 'display_colorscheme' ), $this->hook_suffix, $section ); } /** * Introduce publishers to the Follow Button social plugin. * * @since 1.1 * * @return void */ public function section_header() { echo '
' . esc_html( __( "Encourage visitors to follow to public updates from an author's Facebook account.", 'facebook' ) ) . ' ' . esc_html( __( 'Read more...', 'facebook' ) ) . '
'; } /** * Archive choices and post type choices. * * @since 1.1.9 * * @param string $scope accept the same number of parameters as the parent class function. no effect * @return array list of archive names and public post type names */ public static function get_show_on_choices( $scope = null ) { return array_merge( array( 'home', 'archive' ), self::post_types_supporting_authorship() ); } /** * Limit selectable post types to just public post types supporting authors. * * Not all post types support the concept of an author. * * @since 1.1.9 * * @return array list of public post types supporting author feature */ public static function post_types_supporting_authorship() { // get a list of all public post types $public_post_types = get_post_types( array( 'public' => true ) ); // reduce the list of public post types to just the post types supporting comments $post_types_supporting_authorship = array(); foreach( $public_post_types as $post_type ) { if ( post_type_supports( $post_type, 'author' ) ) { $post_types_supporting_authorship[] = $post_type; } } return $post_types_supporting_authorship; } /** * Where should the button appear? * * @since 1.1 * * @param array $extra_attributes custom form attributes * @return void */ public function display_show_on( $extra_attributes = array() ) { $key = 'show_on'; extract( self::parse_form_field_attributes( $extra_attributes, array( 'id' => 'facebook-follow-show-on', 'class' => '', 'name' => self::OPTION_NAME . '[' . $key . ']' ) ) ); $existing_value = self::get_display_conditionals_by_feature( 'follow', 'all' ); echo ''; echo '' . esc_html( self::show_on_description( self::social_plugin_name() ) ) . '
'; } /** * Describe layout choices. * * @since 1.1 * * @return array layout descriptions keyed by layout choice */ public static function layout_descriptions() { $follow_plural = _x( 'followers', 'Facebook users following public updates from another Facebook user', 'facebook' ); return array( 'standard' => __( 'Display social text next to the button.', 'facebook' ), 'button_count' => sprintf( __( 'Display total number of %s next to the button.', 'facebook' ), $follow_plural ), 'box_count' => sprintf( __( 'Display total number of %s above the button.', 'facebook' ), $follow_plural ) ); } /** * Choose a Follow Button layout option. * * @since 1.1 * * @param array $extra_attributes custom form attributes * @return void */ public function display_layout( $extra_attributes = array() ) { $key = 'layout'; extract( self::parse_form_field_attributes( $extra_attributes, array( 'id' => 'facebook-follow-' . $key, 'class' => '', 'name' => self::OPTION_NAME . '[' . $key . ']' ) ) ); $name = esc_attr( $name ); self::require_follow_button_builder(); if ( isset( $this->existing_options[$key] ) && isset( Facebook_Follow_Button::$layout_choices[ $this->existing_options[$key] ] ) ) $existing_value = $this->existing_options[$key]; else $existing_value = 'standard'; $descriptions = self::layout_descriptions(); $layout_choices = array_keys( Facebook_Follow_Button::$layout_choices ); $choices = array(); foreach( $layout_choices as $layout ) { $choice = '