Copier le contenu “wysiwyg” d’un post dans un contenu flexible “contenu”

/**
 *  PIT - WP ADMIN OPS - Actions
 *  - Transfer WYSIWYG content to Contenu flexible "Section contenu"
 */
add_filter('wpops/actions', 'wpops_pit_wysiwyg_to_contenu_flexible_actions');
function wpops_pit_wysiwyg_to_contenu_flexible_actions($actions) {

    $actions[] = array(
        'slug'  => 'pit_wysiwyg_to_contenu_flexible',
        'title' => 'Transfer WYSIWYG content to ACF Contenu flexible',
        'options' => array(
            array(
                'title' => 'Type of post type',
                'type'  => 'text',
                'name'  => 'post_type',
                'value' => 'post',
                'description' => 'Type of post type'
            ),
        )
    );

    return $actions;
}

/**
 *  PIT - WP ADMIN OPS - Function
 *  - Transfer WYSIWYG content to Contenu flexible "Section contenu"
 */
add_action('wp_ajax_wpops_pit_wysiwyg_to_contenu_flexible', 'wpops_pit_wysiwyg_to_contenu_flexible');
function wpops_pit_wysiwyg_to_contenu_flexible() {

    $offset     = (int) $_POST['offset'];
    $options    = (array) $_POST['options'];
    $post_type  = (string) $options['post_type'] ?? 'post';

    $article_query_id = new WP_Query(array(
        'post_type'         => $post_type,
        'posts_per_page'    => 1,
        'offset'            => $offset,
        'fields'            => 'ids',
    ));

    $articles_total = $article_query_id->found_posts;
    $articles_id    = $article_query_id->posts;
    $update_field   = '';

    if (!empty($articles_id)) {
        foreach ($articles_id as $article_id) {

            $contenu_flexible   = get_field('contenu_flexible', $article_id, false);

            /** To generate the default contenu flexible json of a post, use this */
            // $contenu_flexible_json  = json_encode($contenu_flexible);

            /** If the post already have a specific flexible, don't erase it (for safety) */
            if ($contenu_flexible)
                continue;

            $post_content       = get_post_field('post_content', $article_id);
            if (!$post_content)
                continue;

            $post_content_json  = json_encode($post_content);

            $post_json          = '[{"acf_fc_layout":"template-constructeur","field_flexible_template-constructeur":[{"acf_fc_layout":"template-constructeur","field_clone_template-constructeur":{"field_5ace857c89ca1":[{"acf_fc_layout":"colonne","field_5acec9865ae39":' . $post_content_json . ',"field_5ae1de77d94ed":{"field_5d7f4c3eb4c6f":null,"field_5ae1de84d94ee":{"field_5ae1de93d94ef":[],"field_5ae1dee5d94f0":[],"field_5ae1defad94f1":"8","field_5ae1df02d94f2":[],"field_5ae1df10d94f3":[]},"field_5b2b7d17c4a8a":[],"field_5d7f4c52b4c70":null,"field_5d7f4c5ab4c71":{"field_5b3601a146a4a":"","field_5ae2cfc167760":"p-10","field_5ae2cfc16b475":""},"field_5d7f4d09209d2":"#ffffff","field_5d7f4dd0209d3":"1"}}],"field_5b2b77d58dace":{"field_5b3601eac3cd8":null,"field_5b3601312c6eb":{"field_5b3601a146a4a":"","field_5ae2cfc167760":"","field_5ae2cfc16b475":""},"field_5b3601f4c3cd9":null,"field_5b2b795e90f7a":"justify-content-center","field_5b35fca56c544":"align-items-start"}}}],"field_configuration_template-constructeur":{"field_5b36073833687":null,"field_5ace73a2b2b8d":{"field_5ae7038f9b3d3":"","field_5ace73f1b2b90":"","field_5ace7406b2b91":"","field_5ace74a4b2b9a":{"field_5ace74b3b2b9b":"container","field_5ace74f2b2b9c":"aucun"},"field_5acec15f610dc":{"field_59f0748c4e83a":{"field_59f074534e839":"1","field_59f074c24e83b":"couleur","field_59f0753a4e83e":"#f3f3fb","field_59f075174e83c":null,"field_5ae1c7cce2462":"center","field_5ae1c85ee2463":"center","field_5ae1cc6aeaa73":"cover","field_5ae1cd5b38ab0":["no-repeat"],"field_5ae1d32680f2d":["scroll"],"field_59f0790871238":"","field_59f079827123c":null,"field_59f079ab7123d":"","field_59f079bd7123e":"","field_59f0792f71239":""},"field_59f079f671245":{"field_59f07a1171246":0,"field_5a9ff48d8dc3e":0,"field_59f07e03aaa78":"","field_5a9ff4ed8dc3f":"","field_59f07e14aaa79":"50","field_5aa0017d460e0":["normal"],"field_5e13427772444":0,"field_5e13428c72445":null}}}}}]';
            $post_data          = json_decode($post_json, true);

            /** Update the contenu flexible with wysiwyg data inside it */
            update_field('contenu_flexible', $post_data, $article_id);
        }
    }

    ob_start();
    _print_r('Articles left: ' . $articles_total);
    _print_r($articles_id);
    $html = ob_get_clean();

    /** Debug */
    // wp_send_json_error(array(
    //     'html'  => 'Done',
    //     'debug' => print_r('Done', true),
    //     'stop'  => true,
    // ));

    // Success
    wp_send_json_success(array(
        'html'  => $html,
        'debug' => print_r($article_query_id, true),
        'stop'  => $articles_total == '0' ? true : false,
    ));
}

 

Quelle différence entre UX et UI design ?
Wireframe : les différents types et leurs objectifs
Le manuel du lead magnet : techniques avancées pour le marketeur averti