Skip to content

Commit

Permalink
Merge pull request #17 from TukuToi/develop
Browse files Browse the repository at this point in the history
4.0.0
  • Loading branch information
smileBeda authored Feb 20, 2022
2 parents 05d62e6 + bfdc3c7 commit e4e2354
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 173 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2022-02-19
### Changed
- Removed uninstall hook with class again in favour of uninstall.php file. Peformance issues with uninstall hook never resolved in Core are the reason.
- Updated Header tags to be more dynamic for Generate Plugin features, does not affect functionality.
- Updated prefixes of global functions for better replacement with Generate Plugin Features. Does not affect functionality.
### Fixed
- Issue where activation and deactivation could have thrown notices due to undefined indexes.

## 2021-09-15
### Changed
- Removed uninstall.php file and added uninstall hook with class instead. Allows for dynamic plugin name retrieval during unistall
Expand Down
6 changes: 3 additions & 3 deletions plugin-name/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: Your Name or Your Company Name
Donate link: https://donate.tld/
Tags: comments, spam
Requires at least: 4.9
Tested up to: 5.8
Requires at least: X.X
Tested up to: X.X
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -45,7 +45,7 @@ e.g.

1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
1. Place `<?php do_action('plugin_name_hook'); ?>` in your templates
1. Place `<?php do_action('pfx_hook'); ?>` in your templates

== Frequently Asked Questions ==

Expand Down
6 changes: 4 additions & 2 deletions plugin-name/includes/class-plugin-name-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ private static function get_request() {
*/
private static function validate_request( $plugin ) {

if ( $plugin === self::$request['plugin']
if ( isset( self::$request['plugin'] )
&& $plugin === self::$request['plugin']
&& 'activate' === self::$request['action']
) {

return true;

} elseif ( 'activate-selected' === self::$request['action']
} elseif ( isset( self::$request['plugins'] )
&& 'activate-selected' === self::$request['action']
&& in_array( $plugin, self::$request['plugins'] )
) {
return true;
Expand Down
6 changes: 4 additions & 2 deletions plugin-name/includes/class-plugin-name-deactivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ private static function get_request() {
*/
private static function validate_request( $plugin ) {

if ( $plugin === self::$request['plugin']
if ( isset( self::$request['plugin'] )
&& $plugin === self::$request['plugin']
&& 'deactivate' === self::$request['action']
) {

return true;

} elseif ( 'deactivate-selected' === self::$request['action']
} elseif ( isset( self::$request['plugins'] )
&& 'deactivate-selected' === self::$request['action']
&& in_array( $plugin, self::$request['plugins'] )
) {
return true;
Expand Down
143 changes: 0 additions & 143 deletions plugin-name/includes/class-plugin-name-uninstall.php

This file was deleted.

2 changes: 1 addition & 1 deletion plugin-name/includes/class-plugin-name.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private function define_public_hooks() {
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );

// Shortcode name must be the same as in shortcode_atts() third parameter.
$this->loader->add_shortcode( $this->get_plugin_prefix() . 'shortcode', $plugin_public, 'plugin_name_shortcode_func' );
$this->loader->add_shortcode( $this->get_plugin_prefix() . 'shortcode', $plugin_public, 'pfx_shortcode_func' );

}

Expand Down
31 changes: 10 additions & 21 deletions plugin-name/plugin-name.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
* @package Plugin_Name
*
* @wordpress-plugin
* Plugin Name: Plugin Name
* Plugin Name: My Plugin Name
* Plugin URI: https://plugin.com/plugin-name-uri/
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
* Version: 1.0.0
* Author: Your Name or Your Company Name
* Requires at least: 4.9
* Tested up to: 5.8
* Requires at least: X.X
* Requires PHP: X.X
* Tested up to: X.X
* Author URI: https://example.com/
* License: GPL-2.0+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
Expand Down Expand Up @@ -49,7 +50,7 @@
* This action is documented in includes/class-plugin-name-activator.php
* Full security checks are performed inside the class.
*/
function plugin_name_activate() {
function pfx_activate() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-activator.php';
Plugin_Name_Activator::activate();
}
Expand All @@ -60,25 +61,13 @@ function plugin_name_activate() {
* This action is documented in includes/class-plugin-name-deactivator.php
* Full security checks are performed inside the class.
*/
function plugin_name_deactivate() {
function pfx_deactivate() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-deactivator.php';
Plugin_Name_Deactivator::deactivate();
}

/**
* The code that runs during plugin uninstall.
*
* This action is documented in includes/class-plugin-name-uninstall.php
* Full security checks are performed inside the class.
*/
function plugin_name_uninstall() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-plugin-name-uninstall.php';
Plugin_Name_Uninstall::uninstall();
}

register_activation_hook( __FILE__, 'plugin_name_activate' );
register_deactivation_hook( __FILE__, 'plugin_name_deactivate' );
register_uninstall_hook( __FILE__, 'plugin_name_uninstall' );
register_activation_hook( __FILE__, 'pfx_activate' );
register_deactivation_hook( __FILE__, 'pfx_deactivate' );

/**
* The core plugin class that is used to define internationalization,
Expand All @@ -98,10 +87,10 @@ function plugin_name_uninstall() {
*
* @since 1.0.0
*/
function plugin_name_run() {
function pfx_run() {

$plugin = new Plugin_Name();
$plugin->run();

}
plugin_name_run();
pfx_run();
2 changes: 1 addition & 1 deletion plugin-name/public/class-plugin-name-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function enqueue_scripts() {
* @param mixed $content ShortCode enclosed content.
* @param string $tag The Shortcode tag.
*/
public function plugin_name_shortcode_func( $atts, $content = null, $tag ) {
public function pfx_shortcode_func( $atts, $content = null, $tag ) {

/**
* Combine user attributes with known attributes.
Expand Down
61 changes: 61 additions & 0 deletions plugin-name/uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Fired when the plugin is uninstalled.
*
* We are not using an uninstall hook because WordPress perfoms bad when using it.
* Even if below issue is "fixed", it did not resolve the perfomance issue.
*
* @see https://core.trac.wordpress.org/ticket/31792
*
*
* When populating this file, consider the following flow
* of control:
*
* - Check if the $_REQUEST['plugin'] content actually is plugin-name/plugin-name.php
* - Check if the $_REQUEST['action'] content actually is delete-plugin
* - Run a check_ajax_referer check to make sure it goes through authentication
* - Run a current_user_can check to make sure current user can delete a plugin
*
* @todo Consider multisite. Once for a single site in the network, once sitewide.
*
* @link https://example.com
* @since 1.0.0
* @package Plugin_Name
*/

/**
* Perform Uninstall Actions.
*
* If uninstall not called from WordPress,
* If no uninstall action,
* If not this plugin,
* If no caps,
* then exit.
*
* @since 1.0.0
*/
function pfx_uninstall() {

if ( ! defined( 'WP_UNINSTALL_PLUGIN' )
|| empty( $_REQUEST )
|| ! isset( $_REQUEST['plugin'] )
|| ! isset( $_REQUEST['action'] )
|| 'plugin-name/plugin-name.php' !== $_REQUEST['plugin']
|| 'delete-plugin' !== $_REQUEST['action']
|| ! check_ajax_referer( 'updates', '_ajax_nonce' )
|| ! current_user_can( 'activate_plugins' )
) {

exit;

}

/**
* It is now safe to perform your uninstall actions here.
*
* @see https://developer.wordpress.org/plugins/plugin-basics/uninstall-methods/#method-2-uninstall-php
*/

}

pfx_uninstall();

0 comments on commit e4e2354

Please sign in to comment.