Network.php
1.17 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
<?php
namespace AIOSEO\Plugin\Common\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Route class for the API.
*
* @since 4.2.5
*/
class Network {
/**
* Save network robots rules.
*
* @since 4.2.5
*
* @param \WP_REST_Request $request The REST Request
* @return \WP_REST_Response The response.
*/
public static function saveNetworkRobots( $request ) {
$isNetwork = 'network' === $request->get_param( 'siteId' );
$siteId = $isNetwork ? aioseo()->helpers->getNetworkId() : (int) $request->get_param( 'siteId' );
$body = $request->get_json_params();
$rules = ! empty( $body['rules'] ) ? array_map( 'sanitize_text_field', $body['rules'] ) : [];
$enabled = isset( $body['enabled'] ) ? boolval( $body['enabled'] ) : null;
aioseo()->helpers->switchToBlog( $siteId );
$options = $isNetwork ? aioseo()->networkOptions : aioseo()->options;
$enabled = null === $enabled ? $options->tools->robots->enable : $enabled;
$options->sanitizeAndSave( [
'tools' => [
'robots' => [
'enable' => $enabled,
'rules' => $rules
]
]
] );
return new \WP_REST_Response( [
'success' => true
], 200 );
}
}