Created
December 22, 2024 19:53
-
-
Save gonzalesc/af913aa1a04e5707e7f2a8804d5a9789 to your computer and use it in GitHub Desktop.
New Custom Plugin - Example plugin
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 | |
/** | |
* @link https://www.letsgodev.com/ | |
* @since 1.0.0 | |
* @package Plugins/LetsGoDev/PluginExample | |
* | |
* Plugin Name: Plugin Example | |
* Plugin URI: https://www.letsgodev.com/ | |
* Description: This plugin is an example | |
* Version: 1.0.0 | |
* Author: Lets Go Dev | |
* Author URI: https://www.letsgodev.com/ | |
* Developer: Alexander Gonzales | |
* Developer URI: https://vcard.gonzalesc.org/ | |
* License: GPL-3.0+ | |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt | |
* Text Domain: custom plugin, example plugin, create plugin | |
* WP stable tag: 6.5.0 | |
* WP requires at least: 6.5.0 | |
* WP tested up to: 6.7.0 | |
*/ | |
add_action( 'admin_notices', 'showAdminNotice' ); | |
/** | |
* Show a notice in WPAdmin | |
* @return void | |
*/ | |
function showAdminNotice(): void { | |
printf( | |
'<div class="notice notice-warning is-dismissible"><p>%s - %s</p></div>', | |
esc_html__( 'Hola, este es tu mensaje personalizado', 'letsgo' ), | |
get_option('my_custom_plugin', '') | |
); | |
} | |
add_filter( 'the_content', 'replaceContent' ); | |
/** | |
* Replace content using the_content hook | |
* @param string $content | |
* @return string | |
*/ | |
function replaceContent( string $content ): string { | |
return str_replace( 'example page', 'My Custom Plugin', $content ); | |
} | |
register_activation_hook( __FILE__, 'processActivation' ); | |
register_deactivation_hook( __FILE__, 'processDeactivation' ); | |
function processActivation(): void { | |
update_option( 'my_custom_plugin', 'Activado' ); | |
} | |
function processDeactivation(): void { | |
delete_option( 'my_custom_plugin' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment