Minimum Plugin

English Language

Un esempio di plugin per WordPress.

Minimum Plugin è un piccolo plugin, utile ai novizi di WordPress che abbiano intenzione di scrivere un plugin o personalizzare molto il loro sito.

Il mio augurio è che questo articolo gli permetta di risparmiare un po’ del tempo necessario a familiarizzare con WordPress.

MinimumPlugin è composto da un file singolo ( MinimumPlugin.php ) ed è scritto in linguaggio procedurale.
Contiene una pagina amministrativa con un form per 3 campi di input.
È previsto uno shortcode ( MinimumPlugin ) da inserire in una pagina di front-end.
La quantità di codice è contenuta allo stretto indispensabile.

Che cosa fa Minimum Plugin? Ebbene, visualizza un Conto alla Rovescia nella pagina di front-end.

Le regole di WordPress prevedono che il file principale MinimumPlugin.php inizi con una descrizione, l’header.

Riferimenti:
https://developer.wordpress.org/plugins/plugin-basics/header-requirements/
Costruzione automatica dell’header:

/*
 Plugin Name: Minimum Plugin
 Plugin URI: http://wpd.edilweb.eu
 Description: This is an example plugin for beginners. It is very small, it displays a countdown.
 Version: 1.0.0
 Author: wpd.edilweb.eu
 Author URI: http://wpd.edilweb.eu
 License: GPL-2
 License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 Text Domain: MinimumPlugin
 Domain Path: /languages
 */

Poi si aggiunge una precauzione per evitare che il file venga chiamato fuori dall’ambiente WordPress

if ( !defined( 'ABSPATH' )) { exit; }

Una funzione activate per attivare Minimum Plugin.

Riferimenti:
https://codex.wordpress.org/Function_Reference/activate_plugin https://developer.wordpress.org/reference/functions/activate_plugin/

function activate_MinimumPlugin() {}

Una funzione deactivate per disattivare Minimum Plugin.

Riferimenti:
https://codex.wordpress.org/Function_Reference/deactivate_plugins
https://developer.wordpress.org/reference/functions/deactivate_plugins/

function deactivate_MinimumPlugin(){}

Una funzione per richiamare TextDomain che nel nostro caso è uguale al nome del plugin . La funzione è necessaria per localizzare il plugin.

Riferimenti:
https://codex.wordpress.org/Function_Reference/load_plugin_textdomain
https://developer.wordpress.org/reference/functions/load_plugin_textdomain/

function textDomain_MinimumPlugin() {
     global $pP;
     load_plugin_textdomain( $pP->plugin_name );
 }
donna in piedi

Registriamo in WordPress una funzione che punta alla nostra funzione di convalida del form amministrativo, register_setting_MinimumPlugin()

Riferimenti alla pagina amministrativa:
https://wisdmlabs.com/blog/create-settings-options-page-for-wordpress-plugin/
https://codex.wordpress.org/Function_Reference/add_settings_field
http://qnimate.com/wordpress-settings-api-a-comprehensive-developers-guide/

function register_setting_MinimumPlugin() {
      global $pP;
      register_setting( $pP->plugin_name, $pP->plugin_name,
'validate_settings_MinimumPlugin' );
  }

Adesso vanno impostati i link alla pagina amministrativa.
Come altre funzioni che scriviamo anche queste hanno bisogno di un “hook” di WordPress, un aggancio al CMS. Nella sezione Main Code del file dopo le dichiarazioni di funzione, ci sono i richiami agli “hook” di WordPress.
Le prossime due funzioni fanno comparire il link settings del plugin nei Plugin installati ed il link MinimumPlugin nelle Impostazioni.

Riferimenti:
https://codex.wordpress.org/Function_Reference/add_options_page

Riferimenti ad Hook, Actions e Filters:
https://docs.presscustomizr.com/article/26-wordpress-actions-filters-and-hooks-a-guide-for-non-developers

function add_filter_link_MinimumPlugin( $links ) {
    $mylinks = array( '<a href="' 
    . admin_url( 'options-general.php?page=' 
    . plugin_basename(_FILE_) ) . '">Settings>/a' );

    return array_merge( $links, $mylinks );
}

function add_options_page_MinimumPlugin(){
     global $pP;
     $page_title = $pP->plugin_name;
     $menu_title = $pP->plugin_name;
     $capability = 'manage_options';
     $menu_slug = plugin_basename(_FILE_); 
     if( $pP->cheForm === 'simple' ){
         $function = 'display_setup_MinimumPlugin';
     }
     elseif ( $pP->cheForm === 'complex' ) {
          $function = 'display_setup2_MinimumPlugin';
     }    
    add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function );
 }

Dopo la dichiarazione, la pagina amministrativa viene resa disponibile per WordPress con la funzione display_setup2_MinimumPlugin() .
Dentro c’è tutto l’html amministrativo, ma prima bisogna accedere ai dati archiviati nel database che riguardano questo plugin, nella tabella #_options .
Lo facciamo mediante la funzione di WordPress get_option( $var ) .
Le Options amministrative dei plugin vengono archiviate in questa tabella ( #_options ), per default e tranne la prima volta del plugin, sono già presenti nel database a questo punto dell’esecuzione.
Le opzioni iniziali di Minimum Plugin vengono impostate una volta soltanto, nella sezione Main Code di questo file.
Riferimenti alla tabella e al database:
https://codex.wordpress.org/Database_Description


L’ Url del form è ancora uno dei servizi di WordPress, la funzione admin_url()
Riferimenti:
https://codex.wordpress.org/Function_Reference/admin_url


È necessario aggiungere al form alcuni campi di controllo e sicurezza.
Funzione di WordPress settings_fields( $arg );
Riferimenti:
https://codex.wordpress.org/Function_Reference/settings_fields
https://developer.wordpress.org/reference/functions/settings_fields/


I campi di input del form amministrativo di Minimum Plugin, che in questo caso invia al server un array con tre valori, sono simili a questo:

<td>
  <input 
    type="text" 
    name="<?php echo $plugin_option; ?>[mpTxt]" 
<!-- name_of_the_option[key_option] --> 
    id="mp_txt" 
    title="Countdown event" 
    value="<?php echo $db_options['mpTxt']; ?>" 
<!-- value of the option from database -->
    required>
</td>

Il pulsante di submit del form si ottiene dalla funzione di WordPress submit_button();

display_setup2_MinimumPlugin() La funzione
function display_setup2_MinimumPlugin(){
     global $pP;
     $url = admin_url( 'options.php' );
     $db_options = get_option( $pP->plugin_name );
 /*  translations    */
$cEvent = __( 'Countdown event', 'MinimumPlugin' ); 
$cDate = __( 'Countdown departure date', 'MinimumPlugin' ); 
$cDini = __( 'Countdown start', 'MinimumPlugin' );
$cTime = __( 'Countdown start time', 'MinimumPlugin' );
$cTini = __( 'Time start', 'MinimumPlugin' );

$toBw = <<<EOF
<div class="wrap">
<h1>Minimum Plugin Settings</h1>
<form action="{$url}" method="post" 
id="MinimumPlugin-form">
EOF;
     echo $toBw;

     settings_fields( $pP->plugin_name );

$toBw2 = <<<BW2
<table class="form-table">
<tbody>
<tr>
<th scope="row">
<label for="mp_txt">Your Event </label>
</th>
<td>
<input type="text" name="{$pP->plugin_name}[mpTxt]" 
id="mp_txt" title="{$cEvent}" 
value="{$db_options['mpTxt']}" required>
</td>
</tr>
<tr>
<th scope="row">
<label for="mp_Data">{$cDate} </label>
</th>
<td>
<input type="date" name="{$pP->plugin_name}[mpData]" 
id="mp_Data"  title="{$cDini}" 
value="{$db_options['mpData']}" required>
</td>
</tr>
<tr>
<th scope="row">
<label for="mp_Time">{$cTime} </label>
</th>
<td>
<input type="time" name="{$pP->plugin_name}[mpTime]" 
id="mp_Time"  title="{$cTini}" 
value="{$db_options['mpTime']}" 
required>
</td>
</tr>
</tbody>
</table>
BW2;
echo $toBw2; 

submit_button();

$toBw3 = <<<BW3
     </form>
 </div>
 BW3;
 echo $toBw3;
}

 

Gli input del form vengono convalidati prima che siano registrati nel database. Funzione validate_settings_MinimumPlugin( $input )

function validate_settings_MinimumPlugin( $input ){
     /*  here the code to validate form     */    
     global $pP; 
if( $pP->cheForm === 'simple' ){ /*  single option  1 field */ 
  $valid = sanitize_text_field( $input );
}
elseif ( $pP->cheForm === 'complex' ) { /*  3 fields    */     
 $valid = []; 
$valid[ 'mpTxt' ] = sanitize_text_field( $input[ 'mpTxt' ]);
$valid[ 'mpData' ] = sanitize_text_field( $input[ 'mpData' ]);
$valid[ 'mpTime' ] = sanitize_text_field( $input[ 'mpTime' ]);
} 
else {
die('error');
}
return $valid;
}

Esaurite le funzioni amministrative registriamo in WordPress una funzione che segnala la presenza eventuale di uno shortcode , shortcodes_MinimumPlugin_init() .

Riferimenti:
https://codex.wordpress.org/Function_Reference/add_shortcode
https://developer.wordpress.org/reference/functions/add_shortcode/

function shortcodes_MinimumPlugin_init(){
     global $pP;
     add_shortcode($pP->shortcode,
'shortcodes_MinimumPlugin_exec');
 }

Aggiungiamo una funzione per l’esecuzione dello shortcode nel front-end. shortcodes_MinimumPlugin_exec()

Funzione shortcodes_MinimumPlugin_exec()
function shortcodes_MinimumPlugin_exec(){
 global $pP;
 $db_options = get_option( $pP->plugin_name );
   switch ($pP->cheForm) {
    case 'complex':   /* Here $db_options is an array */
$a = <<<EOF
<p style="font-size: 20px; margin-bottom: 0;">{$db_options['mpTxt']}<br>{$db_options['mpData']}   time {$db_options['mpTime']}<br><br>Time to end:</p>
<p style="height: 50px; font-size: 30px; margin-top: 0px;" id="idMinPlug"></p>
<script>
var dateFromDb = '{$db_options['mpData']}', timeFromDb = '{$db_options['mpTime']}';var countDownDate = new Date( dateFromDb + ' ' + timeFromDb ).getTime();
var xMinimumPlugin = setInterval(function () {var now = new Date().getTime();var distance = countDownDate - now;if (distance > 0) {var days = Math.floor(distance / (1000 * 60 * 60 * 24));var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));var seconds = Math.floor((distance % (1000 * 60)) / 1000);idMinPlug.innerHTML = days + "d - " + hours + "h - " + minutes + "m : " + seconds + "s ";} else {clearInterval(xMinimumPlugin);idMinPlug.innerHTML = "EXPIRED";}}, 1000);
</script>
EOF;
   break;
   case 'simple':  /*  Here $db_options is a simple variable   */
$a = <<<EOF
<p style="font-size: 20px; margin-bottom: 0;">Countdown start: <br>day {$db_options}   <br><span style="font-size: 13px;">Time to end:</span></p>
<p style="height: 50px; font-size: 30px; margin-top: 0px;" id="idMinPlug"></p>
<script>
var dateFromDb = '{$db_options}', timeFromDb = '00:00';var countDownDate = new Date( dateFromDb + ' ' + timeFromDb ).getTime();
var xMinimumPlugin = setInterval(function () {var now = new Date().getTime();var distance = countDownDate - now;if (distance > 0) {var days = Math.floor(distance / (1000 * 60 * 60 * 24));var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));var seconds = Math.floor((distance % (1000 * 60)) / 1000);idMinPlug.innerHTML = days + "d - " + hours + "h - " + minutes + "m : " + seconds + "s ";} else {clearInterval(xMinimumPlugin);idMinPlug.innerHTML = "EXPIRED";}}, 1000);
</script>
EOF;
    break;

   default:
     $a = 'error "shortcodes_MinimumPlugin_exec"';
     break;
    }
    
    return $a;
}

 

Composizione_spaziale_Katarzyna_Kobro

A questo punto dobbiamo eseguire le funzioni dichiarate prima.
Attivazione e deattivazione del plugin :

Riferimenti:
https://codex.wordpress.org/Function_Reference/register_activation_hook

$pP = new stdClass;
$pP->plugin_name = 'MinimumPlugin';
$pP->version = '1.0.0';
//  $pP->cheForm = 'simple';        /*  simple = form admin with one field */
$pP->cheForm = 'complex';           /*  complex = form admin with more than one field    */
$pP->shortcode = 'MinimumPlugin';
register_activation_hook( __FILE__, 'activate_MinimumPlugin' );
register_deactivation_hook( __FILE__, 'deactivate_MinimumPlugin' );

Agganci delle funzioni ad azioni specifiche

Riferimenti:
https://codex.wordpress.org/Plugin_API/Action_Reference
https://developer.wordpress.org/reference/functions/add_action/

add_action( 'plugins_loaded', 'textDomain_MinimumPlugin' );
add_action('init', 'shortcodes_MinimumPlugin_init');
add_action( 'admin_init', 'register_setting_MinimumPlugin' );
add_action( 'admin_menu', 'add_options_page_MinimumPlugin' ); 

Aggancio di una funzione ad uno specifico filtro di WordPress.
Riferimenti:
https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)

add_filter( 'plugin_action_links_'.
 plugin_basename(__FILE__),
 'add_filter_link_MinimumPlugin' ); 

Per ultimo c’è l’inserimento nel database delle opzioni amministrative iniziali. Questo blocco viene eseguito una volta soltanto.

if( false == get_option( $pP->plugin_name )){
    if( $pP->cheForm === 'simple' ){  /*  single option  1 field */
        add_option($pP->plugin_name, '2020-12-25' );
    }
    elseif ( $pP->cheForm === 'complex' ) { /*  3 fields    */
        $ppIniVal = [ 'mpTxt' => 'Wedding Anniversary', 
                'mpData' => '2020-12-25', 'mpTime' => '00:00' ];
        add_option( $pP->plugin_name, ( array )$ppIniVal );
    }
    else { die('error'); }
} 
MinimumPlugin.php Il file intero
/*
Plugin Name: Minimum Plugin
Plugin URI: http://wpd.edilweb.eu
Description: This is an example plugin for beginners. It is very small, it displays a countdown.
Version: 1.0.0
Author: wpd.edilweb.eu
Author URI: http://wpd.edilweb.eu
License: GPL-2
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
Text Domain: MinimumPlugin
Domain Path: /languages
*/

/**
 * Copyright 2019
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

if ( ! defined( 'ABSPATH' ) ) {	exit; }

function activate_MinimumPlugin() {}

function deactivate_MinimumPlugin(){}

function textDomain_MinimumPlugin() {
    global $pP;
    load_plugin_textdomain( $pP->plugin_name );
}

function register_setting_MinimumPlugin() {
    global $pP;
    register_setting( $pP->plugin_name, $pP->plugin_name, 'validate_settings_MinimumPlugin' );
}

function add_options_page_MinimumPlugin(){
    global $pP;
    $page_title = $pP->plugin_name;
    $menu_title = $pP->plugin_name;
    $capability = 'manage_options';
    $menu_slug = plugin_basename(__FILE__); 
    if( $pP->cheForm === 'simple' ){
        $function = 'display_setup_MinimumPlugin';
    }
    elseif ( $pP->cheForm === 'complex' ) {
         $function = 'display_setup2_MinimumPlugin';
    }    
   add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function );
}


function display_setup_MinimumPlugin() {
    global $pP;
    $url = admin_url( 'options.php' );
    $db_options = get_option($pP->plugin_name);
    
    $toBw = <<<EOF
   <div class="wrap">    
    <h1>{$pP->plugin_name} Settings</h1>
    <form action="{$url}" method="post" id="MinimumPlugin-form">
EOF;
    echo $toBw;
    
    settings_fields( $pP->plugin_name );
    
    $toBw2 = <<<BW2
        <table class="form-table">
            <tbody>
                <tr>
                    <th scope="row">
                        <label for="mp_Data">Countdown departure date </label>
                    </th>
                    <td>
                        <input type="date" name="{$pP->plugin_name}" id="mp_Data"  title="countdown start" value="{$db_options}" required>
                    </td>
                </tr>
            </tbody>
        </table>
BW2;
    echo $toBw2;
    
    submit_button();

    $toBw3 = <<<BW3
    </form>
</div>
BW3;
    echo $toBw3;
}

function display_setup2_MinimumPlugin(){
    global $pP;
    $url = admin_url( 'options.php' );
    $db_options = get_option( $pP->plugin_name );
    
    /*  translations    */
    $cEvent = __( 'Countdown event', 'MinimumPlugin' );
    $cDate = __( 'Countdown departure date', 'MinimumPlugin' );
    $cDini = __( 'Countdown start', 'MinimumPlugin' );
    $cTime = __( 'Countdown start time', 'MinimumPlugin' );
    $cTini = __( 'Time start', 'MinimumPlugin' );
    
    $toBw = <<<EOF
   <div class="wrap">    
    <h1>Minimum Plugin Settings</h1>
    <form action="{$url}" method="post" id="MinimumPlugin-form">
EOF;
    echo $toBw;
    
    settings_fields( $pP->plugin_name );
    
    $toBw2 = <<<BW2
        <table class="form-table">
            <tbody>
                <tr>
                    <th scope="row">
                        <label for="mp_txt">Your Event </label>
                    </th>
                    <td>
                        <input type="text" name="{$pP->plugin_name}[mpTxt]" id="mp_txt" title="{$cEvent}" value="{$db_options['mpTxt']}" required>
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        <label for="mp_Data">{$cDate} </label>
                    </th>
                    <td>
                        <input type="date" name="{$pP->plugin_name}[mpData]" id="mp_Data"  title="{$cDini}" value="{$db_options['mpData']}" required>
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        <label for="mp_Time">{$cTime} </label>
                    </th>
                    <td>
                        <input type="time" name="{$pP->plugin_name}[mpTime]" id="mp_Time"  title="{$cTini}" value="{$db_options['mpTime']}" required>
                    </td>
                </tr>
            </tbody>
        </table>
BW2;
    echo $toBw2;
    
    submit_button();

    $toBw3 = <<<BW3
    </form>
</div>
BW3;
    echo $toBw3;
}


function validate_settings_MinimumPlugin( $input ){
    /*  here the code to validate form     */    
    global $pP; 
    
    if( $pP->cheForm === 'simple' ){                        /*  single option  1 field */
        $valid = sanitize_text_field( $input );
    }
    elseif ( $pP->cheForm === 'complex' ) {                 /*  3 fields    */
        $valid = [];
        $valid[ 'mpTxt' ] = sanitize_text_field( $input[ 'mpTxt' ]);
        $valid[ 'mpData' ] = sanitize_text_field( $input[ 'mpData' ]);
        $valid[ 'mpTime' ] = sanitize_text_field( $input[ 'mpTime' ]);
    }
    else { die('error'); }
    
    return $valid;
}

function add_filter_link_MinimumPlugin( $links ) {
    $mylinks = array( '<a href="' . admin_url( 'options-general.php?page=' . plugin_basename(__FILE__) ) . '">Settings</a>' );
    return array_merge( $links, $mylinks );
}


function shortcodes_MinimumPlugin_init(){
    global $pP;
    add_shortcode($pP->shortcode, 'shortcodes_MinimumPlugin_exec');
}


function shortcodes_MinimumPlugin_exec(){
    global $pP;
    $db_options = get_option( $pP->plugin_name );
    
    switch ($pP->cheForm) {
        case 'complex':         /* Here $db_options is an array */
$a = <<<EOF
<p style="font-size: 20px; margin-bottom: 0;">{$db_options['mpTxt']}<br>{$db_options['mpData']}   time {$db_options['mpTime']}<br><br>Time to end:</p>
<p style="height: 50px; font-size: 30px; margin-top: 0px;" id="idMinPlug"></p>
<script>
var dateFromDb = '{$db_options['mpData']}', timeFromDb = '{$db_options['mpTime']}';var countDownDate = new Date( dateFromDb + ' ' + timeFromDb ).getTime();
var xMinimumPlugin = setInterval(function () {var now = new Date().getTime();var distance = countDownDate - now;if (distance > 0) {var days = Math.floor(distance / (1000 * 60 * 60 * 24));var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));var seconds = Math.floor((distance % (1000 * 60)) / 1000);idMinPlug.innerHTML = days + "d - " + hours + "h - " + minutes + "m : " + seconds + "s ";} else {clearInterval(xMinimumPlugin);idMinPlug.innerHTML = "EXPIRED";}}, 1000);
</script>
EOF;
            break;
        
        case 'simple':          /*  Here $db_options is a simple variable   */
$a = <<<EOF
<p style="font-size: 20px; margin-bottom: 0;">Countdown start: <br>day {$db_options}   <br><span style="font-size: 13px;">Time to end:</span></p>
<p style="height: 50px; font-size: 30px; margin-top: 0px;" id="idMinPlug"></p>
<script>
var dateFromDb = '{$db_options}', timeFromDb = '00:00';var countDownDate = new Date( dateFromDb + ' ' + timeFromDb ).getTime();
var xMinimumPlugin = setInterval(function () {var now = new Date().getTime();var distance = countDownDate - now;if (distance > 0) {var days = Math.floor(distance / (1000 * 60 * 60 * 24));var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));var seconds = Math.floor((distance % (1000 * 60)) / 1000);idMinPlug.innerHTML = days + "d - " + hours + "h - " + minutes + "m : " + seconds + "s ";} else {clearInterval(xMinimumPlugin);idMinPlug.innerHTML = "EXPIRED";}}, 1000);
</script>
EOF;
            break;

        default:
            $a = 'error "shortcodes_MinimumPlugin_exec"';
            break;
    }
    
    return $a;
}


/*                                      
 *                       MAIN CODE
 * 
 * ---------------------- warning -------------------------
 * If you change the default  ( $pP->cheForm = 'complex'; )
 * with                       ( $pP->cheForm = 'simple'; ) 
 * first deactivate the plugin or the relative db option
 * --------------------------------------------------------       
 * 
 */


$pP = new stdClass;
$pP->plugin_name = 'MinimumPlugin';
$pP->version = '1.0.0';
//  $pP->cheForm = 'simple';        /*  simple = form admin with one field               */
$pP->cheForm = 'complex';           /*  complex = form admin with more than one field    */
$pP->shortcode = 'MinimumPlugin';


register_activation_hook( __FILE__, 'activate_MinimumPlugin' );
register_deactivation_hook( __FILE__, 'deactivate_MinimumPlugin' );

/*  aggiungere il percorso del file .mo In questo plugin di test non ce ne sono */
add_action( 'plugins_loaded', 'textDomain_MinimumPlugin' ); //*

add_action('init', 'shortcodes_MinimumPlugin_init');

add_action( 'admin_init', 'register_setting_MinimumPlugin' );   //*

/*  aggiunge voce di menu. Submenu   */
add_action( 'admin_menu', 'add_options_page_MinimumPlugin' );   //*

/*      aggiunge solo link settings  */
add_filter( 'plugin_action_links_'. plugin_basename(__FILE__), 'add_filter_link_MinimumPlugin' );   //*
    
   
if( false == get_option( $pP->plugin_name )){
    if( $pP->cheForm === 'simple' ){                        /*  single option  1 field */
        add_option($pP->plugin_name, '2020-12-25' );
    }
    elseif ( $pP->cheForm === 'complex' ) {                 /*  3 fields    */
        $ppIniVal = [ 'mpTxt' => 'Wedding Anniversary', 'mpData' => '2019-12-25', 'mpTime' => '00:00' ];
        add_option( $pP->plugin_name, ( array )$ppIniVal );
    }
    else { die('error'); }
}


Scarica il plugin. Si installa e attiva come gli altri. Shortcode [MinimumPlugin]

DownLoad MinimumPlugin zip

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *