Home › Forum › Plugin e temi di WP › Creazione Plugin Semplice
-
AutorePost
-
-
16 Marzo 2017 alle 17:06 #31333robyonePartecipante
Ciao ragazzi, sto utilizzando la versione 4.7.3 di WordPress. Devo creare un plugin che mostra nel sigle.php delle porzioni di codice. Ho seguito la guida presente sul codex:
codex.wordpress.org/Creating_Options_Pages
Fin qua sono riuscito a creare la pagina di amministrazione del backend, non so come mostrare i valori in pagina, ossia come estrarre i valori presenti nel form del backend.
Ho seguito altre guide sul codex ma senza soluzione, come posso proseguire? Grazie in anticipo
Lascio il codice che sono riuscito a creare, cerco di commentarlo il più possibile
Intestazione
<?php
/**
* Plugin Name: robyone
* Plugin URI: http://test.com
* Description: Importare dati in robyone
* Version: 1.0.0
* Author: Robyone
* Author URI: http://test.com
* License: GPL2
*/
?>
<?php
// Creo le impostazione del plugin
add_action('admin_menu', 'my_cool_plugin_create_menu');
function my_cool_plugin_create_menu() {
//creo una voce di menu di amministrazione
add_menu_page(
'Gestione robyone',
'robyone impostazioni',
'administrator', __FILE__,
'my_cool_plugin_settings_page' ,
plugins_url('images/robyone_icon.png', __FILE__)
);
//richiamo la funzione che registra le impostazioni
add_action( 'admin_init', 'register_my_cool_plugin_settings' );
}
function register_my_cool_plugin_settings() {
//registro le impostazioni
register_setting( 'my-cool-plugin-settings-group', 'new_option_name' );
register_setting( 'my-cool-plugin-settings-group', 'some_other_option' );
register_setting( 'my-cool-plugin-settings-group', 'option_etc' );
}
function my_cool_plugin_settings_page() {
?>
<div class="wrap">
<h1>robyone</h1>
<p>Selezionare i custom filed da mostrare nelll'header della pagina</p>
<p/>I dati verranno mostrati nelle singole pagine e nei singoli articoli</p>
<form method="post" action="options.php">
<?php settings_fields( 'my-cool-plugin-settings-group' ); ?>
<?php do_settings_sections( 'my-cool-plugin-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Pagine</th>
<td>
<input type="checkbox" name="new_option_name" value="Custom Field Uno" />
<input type="checkbox" name="new_option_name" value="Custom Field Due" />
</td>
</tr>
<tr valign="top">
<th scope="row">Articoli</th>
<td>
<input type="text" name="some_other_option" value="Custom Field Uno" />
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
<?php
add_action( 'wp_head', 'data_layer_custom' );
function data_layer_custom() {
if( is_single() ) {
?>
Mostrare qui i custom field selezionati nel back end
<?php
}
}
-
16 Marzo 2017 alle 19:32 #121410SteveAglAmministratore del forum
Leggendo i metadati creati e salvati in backend con get_options
Una bella guida sul’uso delle Setting API è questa (in due parti)
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.