ID) ? $hashtags = get_option('aktt_hash_tags') : $hashtags = get_post_meta($post->ID, '_aktt_hash_meta', true); echo '
'; } add_action('aktt_post_options', 'aktt_hash_post_options'); function aktt_hash_do_blog_post_tweet($tweet, $post) { $hashtags = get_post_meta($post->ID, '_aktt_hash_meta', true); $overall_len = strlen($tweet->tw_text.' '.$hashtags); if ($overall_len <= 140) { $tweet->tw_text .= ' '.$hashtags; } else { // check overall needed length $needed = $overall_len - 140; $title = html_entity_decode($post->post_title, ENT_COMPAT, 'UTF-8'); $title_len = strlen($title); // try to regain the space by truncating the title // if we need more than half of the title, only take half - we'll trim some hashtags later ($needed + 3) >= (ceil($title_len / 2) + 3) ? $title_trim = substr($title, 0, ceil($title_len / 2)).'...' : $title_trim = substr($title, 0, strlen($title) - ($needed + 3)).'...'; // reconstruct the tweet global $aktt; $tweet_text = sprintf(__($aktt->tweet_format, 'twitter-tools'), $title_trim, apply_filters('tweet_blog_post_url', get_permalink($post->ID))); // if hashtags now fit, add hashtags if (strlen($tweet_text.' '.$hashtags) <= 140) { // yay, we're done! $tweet->tw_text = $tweet_text.' '.$hashtags; } else { $tagged_tweet = $tweet_text; // drop hashtags if multiple if (strpos($hashtags, ' ') !== false) { $hashtags_array = explode(' ', $hashtags); foreach ($hashtags_array as $hashtag) { $test = $tagged_tweet.' '.$hashtag; if (strlen($test) <= 140) { $tagged_tweet = $test; } } $tweet->tw_text = $tagged_tweet; } } } return $tweet; } add_filter('aktt_do_blog_post_tweet', 'aktt_hash_do_blog_post_tweet', 10, 2); function aktt_hash_save_post($post_id, $post) { if (current_user_can('edit_post', $post_id)) { update_post_meta($post_id, '_aktt_hash_meta', $_POST['_aktt_hash_meta']); } } add_action('save_post', 'aktt_hash_save_post', 10, 2); function aktt_hash_request_handler() { if (!empty($_POST['cf_action'])) { switch ($_POST['cf_action']) { case 'aktt_hash_update_settings': aktt_hash_save_settings(); wp_redirect(admin_url('options-general.php?page=twitter-tools.php&updated=true')); die(); break; } } } add_action('init', 'aktt_hash_request_handler'); $aktt_hash_settings = array( 'aktt_hash_tags' => array( 'type' => 'string', 'label' => __('Default #hashtags for blog post tweets', 'twitter-tools-hash'), 'default' => '', 'help' => __('include the #, example: #twittertools', 'twitter-tools-hash'), ), ); function aktt_hash_setting($option) { $value = get_option($option); if (empty($value)) { global $aktt_hash_settings; $value = $aktt_hash_settings[$option]['default']; } return $value; } if (!function_exists('cf_settings_field')) { function cf_settings_field($key, $config) { $option = get_option($key); if (empty($option) && !empty($config['default'])) { $option = $config['default']; } $label = ''; $help = ''.$config['help'].''; switch ($config['type']) { case 'select': $output = $label.''.$help; break; case 'textarea': $output = $label.''.$help; break; case 'string': case 'int': default: $output = $label.''.$help; break; } return '