PluginProbe
Redirection / 3.3
Redirection v3.3
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / api / api-settings.php

api-settings.php in Redirection 3.3, at api/api-settings.php

45 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Redirection_Api_Settings extends Redirection_Api_Route {
4 public function __construct( $namespace ) {
5 register_rest_route( $namespace, '/setting', array(
6 $this->get_route( WP_REST_Server::READABLE, 'route_settings' ),
7 $this->get_route( WP_REST_Server::EDITABLE, 'route_save_settings' ),
8 ) );
9 }
10
11 public function route_settings( WP_REST_Request $request ) {
12 if ( ! function_exists( 'get_home_path' ) ) {
13 include_once ABSPATH . '/wp-admin/includes/file.php';
14 }
15
16 return array(
17 'settings' => red_get_options(),
18 'groups' => $this->groups_to_json( Red_Group::get_for_select() ),
19 'installed' => get_home_path(),
20 'canDelete' => ! is_multisite(),
21 'post_types' => red_get_post_types(),
22 );
23 }
24
25 public function route_save_settings( WP_REST_Request $request ) {
26 red_set_options( $request->get_params() );
27
28 return $this->route_settings( $request );
29 }
30
31 private function groups_to_json( $groups, $depth = 0 ) {
32 $items = array();
33
34 foreach ( $groups as $text => $value ) {
35 if ( is_array( $value ) && $depth === 0 ) {
36 $items[] = (object)array( 'text' => $text, 'value' => $this->groups_to_json( $value, 1 ) );
37 } else {
38 $items[] = (object)array( 'text' => $value, 'value' => $text );
39 }
40 }
41
42 return $items;
43 }
44 }
45