| 1 |
<?php |
| 2 |
|
| 3 |
namespace BubbleMenu\Admin; |
| 4 |
|
| 5 |
use BubbleMenu\WOWP_Plugin; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || exit; |
| 8 |
|
| 9 |
class AdminActions { |
| 10 |
|
| 11 |
public static function init(): void { |
| 12 |
add_action( 'admin_init', [ __CLASS__, 'actions' ] ); |
| 13 |
} |
| 14 |
|
| 15 |
public static function actions(): bool { |
| 16 |
$name = self::check_name(); |
| 17 |
|
| 18 |
if ( empty( $name ) ) { |
| 19 |
return false; |
| 20 |
} |
| 21 |
$verify = self::verify( $name ); |
| 22 |
|
| 23 |
if ( ! $verify ) { |
| 24 |
return false; |
| 25 |
} |
| 26 |
|
| 27 |
if ( strpos( $name, '_export_data' ) !== false ) { |
| 28 |
ImporterExporter::export_data(); |
| 29 |
} elseif ( strpos( $name, '_export_item' ) !== false ) { |
| 30 |
ImporterExporter::export_item(); |
| 31 |
} elseif ( strpos( $name, '_import_data' ) !== false ) { |
| 32 |
ImporterExporter::import_data(); |
| 33 |
} elseif ( strpos( $name, '_remove_item' ) !== false ) { |
| 34 |
DBManager::remove_item(); |
| 35 |
} elseif ( strpos( $name, '_settings' ) !== false ) { |
| 36 |
Settings::save_item(); |
| 37 |
} elseif ( strpos( $name, '_activate_item' ) !== false ) { |
| 38 |
Settings::activate_item(); |
| 39 |
} elseif ( strpos( $name, '_deactivate_item' ) !== false ) { |
| 40 |
Settings::deactivate_item(); |
| 41 |
} elseif ( strpos( $name, '_activate_mode' ) !== false ) { |
| 42 |
Settings::activate_mode(); |
| 43 |
} elseif ( strpos( $name, '_deactivate_mode' ) !== false ) { |
| 44 |
Settings::deactivate_mode(); |
| 45 |
} elseif ( strpos( $name, '_capabilities' ) !== false ) { |
| 46 |
ManageCapabilities::save(); |
| 47 |
} |
| 48 |
|
| 49 |
return true; |
| 50 |
} |
| 51 |
|
| 52 |
public static function verify( $name ): bool { |
| 53 |
$nonce_action = WOWP_Plugin::PREFIX . '_nonce'; |
| 54 |
$nonce = isset( $_REQUEST[ $name ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $name ] ) ) : ''; |
| 55 |
$capability = ManageCapabilities::get_capability(); |
| 56 |
|
| 57 |
return ( ! empty( $nonce ) && wp_verify_nonce( $nonce, $nonce_action ) && current_user_can( $capability ) ); |
| 58 |
} |
| 59 |
|
| 60 |
private static function check_name(): string { |
| 61 |
$names = [ |
| 62 |
WOWP_Plugin::PREFIX . '_import_data', |
| 63 |
WOWP_Plugin::PREFIX . '_export_data', |
| 64 |
WOWP_Plugin::PREFIX . '_export_item', |
| 65 |
WOWP_Plugin::PREFIX . '_remove_item', |
| 66 |
WOWP_Plugin::PREFIX . '_settings', |
| 67 |
WOWP_Plugin::PREFIX . '_activate_item', |
| 68 |
WOWP_Plugin::PREFIX . '_deactivate_item', |
| 69 |
WOWP_Plugin::PREFIX . '_activate_mode', |
| 70 |
WOWP_Plugin::PREFIX . '_deactivate_mode', |
| 71 |
WOWP_Plugin::PREFIX . '_capabilities', |
| 72 |
WOWP_Plugin::PREFIX . '_list_action', |
| 73 |
]; |
| 74 |
|
| 75 |
foreach ( $names as $name ) { |
| 76 |
if ( isset( $_REQUEST[ $name ] ) ) { |
| 77 |
return $name; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
return ''; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
} |