diff --git a/assets/css/admin.css b/assets/css/admin.css new file mode 100644 index 0000000..60e73b5 --- /dev/null +++ b/assets/css/admin.css @@ -0,0 +1,29 @@ +.wpicp-tabs .nav-tab { + cursor: pointer; +} +.wpicp-tabs .nav-tab-active { + background: #fff; + border-bottom: 1px solid #fff; +} +.wpicp_certificate_row { + display: flex; + align-items: center; + padding: 20px 0; +} +.wpicp_badge_row { + display: flex; + align-items: center; + padding: 20px 0; +} +.tab-content { + padding: 20px; + border: 1px solid #ddd; + background: #fff; +} +.nav-tab-wrapper, .wrap h2.nav-tab-wrapper, h1.nav-tab-wrapper { + border-bottom: 0px solid #c3c4c7; + padding-top: 0px; +} +div#wpicp_preset_badges_container label { + padding: 5px 0; +} \ No newline at end of file diff --git a/assets/images/12315.jpg b/assets/images/12315.jpg new file mode 100644 index 0000000..15b8692 Binary files /dev/null and b/assets/images/12315.jpg differ diff --git a/assets/images/12377.jpg b/assets/images/12377.jpg new file mode 100644 index 0000000..908b811 Binary files /dev/null and b/assets/images/12377.jpg differ diff --git a/assets/images/a11y.jpg b/assets/images/a11y.jpg new file mode 100644 index 0000000..201557d Binary files /dev/null and b/assets/images/a11y.jpg differ diff --git a/assets/images/cac.jpg b/assets/images/cac.jpg new file mode 100644 index 0000000..201557d Binary files /dev/null and b/assets/images/cac.jpg differ diff --git a/assets/images/cnca.jpg b/assets/images/cnca.jpg new file mode 100644 index 0000000..201557d Binary files /dev/null and b/assets/images/cnca.jpg differ diff --git a/assets/images/cnipr.jpg b/assets/images/cnipr.jpg new file mode 100644 index 0000000..1d95601 Binary files /dev/null and b/assets/images/cnipr.jpg differ diff --git a/assets/images/djbz.png b/assets/images/djbz.png new file mode 100644 index 0000000..e0e7ab6 Binary files /dev/null and b/assets/images/djbz.png differ diff --git a/assets/images/dzjg.png b/assets/images/dzjg.png new file mode 100644 index 0000000..0900451 Binary files /dev/null and b/assets/images/dzjg.png differ diff --git a/assets/images/dzyyzz.jpg b/assets/images/dzyyzz.jpg new file mode 100644 index 0000000..8e64f40 Binary files /dev/null and b/assets/images/dzyyzz.jpg differ diff --git a/assets/images/ebs.jpg b/assets/images/ebs.jpg new file mode 100644 index 0000000..72b3d6f Binary files /dev/null and b/assets/images/ebs.jpg differ diff --git a/assets/images/gongan2.jpg b/assets/images/gongan2.jpg new file mode 100644 index 0000000..cb82e2e Binary files /dev/null and b/assets/images/gongan2.jpg differ diff --git a/assets/images/gxjs.png b/assets/images/gxjs.png new file mode 100644 index 0000000..a0bfa81 Binary files /dev/null and b/assets/images/gxjs.png differ diff --git a/assets/images/iso-27001.png b/assets/images/iso-27001.png new file mode 100644 index 0000000..8919f6b Binary files /dev/null and b/assets/images/iso-27001.png differ diff --git a/assets/images/iso-27018.png b/assets/images/iso-27018.png new file mode 100644 index 0000000..028f1c6 Binary files /dev/null and b/assets/images/iso-27018.png differ diff --git a/assets/images/knet.jpg b/assets/images/knet.jpg new file mode 100644 index 0000000..201557d Binary files /dev/null and b/assets/images/knet.jpg differ diff --git a/assets/images/kxwz.jpg b/assets/images/kxwz.jpg new file mode 100644 index 0000000..8296a1f Binary files /dev/null and b/assets/images/kxwz.jpg differ diff --git a/assets/images/miit.jpg b/assets/images/miit.jpg new file mode 100644 index 0000000..201557d Binary files /dev/null and b/assets/images/miit.jpg differ diff --git a/assets/images/piyao.jpg b/assets/images/piyao.jpg new file mode 100644 index 0000000..8955781 Binary files /dev/null and b/assets/images/piyao.jpg differ diff --git a/assets/images/psb.jpg b/assets/images/psb.jpg new file mode 100644 index 0000000..201557d Binary files /dev/null and b/assets/images/psb.jpg differ diff --git a/assets/images/sfdf.jpg b/assets/images/sfdf.jpg new file mode 100644 index 0000000..7dcd480 Binary files /dev/null and b/assets/images/sfdf.jpg differ diff --git a/assets/images/sydw.png b/assets/images/sydw.png new file mode 100644 index 0000000..f7ccce3 Binary files /dev/null and b/assets/images/sydw.png differ diff --git a/assets/images/sz315.jpg b/assets/images/sz315.jpg new file mode 100644 index 0000000..d24e252 Binary files /dev/null and b/assets/images/sz315.jpg differ diff --git a/assets/images/szcert.jpg b/assets/images/szcert.jpg new file mode 100644 index 0000000..201557d Binary files /dev/null and b/assets/images/szcert.jpg differ diff --git a/assets/images/trustasia.jpg b/assets/images/trustasia.jpg new file mode 100644 index 0000000..201557d Binary files /dev/null and b/assets/images/trustasia.jpg differ diff --git a/assets/images/wenming.jpg b/assets/images/wenming.jpg new file mode 100644 index 0000000..5e6ba86 Binary files /dev/null and b/assets/images/wenming.jpg differ diff --git a/assets/images/zfwzzc.png b/assets/images/zfwzzc.png new file mode 100644 index 0000000..868e591 Binary files /dev/null and b/assets/images/zfwzzc.png differ diff --git a/assets/js/admin.js b/assets/js/admin.js new file mode 100644 index 0000000..56643ba --- /dev/null +++ b/assets/js/admin.js @@ -0,0 +1,9 @@ +jQuery(document).ready(function($) { + $('.wpicp-tabs .nav-tab').on('click', function(e) { + e.preventDefault(); + $('.wpicp-tabs .nav-tab').removeClass('nav-tab-active'); + $(this).addClass('nav-tab-active'); + $('.wpicp-tabs .tab-content').hide(); + $($(this).attr('href')).show(); + }); +}); \ No newline at end of file diff --git a/wpicp-license.php b/wpicp-license.php index 82a4801..3fc8d86 100755 --- a/wpicp-license.php +++ b/wpicp-license.php @@ -1,310 +1,657 @@ '; - echo '

'.__('Enter your ICP license number information.', 'wpicp-license').'

'; - } - add_filter('admin_init', 'add_wpicp_license_setting'); - function add_wpicp_license_setting(){ - add_settings_field( - 'wpicp_license_field', - __('ICP License', 'wpicp-license'), - 'show_wpicp_license_field', - 'general' - ); - register_setting('general', 'wpicp_license'); - } - - - // Settings section callback - function wpicp_license_section_callback() { - echo '

' . __( 'This plugin is free forever, and its purpose is to supplement the essential functions that the Chinese version of WordPress lacks. More information at WPICP.com', 'wpicp-license' ) . '

'; - echo '

' . __( 'Why do you need?', 'wpicp-license' ) . '

'; - echo '

' . __( 'The ICP license is a state-issued registration, All public websites in mainland China must have an ICP number listed on the homepage of the website. (What would happen if not?)', 'wpicp-license' ) . '

'; - echo '

' . __( 'How to use?', 'wpicp-license' ) . '

'; - echo '

' . __( '1. Enter your ICP license information below. (Find My License?)', 'wpicp-license' ) . '

'; - echo '

' . __( '2. Use the shortcode [wpicp_license] to display the license information and link on your website. (Integrate into theme?)', 'wpicp-license' ) . '

'; - } - -// Settings field callback -function wpicp_license_field_callback() { - $wpicp_license = get_option( 'wpicp_license' ); - echo ''; - echo '

' . __( 'Enter your ICP license number information. (Correct format?)', 'wpicp-license' ) . '

'; -} -// Settings section callback -function wpicp_wangan_section_callback() { - echo '

' . __( 'Use the shortcode [wpicp_wangan], You need to register with the Public Security Bureau (PSB) to have this license. (What is PSB filing?)', 'wpicp-license' ) . '

'; +if (!defined('ABSPATH')) { + exit; } -// Add Wangan license field -function wpicp_wangan_field_callback() { - $wpicp_wangan = get_option( 'wpicp_wangan' ); - $wpicp_province = get_option( 'wpicp_province' ); -?> - +add_action('init', 'wpicp_load_textdomain'); +function wpicp_load_textdomain() { + load_plugin_textdomain('wpicp-license', false, dirname(plugin_basename(__FILE__)) . '/languages'); +} - -

+} else { + add_action('admin_menu', 'wpicp_license_menu'); + function wpicp_license_menu() { + add_options_page( + __('WP ICP License Settings', 'wpicp-license'), + __('ICP License', 'wpicp-license'), + 'manage_options', + 'wpicp_license_settings', + 'wpicp_license_settings_page' + ); + } +} - intval($cert['image_id'] ?? 0), + 'title' => sanitize_text_field($cert['title'] ?? '') + ]; + }, $input); +} + +function wpicp_sanitize_badges($input) { + if (!is_array($input)) return []; + return array_map(function($badge) { + return [ + 'image_id' => intval($badge['image_id'] ?? 0), + 'url' => esc_url_raw($badge['url'] ?? '') + ]; + }, $input); +} + +function wpicp_sanitize_array($input) { + if (!is_array($input)) return []; + return array_map('sanitize_text_field', $input); +} + +function wpicp_sanitize_checkbox($input) { + return $input === '1' ? '1' : '0'; +} + +function wpicp_sanitize_tab_visibility($input) { + $default_tabs = [ + 'wpicp_license_tab' => '1', + 'wpicp_certificates_tab' => '1', + 'wpicp_badges_tab' => '1', + 'wpicp_settings_tab' => '1' + ]; + if (!is_array($input)) return $default_tabs; + foreach ($default_tabs as $tab_id => $default_value) { + if ($tab_id === 'wpicp_settings_tab') { + $default_tabs[$tab_id] = '1'; // Settings tab 始终可见 + } else { + $default_tabs[$tab_id] = isset($input[$tab_id]) && $input[$tab_id] === '1' ? '1' : '0'; + } + } + $visible_count = array_sum(array_map('intval', $default_tabs)); + if ($visible_count < 2) { // 确保至少保留一个非 Settings 的标签 + $default_tabs['wpicp_license_tab'] = '1'; + } + return $default_tabs; +} + +add_action('admin_init', 'wpicp_subsite_settings'); +function wpicp_subsite_settings() { + if (!is_network_admin()) { + add_settings_field('wpicp_license_subsite_field', __('ICP License', 'wpicp-license'), 'wpicp_license_subsite_field_callback', 'general', 'default'); + add_settings_field('wpicp_wangan_subsite_field', __('Wangan License', 'wpicp-license'), 'wpicp_wangan_subsite_field_callback', 'general', 'default'); + register_setting('general', 'wpicp_license', 'sanitize_text_field'); + register_setting('general', 'wpicp_wangan', 'sanitize_text_field'); + } +} + +add_action('admin_enqueue_scripts', 'wpicp_enqueue_scripts'); +function wpicp_enqueue_scripts($hook) { + if (strpos($hook, 'settings_page_wpicp_license_settings') !== false) { + wp_enqueue_media(); + wp_enqueue_style('wpicp-admin-css', plugins_url('assets/css/admin.css', __FILE__), [], '1.8.0'); + wp_enqueue_script('wpicp-admin-js', plugins_url('assets/js/admin.js', __FILE__), ['jquery'], '1.8.0', true); + } +} + +function wpicp_license_section_callback() { + echo '

' . __('Manage your ICP and related license information here.', 'wpicp-license') . '

'; +} + +function wpicp_certificates_section_callback() { + echo '

' . __('Add certificates with titles and images. Use [wpicp_certificates] to display them (e.g., [wpicp_certificates id="0"] or [wpicp_certificates ids="0,1"]).', 'wpicp-license') . '

'; +} + +function wpicp_badges_section_callback() { + echo '

' . __('Add custom badges or select presets. Use [wpicp_badges] (e.g., [wpicp_badges id="0"] or [wpicp_badges ids="0,1"]).', 'wpicp-license') . '

'; +} + +function wpicp_settings_section_callback() { + echo '

' . __('General settings for the WPICP License plugin.', 'wpicp-license') . '

'; +} + +function wpicp_license_field_callback() { + $value = is_multisite() ? get_site_option('wpicp_license') : get_option('wpicp_license'); + echo ''; + echo '

' . __('Enter your ICP license number information. (Correct format?)', 'wpicp-license') . '

'; +} + +function wpicp_wangan_field_callback() { + $wangan = is_multisite() ? get_site_option('wpicp_wangan') : get_option('wpicp_wangan'); + $province = is_multisite() ? get_site_option('wpicp_province') : get_option('wpicp_province'); + ?> + + +

+ '; - echo '

' . __( 'Use the shortcode [wpicp_company]', 'wpicp-license' ) . '

'; - + $value = is_multisite() ? get_site_option('wpicp_company') : get_option('wpicp_company'); + echo ''; + echo '

' . __('Use the shortcode [wpicp_company]', 'wpicp-license') . '

'; } function wpicp_email_field_callback() { - $company = get_option('wpicp_email'); - echo ''; - echo '

' . __( 'Use the shortcode [wpicp_email]', 'wpicp-license' ) . '

'; - + $value = is_multisite() ? get_site_option('wpicp_email') : get_option('wpicp_email'); + echo ''; + echo '

' . __('Use the shortcode [wpicp_email]', 'wpicp-license') . '

'; } function wpicp_phone_field_callback() { - $company = get_option('wpicp_phone'); - echo ''; - echo '

' . __( 'Use the shortcode [wpicp_phone]', 'wpicp-license' ) . '

'; - + $value = is_multisite() ? get_site_option('wpicp_phone') : get_option('wpicp_phone'); + echo ''; + echo '

' . __('Use the shortcode [wpicp_phone]', 'wpicp-license') . '

'; } function wpicp_edi_field_callback() { - $edi = get_option('wpicp_edi'); - echo ''; - echo '

' . __( 'Use the shortcode [wpicp_edi]', 'wpicp-license' ) . '

'; - + $value = is_multisite() ? get_site_option('wpicp_edi') : get_option('wpicp_edi'); + echo ''; + echo '

' . __('Use the shortcode [wpicp_edi]', 'wpicp-license') . '

'; } function wpicp_app_field_callback() { - $app = get_option('wpicp_app'); - echo ''; - echo '

' . __( 'Use the shortcode [wpicp_app]', 'wpicp-license' ) . '

'; + $value = is_multisite() ? get_site_option('wpicp_app') : get_option('wpicp_app'); + echo ''; + echo '

' . __('Use the shortcode [wpicp_app]', 'wpicp-license') . '

'; } function wpicp_miniapp_field_callback() { - $minipapp = get_option('wpicp_miniapp'); - echo ''; - echo '

' . __( 'Use the shortcode [wpicp_miniapp]', 'wpicp-license' ) . '

'; - + $value = is_multisite() ? get_site_option('wpicp_miniapp') : get_option('wpicp_miniapp'); + echo ''; + echo '

' . __('Use the shortcode [wpicp_miniapp]', 'wpicp-license') . '

'; } +function wpicp_certificates_field_callback() { + $certificates = is_multisite() ? get_site_option('wpicp_certificates', []) : get_option('wpicp_certificates', []); + if (!is_array($certificates)) $certificates = []; + ?> +
+ $cert) { ?> +
+ 'vertical-align:middle;']); ?> + + + +
+ +
+ + + 'publish']); + ?> + +

+ +
+ $badge) { ?> +
+ 'vertical-align:middle;']); ?> + + + +
+ +
+ + + [ + 'label' => __('Government Certifications', 'wpicp-license'), + 'items' => [ + 'miit' => ['title' => __('MIIT ICP Filing', 'wpicp-license'), 'url' => 'https://beian.miit.gov.cn/', 'image' => plugins_url('/assets/images/miit.jpg', __FILE__)], + 'psb' => ['title' => __('Public Security Bureau', 'wpicp-license'), 'url' => 'https://www.beian.gov.cn/', 'image' => plugins_url('/assets/images/psb.jpg', __FILE__)], + '12377' => ['title' => __('12377 Reporting', 'wpicp-license'), 'url' => 'https://www.12377.cn/', 'image' => plugins_url('/assets/images/12377.jpg', __FILE__)], + 'wenming' => ['title' => __('China Civilization Network', 'wpicp-license'), 'url' => 'http://www.wenming.cn/', 'image' => plugins_url('/assets/images/wenming.jpg', __FILE__)], + ], + ], + 'cybersecurity' => [ + 'label' => __('Cybersecurity Certifications', 'wpicp-license'), + 'items' => [ + 'piyao' => ['title' => __('Piyao Rumors', 'wpicp-license'), 'url' => 'https://www.piyao.org.cn/', 'image' => plugins_url('/assets/images/piyao.jpg', __FILE__)], + 'cac' => ['title' => __('Cyberspace Administration', 'wpicp-license'), 'url' => 'http://www.cac.gov.cn/', 'image' => plugins_url('/assets/images/cac.jpg', __FILE__)], + 'cnca' => ['title' => __('CNCA Certification', 'wpicp-license'), 'url' => 'http://www.cnca.gov.cn/', 'image' => plugins_url('/assets/images/cnca.jpg', __FILE__)], + ], + ], + 'trustworthiness' => [ + 'label' => __('Trustworthiness Certifications', 'wpicp-license'), + 'items' => [ + 'knet' => ['title' => __('Knet Trust', 'wpicp-license'), 'url' => 'https://ss.knet.cn/', 'image' => plugins_url('/assets/images/knet.jpg', __FILE__)], + 'szcert' => ['title' => __('SZCert', 'wpicp-license'), 'url' => 'http://szcert.ebs.org.cn/', 'image' => plugins_url('/assets/images/szcert.jpg', __FILE__)], + 'sz315' => ['title' => __('SZ315 Integrity', 'wpicp-license'), 'url' => 'https://www.sz315.org/', 'image' => plugins_url('/assets/images/sz315.jpg', __FILE__)], + 'trustasia' => ['title' => __('TrustAsia', 'wpicp-license'), 'url' => 'https://www.trustasia.com/', 'image' => plugins_url('/assets/images/trustasia.jpg', __FILE__)], + ], + ], + ]; + ?> +
+ $group_data) { ?> +

+ $preset) { ?> + + + +
+

+ '; + echo ''; + if (WP_DEBUG) { + error_log('WPICP License: Allow Subsite Override displayed as - ' . $value); + } +} + +function wpicp_default_image_size_callback() { + $value = is_multisite() ? get_site_option('wpicp_default_image_size', 'thumbnail') : get_option('wpicp_default_image_size', 'thumbnail'); + ?> + +

+ '; + echo '

' . __('Add a custom CSS class to the shortcode output for styling.', 'wpicp-license') . '

'; +} + +function wpicp_tab_visibility_callback() { + $visibility = is_multisite() ? get_site_option('wpicp_tab_visibility', ['wpicp_license_tab' => '1', 'wpicp_certificates_tab' => '1', 'wpicp_badges_tab' => '1', 'wpicp_settings_tab' => '1']) : get_option('wpicp_tab_visibility', ['wpicp_license_tab' => '1', 'wpicp_certificates_tab' => '1', 'wpicp_badges_tab' => '1', 'wpicp_settings_tab' => '1']); + $tabs = [ + 'wpicp_license_tab' => __('ICP License Number', 'wpicp-license'), + 'wpicp_certificates_tab' => __('Certificates Center', 'wpicp-license'), + 'wpicp_badges_tab' => __('Badges', 'wpicp-license'), + ]; + foreach ($tabs as $tab_id => $label) { + $checked = isset($visibility[$tab_id]) && $visibility[$tab_id] === '1' ? 'checked' : ''; + ?> + + '; + echo '

' . __('Uncheck to hide the corresponding tab from the settings page. The Settings tab is always visible.', 'wpicp-license') . '

'; +} + +function wpicp_license_subsite_field_callback() { + $site_value = get_option('wpicp_license'); + $network_value = get_site_option('wpicp_license'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1') === '1'; // 默认 '1',但确保数据库优先 + $value = $allow_override ? ($site_value ?: $network_value) : $network_value; + $disabled = is_multisite() && !$allow_override ? ' disabled' : ''; + echo ''; + echo '

' . __('Enter your ICP license number information.', 'wpicp-license'); + if (is_multisite() && !$allow_override) echo ' ' . __('Network settings are enforced.', 'wpicp-license'); + echo '

'; +} + +function wpicp_wangan_subsite_field_callback() { + $site_value = get_option('wpicp_wangan'); + $network_value = get_site_option('wpicp_wangan'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1') === '1'; + $value = $allow_override ? ($site_value ?: $network_value) : $network_value; + $disabled = is_multisite() && !$allow_override ? ' disabled' : ''; + echo ''; + echo '

' . __('Enter your Wangan license number.', 'wpicp-license'); + if (is_multisite() && !$allow_override) echo ' ' . __('Network settings are enforced.', 'wpicp-license'); + echo '

'; +} -// Settings page callback function wpicp_license_settings_page() { + if (is_multisite() && !current_user_can('manage_network_options')) { + wp_die(__('You do not have permission to access this page.', 'wpicp-license')); + } + $visibility = is_multisite() ? get_site_option('wpicp_tab_visibility', ['wpicp_license_tab' => '1', 'wpicp_certificates_tab' => '1', 'wpicp_badges_tab' => '1', 'wpicp_settings_tab' => '1']) : get_option('wpicp_tab_visibility', ['wpicp_license_tab' => '1', 'wpicp_certificates_tab' => '1', 'wpicp_badges_tab' => '1', 'wpicp_settings_tab' => '1']); + $tabs = [ + 'wpicp_license_tab' => ['label' => __('ICP License Number', 'wpicp-license'), 'section' => 'wpicp_license_tab'], + 'wpicp_certificates_tab' => ['label' => __('Certificates Center', 'wpicp-license'), 'section' => 'wpicp_certificates_tab'], + 'wpicp_badges_tab' => ['label' => __('Badges', 'wpicp-license'), 'section' => 'wpicp_badges_tab'], + 'wpicp_settings_tab' => ['label' => __('Settings', 'wpicp-license'), 'section' => 'wpicp_settings_tab'], + ]; ?>
-

-
- - +

+ + +
+ + $tab_data) { + $is_hidden = $tab_id !== 'wpicp_settings_tab' && isset($visibility[$tab_id]) && $visibility[$tab_id] === '0'; + $style = $first_visible && !$is_hidden ? '' : ' style="display: none;"'; + echo '
'; + do_settings_sections($tab_data['section']); + echo '
'; + if ($is_hidden) { + // 为隐藏的选项卡添加隐藏字段,保留数据 + if ($tab_id === 'wpicp_license_tab') { + $license = is_multisite() ? get_site_option('wpicp_license', '') : get_option('wpicp_license', ''); + $wangan = is_multisite() ? get_site_option('wpicp_wangan', '') : get_option('wpicp_wangan', ''); + $province = is_multisite() ? get_site_option('wpicp_province', '') : get_option('wpicp_province', ''); + $company = is_multisite() ? get_site_option('wpicp_company', '') : get_option('wpicp_company', ''); + $email = is_multisite() ? get_site_option('wpicp_email', '') : get_option('wpicp_email', ''); + $phone = is_multisite() ? get_site_option('wpicp_phone', '') : get_option('wpicp_phone', ''); + $edi = is_multisite() ? get_site_option('wpicp_edi', '') : get_option('wpicp_edi', ''); + $app = is_multisite() ? get_site_option('wpicp_app', '') : get_option('wpicp_app', ''); + $miniapp = is_multisite() ? get_site_option('wpicp_miniapp', '') : get_option('wpicp_miniapp', ''); + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + } elseif ($tab_id === 'wpicp_certificates_tab') { + $certificates = is_multisite() ? get_site_option('wpicp_certificates', []) : get_option('wpicp_certificates', []); + $certificates_page = is_multisite() ? get_site_option('wpicp_certificates_page', 0) : get_option('wpicp_certificates_page', 0); + foreach ($certificates as $index => $cert) { + echo ''; + echo ''; + } + echo ''; + } elseif ($tab_id === 'wpicp_badges_tab') { + $badges = is_multisite() ? get_site_option('wpicp_badges', []) : get_option('wpicp_badges', []); + $selected_presets = is_multisite() ? get_site_option('wpicp_selected_presets', []) : get_option('wpicp_selected_presets', []); + foreach ($badges as $index => $badge) { + echo ''; + echo ''; + } + foreach ($selected_presets as $preset) { + echo ''; + } + } + } + $first_visible = $first_visible && !$is_hidden ? false : $first_visible; + } + ?> +
' . esc_html($license) . ''; + } + return ''; +} -?> +add_shortcode('wpicp_wangan', 'wpicp_wangan_shortcode'); +function wpicp_wangan_shortcode() { + $site_wangan = get_option('wpicp_wangan'); + $network_wangan = get_site_option('wpicp_wangan'); + $site_province = get_option('wpicp_province'); + $network_province = get_site_option('wpicp_province'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1') === '1'; + $wangan = (is_multisite() && $allow_override) ? ($site_wangan ?: $network_wangan) : $network_wangan; + $province = (is_multisite() && $allow_override) ? ($site_province ?: $network_province) : $network_province; + if (!$wangan || !$province) return ''; + $text = 'Wangan License ' . esc_html($province) . '公网安备' . esc_html($wangan) . '号'; + return '' . $text . ''; +} + +add_shortcode('wpicp_province', 'wpicp_province_shortcode'); +function wpicp_province_shortcode() { + $site_value = get_option('wpicp_province'); + $network_value = get_site_option('wpicp_province'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1'); + $province = (is_multisite() && $allow_override) ? ($site_value ?: $network_value) : $network_value; + $provinces = [ + '京' => __('Beijing', 'wpicp-license'), '津' => __('Tianjin', 'wpicp-license'), '冀' => __('Hebei', 'wpicp-license'), + '晋' => __('Shanxi', 'wpicp-license'), '蒙' => __('Inner Mongolia', 'wpicp-license'), '辽' => __('Liaoning', 'wpicp-license'), + '吉' => __('Jilin', 'wpicp-license'), '黑' => __('Heilongjiang', 'wpicp-license'), '沪' => __('Shanghai', 'wpicp-license'), + '苏' => __('Jiangsu', 'wpicp-license'), '浙' => __('Zhejiang', 'wpicp-license'), '皖' => __('Anhui', 'wpicp-license'), + '闽' => __('Fujian', 'wpicp-license'), '赣' => __('Jiangxi', 'wpicp-license'), '鲁' => __('Shandong', 'wpicp-license'), + '豫' => __('Henan', 'wpicp-license'), '鄂' => __('Hubei', 'wpicp-license'), '湘' => __('Hunan', 'wpicp-license'), + '粤' => __('Guangdong', 'wpicp-license'), '桂' => __('Guangxi', 'wpicp-license'), '琼' => __('Hainan', 'wpicp-license'), + '渝' => __('Chongqing', 'wpicp-license'), '川' => __('Sichuan', 'wpicp-license'), '黔' => __('Guizhou', 'wpicp-license'), + '滇' => __('Yunnan', 'wpicp-license'), '藏' => __('Tibet', 'wpicp-license'), '陕' => __('Shaanxi', 'wpicp-license'), + '甘' => __('Gansu', 'wpicp-license'), '青' => __('Qinghai', 'wpicp-license'), '宁' => __('Ningxia', 'wpicp-license'), + '新' => __('Xinjiang', 'wpicp-license') + ]; + return isset($provinces[$province]) ? esc_html($provinces[$province]) : ''; +} + +add_shortcode('wpicp_p', 'wpicp_province_abbr_shortcode'); +function wpicp_province_abbr_shortcode() { + $site_value = get_option('wpicp_province'); + $network_value = get_site_option('wpicp_province'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1'); + $province = (is_multisite() && $allow_override) ? ($site_value ?: $network_value) : $network_value; + return $province ? esc_html($province) : ''; +} + +add_shortcode('wpicp_company', 'wpicp_company_shortcode'); +function wpicp_company_shortcode() { + $site_value = get_option('wpicp_company'); + $network_value = get_site_option('wpicp_company'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1'); + $company = (is_multisite() && $allow_override) ? ($site_value ?: $network_value) : $network_value; + return $company ? esc_html($company) : ''; +} + +add_shortcode('wpicp_email', 'wpicp_email_shortcode'); +function wpicp_email_shortcode() { + $site_value = get_option('wpicp_email'); + $network_value = get_site_option('wpicp_email'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1'); + $email = (is_multisite() && $allow_override) ? ($site_value ?: $network_value) : $network_value; + return $email ? esc_html($email) : ''; +} + +add_shortcode('wpicp_phone', 'wpicp_phone_shortcode'); +function wpicp_phone_shortcode() { + $site_value = get_option('wpicp_phone'); + $network_value = get_site_option('wpicp_phone'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1'); + $phone = (is_multisite() && $allow_override) ? ($site_value ?: $network_value) : $network_value; + return $phone ? esc_html($phone) : ''; +} + +add_shortcode('wpicp_edi', 'wpicp_edi_shortcode'); +function wpicp_edi_shortcode() { + $site_value = get_option('wpicp_edi'); + $network_value = get_site_option('wpicp_edi'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1'); + $edi = (is_multisite() && $allow_override) ? ($site_value ?: $network_value) : $network_value; + return $edi ? esc_html($edi) : ''; +} + +add_shortcode('wpicp_app', 'wpicp_app_shortcode'); +function wpicp_app_shortcode() { + $site_value = get_option('wpicp_app'); + $network_value = get_site_option('wpicp_app'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1'); + $app = (is_multisite() && $allow_override) ? ($site_value ?: $network_value) : $network_value; + return $app ? esc_html($app) : ''; +} + +add_shortcode('wpicp_miniapp', 'wpicp_miniapp_shortcode'); +function wpicp_miniapp_shortcode() { + $site_value = get_option('wpicp_miniapp'); + $network_value = get_site_option('wpicp_miniapp'); + $allow_override = get_site_option('wpicp_allow_subsite_override', '1'); + $miniapp = (is_multisite() && $allow_override) ? ($site_value ?: $network_value) : $network_value; + return $miniapp ? esc_html($miniapp) : ''; +} + +add_shortcode('wpicp_certificates', 'wpicp_certificates_shortcode'); +function wpicp_certificates_shortcode($atts) { + $atts = shortcode_atts(['full' => 'false', 'id' => '', 'ids' => ''], $atts); + $certificates = is_multisite() ? get_site_option('wpicp_certificates', []) : get_option('wpicp_certificates', []); + $page_id = is_multisite() ? get_site_option('wpicp_certificates_page', 0) : get_option('wpicp_certificates_page', 0); + $default_size = is_multisite() ? get_site_option('wpicp_default_image_size', 'thumbnail') : get_option('wpicp_default_image_size', 'thumbnail'); + $custom_class = is_multisite() ? get_site_option('wpicp_custom_css_class', '') : get_option('wpicp_custom_css_class', ''); + if (!is_array($certificates) || empty($certificates)) return ''; + if ($atts['id'] !== '') { + $index = intval($atts['id']); + $certificates = isset($certificates[$index]) ? [$certificates[$index]] : []; + } elseif ($atts['ids'] !== '') { + $ids = array_map('intval', explode(',', $atts['ids'])); + $certificates = array_filter($certificates, function($key) use ($ids) { + return in_array($key, $ids); + }, ARRAY_FILTER_USE_KEY); + } + if (empty($certificates)) return ''; + $size = $atts['full'] === 'true' ? 'full' : $default_size; + $output = '
'; + $page_url = $page_id ? get_permalink($page_id) : '#'; + foreach ($certificates as $cert) { + $image = wp_get_attachment_image($cert['image_id'], $size); + $title = '
' . esc_html($cert['title']) . '
'; + $content = $atts['full'] === 'true' ? $image . $title : '' . $image . $title . ''; + $output .= '
' . $content . '
'; + } + $output .= '
'; + return $output; +} + +add_shortcode('wpicp_badges', 'wpicp_badges_shortcode'); +function wpicp_badges_shortcode($atts) { + $atts = shortcode_atts(['id' => '', 'ids' => '', 'preset' => 'false'], $atts); + $badges = is_multisite() ? get_site_option('wpicp_badges', []) : get_option('wpicp_badges', []); + $selected_presets = is_multisite() ? get_site_option('wpicp_selected_presets', []) : get_option('wpicp_selected_presets', []); + $default_size = is_multisite() ? get_site_option('wpicp_default_image_size', 'thumbnail') : get_option('wpicp_default_image_size', 'thumbnail'); + $custom_class = is_multisite() ? get_site_option('wpicp_custom_css_class', '') : get_option('wpicp_custom_css_class', ''); + if (!is_array($badges)) $badges = []; + if (!is_array($selected_presets)) $selected_presets = []; + $presets = [ + 'miit' => ['title' => __('MIIT ICP Filing', 'wpicp-license'), 'url' => 'https://beian.miit.gov.cn/', 'image' => plugins_url('/assets/images/miit.jpg', __FILE__)], + 'psb' => ['title' => __('Public Security Bureau', 'wpicp-license'), 'url' => 'https://www.beian.gov.cn/', 'image' => plugins_url('/assets/images/psb.jpg', __FILE__)], + '12377' => ['title' => __('12377 Reporting', 'wpicp-license'), 'url' => 'https://www.12377.cn/', 'image' => plugins_url('/assets/images/12377.jpg', __FILE__)], + 'wenming' => ['title' => __('China Civilization Network', 'wpicp-license'), 'url' => 'http://www.wenming.cn/', 'image' => plugins_url('/assets/images/wenming.jpg', __FILE__)], + 'piyao' => ['title' => __('Piyao Rumors', 'wpicp-license'), 'url' => 'https://www.piyao.org.cn/', 'image' => plugins_url('/assets/images/piyao.jpg', __FILE__)], + 'cac' => ['title' => __('Cyberspace Administration', 'wpicp-license'), 'url' => 'http://www.cac.gov.cn/', 'image' => plugins_url('/assets/images/cac.jpg', __FILE__)], + 'cnca' => ['title' => __('CNCA Certification', 'wpicp-license'), 'url' => 'http://www.cnca.gov.cn/', 'image' => plugins_url('/assets/images/cnca.jpg', __FILE__)], + 'knet' => ['title' => __('Knet Trust', 'wpicp-license'), 'url' => 'https://ss.knet.cn/', 'image' => plugins_url('/assets/images/knet.jpg', __FILE__)], + 'szcert' => ['title' => __('SZCert', 'wpicp-license'), 'url' => 'http://szcert.ebs.org.cn/', 'image' => plugins_url('/assets/images/szcert.jpg', __FILE__)], + 'sz315' => ['title' => __('SZ315 Integrity', 'wpicp-license'), 'url' => 'https://www.sz315.org/', 'image' => plugins_url('/assets/images/sz315.jpg', __FILE__)], + 'trustasia' => ['title' => __('TrustAsia', 'wpicp-license'), 'url' => 'https://www.trustasia.com/', 'image' => plugins_url('/assets/images/trustasia.jpg', __FILE__)], + ]; + $all_badges = $badges; + if ($atts['preset'] !== 'true') { + foreach ($selected_presets as $key) { + if (isset($presets[$key])) { + $all_badges[] = ['image_id' => null, 'url' => $presets[$key]['url'], 'preset_image' => $presets[$key]['image']]; + } + } + } + if (empty($all_badges)) return ''; + if ($atts['id'] !== '') { + $index = intval($atts['id']); + $all_badges = isset($all_badges[$index]) ? [$all_badges[$index]] : []; + } elseif ($atts['ids'] !== '') { + $ids = array_map('intval', explode(',', $atts['ids'])); + $all_badges = array_filter($all_badges, function($key) use ($ids) { + return in_array($key, $ids); + }, ARRAY_FILTER_USE_KEY); + } + if (empty($all_badges)) return ''; + $output = '
'; + foreach ($all_badges as $badge) { + $image = isset($badge['preset_image']) ? '' : wp_get_attachment_image($badge['image_id'], $default_size); + $output .= '' . $image . ''; + } + $output .= '
'; + return $output; +} \ No newline at end of file