PluginProbe
Bubble Menu – Floating Button Menu with Sticky Navigation / 4.0.7
Bubble Menu – Floating Button Menu with Sticky Navigation v4.0.7
trunk 1.3 2.0 2.2 2.2.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.1 4.1.1
bubble-menu / classes / Admin / AdminActions.php

AdminActions.php in Bubble Menu – Floating Button Menu with Sticky Navigation 4.0.7, at classes/Admin/AdminActions.php

91 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AdminActions class for Bubble Menu plugin.
4 *
5 * @package BubbleMenu\Admin
6 *
7 * Methods:
8 * - init() Initialize admin actions hook
9 * - actions() Handle admin requests based on request name
10 * - verify( $name ) Verify nonce and user capability
11 * - check_name() Detect action name from $_REQUEST
12 */
13
14 namespace BubbleMenu\Admin;
15
16 use BubbleMenu\WOWP_Plugin;
17
18 defined( 'ABSPATH' ) || exit;
19
20 class AdminActions {
21
22 public static function init(): void {
23 add_action( 'admin_init', [ __CLASS__, 'actions' ] );
24 }
25
26 public static function actions(): bool {
27 $name = self::check_name();
28
29 if ( empty( $name ) || ! self::verify( $name ) ) {
30 return false;
31 }
32
33 $map = [
34 '_export_data' => [ ImporterExporter::class, 'export_data' ],
35 '_export_item' => [ ImporterExporter::class, 'export_item' ],
36 '_import_data' => [ ImporterExporter::class, 'import_data' ],
37 '_remove_item' => [ DBManager::class, 'remove_item' ],
38 '_settings' => [ Settings::class, 'save_item' ],
39 '_activate_item' => [ Settings::class, 'activate_item' ],
40 '_deactivate_item' => [ Settings::class, 'deactivate_item' ],
41 '_activate_mode' => [ Settings::class, 'activate_mode' ],
42 '_deactivate_mode' => [ Settings::class, 'deactivate_mode' ],
43 '_capabilities' => [ ManageCapabilities::class, 'save' ],
44 ];
45
46 foreach ( $map as $key => $callback ) {
47 if ( is_callable( $callback ) && strpos( $name, $key ) !== false ) {
48 $callback();
49 break;
50 }
51 }
52
53 return true;
54 }
55
56 public static function verify( string $name ): bool {
57 $nonce_action = WOWP_Plugin::PREFIX . '_nonce';
58 $nonce = isset( $_REQUEST[ $name ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $name ] ) ) : '';
59 $capability = ManageCapabilities::get_capability();
60
61 return ( ! empty( $nonce ) && wp_verify_nonce( $nonce, $nonce_action ) && current_user_can( $capability ) );
62 }
63
64 private static function check_name(): string {
65 $actions = [
66 '_import_data',
67 '_export_data',
68 '_export_item',
69 '_remove_item',
70 '_settings',
71 '_activate_item',
72 '_deactivate_item',
73 '_activate_mode',
74 '_deactivate_mode',
75 '_capabilities',
76 '_list_action',
77 ];
78
79 foreach ( $actions as $action ) {
80 $name = WOWP_Plugin::PREFIX . $action;
81 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
82 if ( isset( $_REQUEST[ $name ] ) ) {
83 return $name;
84 }
85 }
86
87 return '';
88 }
89
90 }
91