feat(share): align social sharing runtime
This commit is contained in:
1 parent
26ac8167f3
commit
cf6c11852e
33 files changed
+802
-1919
No files matched your search
+23
-13
@@ -130,24 +130,34 @@ trait FacadeBulk {
|
||||
'dropdown' => !empty($option['dropdown']),
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Share and poster settings.
|
||||
*
|
||||
* @return array{wechat_enabled:bool,wechat_appid:string,wechat_app_secret:string,only_logo:bool,compatible_s:bool,poster_img:string,poster_logo:string,share_img:string,share_desc:string}
|
||||
*/
|
||||
/** Share and poster settings using the reference theme's canonical keys. */
|
||||
public static function get_share_settings(): array {
|
||||
$settings = self::get_all();
|
||||
$wechat = is_array($settings['wechat_share_option'] ?? null) ? $settings['wechat_share_option'] : [];
|
||||
$defaults = [
|
||||
'qzone' => 'QQ空间', 'weibo' => '微博', 'qq' => 'QQ好友', 'poster' => '海报分享', 'copy' => '复制链接',
|
||||
];
|
||||
$configured = is_array($settings['share_items'] ?? null) ? $settings['share_items'] : [];
|
||||
$enabled = is_array($configured['enabled'] ?? null) ? $configured['enabled'] : $defaults;
|
||||
$allowed = ['qzone', 'weibo', 'qq', 'facebook', 'twitter', 'telegram', 'whatsapp', 'linkedin', 'reddit', 'line', 'vk', 'email', 'poster', 'copy'];
|
||||
$items = array_values(array_intersect(array_map('sanitize_key', array_keys($enabled)), $allowed));
|
||||
$poster_enabled = !isset($settings['share_img']) || !empty($settings['share_img']);
|
||||
if (!$poster_enabled) {
|
||||
$items = array_values(array_diff($items, ['poster']));
|
||||
}
|
||||
|
||||
return [
|
||||
'wechat_enabled' => !empty($settings['share_wechat_s']),
|
||||
'wechat_appid' => sanitize_text_field((string) ($settings['share_wechat_appid'] ?? '')),
|
||||
'wechat_app_secret' => sanitize_text_field((string) ($settings['share_wechat_app_secret'] ?? '')),
|
||||
'only_logo' => !empty($settings['share_only_logo']),
|
||||
'enabled' => !isset($settings['share_s']) || !empty($settings['share_s']),
|
||||
'items' => $items,
|
||||
'wechat_enabled' => !empty($settings['wechat_share_s']),
|
||||
'wechat_appid' => sanitize_text_field((string) ($wechat['appid'] ?? '')),
|
||||
'wechat_app_secret' => sanitize_text_field((string) ($wechat['app_secret'] ?? '')),
|
||||
'only_logo' => !empty($wechat['only_logo']),
|
||||
'poster_enabled' => $poster_enabled,
|
||||
'compatible_s' => !empty($settings['share_img_compatible_s']),
|
||||
'poster_img' => esc_url_raw((string) ($settings['share_img_byimg'] ?? '')),
|
||||
'poster_logo' => esc_url_raw((string) ($settings['share_logo'] ?? '')),
|
||||
'share_img' => esc_url_raw((string) ($settings['share_img'] ?? '')),
|
||||
'share_desc' => sanitize_textarea_field((string) ($settings['share_desc'] ?? '')) ?: __('扫一扫 立即查看', 'aksrt'),
|
||||
'poster_img' => esc_url_raw((string) ($settings['share_img_byimg'] ?? get_template_directory_uri() . '/assets/img/slider-bg.jpg')),
|
||||
'poster_logo' => esc_url_raw((string) ($settings['share_logo'] ?? get_template_directory_uri() . '/assets/img/logo.png')),
|
||||
'share_desc' => sanitize_text_field((string) ($settings['share_desc'] ?? '')) ?: __('扫一扫 立即查看', 'aksrt'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user