=')) { 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_publish_activation_check'); // add the meta boxes add_action('admin_menu', 'stc_publish_meta_box_add'); function stc_publish_meta_box_add() { add_meta_box('stc-publish-div', 'Twitter Publisher', 'stc_publish_meta_box', 'post', 'side'); } // add the admin sections to the stc page add_action('admin_init', 'stc_publish_admin_init'); function stc_publish_admin_init() { add_settings_section('stc_publish', 'Publish Settings', 'stc_publish_section_callback', 'stc'); add_settings_field('stc_publish_flags', 'Automatic Publishing', 'stc_publish_auto_callback', 'stc', 'stc_publish'); add_settings_field('stc_publish_text', 'Publish Tweet Text', 'stc_publish_text', 'stc', 'stc_publish'); wp_enqueue_script('jquery'); } function stc_publish_section_callback() { echo "

Settings for the STC-Publish plugin. The manual Twitter Publishing buttons can be found on the Edit Post or Edit Page screen, after you publish a post. If you can't find them, try scrolling down or seeing if you have the box disabled in the Options dropdown.

"; } function stc_publish_auto_callback() { $options = get_option('stc_options'); if (!$options['autotweet_flag']) $options['autotweet_flag'] = false; ?>

screen_name) echo "

Currently logged in as: {$tw->screen_name}

"; if ($options['autotweet_name']) { echo "

Autotweet set to Twitter User: {$options['autotweet_name']}

"; } else { echo "

Autotweet not set to a Twitter user.

"; } echo '

To auto-publish new posts to any Twitter account, click this button and then log into that account to give the plugin access.

Authenticate for auto-tweeting: '.stc_get_connect_button('publish_preauth', 'authorize').'

'; echo '

Afterwards, you can use this button to log back into your own normal account, if you are posting to a different account than your normal one.

Normal authentication: '.stc_get_connect_button('', 'authorize').'

'; } function stc_publish_text() { $options = get_option('stc_options'); if (!$options['publish_text']) $options['publish_text'] = '%title%: %url%'; echo "
"; echo '

Use %title% for the post title.

'; echo '

Use %url% for the post link (or shortlink).

'; } add_action('stc_publish_preauth','stc_publish_preauth'); function stc_publish_preauth() { if ( ! current_user_can('manage_options') ) wp_die(__('You do not have sufficient permissions to manage options for this blog.')); $tw = stc_get_credentials(true); $options = get_option('stc_options'); // save the special settings if ($tw->screen_name) { $options['autotweet_name'] = $tw->screen_name; $options['autotweet_token'] = $_SESSION['stc_acc_token']; $options['autotweet_secret'] = $_SESSION['stc_acc_secret']; } update_option('stc_options', $options); } function stc_publish_meta_box( $post ) { $options = get_option('stc_options'); if ($post->post_status == 'private') { echo '

Why would you put private posts on Twitter, for all to see?

'; return; } if ($post->post_status !== 'publish') { echo '

After publishing the post, you can send it to Twitter from here.

'; return; } ?>

TODO: This isn't finished yet. Sorry.

post_type == 'post' || $post->post_type == 'page') stc_publish_automatic($post->ID, $post); } } function stc_publish_automatic($id, $post) { // check to make sure post is published if ($post->post_status !== 'publish') return; // check options to see if we need to send to FB at all $options = get_option('stc_options'); if (!$options['autotweet_flag'] || !$options['autotweet_token'] || !$options['autotweet_secret'] || !$options['publish_text']) return; // args to send to twitter $args=array(); if (function_exists('wp_get_shortlink')) { // use the shortlink if it's available $link = wp_get_shortlink($postid); } else if (function_exists('get_shortlink')) { // use the shortlink if it's available $link = get_shortlink($id); } else { // use the full permalink (twitter will shorten for you) $link = get_permalink($id); } $args['status'] = $options['publish_text']; $args['status'] = str_replace('%title%', get_the_title($id), $args['status'] ); $args['status'] = str_replace('%url%', $link, $args['status'] ); $args['acc_token'] = $options['autotweet_token']; $args['acc_secret'] = $options['autotweet_secret']; $resp = stc_do_request('http://api.twitter.com/1/statuses/update',$args); } add_filter('stc_validate_options','stc_publish_validate_options'); function stc_publish_validate_options($input) { $options = get_option('stc_options'); if ($input['autotweet_flag'] != 1) $input['autotweet_flag'] = 0; $input['publish_text'] = trim($input['publish_text']); // preserve existing vars which are not inputs $input['autotweet_name'] = $options['autotweet_name']; $input['autotweet_token'] = $options['autotweet_token']; $input['autotweet_secret'] = $options['autotweet_secret']; return $input; }