0

I am creating a plugin in WordPress that will send some data via email. When I activate the plugin, I'm getting a white screen.

I set define('WP_DEBUG', true); in wp-config.php but no error messages are displayed.

Here is the code for my plugin:

<?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@email.com";
    $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');
0

you should remove:

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

and use:

require(ABSPATH.'wp-includes/pluggable.php');

p.s. I advice you, these executions should be hooked in 'init', like:

add_action('init', function(){

    $para = "email@email.com";
    $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 {
  }

});
  • Thanks for the help, see my complete code of this question. I'm not able to make the wp_mail function to work. – Wendell Oct 2 '16 at 2:44
  • I have updated code.. you had to set variables inside same function, not outside of function. – T.Todua Oct 3 '16 at 14:11
  • The problem is that email needs to be sent when it appears the html of the second form. See the full issue here. If you can help me, I will be very grateful. – Wendell Oct 3 '16 at 14:36
  • you saw my review? – Wendell Oct 3 '16 at 15:13
3

Throws an error for me alright:

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

Basically, you can't do this:

require('http://solutionsagencia.com.br/comparasaude/wp-load.php');
  • How can I make the inclusion of wp-load.php to wp_mail to work? – Wendell Sep 29 '16 at 22:48
  • You don't need to include wp-load. Plugins have access to all WP functions - including wp_mail. – vancoder Sep 29 '16 at 22:50
  • If you comment out the line 101 that has require('http://solutionsagencia.com.br/comparasaude/wp-load.php'); Wordpress shows the error: Fatal error: Call to undefined function wp_mail() in... – Wendell Sep 29 '16 at 22:54
  • As indicated, I updated my code for hat here. But the error Fatal error: Call to undefined function wp_mail() still continues. – Wendell Sep 30 '16 at 4:44
2

Make sure to configure PHP to display errors. You can turn on DB logging in WordPress by adding this line to the wp-config.php file:

define( 'WP_DEBUG_LOG', true );

Starting on line 84, you've got some code that is not being fired via a hook. You should wrap that code in a function and fire it on a hook to ensure that you're controlling the timing of the code being fired.

On line 101 your're doing an include for a PHP file over HTTP, which is usually not a good idea and it won't work on some server configurations anyway depending on allow_url_include settings:

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

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

I'm really not sure why you'd be including wp-load.php, AJAX maybe? If so, then check out the Codex article on AJAX in Plugins.

  • The php is configured to display the errors. I do not know how I can put the line of function 84 on a hook. The inclusion of a PHP file via HTTP on line 101, when I remove the line php me of the error: Fatal error: Call to undefined function wp_mail () in. – Wendell Sep 29 '16 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.