1

How would I add the capability in Simple Twitter Connect (in the stc-publish.php file) to not tweet pages, either newly published or edited? I don't need it to be an admin option, just a change for a few of my sites.

It looks like this function would be a good place to add the "don't tweet pages" capabilty (while retaining the check to prevent edited posts from being tweeted) as it checks for edited posts. How can one differentiate between posts and pages?

// this new function prevents edits to existing posts from auto-posting
add_action('transition_post_status','stc_publish_auto_check',10,3);
function stc_publish_auto_check($new, $old, $post) {
    if ($new == 'publish' && $old != 'publish') {
        $post_types = get_post_types( array('public' => true), 'objects' );
        foreach ( $post_types as $post_type ) {
            if ( $post->post_type == $post_type->name ) {
                stc_publish_automatic($post->ID, $post);
                break;
            }
        }
    }
}

Edit 4/03/11

Answer and better edit below.

3
  • @Otto should chime in on this one.
    – Chris_O
    Apr 1, 2011 at 19:00
  • That would be great! I know there's gotta be a better way to do this (that doesn't involve editing the plugin), it's just a bit over my head! Apr 4, 2011 at 11:09
  • @Otto did; see below. Jun 2, 2011 at 21:07

2 Answers 2

1

Even better answer that doesn't involve changing the plugin:

remove_action('transition_post_status','stc_publish_auto_check',10,3);
add_action('transition_post_status','my_custom_publish_rules',10,3);
function my_custom_publish_rules($new, $old, $post) {
  if ($post->post_type == 'page') return;
  else stc_publish_auto_check($new, $old, $post);
}

Put it in a theme's functions.php.

Side note: Whenever you're dealing with a function called by an action or filter hook, then you can easily wrap the call in a different function and add your own code to that function instead. remove_action and remove_filter should be two tools you use a lot in your WP arsenal.

1
  • Ah hah, that is. I'll use it instead of changing your plugin. Thanks! Jun 2, 2011 at 21:06
1

General Disclaimer: This is a plugin edit. Any edits to plugins will be lost when the plugin is updated. Therefore this is not recommended unless you keep good notes and/or remember you did this when the plugin gets updated!! ;) (@songdogtech, I know you are aware of such things, but I thought it would be irresponsible to post this without that)

http://www.rvoodoo.com/projects/wordpress/wordpress-tip-blocking-a-custom-post-type-from-auto-publish-with-simple-facebook-connect-sfc-plugin/

is how I block a CPT in the SFC plugin, the STC plugin works the same

look for the stc_publish_automatic function I believe it is and add post type page to it...

I'll find the code real quick, but wanted to point it out.... yer in the right file, and close to the right code

EDIT:

function stc_publish_automatic($id, $post) {

    // check to make sure post is published
    if ($post->post_status !== 'publish') return;

I'd think editing this bit to:

    function stc_publish_automatic($id, $post) {

        // check to make sure post is published
        if ($post->post_status !== 'publish') return;
     if ($post->post_type == 'page') return;

would do it.... (untested, but if worked for blocking a CPT in the SFC plugin)

If you look at the post I linked, @Otto made some recommendation in the comment you may be able to work with in a better way. I just edit the plugin as a quick and dirty, but looks like you can work it from your theme too.....

If anyone can take the info here, and the info from @Otto's comment on my site, and work it out, I'd love to see that code!

2
  • Thanks! Adding that one line works great to prevent new pages from being tweeeted. I'm obviously just learning php.... Apr 3, 2011 at 17:36
  • I'm glad it worked for you! I'm just learning myself, so the above is what I figured out that works. Apr 4, 2011 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.