.
*/
include "admin/admin.php"; // Plugin admin options setup
global $async_share_options;
add_action( 'wp_enqueue_scripts', 'async_share_script_loader' );
add_filter( 'the_content', 'async_share_display' );
/**
* Get plugin options from database and store in array
* @return array();
*/
function async_share_get_options() {
global $async_share_options;
$async_share_options = get_option( 'async_share_options' );
return $async_share_options;
}
/**
* JavaScripts and CSS for front-end display of social widgets
*/
function async_share_script_loader() {
wp_enqueue_script( 'async_js', plugins_url( 'assets/js/async-share.js', __FILE__ ), array( 'jquery' ), '', true );
wp_enqueue_style( 'async_css', plugins_url( 'assets/css/async-share.css', __FILE__ ), false , '1.0', 'all' );
}
/**
* Sets up link to plugin's options page
*/
function async_share_plugin_action_links( $links, $file ) {
static $this_plugin;
if ( !$this_plugin ) $this_plugin = plugin_basename( __FILE__ );
if ( $file == $this_plugin ) {
$async_share_settings_link = ''.__( 'Settings' ).'';
// make the 'Settings' link appear first
array_unshift( $links, $async_share_settings_link );
}
return $links;
}
/**
* Verifies an option was selected or at least set
* @param string $param option name
* @return bool
*/
function async_share_option_check( $param ) {
$async_share_options = async_share_get_options();
if ( !isset($async_share_options[$param]) ) {
return FALSE;
}
if ( $async_share_options[ $param ] == TRUE ) {
return TRUE;
}
else
return FALSE;
}
/**
* Twitter widget display
*/
function async_share_display_twitter() {
$async_share_options = async_share_get_options();
if ( async_share_option_check('twitter') == TRUE ) {
$twitter = '
';
return $twitter;
}
else
return;
}
/**
* Facebook widget display
*/
function async_share_display_facebook() {
$async_share_options = async_share_get_options();
if ( async_share_option_check('facebook') == TRUE ) {
$facebook = '';
return $facebook;
}
else
return;
}
function async_share_display_fbinit() {
$async_share_options = async_share_get_options();
if ( async_share_option_check('facebook') == TRUE ) {
$fbinit = '';
return $fbinit;
}
else
return;
}
/**
* Google+ widget display
*/
function async_share_display_gplus() {
$async_share_options = async_share_get_options();
if ( async_share_option_check('gplus') == TRUE ) {
$gplus = '';
return $gplus;
}
else
return;
}
/**
* Linkedin widget display
*/
function async_share_display_linkedin() {
$async_share_options = async_share_get_options();
if ( async_share_option_check('linkedin') == TRUE ) {
$linkedin = '';
return $linkedin;
}
else
return;
}
/**
* HackerNews widget display
*/
function async_share_display_hackernews() {
$async_share_options = async_share_get_options();
if ( async_share_option_check('hackernews') == TRUE ) {
$hackernews = 'Vote on HN';
return $hackernews;
}
else
return;
}
/**
* Sets up display of social widgets
* @return string;
*/
function async_share_social_box() {
global $post;
$async_share_options = async_share_get_options();
if ( isset($post) and isset($async_share_options) ) {
$twitter = async_share_display_twitter();
$facebook = async_share_display_facebook();
$fbinit = async_share_display_fbinit();
$gplus = async_share_display_gplus();
$linkedin = async_share_display_linkedin();
$hackernews = async_share_display_hackernews();
/**
* Displaying the sharing widgets
*/
$async_display_share_box = $fbinit.''. $twitter . $facebook . $gplus . $linkedin . $hackernews .'
';
}
else {
$async_display_share_box = '';
}
return $async_display_share_box;
}
/**
* Controls which template files the social widgets are displayed upon
*/
function async_share_display( $content ) {
$async_display_share_box = async_share_social_box();
$async_share_options = async_share_get_options();
if ( is_home() || is_paged() ) {
if ( $async_share_options['paged'] == TRUE ) {
return $content . $async_display_share_box;
}
else
return $content;
}
elseif ( is_single() ) {
$cpt = get_post_type();
if ( 'post' == $cpt ) {
return $content . $async_display_share_box;
}
elseif ( in_array($cpt, $async_share_options['types'])) {
return $content . $async_display_share_box;
}
}
elseif ( is_page() ) {
if (in_array( "page", $async_share_options['types'] ) ) {
return $content . $async_display_share_box;
}
else return $content;
}
}