Plugin Directory

Changeset 3472463


Ignore:
Timestamp:
03/02/2026 08:27:06 AM (4 weeks ago)
Author:
formdev
Message:

shortcodes formdev_champ_libre and activation planning in formation

Location:
formdev/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • formdev/trunk/api/Formdev.php

    r3464133 r3472463  
    867867        $meta_value = $data->idProduit;
    868868
     869        // Debug pour idProduit 56
     870       
     871        /*
     872        if ($meta_value == 56) {
     873            echo '<pre>';
     874            print_r($data);
     875            echo '</pre>';
     876            die();
     877        }
     878        */
     879
    869880        /*
    870881        echo $data->nomFormation;
     
    988999        update_post_meta($product_id, 'id_famille', $data->idFamille);
    9891000
    990         // Ajouter les champs libres
     1001        // Ajouter les champs libres (valeur + nom pour recherche par shortcode)
    9911002        if (!empty($data->formationChampsLibres)) {
    9921003            foreach ($data->formationChampsLibres as $champLibre) {
    9931004                update_post_meta($product_id, 'champ_libre_' . $champLibre->idChampsLibres, $champLibre->valeur);
     1005                if (!empty($champLibre->champsLibres->nom)) {
     1006                    update_post_meta($product_id, 'champ_libre_nom_' . $champLibre->idChampsLibres, $champLibre->champsLibres->nom);
     1007                }
    9941008            }
    9951009        }
  • formdev/trunk/formdev.php

    r3464133 r3472463  
    55 * Plugin URI: https://www.form-dev.fr
    66 * Description: Synchroniser automatiquement les formations présentes dans votre CRM Formdev
    7  * Version: 1.4.5
     7 * Version: 1.4.6
    88 * Author: Formdev
    99 * Author URI: https://app.form-dev.fr
     
    1616// Définition de la version du plugin
    1717if (!defined('FORMEDEV_VERSION')) {
    18     define('FORMEDEV_VERSION', '1.4.5');
     18    define('FORMEDEV_VERSION', '1.4.6');
    1919}
    2020
     
    21502150}
    21512151
     2152/**
     2153 * Shortcode pour afficher la valeur d'un champ libre d'une formation par son nom.
     2154 * Utilisation : [formdev_champ_libre nom="Formacode"] ou [formdev_champ_libre nom="Formacode" idproduit="56"]
     2155 * - nom : nom du champ libre (ex. "Formacode"). Obligatoire.
     2156 * - idproduit : idProduit FormDev (ex. 56). Optionnel : si absent, utilise le produit courant (page produit).
     2157 */
     2158add_shortcode('formdev_champ_libre', 'formdev_champ_libre_shortcode');
     2159function formdev_champ_libre_shortcode($atts) {
     2160    $atts = shortcode_atts(array(
     2161        'nom'    => '',
     2162        'idproduit' => null,
     2163    ), $atts);
     2164
     2165    $nom = trim((string) $atts['nom']);
     2166    if ($nom === '') {
     2167        return '';
     2168    }
     2169
     2170    global $wpdb;
     2171    $product_id = null;
     2172
     2173    if (!empty($atts['idproduit'])) {
     2174        $idproduit = absint($atts['idproduit']);
     2175        $product_id = $wpdb->get_var($wpdb->prepare(
     2176            "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'idProduit' AND meta_value = %s LIMIT 1",
     2177            (string) $idproduit
     2178        ));
     2179    } else {
     2180        $product_id = get_the_ID();
     2181        if (!$product_id || get_post_type($product_id) !== 'product') {
     2182            return '';
     2183        }
     2184    }
     2185
     2186    if (!$product_id) {
     2187        return '';
     2188    }
     2189
     2190    $metas = get_post_meta($product_id);
     2191    if (!is_array($metas)) {
     2192        return '';
     2193    }
     2194
     2195    $id_champ = null;
     2196    foreach ($metas as $key => $value) {
     2197        if (strpos($key, 'champ_libre_nom_') === 0) {
     2198            $val = is_array($value) ? end($value) : $value;
     2199            if (trim((string) $val) === $nom) {
     2200                $id_champ = substr($key, strlen('champ_libre_nom_'));
     2201                break;
     2202            }
     2203        }
     2204    }
     2205
     2206    if ($id_champ === null) {
     2207        return '';
     2208    }
     2209
     2210    $valeur = get_post_meta($product_id, 'champ_libre_' . $id_champ, true);
     2211    if ($valeur === '' || $valeur === false) {
     2212        return '';
     2213    }
     2214
     2215    return wp_kses_post(formdev_clean_content_for_display(formdev_fdcontent($valeur)));
     2216}
     2217
    21522218// Shortcode pour afficher le planning
    21532219add_shortcode('formdev_planning', 'formdev_planning_shortcode');
  • formdev/trunk/include/theme.php

    r3300547 r3472463  
    5252                <strong>Paramètres :</strong><br/><br/>
    5353                <code>[formdev categorie="50"]</code> -> Affiche les formations de la catégorie ayant pour identifiant 50 <i>(cf vos idenfiants ci-dessous)</i><br/><br/>
     54
     55                <strong>Shortcode champs libres :</strong><br/><br/>
     56                <code>[formdev_champ_libre nom="Formacode"]</code> -> Affiche la valeur du champ libre « Formacode » pour la formation de la page produit courante.<br/><br/>
     57                <code>[formdev_champ_libre nom="Formacode" idproduit="56"]</code> -> Affiche la valeur du champ libre « Formacode » pour la formation dont l'idProduit FormDev est 56.<br/><br/>
     58
    5459                <strong>Liste des identifiants disponibles :</strong><br/><br/>
    5560                <?php
  • formdev/trunk/readme.txt

    r3464133 r3472463  
    55Tested up to: 6.9.1 
    66Requires PHP: 7.4 
    7 Stable tag: 1.4.5
     7Stable tag: 1.4.6
    88License: GPLv2 or later 
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html 
     
    6868
    6969== Changelog ==
     70= 1.4.6 =
     71* shortcodes formdev_champ_libre and activation planning in formation
     72
    7073= 1.4.5 =
    7174* fix conflict WooCommerce Analytics and CRON
  • formdev/trunk/templates/single-product.php

    r3460769 r3472463  
    233233        echo '</section>';
    234234       
    235         //echo do_shortcode('[formdev_planning idproduit="'.$datas['idProduit'].'" view="calendar"]');
     235        echo do_shortcode('[formdev_planning idproduit="'.$datas['idProduit'].'" view="calendar"]');
    236236
    237237
Note: See TracChangeset for help on using the changeset viewer.