-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorage.php
38 lines (27 loc) · 986 Bytes
/
storage.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
<?php
namespace JFB_Update_Field;
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die();
}
class Storage {
private $context;
public function get_values() {
return jet_fb_context()->resolve_request();
}
public function set_context( $context ) {
$this->context = $context;
}
public function get_field_value( $field_name ) {
if ( preg_match( '/(?<field_name>.+)\[(?<index>\d+)\]\[(?<sub_name>.+)\]/', $field_name, $matches ) ) {
$field_name = $matches['field_name'];
$sub_name = $matches['sub_name'];
$index = $matches['index'];
return jet_fb_context()->resolve_request()[ $field_name ][ $index ][ $sub_name ] ?? '';
}
if ( is_object( $this->context ) && method_exists( $this->context, 'get_request' ) && preg_match( '/\[(?<sub_name>.+)\]/', $field_name, $matches ) ) {
return $this->context->get_request()[ $matches['sub_name'] ] ?? '';
}
return jet_fb_context()->resolve_request()[ $field_name ] ?? '';
}
}