A fork from Facebook Page Publish, which is no longer updated and don’t work anymore with late versions of WordPress (french wp).

  • Modifications to Facebook Page Publish to make it ok on updated WordPress (abreviation ffp replaced by mmp):
    • replace status transition  functions:
    • $post_types = get_post_types(array('exclude_from_search' => false), 'objects');
      foreach ($post_types as $post_type) {
      ///    add_action('future_'.$post_type->name, 'mmp_future_action');
      ///    add_action('publish_'.$post_type->name, 'mmp_publish_action');
      add_action('transition_post_status', 'mmp_status_change', 20, 3);
      function mmp_status_change($new_status, $old_status, $post) {
      //wlog(LOG,"status change from $old_status to $new_status");
      if ($new_status=='future') mmp_future_action($post);
      if ($new_status=='publish') mmp_publish_action($post);

    • so:
      • only new status future and publish trigg action mmp_future_action($post) or mmp_publish_action($post);
      • if you need some post_types only, filter $post_types
    • replace $post_id by $post in some functions, because $post was transmitted instead of $post_id whan action 'transition_post_status' trigged. $post_id was found as $post->ID
    • change of api url in mmp_verify_profile_access_permissions:
      /// $api_url = ''.urlencode($profile_access_token).'&format=json&query='.urlencode('SELECT * FROM permissions WHERE uid = me()');
      replaced by
      $api_url = ''.urlencode($profile_access_token);
      (use of graph v2)
    • Change permissions to be granted because of change in facebook api
      ///$permissions = array('share_item');
      $permissions = array('publish_actions');
  • Compatibility with xili language plugin so that you can publish to different targets according to page/post language
    • create a set of options for every language defined on the site, modify options page and validating script
    • create tags in settings page, one for general parameters, and one for each media to manage (email and facebook up to now). (see explanation on settings page and parameters)
  •  Use phpmailer class to send email:
    1. set proper character set; recent version of WordPress use only UTF8, so don't bother to get character set, just use: $mail->CharSet="UTF-8";
    2. get right post content; as you update post, it seems that when transition is trigged, $post contains updated content, but get_post_field('post_content', $post_id) get old version of post.
    3. encode subject in case of non ascii characters:$mail->Subject = mb_encode_mimeheader($post->post_title);


  • Use facebook debugging tool to verify published apparence: copy / paste page url to see what Facebook "thinks" of your page. If you have a message like "meta data are within body instead of header", may be it's because one of your plugins doesn't behave properly and echoes characters before header (some echos put for debugging may do that too, also it breaks ajax calls).

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *