-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_rest_api.php
More file actions
197 lines (159 loc) Β· 6.47 KB
/
debug_rest_api.php
File metadata and controls
197 lines (159 loc) Β· 6.47 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* Debug REST API Registration
*
* This script helps debug why the REST API endpoints are not working
* by testing WordPress's REST API registration directly.
*/
// Include WordPress
define('ABSPATH', '/var/www/html/');
require_once ABSPATH . 'wp-config.php';
require_once ABSPATH . 'wp-includes/wp-db.php';
require_once ABSPATH . 'wp-includes/pluggable.php';
// WordPress bootstrap
require_once ABSPATH . 'wp-settings.php';
echo "π WordPress REST API Debug Report\n";
echo "===================================\n\n";
// Test basic WordPress functionality
echo "WordPress Version: " . get_bloginfo('version') . "\n";
echo "Site URL: " . get_site_url() . "\n";
echo "REST API Base: " . rest_url() . "\n\n";
// Check if plugin is active
$active_plugins = get_option('active_plugins', array());
$plugin_active = false;
foreach ($active_plugins as $plugin) {
if (strpos($plugin, 'wp-content-flow') !== false) {
$plugin_active = true;
echo "β
Plugin is active: $plugin\n";
break;
}
}
if (!$plugin_active) {
echo "β WP Content Flow plugin is not active\n";
echo "Active plugins:\n";
foreach ($active_plugins as $plugin) {
echo " - $plugin\n";
}
exit(1);
}
// Check if REST API is enabled
if (!function_exists('rest_url')) {
echo "β WordPress REST API is not available\n";
exit(1);
}
echo "β
WordPress REST API is available\n";
// Test basic REST API
$rest_server = rest_get_server();
echo "β
REST Server initialized\n";
// Check available namespaces
$namespaces = $rest_server->get_namespaces();
echo "\nRegistered REST namespaces:\n";
foreach ($namespaces as $namespace) {
echo " - $namespace\n";
if ($namespace === 'wp-content-flow/v1') {
echo " β
Our namespace is registered!\n";
}
}
// Check if our namespace exists
$our_namespace_exists = in_array('wp-content-flow/v1', $namespaces);
if (!$our_namespace_exists) {
echo "\nβ Our namespace 'wp-content-flow/v1' is NOT registered\n";
// Check if our REST API class exists
if (class_exists('WP_Content_Flow_REST_API')) {
echo "β
WP_Content_Flow_REST_API class exists\n";
// Try to manually initialize
echo "π§ Attempting manual initialization...\n";
// Check if rest_api_init has been called
$current_hook = current_action();
echo "Current hook: $current_hook\n";
// Manually trigger rest_api_init to see what happens
do_action('rest_api_init');
// Check again
$namespaces_after = rest_get_server()->get_namespaces();
$our_namespace_after = in_array('wp-content-flow/v1', $namespaces_after);
if ($our_namespace_after) {
echo "β
Namespace registered after manual init\n";
} else {
echo "β Still not registered after manual init\n";
}
} else {
echo "β WP_Content_Flow_REST_API class does not exist\n";
// Check if the main plugin class exists
if (class_exists('WP_Content_Flow')) {
echo "β
WP_Content_Flow main class exists\n";
} else {
echo "β WP_Content_Flow main class does not exist\n";
}
}
} else {
echo "\nβ
Our namespace is properly registered\n";
// Get routes for our namespace
$routes = $rest_server->get_routes();
echo "\nRegistered routes in our namespace:\n";
foreach ($routes as $route => $handlers) {
if (strpos($route, '/wp-content-flow/v1/') === 0) {
echo " - $route\n";
foreach ($handlers as $handler) {
$methods = $handler['methods'] ?? [];
if (is_array($methods)) {
echo " Methods: " . implode(', ', array_keys($methods)) . "\n";
} else {
echo " Methods: $methods\n";
}
}
}
}
}
// Check file existence
$plugin_dir = WP_PLUGIN_DIR . '/wp-content-flow/';
$rest_api_file = $plugin_dir . 'includes/api/class-rest-api.php';
$main_file = $plugin_dir . 'wp-content-flow.php';
echo "\nFile existence check:\n";
echo "Plugin directory: " . ($plugin_dir ? "β
" : "β") . " $plugin_dir\n";
echo "Main plugin file: " . (file_exists($main_file) ? "β
" : "β") . " $main_file\n";
echo "REST API file: " . (file_exists($rest_api_file) ? "β
" : "β") . " $rest_api_file\n";
// Check if includes are working
if (file_exists($rest_api_file)) {
echo "\nπ§ Testing direct inclusion...\n";
// Check if constants are defined
echo "WP_CONTENT_FLOW_PLUGIN_DIR defined: " . (defined('WP_CONTENT_FLOW_PLUGIN_DIR') ? "β
" : "β") . "\n";
if (!defined('WP_CONTENT_FLOW_PLUGIN_DIR')) {
define('WP_CONTENT_FLOW_PLUGIN_DIR', $plugin_dir);
}
// Try to include the REST API file
try {
require_once $rest_api_file;
echo "β
REST API file included successfully\n";
if (class_exists('WP_Content_Flow_REST_API')) {
echo "β
REST API class is available\n";
// Try to instantiate
$rest_api_instance = new WP_Content_Flow_REST_API();
echo "β
REST API instance created\n";
// Manually call register_rest_routes
$rest_api_instance->register_rest_routes();
echo "β
register_rest_routes called manually\n";
// Check namespaces again
$final_namespaces = rest_get_server()->get_namespaces();
if (in_array('wp-content-flow/v1', $final_namespaces)) {
echo "β
Namespace NOW registered!\n";
// Test the status endpoint
$request = new WP_REST_Request('GET', '/wp-content-flow/v1/status');
$response = rest_do_request($request);
if ($response->is_error()) {
echo "β Status endpoint error: " . $response->get_error_message() . "\n";
} else {
echo "β
Status endpoint works!\n";
echo "Response: " . json_encode($response->get_data()) . "\n";
}
} else {
echo "β Namespace still not registered\n";
}
} else {
echo "β REST API class still not available after include\n";
}
} catch (Exception $e) {
echo "β Error including REST API file: " . $e->getMessage() . "\n";
}
}
echo "\nπ Debug complete\n";
?>