'method_name', 'the_content' => array( 'function_to_add' => 'render', 'priority' => 9999, 'accepted_args' => 1, ), ); } /** * [$var description] * * @var null */ private $social_url = array(); private $options = array(); /** * [__construct description] * * @param [type] $argument [description]. */ function __construct( array $options = array() ) { $this->options = $options; $wpseo_social = get_option( 'wpseo_social' ); $this->via = ! empty( $option['twitter_site'] ) ? '&via=' . $option['twitter_site'] : '' ; // add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 999999 ); add_action( 'wp_footer', array( $this, 'style_in_footer' ), 999999 ); /** * Append css in static variable and print in front-end footer */ // Inline_Style::set( \ItalyStrap\Core\get_file_content( ITALYSTRAP_PLUGIN_PATH . 'css/social.css' ) ); Inline_Style::set( $this->style() ); } /** * Set CSS style * * @param string $value [description] * @return string [description] */ public function style() { $rules = array( 'facebook' => array( 'background-color' => '#465f9e', 'border-color' => '#465f9e', 'color' => '#fff', ), 'twitter' => array( 'background-color' => '#1DA1F2', 'border-color' => '#1DA1F2', 'color' => '#fff', ), 'google-plus' => array( 'background-color' => '#DB4437', 'border-color' => '#DB4437', 'color' => '#fff', ), 'linkedin' => array( 'background-color' => '#0077B5', 'border-color' => '#0077B5', 'color' => '#fff', ), 'pinterest' => array( 'background-color' => '#B4091C', 'border-color' => '#B4091C', 'color' => '#fff', ), ); $style = ''; foreach ( $rules as $key => $value ) { $style .= sprintf( '.%s{%s}', $key, $this->get_props( $value ) ); } return $style; } /** * Function description * * @param string $value [description] * @return string [description] */ public function get_props( array $props = array() ) { $output = ''; foreach ( $props as $prop => $prop_value ) { $output .= sprintf( '%s:%s;', $prop, $prop_value ); } return $output; } /** * Enqueue scripts * * @param string $handle Script name * @param string $src Script url * @param array $deps (optional) Array of script names on which this script depends * @param string|bool $ver (optional) Script version (used for cache busting), set to null to disable * @param bool $in_footer (optional) Whether to enqueue the script before or before */ function enqueue_scripts() { wp_enqueue_style( 'fontello', ITALYSTRAP_PLUGIN_URL . 'css/social.css', null, null, null ); } /** * Load Font Awesome in footer * * @param string $value [description] * @return string [description] */ public function style_in_footer() { echo ''; // echo ''; } /** * Set social url * * @param string $value [description] * @return string [description] */ public function set_social_url() { global $post; $get_permalink = get_permalink(); $get_the_title = esc_attr( $post->post_title ); // $get_the_content = get_the_content(); // $get_the_excerpt = get_the_excerpt(); $get_the_excerpt = ''; // $get_the_excerpt = $this->content; $thumb_url = wp_get_attachment_url( get_post_thumbnail_id( get_the_id() ) ); $this->social_url = array( 'facebook' => sprintf( '//www.facebook.com/sharer.php?u=%s&p[title]=%s', $get_permalink, $get_the_title ), 'twitter' => sprintf( '//twitter.com/share?url=%s&text=%s%s', $get_permalink, $get_the_title, $this->via ), 'google-plus' => sprintf( '//plus.google.com/share?url=%s', $get_permalink ), /** * https://developer.linkedin.com/docs/share-on-linkedin# */ 'linkedin' => sprintf( '//www.linkedin.com/shareArticle?mini=true&url=%s&title=%s', $get_permalink, $get_the_title ), 'pinterest' => sprintf( '//pinterest.com/pin/create/button/?url=%s&media=%s&description=%s', $get_permalink, $thumb_url, $get_the_title ), ); } /** * Render Sharing button * * Alcune idee https://www.google.it/search?site=&source=hp&q=twitter+url+share&oq=twitter+url+share&gs_l=hp.3.0.0i19l3j0i22i10i30i19j0i22i30i19l6.1898.11624.0.13381.18.18.0.0.0.0.2152.4618.0j13j0j1j1j9-1.16.0....0...1c.1.64.hp..2.15.4160.0.93FpzCXhTCY * https://gist.github.com/chrisjlee/5196139 * * @param string $value [description] * @return string [description] */ public function get_social_button() { $this->set_social_url(); $output = ''; return $output; } /** * Add social share * * @param string $value [description] * @return string [description] */ public function render( $content ) { if ( ! is_singular() ) { return $content; } /** * Forced to be an array because if during save option none are selected * the option is an empty string */ $social_button_on_post_types = (array) $this->options['social_button_on_post_types']; $display_social_share_button = (array) get_post_meta( get_the_ID(), '_italystrap_template_settings', true ); /** * If is not the actual post type selected bail out */ if ( ! in_array( get_post_type(), $social_button_on_post_types, true ) || in_array( 'hide_social', $display_social_share_button ) ) { return $content; } $this->content = $content; $positions = array( 'before' => '%2$s%1$s', 'after' => '%1$s%2$s', 'both' => '%2$s%1$s%2$s', ); return sprintf( $positions[ $this->options['social_button_position'] ], $content, $this->get_social_button() ); } }