Plugin Directory

Changeset 561428


Ignore:
Timestamp:
06/21/2012 12:43:48 AM (14 years ago)
Author:
mattwkelly
Message:

Another bug fix for social publishing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • facebook/trunk/fb-social-publisher.php

    r561422 r561428  
    217217
    218218    preg_match_all("/(.*?)@@!!(.*?)@@!!(.*?)$/su", $options['social_publisher']['publish_to_fan_page'], $fan_page_info, PREG_SET_ORDER);
    219    
    220     // does current post type and the current theme support post thumbnails?
    221     if ( post_type_supports( $post->post_type, 'thumbnail' ) && function_exists( 'has_post_thumbnail' ) && has_post_thumbnail() ) {
    222         list( $post_thumbnail_url, $post_thumbnail_width, $post_thumbnail_height ) = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
    223     }
    224 
    225     $fan_page_message = get_post_meta($post_id, 'fb_fan_page_message', true);
    226 
    227     if ( !isset ( $post_thumbnail_url ) ) {
    228         $args = array('access_token' => $fan_page_info[0][3],
    229             'from' => $fan_page_info[0][2],
    230             'link' => apply_filters( 'rel_canonical', get_permalink()),
    231             'name' => get_the_title(),
    232             'caption' => apply_filters( 'the_excerpt', get_the_excerpt() ),
    233             'description' => apply_filters( 'the_excerpt', get_the_excerpt() ),
    234             'message' => $fan_page_message,
    235         );
    236     }
    237     else {
    238         $args = array('access_token' => $fan_page_info[0][3],
    239             'from' => $fan_page_info[0][2],
    240             'link' => apply_filters( 'rel_canonical', get_permalink()),
    241             'picture' => $post_thumbnail_url,
    242             'name' => get_the_title(),
    243             'caption' => apply_filters( 'the_excerpt', get_the_excerpt() ),
    244             'description' => apply_filters( 'the_excerpt', get_the_excerpt() ),
    245             'message' => $fan_page_message,
    246         );
    247     }
    248 
    249     $args['ref'] = 'fbwpp';
    250 
    251     if ( ! isset( $facebook ) )
    252         return;
    253 
    254     $status_messages = array();
    255 
    256     try {
    257         $publish_result = $facebook->api('/' . $fan_page_info[0][2] . '/feed', 'POST', $args);
    258 
    259         update_post_meta($post_id, 'fb_fan_page_post_id', sanitize_text_field($publish_result['id']));
    260     }
    261     catch (FacebookApiException $e) {
    262         $error_result = $e->getResult();
    263        
    264     if ($e->getCode() == 190) {
    265       $options['social_publisher']['publish_to_fan_page'] = false;
     219 
     220  if ( isset( $fan_page_info ) && isset( $fan_page_info[0] ) && isset( $fan_page_info[0][2] ) ) {
     221    // does current post type and the current theme support post thumbnails?
     222    if ( post_type_supports( $post->post_type, 'thumbnail' ) && function_exists( 'has_post_thumbnail' ) && has_post_thumbnail() ) {
     223      list( $post_thumbnail_url, $post_thumbnail_width, $post_thumbnail_height ) = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
     224    }
     225 
     226    $fan_page_message = get_post_meta($post_id, 'fb_fan_page_message', true);
    266227   
    267       update_option( 'fb_options', $options );
     228    if ( !isset ( $post_thumbnail_url ) ) {
     229      $args = array('access_token' => $fan_page_info[0][3],
     230        'from' => $fan_page_info[0][2],
     231        'link' => apply_filters( 'rel_canonical', get_permalink()),
     232        'name' => get_the_title(),
     233        'caption' => apply_filters( 'the_excerpt', get_the_excerpt() ),
     234        'description' => apply_filters( 'the_excerpt', get_the_excerpt() ),
     235        'message' => $fan_page_message,
     236      );
     237    }
     238    else {
     239      $args = array('access_token' => $fan_page_info[0][3],
     240        'from' => $fan_page_info[0][2],
     241        'link' => apply_filters( 'rel_canonical', get_permalink()),
     242        'picture' => $post_thumbnail_url,
     243        'name' => get_the_title(),
     244        'caption' => apply_filters( 'the_excerpt', get_the_excerpt() ),
     245        'description' => apply_filters( 'the_excerpt', get_the_excerpt() ),
     246        'message' => $fan_page_message,
     247      );
     248    }
     249 
     250    $args['ref'] = 'fbwpp';
     251 
     252    if ( ! isset( $facebook ) )
     253      return;
     254 
     255    $status_messages = array();
     256 
     257    try {
     258      $publish_result = $facebook->api('/' . $fan_page_info[0][2] . '/feed', 'POST', $args);
     259 
     260      update_post_meta($post_id, 'fb_fan_page_post_id', sanitize_text_field($publish_result['id']));
     261    }
     262    catch (FacebookApiException $e) {
     263      $error_result = $e->getResult();
    268264     
    269       $status_messages[] = array( 'message' => sprintf( __( 'Failed posting to ' . $fan_page_info[0][1] . '\'s Timeline because the access token expired.  To reactivate publishing, visit the Facebook settings page and re-enable the "Publish to fan page" setting. Full error: ' . json_encode ( $error_result['error'] ), true ) ), 'error' => true);
    270     }
    271     else {
    272       $status_messages[] = array( 'message' => sprintf( __( 'Failed posting to ' . $fan_page_info[0][1] . '\'s Timeline. Error: ' . json_encode ( $error_result['error'] ), true ) ), 'error' => true);
    273     }
    274     }
    275    
    276     if ( isset( $publish_result ) && isset( $publish_result['id'] ) ) {
    277     $status_messages[] = array( 'message' => sprintf( __( 'Posted to <a href="' . fb_get_permalink_from_feed_publish_id( sanitize_text_field( $publish_result['id'] ) ) . '" target="_blank">' . $fan_page_info[0][1] . '\'s Facebook Timeline</a>', true ) ), 'error' => false);
    278     }
    279    
    280   $existing_status_messages = get_post_meta($post_id, 'fb_status_messages', true);
    281  
    282   if ( !empty( $existing_status_messages ) ) {
    283     $status_messages = array_merge($existing_status_messages, $status_messages);
     265      if ($e->getCode() == 190) {
     266        $options['social_publisher']['publish_to_fan_page'] = false;
     267     
     268        update_option( 'fb_options', $options );
     269       
     270        $status_messages[] = array( 'message' => sprintf( __( 'Failed posting to ' . $fan_page_info[0][1] . '\'s Timeline because the access token expired.  To reactivate publishing, visit the Facebook settings page and re-enable the "Publish to fan page" setting. Full error: ' . json_encode ( $error_result['error'] ), true ) ), 'error' => true);
     271      }
     272      else {
     273        $status_messages[] = array( 'message' => sprintf( __( 'Failed posting to ' . $fan_page_info[0][1] . '\'s Timeline. Error: ' . json_encode ( $error_result['error'] ), true ) ), 'error' => true);
     274      }
     275    }
     276   
     277    if ( isset( $publish_result ) && isset( $publish_result['id'] ) ) {
     278      $status_messages[] = array( 'message' => sprintf( __( 'Posted to <a href="' . fb_get_permalink_from_feed_publish_id( sanitize_text_field( $publish_result['id'] ) ) . '" target="_blank">' . $fan_page_info[0][1] . '\'s Facebook Timeline</a>', true ) ), 'error' => false);
     279    }
     280   
     281    $existing_status_messages = get_post_meta($post_id, 'fb_status_messages', true);
     282   
     283    if ( !empty( $existing_status_messages ) ) {
     284      $status_messages = array_merge($existing_status_messages, $status_messages);
     285    }
     286   
     287    update_post_meta( $post->ID, 'fb_status_messages', $status_messages );
     288    add_filter( 'redirect_post_location', 'fb_add_new_post_location' );
    284289  }
    285  
    286     update_post_meta( $post->ID, 'fb_status_messages', $status_messages );
    287     add_filter( 'redirect_post_location', 'fb_add_new_post_location' );
    288290}
    289291
     
    461463 
    462464    try {
    463       $publish_result = $facebook->api('/me/' . $options["app_namespace"] . ':publish', 'POST', array('message' => $author_message, 'article' => get_permalink($post_id)));
     465      //POST https://graph.facebook.com/me/news.reads?article=[article object URL]
     466      $publish_result = $facebook->api('/me/news.publishes', 'POST', array('message' => $author_message, 'article' => get_permalink($post_id)));
    464467     
    465468      update_post_meta($post_id, 'fb_author_post_id', sanitize_text_field($publish_result['id']));
Note: See TracChangeset for help on using the changeset viewer.