123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- {"label":"Plugin","syntax":"php"}
- <?php
- /**
- * Plugin Name: {{plugin}}
- * Plugin URI: http://no-url.com
- * Description: {{description}}
- * Version: 1.0.0
- * Author: {{user.fullname}}
- * Author URI: https://sys1.fr
- * License: Copyright
- */
- function sys1_{{plugin}}_init()
- //Permet de créer un type de posts personnalisé, avec un menu dédié
- $labels = array(
- 'name' => _x( '{{Entity}}s', 'Post Type General Name'),
- 'singular_name' => _x( '{{Entity}}', 'Post Type Singular Name'),
- 'menu_name' => __( '{{Entity}}s'),
- 'all_items' => __( 'Toutes les {{entity}}s'),
- 'view_item' => __( 'Voir l\'{{entity}}'),
- 'add_new_item' => __( 'Ajouter une nouvelle {{entity}}'),
- 'add_new' => __( 'Ajouter'),
- 'edit_item' => __( 'Editer l\'{{entity}}'),
- 'update_item' => __( 'Modifier l\'{{entity}}'),
- 'search_items' => __( 'Rechercher une {{entity}}'),
- 'not_found' => __( 'Non trouvée'),
- 'not_found_in_trash' => __( 'Non trouvée dans la corbeille'),
- );
- $args = array(
- 'label' => __( '{{Entity}}s'),
- 'description' => __( '{{description}}'),
- 'labels' => $labels,
- 'supports' => array( 'title', 'thumbnail'),
- 'menu_icon' => 'dashicons-admin-multisite',
- 'hierarchical' => false,
- 'public' => true,
- 'has_archive' => false,
- 'rewrite' => array( 'slug' => '{{entity}}s'),
- );
- register_post_type( '{{entity}}s', $args );
- //Inclus le fichier action.php
- require_once(__DIR__.DIRECTORY_SEPARATOR.'functions.php');
- add_rewrite_endpoint( 'action.php', EP_ROOT );
- }
- //Permet de gérer l'affichage du conteneur des champs personnalisés dans l'interface de création d'une nouvelle {{entity}}
- function show_{{entity}}_meta_box() {
- global $post;
- $meta = get_post_meta( $post->ID, '{{entity}}_fields', true );
- require_once(__DIR__.DIRECTORY_SEPARATOR.'{{Entity}}.class.php');
- ${{entity}} = new {{Entity}}();
- ${{entity}}->fromArray($meta);
- ?>
- <input type="hidden" name="{{entity}}_meta_box_nonce" value="<?php echo wp_create_nonce( basename(__FILE__) ); ?>">
- <table id="fieldsSettings">
- {{:fields}}<tr>
- <td><label for="{{value.key}}">{{value.label}}</label></td>
- <td>
- <!-- TODO !! : remplacer name="{{value.key}}" par name="{{entity}}_fields[{{value.key}}]" -->
- {{value.input}}
- </td>
- </tr>{{/:fields}}
- </table>
- <?php
- }
- //Permet de sauvegarder les différents champs personnalisés créés avec le custom post type
- //
- function save_{{entity}}_fields_meta($post_id) {
- if (wp_is_post_revision($post_id))
- return;
- // Check du nonce
- if (!wp_verify_nonce($_POST['{{entity}}_meta_box_nonce'], basename(__FILE__))) return $post_id;
- // Check de l'autosave
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
-
- // Check des permissions
- if ('page' === $_POST['post_type']) {
- if ( !current_user_can('edit_page', $post_id) || !current_user_can('edit_post', $post_id))
- return $post_id;
- }
-
- $old = get_post_meta($post_id, '{{entity}}_fields', true);
- $new = $_POST['{{entity}}_fields'];
- if ($new && $new !== $old) {
- update_post_meta($post_id, '{{entity}}_fields', $new);
- } elseif ('' === $new && $old) {
- delete_post_meta($post_id, '{{entity}}_fields', $old);
- }
- }
- //Permet d'afficher l'intégralité du contenu du formulaire de soumission d'une {{entity}}
- function sys1_{{plugin}}_shortcode($attributes) {
-
- ob_start();
- ?>
- <div id="{{plugin}}-submit-form">
- <input type="hidden" name="{{plugin}}_meta_box_nonce" id="{{plugin}}_meta_box_nonce" value="<?php echo wp_create_nonce( '{{plugin}}' ); ?>">
- {{:fields}}<div>
- <label for="post_title"><span>{{value.label}} *</span></label>
- {{value.input}}
- </div>{{/:fields}}
- <div class="g-recaptcha" id="captcha" data-sitekey=" <?php echo get_option( 'recaptcha_public_{{plugin}}' ) ?>"></div>
- <div class="generalButton" id="submitButton" onclick="sys1_{{plugin}}_save();"><div class="hoverButton">Soumettre</div></div>
- </div>
- <?php
- $output = ob_get_clean();
- return $output;
- }
- // Ajout du sous-menu "Paramètres" dans l'onglet {{Plugin}}, afin de gérer les différents élémentsutiles au plugin (captcha keys, email, shortcode)
- function sys1_{{plugin}}_settings() {
- add_submenu_page(
- 'edit.php?post_type={{entity}}s',
- __('Paramètres - Plugin SYS1 {{Plugin}}s','menu-test'),
- __('Paramètres','menu-test'),
- 'manage_options',
- 'sys1_{{plugin}}_settings',
- 'show_{{plugin}}_settings_page'
- );
- }
- //Ajout des champs de configuration du plugin SYS1 {{Entity}} sur l'onglet de menu {{plugin}}cié
- function sys1_{{plugin}}_admin(){
- add_meta_box(
- // id
- '{{entity}}_meta_box',
- // titre
- 'Informations : {{entity}}',
- //Callback
- 'show_{{entity}}_meta_box',
- //Screen
- '{{entity}}s',
- //Contexte
- 'normal',
- //Priorité
- 'high'
- );
- $customsSettings = array(
- "recaptcha_url_{{plugin}}" => array(
- "title" => "Recaptcha url",
- "placeholder" => "https://www.google.com/recaptcha/api/siteverify"
- ),
- "recaptcha_public_{{plugin}}" => array(
- "title" => "Recaptcha clé publique",
- "placeholder" => "ex: 6LeuNQITAAAAAPGRU7dkrCPIrrR64WPvzMc7pn6Z"
- ),
- "recaptcha_secret_{{plugin}}" => array(
- "title" => "Recaptcha clé privée",
- "placeholder" => "ex: 6LeuNQITAAAAAHwUcbXbyFCUudJKRAjcgNRwlaoE"
- ),
- "api_key_gmaps_geocode" => array(
- "title" => "Geocode clé privée",
- "placeholder" => ""
- ),
- "notification_email_{{plugin}}" => array(
- "title" => "Email notification d'inscription d'{{entity}}",
- "placeholder" => "votre.email@example.fr"
- )
- );
- add_settings_section(
- 'sys1_{{plugin}}_settings_section',
- 'Option plugin {{Entity}}s',
- function(){
- echo '<p>Paramétrage du plugin {{plugin}}</p>';
- },
- 'sys1_{{plugin}}_settings'
- );
- foreach($customsSettings as $slug => $values){
- add_settings_field(
- $slug,
- $values['title'],
- function($args){
- $option = get_option($args[0]);
- echo '<input type="text" id="'. $args[0] .'" name="'. $args[0] .'" value="' . $option . '" class="regular-text ltr" placeholder="'.$values['placeholder'].'" />';
- },
- 'sys1_{{plugin}}_settings',
- 'sys1_{{plugin}}_settings_section',
- array($slug)
- );
- register_setting('sys1_{{plugin}}_settings_group',$slug, 'esc_attr');
- }
- }
- //Gestion de l'affichage de la page des paramètres du plugin des {{Entity}}s.
- function show_{{plugin}}_settings_page() {
- ?>
- <div class='wrap'>
- <h2>Paramètres</h2>
- <hr>
- <div id="shortcodeContainer">
- <ul>
- <li>Afin d'afficher le plugin {{plugin}} sur une page, utilisez le shortcode suivant : <strong>[sys1_{{plugin}}]</strong></li>
- </ul>
- </div>
- <hr>
- <form method='post' action='options.php'>
- <?php
- settings_fields( 'sys1_{{plugin}}_settings_group' );
- do_settings_sections( 'sys1_{{plugin}}_settings' );
- ?>
- <p class='submit'>
- <input name='submit' type='submit' id='submit' class='button-primary' value='<?php _e("Save Changes") ?>' />
- </p>
- </form>
- </div>
- <?php
- }
- // Ajout de la variable action.php pour que Wordpress le trouve et ne l'ignore pas
- function {{plugin}}_add_query_vars($vars){
- $vars[] = "action.php";
- return $vars;
- }
- function action_{{plugin}}_parsing(){
- require_once(__DIR__.DIRECTORY_SEPARATOR.'action.php');
- }
- //Création des différents hooks
- wp_enqueue_script('sys1_{{plugin}}_js', plugin_dir_url(__FILE__) . '/js/main.js?v=1', array('jquery'));
- wp_enqueue_style('sys1_{{plugin}}_css', plugin_dir_url(__FILE__) . '/css/main.css?v=1');
- add_action('admin_init', 'sys1_{{plugin}}_admin', 200);
- add_action('admin_menu', 'sys1_{{plugin}}_settings');
- add_action('save_post', 'save_{{entity}}_fields_meta', 10);
- add_action('init', 'sys1_{{plugin}}_init');
- add_action('parse_request','action_{{plugin}}_parsing');
- add_shortcode('sys1_{{plugin}}', 'sys1_{{plugin}}_shortcode', 10);
- add_filter( 'query_vars', '{{plugin}}_add_query_vars');
|