mirror of
https://github.com/mashirozx/sakura.git
synced 2024-11-22 23:08:14 +08:00
fix auth
This commit is contained in:
parent
19a337ed17
commit
c26c98b653
12
inc/api.php
12
inc/api.php
@ -311,12 +311,17 @@ function feature_gallery() {
|
|||||||
* update manifest.json rest api
|
* update manifest.json rest api
|
||||||
* @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/json
|
* @rest api接口路径:https://sakura.2heng.xin/wp-json/sakura/v1/image/json
|
||||||
*/
|
*/
|
||||||
function update_manifest_json(WP_REST_Request $request) {
|
function update_manifest_json() {
|
||||||
if (is_admin()) {
|
$username = $_SERVER['PHP_AUTH_USER'];
|
||||||
|
$password = $_SERVER['PHP_AUTH_PW'];
|
||||||
|
$user = wp_authenticate($username, $password);
|
||||||
|
if (is_a($user, 'WP_User')) {
|
||||||
|
if (in_array('administrator', (array) $user->roles)) {
|
||||||
|
global $wpdb;
|
||||||
$sakura_table_name = $wpdb->base_prefix.'sakura';
|
$sakura_table_name = $wpdb->base_prefix.'sakura';
|
||||||
$manifest = array(
|
$manifest = array(
|
||||||
"key" => "manifest_json",
|
"key" => "manifest_json",
|
||||||
"value" => file_get_contents($_FILES["manifest_json"]["tmp_name"])
|
"value" => file_get_contents($_FILES["manifest"]["tmp_name"])
|
||||||
);
|
);
|
||||||
$time = array(
|
$time = array(
|
||||||
"key" => "json_time",
|
"key" => "json_time",
|
||||||
@ -336,6 +341,7 @@ function update_manifest_json(WP_REST_Request $request) {
|
|||||||
$result = new WP_REST_Response($output, 200);
|
$result = new WP_REST_Response($output, 200);
|
||||||
$result->set_headers(array('Content-Type' => 'application/json'));
|
$result->set_headers(array('Content-Type' => 'application/json'));
|
||||||
return $result;
|
return $result;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$output = array(
|
$output = array(
|
||||||
'status' => 401,
|
'status' => 401,
|
||||||
|
Loading…
Reference in New Issue
Block a user