Last active
December 27, 2017 10:25
-
-
Save AndreaBarghigiani/a007d5dd8f1c5cbd1b68ca2b4abc2ca1 to your computer and use it in GitHub Desktop.
In questi blocchi di codice mostro come sia possibile implementare la libreria TGM Plugin Activation una volta caricata all'interno della cartella del tema. Maggiori informazioni nell'articolo dedicato: https://skillsandmore.org/richiedi-plugin-per-tema-tgm-plugin-activation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Apertura PHP inserita solo per colorazione sintassi | |
//Aggiungo la funzione sam_tgm_plugin() al corretto Hook | |
add_action( 'tgmpa_register', 'sam_tgm_plugin' ); | |
function sam_tgm_plugin(){ | |
//Richiesta plugin e configurazione | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Apertura PHP inserita solo per colorazione sintassi | |
add_action( 'tgmpa_register', 'sam_tgm_plugin' ); | |
function sam_tgm_plugin(){ | |
$plugins = array( | |
//Richiesta plugin | |
); | |
//Configuro la classe in modo da personalizzare Notice e voci menu | |
$config = array( | |
'id' => 'sam-tgmpa', // Specifica un ID univoco per evitare problemi con altre istanze di TGMPA | |
'default_path' => '', // Il percorso di default dove trovare i plugin caricati con il tema. | |
'menu' => 'tgmpa-install-plugins', // Fornisci uno slug per la pagina opzioni. | |
'parent_slug' => 'themes.php', // Definisci il genitore della pagina opzioni nel menu. | |
'capability' => 'edit_theme_options', // Specifica la capability necessaria per consultare la pagina opzioni | |
'has_notices' => true, // Scegli se mostrare o meno le notice. | |
'dismissable' => true, // Se impostato a false, l'utente non potrà chiudere la notice. | |
'dismiss_msg' => '', // Se 'dismissable' è false, questo messaggio verrà mostrato in alto. | |
'is_automatic' => false, // Scegli se attivare automaticamente i plugin installati | |
'message' => '', // Messaggio da mostrare prima della tabella dei plugin. | |
//Tutta la traduzione delle stringhe è facoltativa, puoi anche rimuovere tutto il codice qua sotto | |
'strings' => array( | |
'page_title' => __( 'Install Required Plugins', 'theme-slug' ), | |
'menu_title' => __( 'Install Plugins', 'theme-slug' ), | |
'installing' => __( 'Installing Plugin: %s', 'theme-slug' ), | |
'updating' => __( 'Updating Plugin: %s', 'theme-slug' ), | |
'oops' => __( 'Something went wrong with the plugin API.', 'theme-slug' ), | |
'notice_can_install_required' => _n_noop( | |
'This theme requires the following plugin: %1$s.', | |
'This theme requires the following plugins: %1$s.', | |
'theme-slug' | |
), | |
'notice_can_install_recommended' => _n_noop( | |
'This theme recommends the following plugin: %1$s.', | |
'This theme recommends the following plugins: %1$s.', | |
'theme-slug' | |
), | |
'notice_ask_to_update' => _n_noop( | |
'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', | |
'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', | |
'theme-slug' | |
), | |
'notice_ask_to_update_maybe' => _n_noop( | |
'There is an update available for: %1$s.', | |
'There are updates available for the following plugins: %1$s.', | |
'theme-slug' | |
), | |
'notice_can_activate_required' => _n_noop( | |
'The following required plugin is currently inactive: %1$s.', | |
'The following required plugins are currently inactive: %1$s.', | |
'theme-slug' | |
), | |
'notice_can_activate_recommended' => _n_noop( | |
'The following recommended plugin is currently inactive: %1$s.', | |
'The following recommended plugins are currently inactive: %1$s.', | |
'theme-slug' | |
), | |
'install_link' => _n_noop( | |
'Begin installing plugin', | |
'Begin installing plugins', | |
'theme-slug' | |
), | |
'update_link' => _n_noop( | |
'Begin updating plugin', | |
'Begin updating plugins', | |
'theme-slug' | |
), | |
'activate_link' => _n_noop( | |
'Begin activating plugin', | |
'Begin activating plugins', | |
'theme-slug' | |
), | |
'plugin_activated' => __( 'Plugin activated successfully.', 'theme-slug' ), | |
'activated_successfully' => __( 'The following plugin was activated successfully:', 'theme-slug' ), | |
'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'theme-slug' ), | |
'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'theme-slug' ), | |
'complete' => __( 'All plugins installed and activated successfully. %1$s', 'theme-slug' ), | |
'dismiss' => __( 'Dismiss this notice', 'theme-slug' ), | |
'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'theme-slug' ), | |
'contact_admin' => __( 'Please contact the administrator of this site for help.', 'theme-slug' ), | |
'nag_type' => 'notice-warning', // Determines admin notice type - can only be one of the typical WP notice classes, such as 'updated', 'update-nag', 'notice-warning', 'notice-info' or 'error'. Some of which may not work as expected in older WP versions. | |
), | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Apertura PHP inserita solo per colorazione sintassi | |
add_action( 'tgmpa_register', 'sam_tgm_plugin' ); | |
function sam_tgm_plugin(){ | |
$plugins = array( | |
//Richiesta plugin | |
); | |
$config = array( | |
//Configurazione UI | |
); | |
//Attivo la richiesta di plugin e la personalizzazione della UI | |
tgmpa( $plugins, $config ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Apertura PHP inserita solo per colorazione sintassi | |
/** | |
* Includo la libreria TGM Plugin Activation | |
* Nota che la libreria è stata inclusa all'interno della cartella inc/ presente nel tema | |
*/ | |
require_once get_template_directory() . '/inc/class-tgm-plugin-activation.php'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Apertura PHP inserita solo per colorazione sintassi | |
add_action( 'tgmpa_register', 'sam_tgm_plugin' ); | |
function sam_tgm_plugin(){ | |
$plugins = array( | |
// Ecco come puoi includere un plugin presente all'interno della directory WordPress | |
array( | |
'name' => 'BuddyPress', | |
'slug' => 'buddypress', | |
'required' => true, | |
), | |
array( | |
'name' => 'WooCommerce', | |
'slug' => 'woocommerce', | |
'required' => false, | |
), | |
//Questo e' un esempio per capire come caricare un plugin fuori da WP.org | |
array( | |
'name' => 'Il mio Plugin', | |
'slug' => 'il-mio-plugin', | |
'source' => 'https://percorso.plugin.org/', | |
'required' => true, | |
'external_url' => 'https://github.com/plugin/' //Link di ritorno | |
), | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Apertura PHP inserita solo per colorazione sintassi | |
/* Questo file contiene il codice completo presentato nell'articolo */ | |
add_action( 'tgmpa_register', 'sam_tgm_plugin' ); | |
function sam_tgm_plugin(){ | |
$plugins = array( | |
// Ecco come puoi includere un plugin presente all'interno della directory WordPress | |
array( | |
'name' => 'BuddyPress', | |
'slug' => 'buddypress', | |
'required' => true, | |
), | |
array( | |
'name' => 'WooCommerce', | |
'slug' => 'woocommerce', | |
'required' => false, | |
), | |
//Questo e' un esempio per capire come caricare un plugin fuori da WP.org | |
array( | |
'name' => 'Il mio Plugin', | |
'slug' => 'il-mio-plugin', | |
'source' => 'https://percorso.plugin.org/', | |
'required' => true, | |
'external_url' => 'https://github.com/plugin/' //Link di ritorno | |
), | |
); | |
$config = array( | |
'id' => 'tgmpa', // Unique ID for hashing notices for multiple instances of TGMPA. | |
'default_path' => '', // Default absolute path to bundled plugins. | |
'menu' => 'tgmpa-install-plugins', // Menu slug. | |
'parent_slug' => 'themes.php', // Parent menu slug. | |
'capability' => 'edit_theme_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used. | |
'has_notices' => true, // Show admin notices or not. | |
'dismissable' => true, // If false, a user cannot dismiss the nag message. | |
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag. | |
'is_automatic' => false, // Automatically activate plugins after installation or not. | |
'message' => '', // Message to output right before the plugins table. | |
'strings' => array( | |
'page_title' => __( 'Install Required Plugins', 'theme-slug' ), | |
'menu_title' => __( 'Install Plugins', 'theme-slug' ), | |
'installing' => __( 'Installing Plugin: %s', 'theme-slug' ), | |
'updating' => __( 'Updating Plugin: %s', 'theme-slug' ), | |
'oops' => __( 'Something went wrong with the plugin API.', 'theme-slug' ), | |
'notice_can_install_required' => _n_noop( | |
'This theme requires the following plugin: %1$s.', | |
'This theme requires the following plugins: %1$s.', | |
'theme-slug' | |
), | |
'notice_can_install_recommended' => _n_noop( | |
'This theme recommends the following plugin: %1$s.', | |
'This theme recommends the following plugins: %1$s.', | |
'theme-slug' | |
), | |
'notice_ask_to_update' => _n_noop( | |
'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', | |
'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', | |
'theme-slug' | |
), | |
'notice_ask_to_update_maybe' => _n_noop( | |
'There is an update available for: %1$s.', | |
'There are updates available for the following plugins: %1$s.', | |
'theme-slug' | |
), | |
'notice_can_activate_required' => _n_noop( | |
'The following required plugin is currently inactive: %1$s.', | |
'The following required plugins are currently inactive: %1$s.', | |
'theme-slug' | |
), | |
'notice_can_activate_recommended' => _n_noop( | |
'The following recommended plugin is currently inactive: %1$s.', | |
'The following recommended plugins are currently inactive: %1$s.', | |
'theme-slug' | |
), | |
'install_link' => _n_noop( | |
'Begin installing plugin', | |
'Begin installing plugins', | |
'theme-slug' | |
), | |
'update_link' => _n_noop( | |
'Begin updating plugin', | |
'Begin updating plugins', | |
'theme-slug' | |
), | |
'activate_link' => _n_noop( | |
'Begin activating plugin', | |
'Begin activating plugins', | |
'theme-slug' | |
), | |
'plugin_activated' => __( 'Plugin activated successfully.', 'theme-slug' ), | |
'activated_successfully' => __( 'The following plugin was activated successfully:', 'theme-slug' ), | |
'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'theme-slug' ), | |
'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'theme-slug' ), | |
'complete' => __( 'All plugins installed and activated successfully. %1$s', 'theme-slug' ), | |
'dismiss' => __( 'Dismiss this notice', 'theme-slug' ), | |
'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'theme-slug' ), | |
'contact_admin' => __( 'Please contact the administrator of this site for help.', 'theme-slug' ), | |
'nag_type' => 'notice-warning', // Determines admin notice type - can only be one of the typical WP notice classes, such as 'updated', 'update-nag', 'notice-warning', 'notice-info' or 'error'. Some of which may not work as expected in older WP versions. | |
), | |
); | |
//Attivo la richiesta di plugin e la personalizzazione della UI | |
tgmpa( $plugins, $config ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment