관리-도구
편집 파일: functions.php
<?php defined( 'ABSPATH' ) || die( "Can't access directly" ); // Constants define( 'ARCADE_THEME_DIR', get_template_directory() ); define( 'ARCADE_THEME_URI', get_template_directory_uri() ); define( 'ARCADE_THEME_VERSION', wp_get_theme( 'arcade-theme' )->get( 'Version' ) ); define( 'ARCADE_TEMP', trailingslashit( WP_CONTENT_DIR.'/uploads' ) . 'arcade-theme' ); define( 'ARCADE_IMG', trailingslashit( WP_CONTENT_DIR.'/uploads' ) . 'game-images' ); defined('WP_HOME') or define('WP_HOME', home_url( '/' )); /** * Sets up theme defaults and registers support for various WordPress features. * * Note that this function is hooked into the after_setup_theme hook, which * runs before the init hook. The init hook is too late for some features, such * as indicating support for post thumbnails. */ function arcade_setup() { /* * Let WordPress manage the document title. * By adding theme support, we declare that this theme does not use a * hard-coded <title> tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support( 'title-tag' ); /* * Make theme available for translation. * Translations can be filed in the /languages/ directory. * If you're building a theme based on Arcade Theme, use a find and replace * to change 'arcade' to the name of your theme in all the template files. */ load_theme_textdomain( 'arcade', ARCADE_THEME_DIR . '/languages' ); // Set up the WordPress core custom background feature. $defaults = array( 'default-color' => '#4fc6f9', 'default-image' => '', 'default-repeat' => 'repeat', 'default-position-x' => 'left', 'default-position-y' => 'top', 'default-size' => 'auto', 'default-attachment' => 'scroll', //'wp-head-callback' => '_custom_background_cb', 'admin-head-callback' => '', 'admin-preview-callback' => '' ); add_theme_support( 'custom-background', $defaults ); // Custom logo. add_theme_support( 'custom-logo', array( 'width' => 180, 'height' => 48, 'flex-width' => true, 'flex-height' => true, ) ); // Register nav menu's. register_nav_menus( array( 'main' => __( 'Main Menu', 'arcade' ), 'footer' => __( 'Footer Menu', 'arcade' ), ) ); } add_action( 'after_setup_theme', 'arcade_setup' ); /** * */ function arcade_admin_notice_success_theme_activation() { if ( !empty(get_theme_mod('importer')) ) return; ?> <div class="notice notice-success is-dismissible"> <h3>Thank you for installing the ARCADE THEME!</h3> <p><?php _e( 'Arcade Theme has been activated. To adjust the settings, follow this path: WordPress Dashboard > Appearance > Customize', 'arcade' ); ?></p> </div> <?php } add_action( 'admin_notices', 'arcade_admin_notice_success_theme_activation' ); /** * Enqueue scripts & styles. */ function arcade_scripts() { // jQuery if(!is_admin()) { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js', array(), '3.5.1', true ); wp_enqueue_script( 'jquery' ); } // Main JS file. wp_enqueue_script( 'arcade-site', ARCADE_THEME_URI . '/assets/site.js', array( 'jquery' ), ARCADE_THEME_VERSION, true ); // Theme Main Stylesheet wp_enqueue_style( 'arcade-style', get_stylesheet_uri(), '', ARCADE_THEME_VERSION ); // Comment reply. if ( is_singular() && comments_open() ) { wp_enqueue_script( 'comment-reply' ); } if ( is_rtl() ) { // RTL. //wp_enqueue_style( 'arcade-rtl', ARCADE_THEME_URI . '/css/rtl-min.css', '', ARCADE_THEME_VERSION ); } } add_action( 'wp_enqueue_scripts', 'arcade_scripts', 10 ); /** * Theme core functions */ require_once ARCADE_THEME_DIR . '/inc/core.php'; /** * Required plugins activator */ require_once ARCADE_THEME_DIR . '/inc/tgm-plugin-activation/activator.php'; /** * Theme Settings */ // Load Settings if ( class_exists( 'Kirki' ) ) require_once ARCADE_THEME_DIR . '/inc/settings.php'; // Use Google Fonts Server if ( get_theme_mod('fonts_server') == "google" ) { add_filter( 'kirki_use_local_fonts', '__return_false' ); } /** * Theme User CSS + Critical CSS */ require_once ARCADE_THEME_DIR . '/inc/css.php'; /** * Importer */ require_once ARCADE_THEME_DIR . '/inc/importer.php'; /** * Updater */ require_once ARCADE_THEME_DIR . '/inc/updater.php'; /** * Crons */ require_once ARCADE_THEME_DIR . '/inc/cron.php'; /** * Handles JavaScript detection. * Adds a `js` class to the root `<html>` element when JavaScript is detected. * @since Twenty Seventeen 1.0 */ function arcade_javascript_detection() { echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n"; } add_action( 'wp_head', 'arcade_javascript_detection', 0 ); /** * Disable emojis in WordPress */ add_action( 'init', 'arcade_disable_emojis' ); function arcade_disable_emojis() { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); } /** * Disable Fedds */ function arcade_disable_feed() { wp_redirect(home_url( '/' )); exit; } add_action('do_feed', 'arcade_disable_feed', 1); add_action('do_feed_rdf', 'arcade_disable_feed', 1); add_action('do_feed_rss', 'arcade_disable_feed', 1); add_action('do_feed_rss2', 'arcade_disable_feed', 1); add_action('do_feed_atom', 'arcade_disable_feed', 1); add_action('do_feed_rss2_comments', 'arcade_disable_feed', 1); add_action('do_feed_atom_comments', 'arcade_disable_feed', 1); /** * IMG SRC */ function arcade_img_src ($post = null, $size = null, $data = null) { if (!$data) $data = json_decode(get_post_meta( $post->ID, 'data', true )); if ( isset($data->image) ) { if ( preg_match("/^http/", $data->image) ) { $parsed = parse_url($data->image); return esc_url( home_url($parsed['path']) ); } return esc_url( home_url($data->image) ); } return false; } /** * Pagination */ function arcade_pager () { ?> <div class="pager"> <?php // Previous/next page navigation. $pnav = get_the_posts_pagination( array( 'mid_size' => 5, 'prev_text' => '<span class="btn btn-inline btn-color btn-yellow"><i class="fas fa-arrow-left"></i> ' . __('Previous Page', 'arcade') . '</span>', 'next_text' => '<span class="btn btn-inline btn-color btn-yellow">' . __('Next Page', 'arcade'). ' <i class="fas fa-arrow-right"></i></span>', 'screen_reader_text'=> __('Page Navigation', 'arcade'), ) ); $pnav = str_replace( array('<h2','</h2>', 'page-numbers'), array('<cite','</cite>', 'page-numbers'), // btn btn-inline btn-color btn-yellow $pnav); $btn = '><span class="btn btn-inline btn-color btn-yellow">$1</span><'; $pnav = preg_replace("@>([\d]+)<@i", $btn, $pnav); echo $pnav; ?> </div> <?php } /** * Search-box */ if (isset($_GET['search-box'])) { $search_by = get_theme_mod('search_by', 'wp'); if ($search_by == 'wp') { echo '<div class="qsearch">'; get_search_form(); echo '</div>'; } else if($search_by == 'cse') {?> <style> .gsc-control-cse { border-color: #FFFFFF00; background-color: #FFFFFF00; } .gsc-cursor .gsc-cursor-page { font-size: 3em; background: white; padding: 0.2em 0.4em; border-radius: 50%; } .gcsc-more-maybe-branding-root { display: none; } </style> <script async src="https://cse.google.com/cse.js?cx=<?php echo get_theme_mod('cse_id', '');?>"></script> <div class="gcse-search"></div> <?php } exit; } /** * Sharer JS */ if (isset($_GET['share'])) {?> <style> #toggle { padding:1em; }</style> <!-- AddToAny BEGIN --> <div class="a2a_kit a2a_kit_size_32 a2a_default_style" style="line-height: 32px;margin: 0 auto;width: max-content;"> <a class="a2a_dd" href="https://www.addtoany.com/share"></a> <a class="a2a_button_facebook a2a_counter"></a> <a class="a2a_button_whatsapp"></a> <a class="a2a_button_pinterest"></a> <a class="a2a_button_facebook_messenger"></a> <a class="a2a_button_twitter a2a_counter"></a> <a class="a2a_button_google_gmail"></a> <a class="a2a_button_copy_link"></a> <a class="a2a_button_email"></a> </div> <script> var a2a_config = a2a_config || {}; a2a_config.num_services = 10; </script> <script async src="https://static.addtoany.com/menu/page.js"></script> <!-- AddToAny END --> <?php exit; } /** * cookieconsent */ if (isset($_GET['cookieconsent'])) {?> <!-- cookie consent --> <link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css" /> <script src="//cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js" data-cfasync="false"></script> <script> setTimeout(function(){ window.cookieconsent.initialise({ "palette": { "popup": { "background": "#ffffff", "text": "#636363" }, "button": { "background": "#18b84e", "text": "#ffffff" } }, "theme": "classic", "type": "opt-in", "content": { "message": "This website and our partners will collect data and use cookies for ad personalization and measurement." } }); }, 1500); </script> <?php exit; } /** * Prevent WP from adding <p> tags on pages */ function arcade_disable_wp_auto_p( $content ) { if ( is_singular( 'post' ) ) { remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); } return $content; } add_filter( 'the_content', 'arcade_disable_wp_auto_p', 0 ); /** * Collect data to output in JSON-LD. * * @param array $unsigned An array of data to output in json-ld. * @param JsonLD $unsigned JsonLD instance. */ add_filter( 'rank_math/json_ld', function( $json_ld, $json ) { if ( is_singular() && ! isset( $json_ld['richSnippet'] ) ) { $json_ld['richSnippet'] = [ '@context' => 'https://schema.org', '@type' => "VideoGame", 'headline' => $json->parts['title'], 'description' => $json->parts['desc'], 'datePublished' => $json->parts['published'], 'dateModified' => $json->parts['modified'], //'publisher' => $json->get_publisher( (array) $json->post ), 'mainEntityOfPage' => [ '@type' => 'WebPage', '@id' => $json->parts['canonical'], ], 'applicationCategory' => 'Game' ]; $json->add_prop( 'thumbnail', $json_ld['richSnippet'] ); } return $json_ld; }, 11, 2); /** * Top Categories * for header... */ function arcade_top_categories () { $tags = get_tags( ['orderby'=>'count', 'order'=>'DESC', 'number'=>29] ); if (!$tags) return; $li = array(); foreach ($tags as $tag) { $li [] = sprintf('<li><a href="%s">%s</a></li>', get_term_link($tag->term_id), esc_attr($tag->name)); } // To all cats $acp = get_theme_mod('all_categories_page', false); if ($acp) $li [] = sprintf('<li><a href="%s">%s</a></li>', get_permalink($acp), '<i class="fas fa-th"></i> ' . __('Show All', 'arcade')); printf('<ul id="tc" style="display:none" class="w gtc">%s</ul>', implode('', $li)); } /** * Footer Content Template */ function arcade_footer_content ($mod = null) { $ID = get_theme_mod($mod, 0); if ( ! is_numeric($ID) ) return; $post = get_page($ID); if (!$post) return; printf('<div class="w">%s</div>', apply_filters('the_content', $post->post_content)); } /** * Arcade Example AD Code */ function arcade_ex_ad($size = null) { return '<a href="https://arcadetheme.com/"><img loading="lazy" src="'.ARCADE_THEME_URI.'/assets/images/ad-sizes/'.$size.'.png" /></a>'; } /** * Custom Logo SRCSET Fix */ function ssl_post_thumbnail_urls($url, $post_id) { //Skip file attachments if(!wp_attachment_is_image($post_id)) { return $url; } //Correct protocol for https connections list($protocol, $uri) = explode('://', $url, 2); if(is_ssl()) { if('http' == $protocol) { $protocol = 'https'; } } else { if('https' == $protocol) { $protocol = 'http'; } } return $protocol.'://'.$uri; } add_filter('wp_get_attachment_url', 'ssl_post_thumbnail_urls', 10, 2); /** * Delete DIR */ function recursive_remove_directory($directory=null) { foreach(glob("{$directory}/*") as $file) { if(is_dir($file)) { recursive_remove_directory($file); } else { unlink($file); debug("unlink($file)","yellow"); } } rmdir($directory); debug("rmdir($directory)","white"); } /** * Clear Old PNG files */ function clear_old_pngs() { $s = ABSPATH."images/s"; $m = ABSPATH."images/m"; if ( file_exists($s) ) recursive_remove_directory($s); if ( file_exists($m) ) recursive_remove_directory($m); } /*** * ADS.TXT * Auto add ads.txt lines for GD, GM and Tubia */ function arcade_ads_txt_content($lines){ return $lines . "\n". file_get_contents(get_parent_theme_file_path( '/ads.txt' )); } if ( get_theme_mod('auto_add_ads_txt_lines', 1) ) add_action("advanced-ads-ads-txt-content", "arcade_ads_txt_content"); /** * Menu Icons by ThemeIsle * Override menu item markup * * @param string $markup Menu item title markup. * @param integer $id Menu item ID. * @param array $meta Menu item meta values. * @param string $title Menu item title. * * @return string */ function my_menu_icons_override_markup( $markup, $id, $meta, $title ) { return '<i>' . $markup . '</i>'; } add_filter( 'menu_icons_item_title', 'my_menu_icons_override_markup', 10, 4 );