WordPress API v2 with Polylang and ACF

Using WordPress with Custom Post Types enriched with Advanced Custom Fields offers a simple solution to provide an intuitive Database management solution. With WP REST API v2 it’s even possible to use WordPress as a simple mobile backend. ACF to WP-API allows accessing the ACF attributes.
But using WP REST API v2 with ACF (through ACF to WP-API) does not work by default if you add Multilanguage support through Polylang. Even though you can filter post types through the filter parameter (e.g. filter[lang]=de) the ACF attributes are not resolved properly (AFAICT this only affects relationship fields).

Fortunately there are some smart folks out there that already figured out how to set the language for REST requests:

<?php
function polylang_json_api_init() {
  global $polylang;

  $default = pll_default_language();
  $langs = pll_languages_list();

  $cur_lang = $_GET['lang'];

  if (!in_array($cur_lang, $langs)) {
    $cur_lang = $default;
  }

  $polylang->curlang = $polylang->model->get_language($cur_lang);
  $GLOBALS['text_direction'] = $polylang->curlang->is_rtl ? 'rtl' : 'ltr';
}

add_action('rest_api_init', 'polylang_json_api_init');
?>

dompdf: Explicit page break via CSS (page-break-*)

Switching from TCPDF to dompdf – due to image rendering / scaling / quality difficulties with TCPDF – I (unsurprisingly) stumbled upon some differences how dompdf handles the provided HTML. One of which is the way explicit page breaks can be accomplished. TCPDF expects you to use a special pagebreak attribute:

Whereas dompdf pays attention to the page-break-* CSS properties. A TCPDF-style replacement for an explicit page break might look like this:

PHP: Delayed Redirect with message without Meta refresh

Messing around with dompdf I tried to show a little teaser right before downloading a generated PDF file. Using WordPress I initially thought about simply putting a Meta refresh into the head by using a suitable hook:

Actually I stumbled upon a simpler and imho cleaner solution to implement a delayed redirect with a nice message: