tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support('title-tag'); /* * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support('post-thumbnails'); add_image_size('twentyseventeen-featured-image', 2000, 1200, true); add_image_size('twentyseventeen-thumbnail-avatar', 100, 100, true); // Set the default content width. $GLOBALS['content_width'] = 525; // This theme uses wp_nav_menu() in two locations. register_nav_menus(array( 'top' => __('Top Menu', 'twentyseventeen'), 'social' => __('Social Links Menu', 'twentyseventeen'), )); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support('html5', array( 'comment-form', 'comment-list', 'gallery', 'caption', )); /* * Enable support for Post Formats. * * See: https://codex.wordpress.org/Post_Formats */ add_theme_support('post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'gallery', 'audio', )); // Add theme support for Custom Logo. add_theme_support('custom-logo', array( 'width' => 250, 'height' => 250, 'flex-width' => true, )); // Add theme support for selective refresh for widgets. add_theme_support('customize-selective-refresh-widgets'); /* * This theme styles the visual editor to resemble the theme style, * specifically font, colors, and column width. */ add_editor_style(array('assets/css/editor-style.css', twentyseventeen_fonts_url())); // Define and register starter content to showcase the theme on new sites. $starter_content = array( 'widgets' => array( // Place three core-defined widgets in the sidebar area. 'sidebar-1' => array( 'text_business_info', 'search', 'text_about', ), // Add the core-defined business info widget to the footer 1 area. 'sidebar-2' => array( 'text_business_info', ), // Put two core-defined widgets in the footer 2 area. 'sidebar-3' => array( 'text_about', 'search', ), ), // Specify the core-defined pages to create and add custom thumbnails to some of them. 'posts' => array( 'home', 'about' => array( 'thumbnail' => '{{image-sandwich}}', ), 'contact' => array( 'thumbnail' => '{{image-espresso}}', ), 'blog' => array( 'thumbnail' => '{{image-coffee}}', ), 'homepage-section' => array( 'thumbnail' => '{{image-espresso}}', ), ), // Create the custom image attachments used as post thumbnails for pages. 'attachments' => array( 'image-espresso' => array( 'post_title' => _x('Espresso', 'Theme starter content', 'twentyseventeen'), 'file' => 'assets/images/espresso.jpg', // URL relative to the template directory. ), 'image-sandwich' => array( 'post_title' => _x('Sandwich', 'Theme starter content', 'twentyseventeen'), 'file' => 'assets/images/sandwich.jpg', ), 'image-coffee' => array( 'post_title' => _x('Coffee', 'Theme starter content', 'twentyseventeen'), 'file' => 'assets/images/coffee.jpg', ), ), // Default to a static front page and assign the front and posts pages. 'options' => array( 'show_on_front' => 'page', 'page_on_front' => '{{home}}', 'page_for_posts' => '{{blog}}', ), // Set the front page section theme mods to the IDs of the core-registered pages. 'theme_mods' => array( 'panel_1' => '{{homepage-section}}', 'panel_2' => '{{about}}', 'panel_3' => '{{blog}}', 'panel_4' => '{{contact}}', ), // Set up nav menus for each of the two areas registered in the theme. 'nav_menus' => array( // Assign a menu to the "top" location. 'top' => array( 'name' => __('Top Menu', 'twentyseventeen'), 'items' => array( 'link_home', // Note that the core "home" page is actually a link in case a static front page is not used. 'page_about', 'page_blog', 'page_contact', ), ), // Assign a menu to the "social" location. 'social' => array( 'name' => __('Social Links Menu', 'twentyseventeen'), 'items' => array( 'link_yelp', 'link_facebook', 'link_twitter', 'link_instagram', 'link_email', ), ), ), ); /** * Filters Twenty Seventeen array of starter content. * * @since Twenty Seventeen 1.1 * * @param array $starter_content Array of starter content. */ $starter_content = apply_filters('twentyseventeen_starter_content', $starter_content); add_theme_support('starter-content', $starter_content); } add_action('after_setup_theme', 'twentyseventeen_setup'); /** * Set the content width in pixels, based on the theme's design and stylesheet. * * Priority 0 to make it available to lower priority callbacks. * * @global int $content_width */ function twentyseventeen_content_width() { $content_width = $GLOBALS['content_width']; // Get layout. $page_layout = get_theme_mod('page_layout'); // Check if layout is one column. if ('one-column' === $page_layout) { if (twentyseventeen_is_frontpage()) { $content_width = 644; } elseif (is_page()) { $content_width = 740; } } // Check if is single post and there is no sidebar. if (is_single() && ! is_active_sidebar('sidebar-1')) { $content_width = 740; } /** * Filter Twenty Seventeen content width of the theme. * * @since Twenty Seventeen 1.0 * * @param $content_width integer */ $GLOBALS['content_width'] = apply_filters('twentyseventeen_content_width', $content_width); } add_action('template_redirect', 'twentyseventeen_content_width', 0); /** * Register custom fonts. */ function twentyseventeen_fonts_url() { $fonts_url = ''; /** * Translators: If there are characters in your language that are not * supported by Libre Franklin, translate this to 'off'. Do not translate * into your own language. */ $libre_franklin = _x('on', 'Libre Franklin font: on or off', 'twentyseventeen'); if ('off' !== $libre_franklin) { $font_families = array(); $font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i'; $query_args = array( 'family' => urlencode(implode('|', $font_families)), 'subset' => urlencode('latin,latin-ext'), ); $fonts_url = add_query_arg($query_args, 'https://fonts.googleapis.com/css'); } return esc_url_raw($fonts_url); } /** * Add preconnect for Google Fonts. * * @since Twenty Seventeen 1.0 * * @param array $urls URLs to print for resource hints. * @param string $relation_type The relation type the URLs are printed. * @return array $urls URLs to print for resource hints. */ function twentyseventeen_resource_hints($urls, $relation_type) { if (wp_style_is('twentyseventeen-fonts', 'queue') && 'preconnect' === $relation_type) { $urls[] = array( 'href' => 'https://fonts.gstatic.com', 'crossorigin', ); } return $urls; } add_filter('wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2); /** * Register widget area. * * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar */ function twentyseventeen_widgets_init() { register_sidebar(array( 'name' => __('Sidebar', 'twentyseventeen'), 'id' => 'sidebar-1', 'description' => __('Add widgets here to appear in your sidebar.', 'twentyseventeen'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); register_sidebar(array( 'name' => __('Footer 1', 'twentyseventeen'), 'id' => 'sidebar-2', 'description' => __('Add widgets here to appear in your footer.', 'twentyseventeen'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); register_sidebar(array( 'name' => __('Footer 2', 'twentyseventeen'), 'id' => 'sidebar-3', 'description' => __('Add widgets here to appear in your footer.', 'twentyseventeen'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); } add_action('widgets_init', 'twentyseventeen_widgets_init'); /** * Replaces "[...]" (appended to automatically generated excerpts) with ... and * a 'Continue reading' link. * * @since Twenty Seventeen 1.0 * * @return string 'Continue reading' link prepended with an ellipsis. */ function twentyseventeen_excerpt_more($link) { if (is_admin()) { return $link; } $link = sprintf( '', esc_url(get_permalink(get_the_ID())), /* translators: %s: Name of current post */ sprintf(__('Continue reading "%s"', 'twentyseventeen'), get_the_title(get_the_ID())) ); return ' … ' . $link; } add_filter('excerpt_more', 'twentyseventeen_excerpt_more'); /** * Handles JavaScript detection. * * Adds a `js` class to the root `` element when JavaScript is detected. * * @since Twenty Seventeen 1.0 */ function twentyseventeen_javascript_detection() { echo "\n"; } add_action('wp_head', 'twentyseventeen_javascript_detection', 0); /** * Add a pingback url auto-discovery header for singularly identifiable articles. */ function twentyseventeen_pingback_header() { if (is_singular() && pings_open()) { printf('' . "\n", get_bloginfo('pingback_url')); } } add_action('wp_head', 'twentyseventeen_pingback_header'); /** * Display custom color CSS. */ function twentyseventeen_colors_css_wrap() { if ('custom' !== get_theme_mod('colorscheme') && ! is_customize_preview()) { return; } require_once(get_parent_theme_file_path('/inc/color-patterns.php')); $hue = absint(get_theme_mod('colorscheme_hue', 250)); ?> twentyseventeen_get_svg(array('icon' => 'quote-right')), ); if (has_nav_menu('top')) { wp_enqueue_script('twentyseventeen-navigation', get_theme_file_uri('/assets/js/navigation.js'), array(), '1.0', true); $twentyseventeen_l10n['expand'] = __('Expand child menu', 'twentyseventeen'); $twentyseventeen_l10n['collapse'] = __('Collapse child menu', 'twentyseventeen'); $twentyseventeen_l10n['icon'] = twentyseventeen_get_svg(array('icon' => 'angle-down', 'fallback' => true)); } wp_enqueue_script('twentyseventeen-global', get_theme_file_uri('/assets/js/global.js'), array('jquery'), '1.0', true); wp_enqueue_script('jquery-scrollto', get_theme_file_uri('/assets/js/jquery.scrollTo.js'), array('jquery'), '2.1.2', true); wp_localize_script('twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n); if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } } add_action('wp_enqueue_scripts', 'twentyseventeen_scripts'); /** * Add custom image sizes attribute to enhance responsive image functionality * for content images. * * @since Twenty Seventeen 1.0 * * @param string $sizes A source size value for use in a 'sizes' attribute. * @param array $size Image size. Accepts an array of width and height * values in pixels (in that order). * @return string A source size value for use in a content image 'sizes' attribute. */ function twentyseventeen_content_image_sizes_attr($sizes, $size) { $width = $size[0]; if (740 <= $width) { $sizes = '(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px'; } if (is_active_sidebar('sidebar-1') || is_archive() || is_search() || is_home() || is_page()) { if (! (is_page() && 'one-column' === get_theme_mod('page_options')) && 767 <= $width) { $sizes = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px'; } } return $sizes; } add_filter('wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2); /** * Filter the `sizes` value in the header image markup. * * @since Twenty Seventeen 1.0 * * @param string $html The HTML image tag markup being filtered. * @param object $header The custom header object returned by 'get_custom_header()'. * @param array $attr Array of the attributes for the image tag. * @return string The filtered header image HTML. */ function twentyseventeen_header_image_tag($html, $header, $attr) { if (isset($attr['sizes'])) { $html = str_replace($attr['sizes'], '100vw', $html); } return $html; } add_filter('get_header_image_tag', 'twentyseventeen_header_image_tag', 10, 3); /** * Add custom image sizes attribute to enhance responsive image functionality * for post thumbnails. * * @since Twenty Seventeen 1.0 * * @param array $attr Attributes for the image markup. * @param int $attachment Image attachment ID. * @param array $size Registered image size or flat array of height and width dimensions. * @return string A source size value for use in a post thumbnail 'sizes' attribute. */ function twentyseventeen_post_thumbnail_sizes_attr($attr, $attachment, $size) { if (is_archive() || is_search() || is_home()) { $attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px'; } else { $attr['sizes'] = '100vw'; } return $attr; } add_filter('wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3); /** * Use front-page.php when Front page displays is set to a static page. * * @since Twenty Seventeen 1.0 * * @param string $template front-page.php. * * @return string The template to be used: blank if is_home() is true (defaults to index.php), else $template. */ function twentyseventeen_front_page_template($template) { return is_home() ? '' : $template; } add_filter('frontpage_template', 'twentyseventeen_front_page_template'); /** * Implement the Custom Header feature. */ require get_parent_theme_file_path('/inc/custom-header.php'); /** * Custom template tags for this theme. */ require get_parent_theme_file_path('/inc/template-tags.php'); /** * Additional features to allow styling of the templates. */ require get_parent_theme_file_path('/inc/template-functions.php'); /** * Customizer additions. */ require get_parent_theme_file_path('/inc/customizer.php'); /** * SVG icons functions and filters. */ require get_parent_theme_file_path('/inc/icon-functions.php'); show_admin_bar(false); function link_button1_func($atts = array(), $content = "") { # first for wiki-category posts return '
' . $atts['text'] . '
'; } add_shortcode('link_btn1', 'link_button1_func'); // Remove WordPress Meta Generator remove_action('wp_head', 'wp_generator'); // Hide WordPress Version Info function hide_wordpress_version() { return ''; } add_filter('the_generator', 'hide_wordpress_version'); // Remove WordPress Version Number In URL Parameters From JS/CSS function hide_wordpress_version_in_script($src, $handle) { $src = remove_query_arg('ver', $src); $src = add_query_arg('v', str_replace('?', '', FE_VER), $src); return $src; } add_filter('style_loader_src', 'hide_wordpress_version_in_script', 10, 2); add_filter('script_loader_src', 'hide_wordpress_version_in_script', 10, 2); remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('admin_print_styles', 'print_emoji_styles'); remove_action('wp_head', 'wp_resource_hints', 2); #https://wordpress.org/support/topic/remove-the-new-dns-prefetch-code/ /* function datasci_wp_title( $title ) { var_dump($title); return 'xxx'.$title; } add_filter( 'wp_title', 'datasci_wp_title' ); */ function datasci_wp_title($title) { // https://make.wordpress.org/core/2015/10/20/document-title-in-4-4/ global $post; $post_title = $post->post_title; $cat_id = get_query_var('cat'); $pagename = get_query_var('pagename'); $title = ''; if (is_home()) { $title = ''; } elseif ($pagename) { $title = $post_title . ' - '; } elseif ($cat_id) { if ($cat_id == SPEAKER_CAT_ID) { $cur_page_num = get_query_var('paged'); if ($cur_page_num < 1) { $cur_page_num = 1; } $title = '演講一覽 (第 ' . $cur_page_num . ' 頁) - '; } else { $cat = get_category($cat_id); $title = $cat->name . '列表頁 - '; } } elseif ($post_title) { $title = str_replace('’', "'", trim($post_title)) . ' - '; } $bloginfo_name = get_bloginfo('name'); /* if(DataConf::is_DS_conf()){ $bloginfo_name = str_replace('人工智慧','資料科學',$bloginfo_name); }else{ $bloginfo_name = str_replace('資料科學','人工智慧',$bloginfo_name); } */ return $title . $bloginfo_name; #.'-人工智慧.智慧台灣'; } add_filter('pre_get_document_title', 'datasci_wp_title', 999, 1); add_action('admin_menu', 'example_admin_menu'); function example_admin_menu() { global $submenu; // d($submenu); $submenu['tools.php'][] = array('[內部]更新講者資料', 'manage_options', TOOLS_URL . 'update_speaker/'); $submenu['tools.php'][] = array('[內部] EDM 寄信', 'manage_options', TOOLS_URL . 'sendmail/'); $submenu['tools.php'][] = array('[內部] agenda', 'manage_options', TOOLS_URL . 'Agenda/'); } #add_menu_page( 'redirecting', '更新講師', 'read', 'my-top-level-handle', 'redirect_home_987'); function callback_tech2021_remove_hacker_content($buffer) { $buffer = preg_replace('//', '', $buffer); $buffer = str_replace('http://datasci.tw', 'https://' . LIVE_DOMAIN_WITH_WWW, $buffer); return $buffer; } // function tech2021_buffer_start_remove_hacker_content() { ob_start('callback_tech2021_remove_hacker_content'); } // function tech2021_buffer_end_remove_hacker_content() { ob_end_flush(); } // http://codex.wordpress.org/Plugin_API/Action_Reference // add_action('registered_taxonomy', 'tech2021_buffer_start_remove_hacker_content'); // add_action('shutdown', 'tech2021_buffer_end_remove_hacker_content'); remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'rest_output_link_wp_head'); remove_action('wp_head', 'wlwmanifest_link'); /* JSON API restrict */ // add_filter('rest_authentication_errors', 'wpse150207_filter_incoming_connections'); function wpse150207_filter_incoming_connections($errors) { $allowed_ips = array('61.222.27.93', '172.18.0.1','172.18.0.5','202.182.123.223', '172.18.0.5'); $request_server = $_SERVER['REMOTE_ADDR']; if (! in_array($request_server, $allowed_ips)) return new WP_Error('forbidden_access', 'Access denied', array('status' => 403)); return $errors; } /** * Only allow access for specific IP addresses */ function restrict_access_to_specific_ips() { $allowed_ips = unserialize(ALLOWED_IPS); // 解析 wp-config.php 的定義 $is_opening = WEB_PUBLIC; // 解析 wp-config.php 的定義 if (!$is_opening && !(in_array($_SERVER['REMOTE_ADDR'], $allowed_ips))) { wp_redirect("https://aiacademy.tw/"); exit(); } } add_action('template_redirect', 'restrict_access_to_specific_ips'); /** * Restrict access to pages */ function restrict_access_to_pages() { $restricted_pages = unserialize(RESTRICTED_PAGES); // 解析 wp-config.php 的定義 $allowed_ips = unserialize(ALLOWED_IPS); // 解析 wp-config.php 的定義 if (is_page($restricted_pages) && !(in_array($_SERVER['REMOTE_ADDR'], $allowed_ips))) { // die($_SERVER['REMOTE_ADDR']); // die('Access denied'); wp_redirect("/"); exit(); } } add_action('template_redirect', 'restrict_access_to_pages'); // 確認是否為售票期間 function is_signup_time() { $date = new DateTime(); $date->setTimezone(new DateTimeZone('Asia/Taipei')); set_query_var('is_signup_period', $date >= new DateTime(SIGNUP_START_TIME) && $date <= new DateTime(SIGNUP_END_TIME)); } add_action('template_redirect', 'is_signup_time'); // close session if it is active at the end of the script function close_session_at_end() { if (session_status() === PHP_SESSION_ACTIVE) { session_write_close(); } } add_action('shutdown', 'close_session_at_end');