Support » Plugin: Publish To Apple News » Malformed JSON Content

  • Resolved dlbyron

    (@dlbyron)


    Still tracking down why we get the white page of death upon publish, and if/when it does occasionally publish, the entire article isn’t there. Using the Apple New preview engine to view a file created by the plugin, looks like the parsers is stopping at the excerpt, and not including the body of the post. Any help would be appreciated.

    {“version”:”1.1″,”identifier”:”post-14858″,”language”:”en”,”title”:”Iron Horse Trail: Tunnels Between Hyak and Easton”,”documentStyle”:{“backgroundColor”:”#fafafa”},”layout”:{“columns”:7,”width”:1024,”margin”:100,”gutter”:20},”components”:[{“role”:”header”,”layout”:”headerPhotoLayout”,”components”:[{“role”:”photo”,”layout”:”headerPhotoLayout”,”URL”:”bundle:\/\/14026720_169995040090789_916838851_n.jpg”}],”behavior”:{“type”:”parallax”,”factor”:0.8}},{“role”:”container”,”layout”:{“columnStart”:0,”columnSpan”:7,”ignoreDocumentMargin”:true},”style”:{“backgroundColor”:”#fafafa”},”components”:[{“role”:”title”,”text”:”Iron Horse Trail: Tunnels Between Hyak and Easton”,”textStyle”:”default-title”,”layout”:”title-layout”},{“role”:”byline”,”text”:”by Byron | Aug 22, 2016 | 3:59 PM”,”textStyle”:”default-byline”,”layout”:”byline-layout”}]}],”componentTextStyles”:{“default-title”:{“fontName”:”AvenirNext-Bold”,”fontSize”:48,”lineHeight”:52,”textColor”:”#333333″,”textAlignment”:”left”},”default-byline”:{“textAlignment”:”left”,”fontName”:”AvenirNext-Medium”,”fontSize”:13,”textColor”:”#7c7c7c”}},”componentLayouts”:{“headerPhotoLayout”:{“columnStart”:0,”columnSpan”:7,”ignoreDocumentMargin”:true},”headerBelowTextPhotoLayout”:{“columnStart”:0,”columnSpan”:7,”ignoreDocumentMargin”:true,”margin”:{“top”:30,”bottom”:0}},”title-layout”:{“margin”:{“top”:30,”bottom”:0}},”byline-layout”:{“columnStart”:0,”columnSpan”:7,”margin”:{“top”:10,”bottom”:10}}},”metadata”:{“excerpt”:”  Iron Horse Trail presented itself beautifully yesterday, and we had a video camera with us. These tunnel are between Hyak and Easton in a section that passes two lakes. Seen in the video, is the 3T Exploro, an aero-gravel bike. \u201cWhat\u2019s that?\u201d I\u2019ve been talking about going slow fast on Medium Bicycles with more…”,”thumbnailURL”:”bundle:\/\/14026720_169995040090789_916838851_n.jpg”,”dateCreated”:”2016-08-22T22:59:08+00:00″,”dateModified”:”2016-09-02T00:16:50+00:00″,”datePublished”:”2016-08-22T22:59:08+00:00″,”canonicalURL”:”http:\/\/www.bikehugger.com\/posts\/iron-horse-trail-tunnels-between-hyak-and-easton\/”,”generatorIdentifier”:”publish-to-apple-news”,”generatorName”:”Publish to Apple News”,”generatorVersion”:”1.1.8″},”advertisingSettings”:{“frequency”:1,”layout”:{“margin”:{“top”:15,”bottom”:15}}}}

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Bradford Campeau-Laurion

    (@potatomaster)

    Have you tried disabling your custom plugins and/or themes to try and isolate the issue? Also have you checked your PHP error logs?

    dlbyron

    (@dlbyron)

    The site is in production, so we’re not turning off plugins or templates to track this bug down, but did find this in the logs.

    [Mon Sep 26 13:41:10 2016] [error] [pid 11812] sapi_apache2.c(326): [98.129.217.103:58918] PHP Warning:  Invalid argument supplied for foreach() in /storage/av00158/www/wp_html/wp-content/plugins/publish-to-apple-news/includes/apple-exporter/builders/class-components.php on line 240

    Thanks for responding.

    Plugin Author Bradford Campeau-Laurion

    (@potatomaster)

    Were you able to directly associate that error (given the provided time) to your publishing issue?

    Are you able to set up a staging site or local development copy where you might be able to troubleshoot? You wouldn’t necessarily need to publish to Apple News but just download the JSON file since it would in theory yield the same issue.

    Thanks.

    dlbyron

    (@dlbyron)

    Yes. That error happened at the exact same time. We do have a staging environment.

    Hi @potatomaster,

    I tested this out on our local dev install, and I think I’ve found the source of the issue. We’re calling the following code to insert a Google Ad into the content after the second paragraph. When I remove that content filter, the error is resolved. I know you worked around other issues like this before, so I’m curious if this is something you want to account for in the plugin, or if it’s better that I add a conditional to not run this code when the_content is called by the plugin code.

    // Display Google Ads after 2nd paragraph on post pages
    add_filter( 'the_content', 'hugga_ads_inside_content' );
     function hugga_ads_inside_content( $content ) {
    
          //We don't want to modify the_content in de admin area
          if( !is_admin() ) {
              $ads = '<!-- BH Responsive Ads with Mag Backup use no more than 3 times--><div class="bh-r-ads"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-9243217993604494" data-ad-slot="9642627916" data-ad-format="auto"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div><!-- bh-r-ads -->';
              $p_array = explode('</p>', $content );
              $p_count = 2;
              if( !empty( $p_array ) ){
                  array_splice( $p_array, $p_count, 0, $ads );
                  $output = '';
                  foreach( $p_array as $key=>$value ){
                      $output .= $value;
                   }
              }
          }
          return $output;
     }

    I already have a conditional to not run it in the admin screens, so if there’s a way to not run it when this plugin calls the content filter, it should be easy enough to add. Is there a way to determine when the plugin is calling this?

    Thanks,
    Robert

    Plugin Author Bradford Campeau-Laurion

    (@potatomaster)

    There are filters for apple_news_exporter_content_pre and apple_news_exporter_content that execute before and after the plugin calls the_content. I’m sure you can sort out a solution using those.

    See: https://github.com/alleyinteractive/apple-news/blob/master/admin/apple-actions/index/class-export.php#L112-L114

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Malformed JSON Content’ is closed to new replies.