Ejemplo n.º 1
0
require_once '../../../../../../wp-load.php';
use Supertext\Polylang\Core;
use Supertext\Polylang\Api\Wrapper;
use Supertext\Polylang\Api\Multilang;
// Get json request body
$response = array('message' => 'unknown error');
$requestBody = file_get_contents('php://input');
$json = json_decode($requestBody);
$refData = explode('-', $json->ReferenceData, 2);
$postId = $refData[0];
$secureToken = $refData[1];
// check md5 Secure String
if (md5(Wrapper::REFERENCE_HASH . $postId) == $secureToken) {
    // Yes a valid confirmation -> load post object
    $targetLang = substr($json->TargetLang, 0, 2);
    $translationPostId = intval(Multilang::getPostInLanguage($postId, $targetLang));
    // Only if valid, countinue
    if ($translationPostId > 0) {
        // Get the translation post object
        $post = get_post($translationPostId);
        // check if correct language
        if ($post->post_status == 'draft') {
            // Load attachments to merge later
            $attachments = get_children(array('post_parent' => $post->ID, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'));
            // Create file links
            $attachmentFiles = array();
            foreach ($attachments as $attachment) {
                $fileLink = get_post_meta($attachment->ID, '_wp_attached_file', true);
                $attachmentFiles[$fileLink] = $attachment;
            }
            // Save all translations