当前位置:首页-文章-代码记录-正文

记录对Mnews-pro主题的修改

记录对Mnews-pro主题的修改

一、代码高亮

电脑端显示效果还好,手机端屏幕太小,代码折叠比较严重,看着界面非常不美观,使用了Prism的开源代码高亮文件,主题functions.php添加如下代码(需要引入相关样式文件,需要在本页面留言):

# 添加代码高亮
function add_prism() {
         wp_register_style(
            'PrismCSS', 
            get_stylesheet_directory_uri() . '/assets/css/prism.css' 
         );
         wp_register_script(
            'PrismJS', 
            get_stylesheet_directory_uri() . '/assets/js/prism.js' 
         );
          /*wp_register_script(
            'pure',
            get_stylesheet_directory_uri() . '/assets/js/pure-highlight.js'   
         );*/
        wp_enqueue_style('PrismCSS');
        wp_enqueue_script('PrismJS');
        //wp_enqueue_script('pure');
    }
add_action('wp_enqueue_scripts', 'add_prism');

代码高亮的使用方法

<pre class="highlight"><code class="language-php line-numbers">代码写在这里</code></pre>

二、Woocommerce更改虚拟商品字段

//虚拟商品移除地址字段
add_filter('woocommerce_checkout_fields', function ($fields){
    $only_virtual = true;
    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
        // Check if there are non-virtual products
        if ( ! $cart_item[ 'data' ]->is_virtual()) {
            $only_virtual = false;
        }
    }
    if ($only_virtual) {
        unset($fields[ 'billing' ][ 'billing_first_name' ]);//姓
        unset($fields[ 'billing' ][ 'billing_last_name' ]);//名
        //unset($fields[ 'billing' ][ 'billing_email' ]);//电子邮件地址
        //unset($fields[ 'billing' ][ 'billing_company' ]);公司
        unset($fields[ 'billing' ][ 'billing_address_1' ]);//街道名称/房屋编号
        unset($fields[ 'billing' ][ 'billing_address_2' ]);//公寓/单元房
        unset($fields[ 'billing' ][ 'billing_city' ]);//市
        unset($fields[ 'billing' ][ 'billing_postcode' ]);//邮政编码
        unset($fields[ 'billing' ][ 'billing_country' ]);//国家
        unset($fields[ 'billing' ][ 'billing_state' ]);//省
        //unset($fields[ 'billing' ][ 'billing_phone' ]);//电话字段
        add_filter( 'woocommerce_checkout_fields' , 'meediy_override_checkout_fields' );
        //add_filter('woocommerce_enable_order_notes_field', '__return_false');
    }
    return $fields;
});

四、主题样式修改

1、网站灰度及其滚动条

<!--网站灰度-->
<script type="text/javascript" src="https://cdn.iox7.com/custom/Grayscale/black-pw.js"></script>
<!--滚动条样式(本站点红色滚动条)-->
<link type="text/css" rel="stylesheet" href="https://cdn.iox7.com/custom/scroll-bar-style/scroll.css" />

2、加快弹窗背景虚化时间

.animate-transition{transition:ease-in-out 0.4s}

3、登录窗口样式修改

.login-box .form-effect {margin-bottom: 25px;}
.login-box.have-bg .title {color: #000000;}
.login-box .login-header {margin-bottom: 30px;}

4、对齐文章作者等meta

.post-metas img {margin: 0 6px 8px 0;}
.post-metas b {margin-top: -6px;}

5、下载框样式微调

.pay-download .download-main:not(.have-thumb) .capability-list ul{grid-template-columns:repeat(2,55%);}
.pay-download .capability-list label{min-width:0px;}

6、会员页样式

.user-level .level-list .user-count {font-size: 14px;}
.user-level .level-list .post-count {font-size: 14px;}

7、Header修改

.sub-menu {border-top: 4px #b1244e solid;}
.header-pc .header-menu ul.menu>li>.sub-menu:before {
    content: '';
    height: 0;
    width: 0;
    display: block;
    border: 8px transparent solid;
    border-top-width: 0;
    border-bottom-color: #b1244e;
    position: absolute;
    left: 30px;
    top: -12px;
}
.header-pc .header-menu ul.menu>li>.sub-menu .sub-menu {
    top: -4px;
    left: 110%;
}

主题 404.php 添加如下代码:

$error_url = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$error_log = "badlink.txt";
$entries = file($error_log);
$check=true;
foreach($entries as $f){
if($f == $error_url."\n")
    $check = false;
}
if($check){
    $fp = fopen($error_log,"a");
    flock ($fp, LOCK_EX) ;
    fwrite ($fp, $error_url."\n");
    flock ($fp, LOCK_UN);
    fclose ($fp);
}

坏链地址:https://iox7.com/badlink.txt

文章中添加 Woocommerce 商品会报错 Cannot modify header information - headers already sent by /class-jwt-auth-public.php on line 94

记录对Mnews-pro主题的修改 - 第1张

在如下目录:

/wp-content/plugins/jwt-authentication-for-wp-rest-api/includes/class-jwt-auth.php

找到 define_public_hooks() 函数,修改如下字段:

private function define_public_hooks(){
    $plugin_public = new Jwt_Auth_Public($this->get_plugin_name(), $this->get_version());
    $this->loader->add_action('rest_api_init', $plugin_public, 'add_api_routes');
    $this->loader->add_filter('init', $plugin_public, 'add_cors_support');//添加此行
    //$this->loader->add_filter('rest_api_init', $plugin_public, 'add_cors_support');//注释掉
    $this->loader->add_filter('rest_pre_dispatch', $plugin_public, 'rest_pre_dispatch', 10, 2);
    $this->loader->add_filter('determine_current_user', $plugin_public, 'determine_current_user', 10);
}
本文原创,作者:鸭鸭吖,其版权均为技术园所有。
如需转载,请注明出处:https://iox7.com/9.html