激活通过WordPress发送表单的插件时出现白屏

时间:2016-09-29 作者:Wendell

我正在WordPress中创建一个插件,可以通过电子邮件发送一些数据。当我激活插件时,我会看到一个白色屏幕。

我设置define(\'WP_DEBUG\', true); 在里面wp-config.php 但不会显示任何错误消息。

以下是我的插件代码:

<?php
/* 
Plugin Name: Formulario Cotação
Plugin URI: http://solutionsagencia.com.br
Description: Plugin para cotação em 2 passos.
Version: 0.0.1
Author: Wendell Christian
Author URI: http://solutionsagencia.com.br
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/


// Verifica se não existe nenhum classe com o mesmo nome
if ( ! class_exists(\'FormularioCotacao\') ) {

    class FormularioCotacao
    {


    public function __construct() {
        /* Adiciona o shortcode */
        add_shortcode( \'cotacao\', array( $this, \'ExibirTexto\' ) );
    }

    /**
     * Este é um método simples que irá exibir o texto do nosso shortcode
     */
    public function ExibirTexto () {
        $FormularioCotacaoURL = WP_CONTENT_URL;
        $FormularioCotacaoURL = WP_CONTENT_URL.\'/plugins/\'.plugin_basename( dirname(__FILE__)).\'/\';
        return "<div class=\'principal-form\' id=\'principal-form\'>
        <form type=\'post\' action=\'\' id=\'cadastraForm\'>
        <div class=\'col-md-65\'><div class=\'col-md-34\'><input type=\'text\' name=\'nome\' id=\'nome\' class=\'campo-form\' placeholder=\'Nome\' maxlength=\'50\'></div>
        <div class=\'col-md-34-2\'><input type=\'email\' name=\'email\' id=\'email\' class=\'campo-form\' placeholder=\'Email\' maxlength=\'120\'/></div>
        <input type=\'hidden\' name=\'action\' value=\'addCustomer\'/>
        <div class=\'col-md-30\'><button type=\'submit\' id=\'enviarform\' class=\'botao-enviar\'><span class=\'icone-cadastrar\'></span>Efetue sua simulação</button>
        </div>
        </div>

        </div>
        <div id=\'feedback\'></div>
        <div id=\'passo2form\' class=\'passo2form\'></div>

";
    }

} 

/* Carrega a classe */
$FormularioCotacao_settings = new FormularioCotacao();

} // class_exists


function addCustomer(){

    global $wpdb;

    $nome = trim($_POST[\'nome\']);
    $email = trim($_POST[\'email\']); 

    if($wpdb->insert(\'wp_formclientes\',array(
        \'nome\'=>$nome,
        \'email\'=>$email
    ))===FALSE){

    echo "Error";

    }
    else {

    //mensagem de sucesso

    }
    die();
    }
    add_action(\'wp_ajax_addCustomer\', \'addCustomer\');
    add_action(\'wp_ajax_nopriv_addCustomer\', \'addCustomer\'); // not really needed


    /*Enviando email completo*/

if( isset($_POST[\'nome\']) && ($_POST[\'email\'])){


    $para = "[email protected]";
    $assunto = "Assunto" . $nome;
    $conteudo =
    "<b>Nome:</b> {$nome}" .
    "<b>Email:</b> {$email}" .

    $headers = array(
        \'Reply-To\' => $name . \'<\' . $email . \'>\',
    );

}

add_filter( \'wp_mail_content_type\', \'set_html_content_type\' );

require(\'http://solutionsagencia.com.br/comparasaude/wp-load.php\');

$status = wp_mail( $para, $assunto, $conteudo );


remove_filter( \'wp_mail_content_type\', \'set_html_content_type\' );

function set_html_content_type() {
    return \'text/html\';
}


if ( $status ){
    echo "sucesso";
} else {
}



function FormularioCotacao_addJS() {
    $FormularioCotacaoURL = WP_CONTENT_URL.\'/plugins/\'.plugin_basename( dirname(__FILE__)).\'/\';
    wp_register_style(\'estilo\', $FormularioCotacaoURL . \'css/estilo.css\');
    wp_enqueue_style(\'estilo\', $FormularioCotacaoURL . \'css/estilo.css\');
}

add_action(\'wp_print_scripts\', \'FormularioCotacao_addJS\');

3 个回复
最合适的回答,由SO网友:T.Todua 整理而成

您应该删除:

require(\'http://solutionsagencia.com.br/comparasaude/wp-load.php\');
和使用:

require(ABSPATH.\'wp-includes/pluggable.php\');
另请注意,这些执行应该挂接在“init”中,例如:

add_action(\'init\', function(){

    $para = "[email protected]";
    $assunto = "Assunto" . $nome;
    $conteudo =
    "<b>Nome:</b> {$nome}" .
    "<b>Email:</b> {$email}" .

    $headers = array(
        \'Reply-To\' => $name . \'<\' . $email . \'>\',
    );

  $status = wp_mail( $para, $assunto, $conteudo );

  remove_filter( \'wp_mail_content_type\', \'set_html_content_type\' );

  if ( $status ){
    echo "sucesso";
  } else {
  }

});

SO网友:vancoder

为我抛出一个错误好的:

Warning: require(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /var/www/europeanvoice/wp-content/plugins/test.php on line 101

Warning: require(http://solutionsagencia.com.br/comparasaude/wp-load.php): failed to open stream: no suitable wrapper could be found in /var/www/europeanvoice/wp-content/plugins/test.php on line 101

Fatal error: require(): Failed opening required \'http://solutionsagencia.com.br/comparasaude/wp-load.php\' (include_path=\'.:/usr/share/php:/usr/share/pear\') in /var/www/europeanvoice/wp-content/plugins/test.php on line 101
基本上,你不能这样做:

require(\'http://solutionsagencia.com.br/comparasaude/wp-load.php\');

SO网友:Dave Romsey

确保configure PHP to display errors. 您可以通过将此行添加到wp-config.php 文件:

define( \'WP_DEBUG_LOG\', true );
从第84行开始,您有一些代码不是通过钩子触发的。您应该将该代码包装在函数中并在挂钩上启动它,以确保您控制了启动代码的时间。

在第101行,您正在通过HTTP对PHP文件进行包含,这通常不是一个好主意,而且在某些服务器配置上也无法正常工作,具体取决于allow_url_include 设置:

require(\'http://solutionsagencia.com.br/comparasaude/wp-load.php\');

$status = wp_mail( $para, $assunto, $conteudo );
我真的不知道你为什么要包括wp-load.php, 也许是AJAX?如果是这样的话,请查看AJAX in Plugins.

相关推荐

Cron not sending wp-mail()

我对cron计划功能有问题,它不想用wp_mail() 作用This is my code:它被放置在函数中。php<?php add_filter(\'cron_schedules\', \'add_review_invites_schedule\'); function add_review_invites_schedule($schedules){ $schedules[\'send_review_invites_interva