Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* sorry for this quick and dirty way */
- add_filter('the_content', 'imath_test_checkin_for_post', 10, 1);
- function imath_test_checkin_for_post( $content ) {
- if( is_single() ) {
- $post_address = get_post_meta( get_the_ID(), 'bpci_places_address', true );
- if( empty( $post_address ) )
- return $content;
- $lat = get_post_meta( get_the_ID(), 'bpci_places_lat', true );;
- $lng = get_post_meta( get_the_ID(), 'bpci_places_lng', true );;
- return $content . '<div style="clear:both" id="checkin-btn">
- <a href="#checkin">Checkin</a>
- <input type="hidden" id="lat" value="'.$lat.'">
- <input type="hidden" id="lng" value="'.$lng.'">
- <input type="hidden" id="address" value="'.$post_address.'">
- <input type="hidden" id="ci_post_id" value="'.get_the_ID().'">
- </div>';
- }
- else
- return $content;
- }
- add_action('wp_footer', 'imath_add_js_to_footer');
- function imath_add_js_to_footer(){
- if( is_single() ) {
- ?>
- <script>
- jQuery(document).ready(function($){
- $("#checkin-btn a").click(function(){
- if( !$('#lat').val() || !$('#lng').val() || !$('#address').val() )
- return false;
- $.post( ajaxurl, {
- action: 'imath_regular_post_checkin',
- 'bpci-lat': $('#lat').val(),
- 'bpci-lng': $('#lng').val(),
- 'bpci-address': $('#address').val(),
- 'post_id': $('#ci_post_id').val()
- },
- function(response)
- {
- if( response == "checkedin") {
- $('#checkin-btn').html('checked in!');
- }
- else {
- alert(response);
- }
- });
- return false
- });
- });
- </script>
- <?php
- }
- }
- function imath_save_activity_checkin(){
- global $blog_id;
- //user stuff
- $user_id = bp_loggedin_user_id();
- $from_user_link = bp_core_get_userlink( $user_id );
- //post stuff
- $post_id = intval( $_POST['post_id'] );
- $title = get_the_title( $post_id );
- $postlink = get_permalink( $post_id );
- $activity_link = '<a href="' . $postlink .'" title="' . $title . '">' . $title . '</a>';
- $activity_action = sprintf( __( '%s checked-in %s'), $from_user_link, $activity_link );
- $primary_link = bp_core_get_userlink( $user_id, false, true );
- $activity_content = false;
- $activity_id = bp_activity_add( array(
- 'user_id' => $user_id,
- 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
- 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
- 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
- 'component' => 'activity', /* replace with your custom component */
- 'type' => 'activity_update', /* replace with your custom type */
- 'item_id' => $blog_id,
- 'secondary_item_id' => $post_id
- ) );
- // it's important to add this hook so that the geo data will be saved as activity meta...
- do_action( 'bp_activity_posted_update', $activity_content, $user_id, $activity_id );
- if( $activity_id )
- echo 'checkedin';
- else
- echo 'OOps caramba !';
- die();
- }
- add_action( 'wp_ajax_imath_regular_post_checkin', 'imath_save_activity_checkin' );
- add_action( 'wp_ajax_nopriv_imath_regular_post_checkin', 'imath_save_activity_checkin' );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement