=')) { return; } } deactivate_plugins(basename(__FILE__)); // Deactivate ourself wp_die("The base stc plugin must be activated before this plugin will run."); } register_activation_hook(__FILE__, 'stc_tweetbutton_activation_check'); global $stc_tweetbutton_defaults; $stc_tweetbutton_defaults = array( 'id'=>0, 'style'=>'vertical', 'source'=>'', 'related'=>'', 'text'=>'', ); /** * Simple tweet button */ function get_stc_tweetbutton($args='') { global $stc_tweetbutton_defaults; $options = get_option('stc_options'); // remove me as the source, tired of the spam on that account if ($options['tweetbutton_source'] == 'ottodestruct') { $options['tweetbutton_source'] = ''; update_option('stc_options',$options); } if (!empty($options['tweetbutton_source'])) $stc_tweetbutton_defaults['source'] = $options['tweetbutton_source']; if (!empty($options['tweetbutton_style'])) $stc_tweetbutton_defaults['style'] = $options['tweetbutton_style']; if (!empty($options['tweetbutton_related'])) $stc_tweetbutton_defaults['related'] = $options['tweetbutton_related']; $args = wp_parse_args($args, $stc_tweetbutton_defaults); extract($args); // fix for missing ID in some cases (some shortlink plugins don't work well with ID = zero) if (!$id) $id = get_the_ID(); $url = wp_get_shortlink($id); $counturl = get_permalink($id); $post = get_post($id); $text = esc_attr(strip_tags($post->post_title));; if (!empty($related)) $datarelated = " data-related='{$related}'"; $query = http_build_query(array( 'url' => $url, 'count' => $style, 'related' => $related, )); $query .= '&text='.$text; $out = ""; return $out; } function stc_tweetbutton($args='') { echo get_stc_tweetbutton($args); } // we need this script in the footer to make the tweet buttons show up add_action('wp_footer','stc_tweetbutton_footer'); function stc_tweetbutton_footer() { ?>Choose where you want the Tweetbutton button to add the button in your content.
'; } function stc_tweetbutton_source() { $options = get_option('stc_options'); if (!$options['tweetbutton_source']) $options['tweetbutton_source'] = 'ottodestruct'; echo " (Username that appears to be RT'd)"; } function stc_tweetbutton_position() { $options = get_option('stc_options'); if (!$options['tweetbutton_position']) $options['tweetbutton_position'] = 'manual'; ?> Users that the person will be suggested to follow. Max 2, separate with comma. Example: otto42,ottodestruct"; } add_filter('stc_validate_options','stc_tweetbutton_validate_options'); function stc_tweetbutton_validate_options($input) { if (!in_array($input['tweetbutton_position'], array('before', 'after', 'both', 'manual'))) { $input['tweetbutton_position'] = 'manual'; } if (!in_array($input['tweetbutton_style'], array('none', 'horizontal', 'vertical'))) { $input['tweetbutton_style'] = 'none'; } if (!$input['tweetbutton_source']) $input['tweetbutton_source'] = ''; else { // only alnum and underscore allowed in twitter names $input['tweetbutton_source'] = preg_replace('/[^a-zA-Z0-9_\s]/', '', $input['tweetbutton_source']); } if (!$input['tweetbutton_related']) $input['tweetbutton_related'] = ''; else { // only alnum and underscore allowed in twitter names $input['tweetbutton_related'] = preg_replace('/[^a-zA-Z0-9_,:\s]/', '', $input['tweetbutton_related']); } return $input; }