• I’ve been modifying the WordPress “Live Blogging” plugin, which contains functionality to send out automatic tweets whenever an entry is posted. I’ve been modifying this so that I can put in a custom Twitter update. I’ve been doing this as follows:

    add_meta_box('custom_tweet_box', __('Custom Tweet', 'live-blogging'), 'custom_tweet', 'liveblog_entry', 'side');
    
    [... blah ...]
    
    function custom_tweet(){
         global $post;
         $metac = get_post_meta($post->ID, 'custom_tweet', true);
         echo '<textarea name="custom_tweet">' . $metac . '</textarea>';
    }
    
    add_action('save_post', 'save_details');
    
    function save_details($id) {
         global $post;
    
         if(isset($_POST['post_type']) && ($_POST['post_type'] == "liveblog_entry")) {
              $data = $_POST['custom_tweet'];
              update_post_meta($id, 'custom_tweet', $data);
         }
    }

    This is followed by a function which sets up Twitter integration: testing if custom_tweet exists, and then sending that out as a tweet.

    Essentially what happens is this: the plugin won’t send out the custom tweet unless I’ve saved the entry as a draft first. This is presumably because when the tweet function executes, the custom tweet string hasn’t yet been stored and so there’s no custom tweet to send out.

    Is there any way to store the string before the tweeting function executes (or equivalently, to delay the execution of the tweeting function until the string has been stored)? I’m fairly new to PHP and “flying blind” here, so I apologize for the fact that this is probably a rather basic question.

  • The topic ‘Storing a string before a function executes’ is closed to new replies.