Global-2026-07-12
This commit is contained in:
parent
1fa6f06ccf
commit
ca70d76648
14
wp-content/mu-plugins/object-cache-bootstrap.php
Normal file
14
wp-content/mu-plugins/object-cache-bootstrap.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// Auto-enable Redis object cache if available
|
||||
if ( extension_loaded("redis") ) {
|
||||
$host = getenv("WP_REDIS_HOST") ?: "127.0.0.1";
|
||||
$port = (int)(getenv("WP_REDIS_PORT") ?: 6379);
|
||||
$db = (int)(getenv("WP_REDIS_DATABASE") ?: 0);
|
||||
|
||||
if ( @fsockopen($host, $port, $errno, $errstr, 0.5) ) {
|
||||
define("WP_REDIS_HOST", $host);
|
||||
define("WP_REDIS_PORT", $port);
|
||||
define("WP_REDIS_DATABASE", $db);
|
||||
define("WP_CACHE", true);
|
||||
}
|
||||
}
|
||||
@ -55,12 +55,18 @@ class Pksh_Data {
|
||||
* Адрес филиала
|
||||
*/
|
||||
public function get_address(): string {
|
||||
$cache_key = 'dekart_branch_address';
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_branch' );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
if ( ! array_key_exists( 'address', $this->branch ) ) {
|
||||
$this->branch['address'] = get_option( 'branch_address' ) ?:
|
||||
carbon_get_theme_option( 'site_address' ) ?:
|
||||
carbon_get_post_meta( $this->post_id, 'contact_address' ) ?:
|
||||
'';
|
||||
}
|
||||
wp_cache_set( $cache_key, $this->branch['address'], 'dekart_branch', DAY_IN_SECONDS );
|
||||
return $this->branch['address'];
|
||||
}
|
||||
|
||||
@ -68,11 +74,17 @@ class Pksh_Data {
|
||||
* Координаты филиала (для карты)
|
||||
*/
|
||||
public function get_coords(): string {
|
||||
$cache_key = 'dekart_branch_coords';
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_branch' );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
if ( ! array_key_exists( 'coords', $this->branch ) ) {
|
||||
$this->branch['coords'] = get_option( 'branch_coords' ) ?:
|
||||
carbon_get_post_meta( $this->post_id, 'contact_location' ) ?:
|
||||
'';
|
||||
}
|
||||
wp_cache_set( $cache_key, $this->branch['coords'], 'dekart_branch', DAY_IN_SECONDS );
|
||||
return $this->branch['coords'];
|
||||
}
|
||||
|
||||
@ -80,12 +92,18 @@ class Pksh_Data {
|
||||
* Телефон филиала
|
||||
*/
|
||||
public function get_phone(): string {
|
||||
$cache_key = 'dekart_branch_phone';
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_branch' );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
if ( ! array_key_exists( 'phone', $this->branch ) ) {
|
||||
$this->branch['phone'] = get_option( 'branch_phone' ) ?:
|
||||
carbon_get_theme_option( 'site_phone' ) ?:
|
||||
carbon_get_post_meta( $this->post_id, 'contact_tel' ) ?:
|
||||
'';
|
||||
}
|
||||
wp_cache_set( $cache_key, $this->branch['phone'], 'dekart_branch', DAY_IN_SECONDS );
|
||||
return $this->branch['phone'];
|
||||
}
|
||||
|
||||
@ -103,12 +121,18 @@ class Pksh_Data {
|
||||
* Email филиала
|
||||
*/
|
||||
public function get_email(): string {
|
||||
$cache_key = 'dekart_branch_email';
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_branch' );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
if ( ! array_key_exists( 'email', $this->branch ) ) {
|
||||
$this->branch['email'] = get_option( 'branch_email' ) ?:
|
||||
carbon_get_theme_option( 'site_mail' ) ?:
|
||||
carbon_get_post_meta( $this->post_id, 'contact_mail' ) ?:
|
||||
'';
|
||||
}
|
||||
wp_cache_set( $cache_key, $this->branch['email'], 'dekart_branch', DAY_IN_SECONDS );
|
||||
return $this->branch['email'];
|
||||
}
|
||||
|
||||
@ -116,11 +140,17 @@ class Pksh_Data {
|
||||
* Название филиала / организации
|
||||
*/
|
||||
public function get_name(): string {
|
||||
$cache_key = 'dekart_branch_name';
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_branch' );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
if ( ! array_key_exists( 'name', $this->branch ) ) {
|
||||
$this->branch['name'] = get_option( 'branch_name' ) ?:
|
||||
carbon_get_theme_option( 'site_name' ) ?:
|
||||
'Декарт';
|
||||
}
|
||||
wp_cache_set( $cache_key, $this->branch['name'], 'dekart_branch', DAY_IN_SECONDS );
|
||||
return $this->branch['name'];
|
||||
}
|
||||
|
||||
@ -128,9 +158,15 @@ class Pksh_Data {
|
||||
* Город с предлогом (например "в Щёлково")
|
||||
*/
|
||||
public function get_city_prep(): string {
|
||||
$cache_key = 'dekart_branch_city_prep';
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_branch' );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
if ( ! array_key_exists( 'city_prep', $this->branch ) ) {
|
||||
$this->branch['city_prep'] = get_option( 'branch_city_prep', 'в Щёлково' );
|
||||
}
|
||||
wp_cache_set( $cache_key, $this->branch['city_prep'], 'dekart_branch', DAY_IN_SECONDS );
|
||||
return $this->branch['city_prep'];
|
||||
}
|
||||
|
||||
@ -148,9 +184,15 @@ class Pksh_Data {
|
||||
* Количество отзывов на внешних площадках
|
||||
*/
|
||||
public function get_ext_review_count(): string {
|
||||
$cache_key = 'dekart_branch_ext_review_count';
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_branch' );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
if ( ! array_key_exists( 'ext_review_count', $this->branch ) ) {
|
||||
$this->branch['ext_review_count'] = get_option( 'branch_ext_review_count', '247' );
|
||||
}
|
||||
wp_cache_set( $cache_key, $this->branch['ext_review_count'], 'dekart_branch', DAY_IN_SECONDS );
|
||||
return $this->branch['ext_review_count'];
|
||||
}
|
||||
|
||||
@ -158,12 +200,18 @@ class Pksh_Data {
|
||||
* Социальные сети (из branch_social option или CF)
|
||||
*/
|
||||
public function get_social_links(): array {
|
||||
$cache_key = 'dekart_branch_social';
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_branch' );
|
||||
if ( false !== $cached ) {
|
||||
return $cached;
|
||||
}
|
||||
if ( ! array_key_exists( 'social', $this->branch ) ) {
|
||||
$raw = get_option( 'branch_social' ) ?:
|
||||
carbon_get_post_meta( $this->post_id, 'social_media' ) ?:
|
||||
[];
|
||||
$this->branch['social'] = is_array( $raw ) ? $raw : [];
|
||||
}
|
||||
wp_cache_set( $cache_key, $this->branch['social'], 'dekart_branch', DAY_IN_SECONDS );
|
||||
return $this->branch['social'];
|
||||
}
|
||||
|
||||
|
||||
@ -67,6 +67,15 @@ function dekart_schema_output(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
// Object Cache key: page ID + locale + schema version
|
||||
$cache_key = 'dekart_schema_graph_' . get_the_ID() . '_' . determine_locale();
|
||||
$cached = wp_cache_get( $cache_key, 'dekart_schema' );
|
||||
|
||||
if ( false !== $cached ) {
|
||||
echo $cached;
|
||||
return;
|
||||
}
|
||||
|
||||
$graph = array();
|
||||
|
||||
// 1. WebPage
|
||||
@ -180,7 +189,12 @@ function dekart_schema_output(): void {
|
||||
return; // тихий выход вместо WSOD
|
||||
}
|
||||
|
||||
echo '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>' . "\n";
|
||||
$output = '<script type="application/ld+json">' . "\n" . $json . "\n" . '</script>' . "\n";
|
||||
|
||||
// Cache for 1 hour (3600 seconds) in 'dekart_schema' group
|
||||
wp_cache_set( $cache_key, $output, 'dekart_schema', 3600 );
|
||||
|
||||
echo $output;
|
||||
}
|
||||
|
||||
/* =====================================================================
|
||||
|
||||
Loading…
Reference in New Issue
Block a user