【问题标题】:Cannot use $this as parameter in contact-form.php不能在 contact-form.php 中使用 $this 作为参数
【发布时间】:2017-04-07 09:40:17
【问题描述】:

我正在尝试使用来自 themeforest 的主题为“Total”的 xampp 运行 wordpress。

上面写着

Fatal error: Cannot use $this as parameter in /Applications/XAMPP/xamppfiles/htdocs/wp-content/themes/Total/framework/3rd-party/contact-form-7.php on line 38

我也提到了this链接和堆栈溢出之外的其他网站。

contact-form-7.php的代码如下,

<?php
/**
 * Contat Form 7 Configuration Class
 *
 * @package Total WordPress Theme
 * @subpackage 3rd Party
 * @version 3.6.0
 */

if ( ! class_exists( 'WPEX_Contact_Form_7' ) ) {

    class WPEX_Contact_Form_7 {

        /**
         * Start things up
         *
         * @version 3.6.0
         */
        public function __construct() {

            // Remove CSS Completely - theme adds styles
            add_filter( 'wpcf7_load_css', '__return_false' );

            // Remove JS
            add_filter( 'wpcf7_load_js', '__return_false' );

            // Conditionally load JS
            add_action( 'wpcf7_contact_form', array( 'WPEX_Contact_Form_7', 'enqueue_js' ), 1 );

            }

        /**
         * Load JS conditionally
         *
         * @version 3.6.0
         */

        public static function enqueue_js( $this ) {
            if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
                wpcf7_enqueue_scripts();
            }
        }

    }

}
new WPEX_Contact_Form_7();

这就是我所做的,

我首先将它安装在我的办公室计算机上,它运行良好。现在我厌倦了在我的个人笔记本电脑上实现同样的功能。

因此只需复制我的htdocs 文件夹并替换到我的笔记本电脑中。还将数据库导出并导入到 phpMyAdmin。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    尝试删除$this,例如

    public static function enqueue_js() {
        if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
            wpcf7_enqueue_scripts();
        }
    }
    

    查看代码gist

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-06
      • 2018-03-03
      • 1970-01-01
      • 2014-08-08
      • 2011-10-04
      • 1970-01-01
      • 2020-07-31
      • 2019-11-08
      相关资源
      最近更新 更多