-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.rc-map-settings.php
159 lines (121 loc) · 5.37 KB
/
class.rc-map-settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
use JetBrains\PhpStorm\NoReturn;
if (!class_exists('RC_Map_Settings')) {
class RC_Map_Settings {
public static mixed $options;
/**
* @var false|mixed|null
*/
public static mixed $options_6;
public static mixed $options_styles;
public function __construct() {
self::$options = get_option( 'rc_map_options' );
self::$options_6 = get_option( 'rc_map_options_6' );
self::$options_styles = get_option( 'rc_map_group_styles_options' );
add_action( 'admin_init', array( $this, 'adminInit' ) );
// in the form admin_post_{hidden-html-input-value}
add_action( 'admin_post_run_custom_script', [ $this, 'handle_map_import_script' ], 10 );
add_action( 'admin_post_generate_code', [ $this, 'handle_map_process_script' ], 10 );
add_action( 'admin_post_get_geo_cords', [ $this, 'handle_map_get_geo_cords' ], 10 );
// HANDLE UPDATED POST_META AND OPTION
add_action( 'updated_post_meta', [ $this, 'handleAfterUpdatePostMeta' ], 10, 4 );
add_action( 'updated_option', [ $this, 'handleAfterUpdateOption' ], 10, 4 );
// Load Tab One in settings page.
include_once( RC_MAP_PATH . 'settings/class.RC_MAP_settings_main-options.php' );
$tabOne = new RC_MAP_SETTINGS_MAIN_OPTIONS();
// Load Tab Three in settings page.
include_once( RC_MAP_PATH . 'settings/class.RC_MAP_settings_snazzy-style-options.php' );
$tabThree = new RC_MAP_SETTINGS_SNAZZY_STYLE_OPTIONS();
// Load Google Map Tab
include_once( RC_MAP_PATH . 'includes/class.RC_DataEncryption.php' );
include( RC_MAP_PATH . 'settings/class.RC_MAP_settings_google-map-options.php' );
$tabTwo = new RC_MAP_SETTINGS_GOOGLE_MAP_OPTIONS( new RC_DataEncryption() );
// Load Additional Options Tab
include( RC_MAP_PATH . 'settings/class.RC_Map_settings_additional_options.php' );
$additionalOptionsTab = new RC_MAP_SETTINGS_ADDITIONAL_OPTIONS();
}
public function adminInit(): void {
// PAGE 4 ***************************** //
// THIS HTML IS IN THE settings-page.php file
add_settings_section(
id: 'rc_map_fourth_section',
title: 'Load Map Data',
callback: null,
page: 'rc_map_page4',
args: null
);
// PAGE 5 ***************************** //
// THIS HTML IS IN THE settings-page.php file
add_settings_section(
id: 'rc_map_fifth_section',
title: 'Generate map data',
callback: null,
page: 'rc_map_page5',
args: null
);
}
// UPDATED POST META ALL PAGES
public function handleAfterUpdatePostMeta(): void {
include_once( RC_MAP_PATH . 'includes/process.php' );
}
// UPDATED OPTION ALL PAGES
public function handleAfterUpdateOption(): void {
include_once( RC_MAP_PATH . 'includes/process.php' );
}
// PAGE 4 HTML ******************************* /
// SEE views/settings-page.php
// PAGE 5 HTML ******************************* /
// SEE views/settings-page.php
// Callback function to handle the custom script
#[NoReturn] public function handle_map_import_script(): void {
// TODO: NEED TO ADD THIS SECURITY CHECK
// Verify the nonce for security
// if ( ! isset( $_POST['custom_action_nonce'] ) || ! wp_verify_nonce( $_POST['custom_action_nonce'], 'custom_action' ) ) {
// wp_die( 'Invalid nonce.' );
// }
require_once( RC_MAP_PATH . 'includes/import.php' );
// Redirect back to the admin page after processing
//wp_safe_redirect( admin_url( 'admin.php?page=rc_map_admin&tab=load_map_data_options' ) );
// Get the current page's path from REQUEST_URI
$current_page_path = $_SERVER['REQUEST_URI'];
// Generate the URL for the current page in the WordPress admin area
$admin_current_page_url = admin_url( $current_page_path );
// Redirect the user to the generated URL
wp_safe_redirect( admin_url( 'edit.php?post_type=rc-poi' ) );
//wp_safe_redirect($admin_current_page_url);
exit(); // It's important to use exit() after the redirect to ensure the script execution stops.
}
// Callback function to handle the custom script for processing data
/**
* @return void
* purpose: builds html/css/javascript
*
* hook: admin_post_{custom-script-name}
*/
#[NoReturn] public function handle_map_process_script(): void {
// Verify the nonce for security
if ( ! isset( $_POST['process_nonce'] ) || ! wp_verify_nonce( $_POST['process_nonce'], 'process_nonce' ) ) {
wp_die( 'Invalid nonce.' );
}
require_once( RC_MAP_PATH . 'includes/process.php' );
// Redirect back to the admin page after processing
wp_safe_redirect( admin_url( 'admin.php?page=rc_map_admin&tab=generate_map' ) );
exit;
}
/**
* @return void
* hook :admin_post_{custom-script-name}
* purpose: run a custom php script from WordPress admin dashboard
*/
#[NoReturn] public function handle_map_get_geo_cords(): void {
// Verify the nonce for security
if ( ! isset( $_POST['get_geo_cords'] ) || ! wp_verify_nonce( $_POST['get_geo_cords'], 'get_geo_cords' ) ) {
wp_die( 'Invalid nonce.' );
}
require_once( RC_MAP_PATH . 'includes/get_coordinates.php' );
// Redirect back to the admin page after processing
wp_safe_redirect( admin_url( 'edit.php?post_type=rc-poi' ) );
exit;
}
}
}