'f5efe0', ) ); // Set content-width. global $content_width; if ( ! isset( $content_width ) ) { $content_width = 580; } /* * 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' ); // Set post thumbnail size. set_post_thumbnail_size( 1200, 9999 ); // Add custom image size used in Cover Template. add_image_size( 'twentytwenty-fullscreen', 1980, 9999 ); // Custom logo. $logo_width = 120; $logo_height = 90; // If the retina setting is active, double the recommended width and height. if ( get_theme_mod( 'retina_logo', false ) ) { $logo_width = floor( $logo_width * 2 ); $logo_height = floor( $logo_height * 2 ); } add_theme_support( 'custom-logo', array( 'height' => $logo_height, 'width' => $logo_width, 'flex-height' => true, 'flex-width' => true, ) ); /* * Let WordPress manage the document title. * By adding theme support, we declare that this theme does not use a * hard-coded tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support( 'title-tag' ); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style', 'navigation-widgets', ) ); /* * Make theme available for translation. * Translations can be filed in the /languages/ directory. * If you're building a theme based on Twenty Twenty, use a find and replace * to change 'twentytwenty' to the name of your theme in all the template files. */ load_theme_textdomain( 'twentytwenty' ); // Add support for full and wide align images. add_theme_support( 'align-wide' ); // Add support for responsive embeds. add_theme_support( 'responsive-embeds' ); /* * Adds starter content to highlight the theme on fresh sites. * This is done conditionally to avoid loading the starter content on every * page load, as it is a one-off operation only needed once in the customizer. */ if ( is_customize_preview() ) { require get_template_directory() . '/inc/starter-content.php'; add_theme_support( 'starter-content', twentytwenty_get_starter_content() ); } // Add theme support for selective refresh for widgets. add_theme_support( 'customize-selective-refresh-widgets' ); /* * Adds `async` and `defer` support for scripts registered or enqueued * by the theme. */ $loader = new TwentyTwenty_Script_Loader(); add_filter( 'script_loader_tag', array( $loader, 'filter_script_loader_tag' ), 10, 2 ); } add_action( 'after_setup_theme', 'twentytwenty_theme_support' ); /** * REQUIRED FILES * Include required files. */ require get_template_directory() . '/inc/template-tags.php'; // Handle SVG icons. require get_template_directory() . '/classes/class-twentytwenty-svg-icons.php'; require get_template_directory() . '/inc/svg-icons.php'; // Handle Customizer settings. require get_template_directory() . '/classes/class-twentytwenty-customize.php'; // Require Separator Control class. require get_template_directory() . '/classes/class-twentytwenty-separator-control.php'; // Custom comment walker. require get_template_directory() . '/classes/class-twentytwenty-walker-comment.php'; // Custom page walker. require get_template_directory() . '/classes/class-twentytwenty-walker-page.php'; // Custom script loader class. require get_template_directory() . '/classes/class-twentytwenty-script-loader.php'; // Non-latin language handling. require get_template_directory() . '/classes/class-twentytwenty-non-latin-languages.php'; // Custom CSS. require get_template_directory() . '/inc/custom-css.php'; // Block Patterns. require get_template_directory() . '/inc/block-patterns.php'; /** * Register and Enqueue Styles. */ function twentytwenty_register_styles() { $theme_version = wp_get_theme()->get( 'Version' ); wp_enqueue_style( 'twentytwenty-style', get_stylesheet_uri(), array(), $theme_version ); wp_style_add_data( 'twentytwenty-style', 'rtl', 'replace' ); // Add output of Customizer settings as inline style. wp_add_inline_style( 'twentytwenty-style', twentytwenty_get_customizer_css( 'front-end' ) ); // Add print CSS. wp_enqueue_style( 'twentytwenty-print-style', get_template_directory_uri() . '/print.css', null, $theme_version, 'print' ); } add_action( 'wp_enqueue_scripts', 'twentytwenty_register_styles' ); /** * Register and Enqueue Scripts. */ function twentytwenty_register_scripts() { $theme_version = wp_get_theme()->get( 'Version' ); if ( ( ! is_admin() ) && is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } wp_enqueue_script( 'twentytwenty-js', get_template_directory_uri() . '/assets/js/index.js', array(), $theme_version, false ); wp_script_add_data( 'twentytwenty-js', 'async', true ); } add_action( 'wp_enqueue_scripts', 'twentytwenty_register_scripts' ); /** * Fix skip link focus in IE11. * * This does not enqueue the script because it is tiny and because it is only for IE11, * thus it does not warrant having an entire dedicated blocking script being loaded. * * @link https://git.io/vWdr2 */ function twentytwenty_skip_link_focus_fix() { // The following is minified via `terser --compress --mangle -- assets/js/skip-link-focus-fix.js`. ?> <script> /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1); </script> <?php } add_action( 'wp_print_footer_scripts', 'twentytwenty_skip_link_focus_fix' ); /** Enqueue non-latin language styles * * @since Twenty Twenty 1.0 * * @return void */ function twentytwenty_non_latin_languages() { $custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'front-end' ); if ( $custom_css ) { wp_add_inline_style( 'twentytwenty-style', $custom_css ); } } add_action( 'wp_enqueue_scripts', 'twentytwenty_non_latin_languages' ); /** * Register navigation menus uses wp_nav_menu in five places. */ function twentytwenty_menus() { $locations = array( 'primary' => __( 'Desktop Horizontal Menu', 'twentytwenty' ), 'expanded' => __( 'Desktop Expanded Menu', 'twentytwenty' ), 'mobile' => __( 'Mobile Menu', 'twentytwenty' ), 'footer' => __( 'Footer Menu', 'twentytwenty' ), 'social' => __( 'Social Menu', 'twentytwenty' ), ); register_nav_menus( $locations ); } add_action( 'init', 'twentytwenty_menus' ); /** * Get the information about the logo. * * @param string $html The HTML output from get_custom_logo (core function). * @return string */ function twentytwenty_get_custom_logo( $html ) { $logo_id = get_theme_mod( 'custom_logo' ); if ( ! $logo_id ) { return $html; } $logo = wp_get_attachment_image_src( $logo_id, 'full' ); if ( $logo ) { // For clarity. $logo_width = esc_attr( $logo[1] ); $logo_height = esc_attr( $logo[2] ); // If the retina logo setting is active, reduce the width/height by half. if ( get_theme_mod( 'retina_logo', false ) ) { $logo_width = floor( $logo_width / 2 ); $logo_height = floor( $logo_height / 2 ); $search = array( '/width=\"\d+\"/iU', '/height=\"\d+\"/iU', ); $replace = array( "width=\"{$logo_width}\"", "height=\"{$logo_height}\"", ); // Add a style attribute with the height, or append the height to the style attribute if the style attribute already exists. if ( strpos( $html, ' style=' ) === false ) { $search[] = '/(src=)/'; $replace[] = "style=\"height: {$logo_height}px;\" src="; } else { $search[] = '/(style="[^"]*)/'; $replace[] = "$1 height: {$logo_height}px;"; } $html = preg_replace( $search, $replace, $html ); } } return $html; } add_filter( 'get_custom_logo', 'twentytwenty_get_custom_logo' ); if ( ! function_exists( 'wp_body_open' ) ) { /** * Shim for wp_body_open, ensuring backward compatibility with versions of WordPress older than 5.2. */ function wp_body_open() { do_action( 'wp_body_open' ); } } /** * Include a skip to content link at the top of the page so that users can bypass the menu. */ function twentytwenty_skip_link() { echo '<a class="skip-link screen-reader-text" href="#site-content">' . __( 'Skip to the content', 'twentytwenty' ) . '</a>'; } add_action( 'wp_body_open', 'twentytwenty_skip_link', 5 ); /** * Register widget areas. * * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar */ function twentytwenty_sidebar_registration() { // Arguments used in all register_sidebar() calls. $shared_args = array( 'before_title' => '<h2 class="widget-title subheading heading-size-3">', 'after_title' => '</h2>', 'before_widget' => '<div class="widget %2$s"><div class="widget-content">', 'after_widget' => '</div></div>', ); // Footer #1. register_sidebar( array_merge( $shared_args, array( 'name' => __( 'Footer #1', 'twentytwenty' ), 'id' => 'sidebar-1', 'description' => __( 'Widgets in this area will be displayed in the first column in the footer.', 'twentytwenty' ), ) ) ); // Footer #2. register_sidebar( array_merge( $shared_args, array( 'name' => __( 'Footer #2', 'twentytwenty' ), 'id' => 'sidebar-2', 'description' => __( 'Widgets in this area will be displayed in the second column in the footer.', 'twentytwenty' ), ) ) ); } add_action( 'widgets_init', 'twentytwenty_sidebar_registration' ); /** * Enqueue supplemental block editor styles. */ function twentytwenty_block_editor_styles() { // Enqueue the editor styles. wp_enqueue_style( 'twentytwenty-block-editor-styles', get_theme_file_uri( '/assets/css/editor-style-block.css' ), array(), wp_get_theme()->get( 'Version' ), 'all' ); wp_style_add_data( 'twentytwenty-block-editor-styles', 'rtl', 'replace' ); // Add inline style from the Customizer. wp_add_inline_style( 'twentytwenty-block-editor-styles', twentytwenty_get_customizer_css( 'block-editor' ) ); // Add inline style for non-latin fonts. wp_add_inline_style( 'twentytwenty-block-editor-styles', TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'block-editor' ) ); // Enqueue the editor script. wp_enqueue_script( 'twentytwenty-block-editor-script', get_theme_file_uri( '/assets/js/editor-script-block.js' ), array( 'wp-blocks', 'wp-dom' ), wp_get_theme()->get( 'Version' ), true ); } add_action( 'enqueue_block_editor_assets', 'twentytwenty_block_editor_styles', 1, 1 ); /** * Enqueue classic editor styles. */ function twentytwenty_classic_editor_styles() { $classic_editor_styles = array( '/assets/css/editor-style-classic.css', ); add_editor_style( $classic_editor_styles ); } add_action( 'init', 'twentytwenty_classic_editor_styles' ); /** * Output Customizer settings in the classic editor. * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution. * * @param array $mce_init TinyMCE styles. * @return array TinyMCE styles. */ function twentytwenty_add_classic_editor_customizer_styles( $mce_init ) { $styles = twentytwenty_get_customizer_css( 'classic-editor' ); if ( ! isset( $mce_init['content_style'] ) ) { $mce_init['content_style'] = $styles . ' '; } else { $mce_init['content_style'] .= ' ' . $styles . ' '; } return $mce_init; } add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_customizer_styles' ); /** * Output non-latin font styles in the classic editor. * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution. * * @param array $mce_init TinyMCE styles. * @return array TinyMCE styles. */ function twentytwenty_add_classic_editor_non_latin_styles( $mce_init ) { $styles = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'classic-editor' ); // Return if there are no styles to add. if ( ! $styles ) { return $mce_init; } if ( ! isset( $mce_init['content_style'] ) ) { $mce_init['content_style'] = $styles . ' '; } else { $mce_init['content_style'] .= ' ' . $styles . ' '; } return $mce_init; } add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_non_latin_styles' ); /** * Block Editor Settings. * Add custom colors and font sizes to the block editor. */ function twentytwenty_block_editor_settings() { // Block Editor Palette. $editor_color_palette = array( array( 'name' => __( 'Accent Color', 'twentytwenty' ), 'slug' => 'accent', 'color' => twentytwenty_get_color_for_area( 'content', 'accent' ), ), array( 'name' => _x( 'Primary', 'color', 'twentytwenty' ), 'slug' => 'primary', 'color' => twentytwenty_get_color_for_area( 'content', 'text' ), ), array( 'name' => _x( 'Secondary', 'color', 'twentytwenty' ), 'slug' => 'secondary', 'color' => twentytwenty_get_color_for_area( 'content', 'secondary' ), ), array( 'name' => __( 'Subtle Background', 'twentytwenty' ), 'slug' => 'subtle-background', 'color' => twentytwenty_get_color_for_area( 'content', 'borders' ), ), ); // Add the background option. $background_color = get_theme_mod( 'background_color' ); if ( ! $background_color ) { $background_color_arr = get_theme_support( 'custom-background' ); $background_color = $background_color_arr[0]['default-color']; } $editor_color_palette[] = array( 'name' => __( 'Background Color', 'twentytwenty' ), 'slug' => 'background', 'color' => '#' . $background_color, ); // If we have accent colors, add them to the block editor palette. if ( $editor_color_palette ) { add_theme_support( 'editor-color-palette', $editor_color_palette ); } // Block Editor Font Sizes. add_theme_support( 'editor-font-sizes', array( array( 'name' => _x( 'Small', 'Name of the small font size in the block editor', 'twentytwenty' ), 'shortName' => _x( 'S', 'Short name of the small font size in the block editor.', 'twentytwenty' ), 'size' => 18, 'slug' => 'small', ), array( 'name' => _x( 'Regular', 'Name of the regular font size in the block editor', 'twentytwenty' ), 'shortName' => _x( 'M', 'Short name of the regular font size in the block editor.', 'twentytwenty' ), 'size' => 21, 'slug' => 'normal', ), array( 'name' => _x( 'Large', 'Name of the large font size in the block editor', 'twentytwenty' ), 'shortName' => _x( 'L', 'Short name of the large font size in the block editor.', 'twentytwenty' ), 'size' => 26.25, 'slug' => 'large', ), array( 'name' => _x( 'Larger', 'Name of the larger font size in the block editor', 'twentytwenty' ), 'shortName' => _x( 'XL', 'Short name of the larger font size in the block editor.', 'twentytwenty' ), 'size' => 32, 'slug' => 'larger', ), ) ); add_theme_support( 'editor-styles' ); // If we have a dark background color then add support for dark editor style. // We can determine if the background color is dark by checking if the text-color is white. if ( '#ffffff' === strtolower( twentytwenty_get_color_for_area( 'content', 'text' ) ) ) { add_theme_support( 'dark-editor-style' ); } } add_action( 'after_setup_theme', 'twentytwenty_block_editor_settings' ); /** * Overwrite default more tag with styling and screen reader markup. * * @param string $html The default output HTML for the more tag. * @return string */ function twentytwenty_read_more_tag( $html ) { return preg_replace( '/<a(.*)>(.*)<\/a>/iU', sprintf( '<div class="read-more-button-wrap"><a$1><span class="faux-button">$2</span> <span class="screen-reader-text">"%1$s"</span></a></div>', get_the_title( get_the_ID() ) ), $html ); } add_filter( 'the_content_more_link', 'twentytwenty_read_more_tag' ); /** * Enqueues scripts for customizer controls & settings. * * @since Twenty Twenty 1.0 * * @return void */ function twentytwenty_customize_controls_enqueue_scripts() { $theme_version = wp_get_theme()->get( 'Version' ); // Add main customizer js file. wp_enqueue_script( 'twentytwenty-customize', get_template_directory_uri() . '/assets/js/customize.js', array( 'jquery' ), $theme_version, false ); // Add script for color calculations. wp_enqueue_script( 'twentytwenty-color-calculations', get_template_directory_uri() . '/assets/js/color-calculations.js', array( 'wp-color-picker' ), $theme_version, false ); // Add script for controls. wp_enqueue_script( 'twentytwenty-customize-controls', get_template_directory_uri() . '/assets/js/customize-controls.js', array( 'twentytwenty-color-calculations', 'customize-controls', 'underscore', 'jquery' ), $theme_version, false ); wp_localize_script( 'twentytwenty-customize-controls', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() ); } add_action( 'customize_controls_enqueue_scripts', 'twentytwenty_customize_controls_enqueue_scripts' ); /** * Enqueue scripts for the customizer preview. * * @since Twenty Twenty 1.0 * * @return void */ function twentytwenty_customize_preview_init() { $theme_version = wp_get_theme()->get( 'Version' ); wp_enqueue_script( 'twentytwenty-customize-preview', get_theme_file_uri( '/assets/js/customize-preview.js' ), array( 'customize-preview', 'customize-selective-refresh', 'jquery' ), $theme_version, true ); wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() ); wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyPreviewEls', twentytwenty_get_elements_array() ); wp_add_inline_script( 'twentytwenty-customize-preview', sprintf( 'wp.customize.selectiveRefresh.partialConstructor[ %1$s ].prototype.attrs = %2$s;', wp_json_encode( 'cover_opacity' ), wp_json_encode( twentytwenty_customize_opacity_range() ) ) ); } add_action( 'customize_preview_init', 'twentytwenty_customize_preview_init' ); /** * Get accessible color for an area. * * @since Twenty Twenty 1.0 * * @param string $area The area we want to get the colors for. * @param string $context Can be 'text' or 'accent'. * @return string Returns a HEX color. */ function twentytwenty_get_color_for_area( $area = 'content', $context = 'text' ) { // Get the value from the theme-mod. $settings = get_theme_mod( 'accent_accessible_colors', array( 'content' => array( 'text' => '#000000', 'accent' => '#cd2653', 'secondary' => '#6d6d6d', 'borders' => '#dcd7ca', ), 'header-footer' => array( 'text' => '#000000', 'accent' => '#cd2653', 'secondary' => '#6d6d6d', 'borders' => '#dcd7ca', ), ) ); // If we have a value return it. if ( isset( $settings[ $area ] ) && isset( $settings[ $area ][ $context ] ) ) { return $settings[ $area ][ $context ]; } // Return false if the option doesn't exist. return false; } /** * Returns an array of variables for the customizer preview. * * @since Twenty Twenty 1.0 * * @return array */ function twentytwenty_get_customizer_color_vars() { $colors = array( 'content' => array( 'setting' => 'background_color', ), 'header-footer' => array( 'setting' => 'header_footer_background_color', ), ); return $colors; } /** * Get an array of elements. * * @since Twenty Twenty 1.0 * * @return array */ function twentytwenty_get_elements_array() { // The array is formatted like this: // [key-in-saved-setting][sub-key-in-setting][css-property] = [elements]. $elements = array( 'content' => array( 'accent' => array( 'color' => array( '.color-accent', '.color-accent-hover:hover', '.color-accent-hover:focus', ':root .has-accent-color', '.has-drop-cap:not(:focus):first-letter', '.wp-block-button.is-style-outline', 'a' ), 'border-color' => array( 'blockquote', '.border-color-accent', '.border-color-accent-hover:hover', '.border-color-accent-hover:focus' ), 'background-color' => array( 'button', '.button', '.faux-button', '.wp-block-button__link', '.wp-block-file .wp-block-file__button', 'input[type="button"]', 'input[type="reset"]', 'input[type="submit"]', '.bg-accent', '.bg-accent-hover:hover', '.bg-accent-hover:focus', ':root .has-accent-background-color', '.comment-reply-link' ), 'fill' => array( '.fill-children-accent', '.fill-children-accent *' ), ), 'background' => array( 'color' => array( ':root .has-background-color', 'button', '.button', '.faux-button', '.wp-block-button__link', '.wp-block-file__button', 'input[type="button"]', 'input[type="reset"]', 'input[type="submit"]', '.wp-block-button', '.comment-reply-link', '.has-background.has-primary-background-color:not(.has-text-color)', '.has-background.has-primary-background-color *:not(.has-text-color)', '.has-background.has-accent-background-color:not(.has-text-color)', '.has-background.has-accent-background-color *:not(.has-text-color)' ), 'background-color' => array( ':root .has-background-background-color' ), ), 'text' => array( 'color' => array( 'body', '.entry-title a', ':root .has-primary-color' ), 'background-color' => array( ':root .has-primary-background-color' ), ), 'secondary' => array( 'color' => array( 'cite', 'figcaption', '.wp-caption-text', '.post-meta', '.entry-content .wp-block-archives li', '.entry-content .wp-block-categories li', '.entry-content .wp-block-latest-posts li', '.wp-block-latest-comments__comment-date', '.wp-block-latest-posts__post-date', '.wp-block-embed figcaption', '.wp-block-image figcaption', '.wp-block-pullquote cite', '.comment-metadata', '.comment-respond .comment-notes', '.comment-respond .logged-in-as', '.pagination .dots', '.entry-content hr:not(.has-background)', 'hr.styled-separator', ':root .has-secondary-color' ), 'background-color' => array( ':root .has-secondary-background-color' ), ), 'borders' => array( 'border-color' => array( 'pre', 'fieldset', 'input', 'textarea', 'table', 'table *', 'hr' ), 'background-color' => array( 'caption', 'code', 'code', 'kbd', 'samp', '.wp-block-table.is-style-stripes tbody tr:nth-child(odd)', ':root .has-subtle-background-background-color' ), 'border-bottom-color' => array( '.wp-block-table.is-style-stripes' ), 'border-top-color' => array( '.wp-block-latest-posts.is-grid li' ), 'color' => array( ':root .has-subtle-background-color' ), ), ), 'header-footer' => array( 'accent' => array( 'color' => array( 'body:not(.overlay-header) .primary-menu > li > a', 'body:not(.overlay-header) .primary-menu > li > .icon', '.modal-menu a', '.footer-menu a, .footer-widgets a', '#site-footer .wp-block-button.is-style-outline', '.wp-block-pullquote:before', '.singular:not(.overlay-header) .entry-header a', '.archive-header a', '.header-footer-group .color-accent', '.header-footer-group .color-accent-hover:hover' ), 'background-color' => array( '.social-icons a', '#site-footer button:not(.toggle)', '#site-footer .button', '#site-footer .faux-button', '#site-footer .wp-block-button__link', '#site-footer .wp-block-file__button', '#site-footer input[type="button"]', '#site-footer input[type="reset"]', '#site-footer input[type="submit"]' ), ), 'background' => array( 'color' => array( '.social-icons a', 'body:not(.overlay-header) .primary-menu ul', '.header-footer-group button', '.header-footer-group .button', '.header-footer-group .faux-button', '.header-footer-group .wp-block-button:not(.is-style-outline) .wp-block-button__link', '.header-footer-group .wp-block-file__button', '.header-footer-group input[type="button"]', '.header-footer-group input[type="reset"]', '.header-footer-group input[type="submit"]' ), 'background-color' => array( '#site-header', '.footer-nav-widgets-wrapper', '#site-footer', '.menu-modal', '.menu-modal-inner', '.search-modal-inner', '.archive-header', '.singular .entry-header', '.singular .featured-media:before', '.wp-block-pullquote:before' ), ), 'text' => array( 'color' => array( '.header-footer-group', 'body:not(.overlay-header) #site-header .toggle', '.menu-modal .toggle' ), 'background-color' => array( 'body:not(.overlay-header) .primary-menu ul' ), 'border-bottom-color' => array( 'body:not(.overlay-header) .primary-menu > li > ul:after' ), 'border-left-color' => array( 'body:not(.overlay-header) .primary-menu ul ul:after' ), ), 'secondary' => array( 'color' => array( '.site-description', 'body:not(.overlay-header) .toggle-inner .toggle-text', '.widget .post-date', '.widget .rss-date', '.widget_archive li', '.widget_categories li', '.widget cite', '.widget_pages li', '.widget_meta li', '.widget_nav_menu li', '.powered-by-wordpress', '.to-the-top', '.singular .entry-header .post-meta', '.singular:not(.overlay-header) .entry-header .post-meta a' ), ), 'borders' => array( 'border-color' => array( '.header-footer-group pre', '.header-footer-group fieldset', '.header-footer-group input', '.header-footer-group textarea', '.header-footer-group table', '.header-footer-group table *', '.footer-nav-widgets-wrapper', '#site-footer', '.menu-modal nav *', '.footer-widgets-outer-wrapper', '.footer-top' ), 'background-color' => array( '.header-footer-group table caption', 'body:not(.overlay-header) .header-inner .toggle-wrapper::before' ), ), ), ); /** * Filters Twenty Twenty theme elements * * @since Twenty Twenty 1.0 * * @param array Array of elements */ return apply_filters( 'twentytwenty_get_elements_array', $elements ); } /********************* カードタイプ記事のショートコード *********************/ add_shortcode('card4', 'sng_longcard_link4'); // カードタイプ(横長)の関連記事を出力 if (!function_exists('sng_longcard_link4')) { function sng_longcard_link4($atts) { $output = ''; $ids = isset($atts['id']) ? explode(',', $atts['id']) : null; if(!$ids) return ""; $target = isset($atts['target']) ? ' target="_blank"' : ""; foreach ($ids as $eachid) { list($url, $title, $img, $date) = sng_get_entry_link_data($eachid, 'thumb-520', true); if ($url && $title) { $output .= <<<EOF <a class="e_linkto longc_linkto" href="{$url}"{$target}> <span class="longc_img">{$img}</span> <p>{$date}<span class="longc_title">{$title}</span></p> </a> EOF; } // endif } // end foreach return $output; } } function wptypes_listvfav_func($atts=array(), $content=null) { extract( shortcode_atts( array(), $atts ) ); if (function_exists('wpfp_get_users_favorites')): $favorite_post_ids = wpfp_get_users_favorites(); $limit = 10; $content .= " "; if ($favorite_post_ids): $c = 0; $favorite_post_ids = array_reverse($favorite_post_ids); foreach ($favorite_post_ids as $post_id) { if ($c++ == $limit) break; $p = get_post($post_id); $image = $p->pic; set_post_thumbnail_size(600, 600); $content .= " "; $content .= "<a href='".get_permalink($post_id)."' class='card mb-1' style='max-width: 540px'>"; $content .= "<div class='row no-gutters'>"; $content .= "<div class='col-md-4 d-flex text-center'>"; $content .= wp_get_attachment_image($image, 'medium'); $content .= "</div>"; $content .= "<div class='col-md-8'>"; $content .= "<div class='card-body'>"; $content .= "<h5 class='card-title mt-0'>" . $p->post_title . "</h5>"; $content .= "<p class='card-text'>" . $p->content . "</p>"; $content .= "<p class='card-text'>" . $p->price . "</p>"; $content .= "</div>"; $content .= "</div>"; $content .= "</div>"; $content .= "</a>"; $content .= " "; } else: $content .= " "; $content .= "お気に入りした投稿が表示されます。"; $content .= " "; endif; $content .= " "; endif; return $content; } add_shortcode('wptypes_listvfav', 'wptypes_listvfav_func'); function load_scripts() { wp_enqueue_script('rotate_logo_script', get_template_directory_uri() . '/js/rotateLogo.js'); } add_action('wp_enqueue_scripts', 'load_scripts'); // ログを出力 if(!function_exists('_log')){ function _log($message) { if (WP_DEBUG_LOG === true) { if (is_array($message) || is_object($message)) { error_log(print_r($message, true)); } else { error_log($message); } } } } // チャットルーム一覧表示 function display_chat_room_list($atts) { global $wpdb; $table = $wpdb->prefix . 'wise_chat_channels'; $results = $wpdb->get_results("SELECT * FROM " . $table); $html = '<ul class="list-group mb-2">'; foreach($results as $row) { $name = $row->name; $supplier_id = $atts['supplier_id']; preg_match("/chat-room-{$supplier_id}-(\w+)/", $name, $match); if (isset($match[1])) { $customer_id = $match[1]; $customer_name = get_userdata($customer_id)->user_login; $channel = 'chat-room-' .$supplier_id. '-' .$customer_id; $msg_count = get_message_count_by_channel($channel); $last_datetime = get_last_message_datetime($channel); $html .= "<li class='list-group-item list-group-item-action'><a href='https://source.oysterworld.jp/matching-app/?page_id=414&supplier_id={$atts['supplier_id']}&customer_id={$customer_id}'>"; $html .= "{$customer_name}とのチャットルーム</a>"; $html .= "<small class='text-muted'> 更新日時:{$last_datetime}</small>"; $html .= "<span class='badge badge-info'>{$msg_count}</span>"; $html .= '</li>'; } } $html .= '</ul>'; return $html; } add_shortcode('display_chat_room_list', 'display_chat_room_list'); function get_message_count_by_channel($channel) { global $wpdb; $table = $wpdb->prefix . 'wise_chat_messages'; $result = $wpdb->get_results("SELECT * FROM {$table} WHERE channel='{$channel}'"); return $wpdb->num_rows; } function get_last_message_datetime($channel) { global $wpdb; $table = $wpdb->prefix . 'wise_chat_messages'; $result = $wpdb->get_results("SELECT * FROM {$table} WHERE time = (SELECT MAX(time) FROM {$table} WHERE channel='{$channel}')"); $unixtime = $result[0]->time; date_default_timezone_set ('Asia/Tokyo'); if ($unixtime == 0) { return 'なし'; } return date('Y年m月d日 H時i分s秒', $unixtime); } // 最終ログインを記録 function user_last_login($user_login, $user) { update_user_meta($user->ID, 'last_login', time()); } add_action('wp_login', 'user_last_login', 10, 2); // 最終ログイン日時を管理画面に表示 function add_users_columns($columns) { $columns['columns_lastlogin'] = '最終ログイン'; return $columns; } function add_users_custom_column($column_name, $column, $user_id) { if($column == 'columns_lastlogin') { $user_info = get_userdata($user_id); $user_lastlogin_time = $user_info->last_login; date_default_timezone_set ('Asia/Tokyo'); return date('Y/m/d H:i:s',intval($user_lastlogin_time)); } } add_filter( 'manage_users_columns', 'add_users_columns' ); add_filter( 'manage_users_custom_column', 'add_users_custom_column', 10, 3 ); // チャットを既読にする function read_wise_chat($supplier_id, $customer_id) { global $wpdb; $table_message = $wpdb->prefix . 'wise_chat_messages'; $table_notification = $wpdb->prefix . 'wise_chat_notification'; $channel = 'chat-room-' .$supplier_id. '-' .$customer_id; $current_user_id = wp_get_current_user()->ID; $sendor_id = $current_user_id == $supplier_id ? $customer_id : $supplier_id; $sendor_name = get_userdata($sendor_id)->display_name; $message_ids = $wpdb->get_col( "SELECT id FROM {$table_message} WHERE channel='{$channel}' AND user='{$sendor_name}'" ); foreach($message_ids as $message_id) { $wpdb->update( $table_notification, array( 'has_read' => 1, 'read_time' => time() ), array( 'message_id' => $message_id, 'has_read' => '0' ) ); } } // チャット未読の件数取得、表示 function get_unread_chat_rooms() { global $wpdb; $table_message = $wpdb->prefix . 'wise_chat_messages'; $table_notification = $wpdb->prefix . 'wise_chat_notification'; $current_user_id = wp_get_current_user()->ID; $current_user_name = get_userdata($current_user_id)->display_name; $channel_sup = 'chat-room-' .$current_user_id. '-_'; $channel_cus = 'chat-room-_-' .$current_user_id; $messages = $wpdb->get_results( "SELECT id, channel FROM {$table_message} WHERE (channel LIKE '{$channel_sup}' OR channel LIKE '{$channel_cus}') AND user!='{$current_user_name}'" ); $unread_chat_rooms = array(); foreach($messages as $message) { $result = $wpdb->get_results( "SELECT id, has_read FROM {$table_notification} WHERE message_id = '{$message->id}'" ); if($result[0]->id != 0 && $result[0]->has_read == 0) { $url = get_chat_room_url_by_channel($message->channel); if (array_key_exists($url, $unread_chat_rooms)) { $unread_chat_rooms[$url] += 1; } else { $unread_chat_rooms[$url] = 1; } } } return $unread_chat_rooms; } function show_count_unread_wise_chat() { $unread_chat_rooms = get_unread_chat_rooms(); $count = 0; foreach($unread_chat_rooms as $unread_chat_count) { $count += $unread_chat_count; } return $count; } function get_chat_room_url_by_channel($channel) { preg_match('/chat-room-(\w+)-(\w+)/', $channel, $match); $supplier_id = $match[1]; $customer_id = $match[2]; $url = "https://source.oysterworld.jp/matching-app/?page_id=414&supplier_id={$supplier_id}&customer_id={$customer_id}"; return $url; } function display_unread_chat_room_list() { $html = '<ul class="list-group">'; $unread_chat_rooms = get_unread_chat_rooms(); foreach($unread_chat_rooms as $url => $count) { $partner_name = get_chat_partner_name_by_url($url); $html .= <<< HTML <li class='list-group-item list-group-item-action'> <a href=$url>{$partner_name}とのチャット 未読:{$count}件</a> </li> HTML; } $html .= '</ul>'; return $html; } add_shortcode('display_unread_chat_room_list', 'display_unread_chat_room_list'); function get_chat_partner_name_by_url($url) { preg_match('/supplier_id=(\w+)&customer_id=(\w+)/', $url, $match); $current_user_id = wp_get_current_user()->ID; if($current_user_id == $match[1]) { return get_userdata($match[2])->display_name; } return get_userdata($match[1])->display_name; } // ポストのスラッグを変更 function auto_post_slug( $slug, $post_ID, $post_status, $post_type ) { if ( preg_match( '/(%[0-9a-f]{2})+/', $slug ) ) { $slug = utf8_uri_encode( $post_type ) . '-' . $post_ID; } return $slug; } add_filter( 'wp_unique_post_slug', 'auto_post_slug', 10, 4 ); /** * ページネーションHTML出力 * * $limit ページあたりの表示上限数 * $post_typed 投稿タイプのスラッグ */ function pagenation($limit = 5, $post_typed = 'service') { global $wp_rewrite; global $paged; global $wp_query; // 検索条件 $query = array(); if ($limit != 5) { $query['posts_per_page'] = $limit; } if (count($query) != 0) { $wp_query->query($query); } $wp_query->query(array( 'post_type' => $post_typed, )); $paginate_base = get_pagenum_link(); if( strpos( $paginate_base, '?' ) || !$wp_rewrite->using_permalinks() ) { $paginate_format = ''; $paginate_base = add_query_arg( 'paged', '%#%' ); } else { $paginate_format = (substr( $paginate_base, -1, 1 ) == '/' ? '' : '/') . user_trailingslashit('page/%#%/','paged'); $paginate_base .= '%_%'; } if( $paged < 2 ) { $paged = 1; } $args = array( 'base' => $paginate_base, 'format' => $paginate_format, 'total' => $wp_query->max_num_pages, 'current' => $paged, 'show_all' => false, 'prev_next' => true, 'prev_text' => '«', 'next_text' => '»', 'type' => 'array', ); $pagenate_array = paginate_links($args); // 配列がある場合のみ if (is_array($pagenate_array) == TRUE) { $pagenate .= '<div class="wp-pagenavi">'; foreach ($pagenate_array as $key => $value) { if (preg_match('/current/', $value) == TRUE) { $class = ''; } else { $class = ''; } // $value = "<span class=\"{$class}\">".$value.'</span>'; // リンク追加 $pagenate .= $value; } $pagenate .= '</div>'; echo $pagenate; } }