Events Made Easy Forums How do I … Trigger a Post

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #43840
    Anonymous
    Inactive

    I’m starting to use another plugin (“Social” by MailChimp) that automatically broadcasts Facebook updates and Tweets whenever a post is made.

    Most of our content is actually EME Events, not posts, so none of that can be “broadcast” with the Social plugin.

    I have asked in Social support whether we can use EME’s existing eme_insert_event_action hooks, but I don’t yet know if it can be done.

    However, if EME could simply trigger that a post (somewhere, anywhere, perhaps in a specific Category) be published every time an EME event was published, the Social plugin, and OTHER plugins that are post-based, could pick up on it.

    It could be as simple as creating a series of posts mimicking the EME event content, or perhaps blank with http-equiv auto-refreshing to the proper EME page. Or it could just be a single post that gets overwritten and republished (somewhat similar to your current Page placeholder). The point is just to generate the post activity so the other plugin identifies the need to broadcast…

    In any case, I love Events Made Easy, and our site could not run without it. Thanks.

    #49872
    Anonymous
    Inactive

    Oh, I just now got another request that would benefit from the same thing.

    We are using “MailPress” for mailings, and it can generate automatic newsletters based on site updates. But it will probably ignore EME events?

    If ordinary posts were triggered (mimicking the EME events) then MailPress, too, would be able to pick up on them and turn them into “newsletters”.

    #49873
    Anonymous
    Inactive

    No comment, Franky?

    I see that I can create a post with http://codex.wordpress.org/Function_Reference/wp_insert_post

    but I’m not a programmer and would probably mess up the implementation…

    Edit: It seems that in WP 3.4 the Xml-rpc interface is the way to go?

    http://codex.wordpress.org/XML-RPC_WordPress_API/Posts

    #49874
    Franky
    Keymaster

    Why not use the current available ical possibilities? And use those for notifications (I’ve read about somebody else doing this on the forum).

    #49875
    Anonymous
    Inactive

    You mean an iCal – to RSS feed aggregator – to FaceBook/Twitter publisher path?

    I don’t think that’s a great solution for me. (It certainly doesn’t address any MailPress newsletter integration.)

    I’m trying my best NOT to have to manually create posts AND events for each event description.

    So I really think generating “shadow” Posts would be a very useful feature when an EME event is published.

    #49876
    Anonymous
    Inactive

    Well, I managed to have a test WP post get generated by the end of function eme_db_insert_event in eme_events.php . First try, too. Maybe I should be using eme_insert_event_action instead.

    But I really do NOT like mucking with the EME source code, because I don’t know what I’m doing. 🙁

    #49877
    Franky
    Keymaster

    Well, the action hook is there exactly for that 🙂

    #49878
    Anonymous
    Inactive

    Oh, wait, I can use your hook to call my wp_insert_post code? Why didn’t I think of that. Thank you!

    But before I saw your reply, after a lot of testing I had come up with a good place to put code in eme_events.php , towards the bottom of the “// UPDATE or CREATE action” section, so that it affects BOTH inserts and updates. Right before the wpdb query section, as shown below.

    But for some reason the only fields that will pass through in practice are event_name and event_notes. I really want to get event_id passed but it’s not happening. But I was able to create a new WP category “Shadow EME Events” and automatically assign these new shadow posts to it. 🙂

    $feedback_message = __('You have no right to update','eme'). " '" . $tmp_event ['event_name'] . "' !";
    }
    }
    }

    // TEST CODE FOR CREATING POST, 8-2012

    $new_post = array(
    'post_title' => $event ['event_name'],
    'post_content' => $event ['event_id'] . $event ['event_name'] . $event ['event_url'] . $event ['location_id'] . $event ['event_notes'],
    'post_category' => array( 35 ),
    'post_status' => 'publish'
    );

    $post_id = wp_insert_post($new_post);

    // END TEST CODE

    //$wpdb->query($sql);

    #49879
    Franky
    Keymaster

    Not going to check your code here 🙂 Since the action hook should do what you want, just use those. See here for all possible hooks btw: http://www.e-dynamics.be/wordpress/?cat=41

    #49880
    Anonymous
    Inactive

    Man, Franky, I have to say you give me exactly the right amount of “tough love”; just enough information to keep me going. 🙂

    This is going surprisingly quickly. I’ve changed to using your hooks in functions.php, and event_id IS being passed now, so I was able to craft a meta http-equiv redirect into the “shadow” posts, so they bounce over to their corresponding EME events!

    Strangely, the inserted meta tag does NOT appear in the HTML Post Editor. But it’s there.

    So far I have it working only with new events. I’m just posting my progress for anyone else who might be interested:

    // TEST CODE FOR CREATING POSTS FROM EME (EVENTS MADE EASY) EVENTS, 8-2012
    // SEE ALSO PREVIOUS EME-RELATED MODIFICATIONS ABOVE FOR the_excerpt INSTEAD of the_content

    add_action('eme_insert_event_action','make_shadow_eme_post');

    function make_shadow_eme_post($event_passed) {
    $new_post = array(
    'post_title' => $event_passed ['event_name'],
    // ONE CAN PASS OTHER EME EVENT FIELDS INTO CONTENT, PARTICULARLY $event_passed ['event_notes']
    'post_content' => "<meta http-equiv="refresh" content="0;url=http://example.org/events/?event_id=" . $event_passed ['event_id'] . ""> Redirecting to Event Page at <a href="http://example.org/events/?event_id=" . $event_passed ['event_id'] . "">http://example.org/events/?event_id=" . $event_passed ['event_id'] . "</a> ...",
    'post_category' => array( 39 ),
    'post_status' => 'publish'
    );

    $post_id = wp_insert_post($new_post);
    }
    // END TEST CODE - 8-2012

    Thank you for the pointers.

    #49881
    Franky
    Keymaster

    Nice!

    For the update of events it is just about the same, but the action hook is different:

    add_action(’eme_update_event_action’,’make_shadow_eme_post’);

    #49882
    Anonymous
    Inactive

    Thanks! Well, I eventually added all 4 post cases, and have now incorporated some code to pass a Featured Image from the Event into the new shadow post as well. (This was primarily because Facebook’s “OpenGraph” images don’t work very well or very sanely, especially without a featured image set. I also ended up installing the “Open Graph Protocol” plugin to add more FB OG meta headers.) One tip — Twitter truncates like crazy, so for your URLs to work, keep everything as brief as possible (event titles, shadow post content, etc.).

    UPDATED CODE

    // TEST CODE FOR CREATING POSTS FROM EME (EVENTS MADE EASY) EVENTS, 8-2012
    // SEE ALSO PREVIOUS EME-RELATED MODIFICATIONS ABOVE FOR the_excerpt INSTEAD of the_content
    // Included all event action types, calling same post routine, 9/4/2012
    // Added featured image code, 9/28/2012

    add_action('eme_insert_event_action','make_shadow_eme_post');
    add_action('eme_update_event_action','make_shadow_eme_post');
    add_action('eme_insert_recurrence_action','make_shadow_eme_post');
    add_action('eme_update_event_action','make_shadow_eme_post');

    function make_shadow_eme_post($event_passed) {
    $new_post = array(
    'post_title' => $event_passed ['event_name'],
    // One can pass other EME event fields into content, particularly $event_passed ['event_notes']
    'post_content' => "<meta http-equiv="refresh" content="0;url=http://example.com/events/?event_id=" . $event_passed ['event_id'] . ""> Redirect to <a href="http://example.com/events/?event_id=" . $event_passed ['event_id'] . "">http://example.com/events/?event_id=" . $event_passed ['event_id'] . "</a> ...",
    'post_category' => array( 39 ),
    'post_status' => 'publish'
    );

    $post_id = wp_insert_post($new_post);

    // Thumbnail / Featured Image code from Rob Vermeer at http://wordpress.stackexchange.com/questions/40301/how-do-i-set-a-featured-image-thumbnail-by-image-url-when-using-wp-insert-post
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($event_passed ['event_image_url']);
    $filename = basename($event_passed ['event_image_url']);
    if(wp_mkdir_p($upload_dir['path']))
    $file = $upload_dir['path'] . '/' . $filename;
    else
    $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);

    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => sanitize_file_name($filename),
    'post_content' => '',
    'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );

    set_post_thumbnail( $post_id, $attach_id );
    // END OF ROB VERMEER CODE
    }
    // END TEST CODE - 9-2012

    ?>

    (As a byproduct, this is now also adding the EME Event Image to the regular WordPress Media Library, named with its event_id number. I’d prefer to include the event title when it gets added but haven’t figured that out.)

    #49883
    Anonymous
    Inactive

    Minor fix — added check as to whether Event Image exists, before proceeding to create Featured Image. (Otherwise non-critical error message displayed when event image URL was empty.)

    // TEST CODE FOR CREATING POSTS FROM EME (EVENTS MADE EASY) EVENTS, 8-2012
    // SEE ALSO PREVIOUS EME-RELATED MODIFICATIONS ABOVE FOR the_excerpt INSTEAD of the_content
    // Included all event action types, calling same post routine, 9/4/2012
    // Added featured image code, 9/28/2012

    add_action('eme_insert_event_action','make_shadow_eme_post');
    add_action('eme_update_event_action','make_shadow_eme_post');
    add_action('eme_insert_recurrence_action','make_shadow_eme_post');
    add_action('eme_update_event_action','make_shadow_eme_post');

    function make_shadow_eme_post($event_passed) {
    $new_post = array(
    'post_title' => $event_passed ['event_name'],
    // One can pass other EME event fields into content, particularly $event_passed ['event_notes']
    'post_content' => "<meta http-equiv="refresh" content="0;url=http://example.com/events/?event_id=" . $event_passed ['event_id'] . ""> Redirect to <a href="http://example.com/events/?event_id=" . $event_passed ['event_id'] . "">http://example.com/events/?event_id=" . $event_passed ['event_id'] . "</a> ...",
    'post_category' => array( 39 ),
    'post_status' => 'publish'
    );

    $post_id = wp_insert_post($new_post);

    // Migrate Event Image into post's Featured Image if and only if one exists for this event
    if (trim($event_passed ['event_image_url']) != "") {
    // Thumbnail / Featured Image code from Rob Vermeer at http://wordpress.stackexchange.com/questions/40301/how-do-i-set-a-featured-image-thumbnail-by-image-url-when-using-wp-insert-post
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($event_passed ['event_image_url']);
    $filename = basename($event_passed ['event_image_url']);
    if(wp_mkdir_p($upload_dir['path']))
    $file = $upload_dir['path'] . '/' . $filename;
    else
    $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);

    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title' => sanitize_file_name($filename),
    'post_content' => '',
    'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );

    set_post_thumbnail( $post_id, $attach_id );
    // END OF ROB VERMEER CODE
    }
    // END of if ($event_passed ['event_image_url'])
    }
    // END TEST CODE - 9-2012

    ?>

    #55016
    Anonymous
    Inactive

    This snippet looks very useful, but I could not get it to work.
    Does anyone have any advice on how to get this working?

Viewing 14 posts - 1 through 14 (of 14 total)
  • The forum ‘How do I …’ is closed to new topics and replies.
Scroll to Top