Skip to content

Commit

Permalink
add uninstall hook (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrisbee authored Dec 15, 2023
1 parent 2ecd7f7 commit 84a0b10
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 38 deletions.
35 changes: 35 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Storipress
*
* @package Storipress
*/

spl_autoload_register(
function ( string $class_name ) {
if ( ! str_contains( $class_name, 'Storipress' ) ) {
return;
}

$path = str_replace(
array( 'storipress', '_', '\\' ),
array( '', '-', DIRECTORY_SEPARATOR ),
strtolower( $class_name )
);

$file = sprintf(
'%s/src/%s/class-%s.php',
__DIR__,
dirname( $path ),
basename( $path )
);

$realpath = realpath( $file );

if ( ! is_string( $realpath ) ) {
return;
}

require_once $realpath;
}
);
20 changes: 10 additions & 10 deletions src/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ public function generate_auth(): string {

$data = wp_json_encode(
array(
'version' => Storipress::instance()->version,
'token' => $password[0],
'hash_key' => $password[1]['password'],
'email' => $user->user_email,
'username' => $user->user_login,
'user_id' => $user_id,
'site_name' => get_bloginfo( 'name' ),
'url' => get_bloginfo( 'url' ),
'rest_prefix' => rest_get_url_prefix(),
'permalink_structure' => get_option('permalink_structure'),
'version' => Storipress::instance()->version,
'token' => $password[0],
'hash_key' => $password[1]['password'],
'email' => $user->user_email,
'username' => $user->user_login,
'user_id' => $user_id,
'site_name' => get_bloginfo( 'name' ),
'url' => get_bloginfo( 'url' ),
'rest_prefix' => rest_get_url_prefix(),
'permalink_structure' => get_option( 'permalink_structure' ),
)
);

Expand Down
29 changes: 1 addition & 28 deletions storipress.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,7 @@
wp_die( 'Storipress Exporter requires PHP 7.2 or later.' );
}

spl_autoload_register(
function ( string $class_name ) {
if ( ! str_contains( $class_name, 'Storipress' ) ) {
return;
}

$path = str_replace(
array( 'storipress', '_', '\\' ),
array( '', '-', DIRECTORY_SEPARATOR ),
strtolower( $class_name )
);

$file = sprintf(
'%s/src/%s/class-%s.php',
__DIR__,
dirname( $path ),
basename( $path )
);

$realpath = realpath( $file );

if ( ! is_string( $realpath ) ) {
return;
}

require_once $realpath;
}
);
require_once __DIR__ . '/autoload.php';

require_once __DIR__ . '/class-storipress.php';

Expand Down
21 changes: 21 additions & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Storipress
*
* @package Storipress
*/

// If uninstall.php is not called by WordPress, die.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
die;
}

require_once __DIR__ . '/autoload.php';

$core = new \Storipress\Storipress\Core();

delete_option( $core->option_key );

$user = wp_get_current_user();

$core->delete_application_password( $user->ID );

0 comments on commit 84a0b10

Please sign in to comment.