PluginProbe
Float menu – awesome floating side menu / 6.0
Float menu – awesome floating side menu v6.0
7.2.5 trunk 2.1 2.2 3.0.1 3.1 3.2.2 3.3.1 3.5 3.5.1 3.5.2 3.5.3. 3.5.4 4.0 4.1 4.1.1 4.2 4.3 4.3.1 4.3.2 5.0 5.0.1 5.0.2 5.0.3 5.1 All 57 releases
float-menu / classes / Admin / AdminActions.php

AdminActions.php in Float menu – awesome floating side menu 6.0, at classes/Admin/AdminActions.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class AdminActions
5 *
6 * This class handles administrative actions in the plugin.
7 *
8 * @package WowPlugin
9 * @subpackage Admin
10 * @author Dmytro Lobov <dev@wow-company.com>, Wow-Company
11 * @copyright 2024 Dmytro Lobov
12 * @license GPL-2.0+
13 *
14 */
15
16 namespace FloatMenuLite\Admin;
17
18 use FloatMenuLite\WOWP_Plugin;
19
20 defined( 'ABSPATH' ) || exit;
21
22 class AdminActions {
23
24 public static function init(): void {
25 add_action( 'admin_init', [ __CLASS__, 'actions' ] );
26 }
27
28 public static function actions(): bool {
29 $name = self::check_name( $_REQUEST );
30 if ( ! $name ) {
31 return false;
32 }
33 $verify = self::verify( $name );
34
35 if ( ! $verify ) {
36 return false;
37 }
38
39 if ( strpos( $name, '_export_data' ) !== false ) {
40 ImporterExporter::export_data();
41 } elseif ( strpos( $name, '_export_item' ) !== false ) {
42 ImporterExporter::export_item();
43 } elseif ( strpos( $name, '_import_data' ) !== false ) {
44 ImporterExporter::import_data();
45 } elseif ( strpos( $name, '_remove_item' ) !== false ) {
46 DBManager::remove_item();
47 } elseif ( strpos( $name, '_settings' ) !== false ) {
48 Settings::save_item();
49 } elseif ( strpos( $name, '_activate_item' ) !== false ) {
50 Settings::activate_item();
51 } elseif ( strpos( $name, '_deactivate_item' ) !== false ) {
52 Settings::deactivate_item();
53 } elseif ( strpos( $name, '_activate_mode' ) !== false ) {
54 Settings::activate_mode();
55 } elseif ( strpos( $name, '_deactivate_mode' ) !== false ) {
56 Settings::deactivate_mode();
57 }
58
59 return true;
60 }
61
62 private static function verify( $name ): bool {
63 $nonce_action = WOWP_Plugin::PREFIX . '_nonce';
64
65 return ! ( ! isset( $_REQUEST[ $name ] ) || ! wp_verify_nonce( $_REQUEST[ $name ], $nonce_action ) || ! current_user_can( 'manage_options' ) );
66 }
67
68 private static function check_name( $request ) {
69 $names = [
70 WOWP_Plugin::PREFIX . '_import_data',
71 WOWP_Plugin::PREFIX . '_export_data',
72 WOWP_Plugin::PREFIX . '_export_item',
73 WOWP_Plugin::PREFIX . '_remove_item',
74 WOWP_Plugin::PREFIX . '_settings',
75 WOWP_Plugin::PREFIX . '_activate_item',
76 WOWP_Plugin::PREFIX . '_deactivate_item',
77 WOWP_Plugin::PREFIX . '_activate_mode',
78 WOWP_Plugin::PREFIX . '_deactivate_mode',
79 ];
80
81 foreach ( $request as $key => $value ) {
82
83 if ( in_array( $key, $names, true ) ) {
84 return $key;
85 }
86 }
87
88 return false;
89
90 }
91
92 }