Conditions | 2 |
Paths | 2 |
Total Lines | 19 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
39 | function fetch( $endpoint, $ttl = 10 ) { |
||
40 | |||
41 | $request_url = $this->root_url . $endpoint; |
||
42 | |||
43 | $cache_key = md5( $request_url ); |
||
44 | |||
45 | $cached = get_transient( 'bwp_' . $cache_key ); |
||
46 | |||
47 | if ( $cached ) { |
||
48 | return $cached; |
||
49 | } |
||
50 | |||
51 | $response = wp_remote_get( $request_url ); |
||
52 | |||
53 | set_transient( 'bwp_' . $cache_key, $response, $ttl ); |
||
54 | |||
55 | return $response; |
||
56 | |||
57 | } |
||
58 | |||
60 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.