PluginProbe
BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP / trunk
BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP vtrunk
3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 3.0.0 2.4.13 2.4.12 2.4.11 2.4.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 110 releases
betterlinks / includes / Admin / Cache.php

Cache.php in BetterLinks – Link Shortener, Link Cloaking, Redirects, Affiliate Link Manager & MCP trunk, at includes/Admin/Cache.php

37 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace BetterLinks\Admin;
3 if ( ! defined( 'ABSPATH' ) ) { exit; }
4
5 class Cache {
6 public static function init() {
7 self::write_json_settings();
8 }
9 public static function write_json_settings() {
10 $betterlinks_links = get_option( BETTERLINKS_LINKS_OPTION_NAME, array() );
11 if ( is_string( $betterlinks_links ) ) {
12 $betterlinks_links = json_decode( $betterlinks_links, true );
13 }
14
15 // Security: Remove sensitive API keys from JSON cache
16 // API keys are stored separately in BETTERLINKS_AI_API_KEYS_OPTION_NAME
17 unset( $betterlinks_links['openai_api_key'] );
18 unset( $betterlinks_links['gemini_api_key'] );
19
20 if( !is_dir( BETTERLINKS_UPLOAD_DIR_PATH ) ){
21 wp_mkdir_p(BETTERLINKS_UPLOAD_DIR_PATH);
22 }
23 file_put_contents( BETTERLINKS_UPLOAD_DIR_PATH . '/settings.json', json_encode( $betterlinks_links ) );
24 return $betterlinks_links;
25 }
26
27 public static function get_json_settings() {
28 if ( file_exists( BETTERLINKS_UPLOAD_DIR_PATH . '/settings.json' ) ) {
29 $settings = json_decode( file_get_contents( BETTERLINKS_UPLOAD_DIR_PATH . '/settings.json' ), true );
30 if ( ! empty( $settings ) ) {
31 return $settings;
32 }
33 }
34 return self::write_json_settings();
35 }
36 }
37