Wordpress plugin does not work external FORM call

1

I am trying to reply to a form sent by a third party to my Wordpress. I then created a plugin to receive this form and put inside the plugin folder the form file:

<form action="http://www.meusite.com/staging/wp-content/plugins/Integrador/integrador.php" >
  <input name="codigo_cliente" value="0" />
  <input name="nome" value="XY" />
  <input name="fone" value="99 9999.9999" />
  <input name="url_xml" value="http://www.site.com/arquivo.xml" />
  <input type="submit" name="registernow" value="Inscreva-se"/>
</form>

The file path is OK, the form gets to the address, but when it arrives the result is:

  

Fatal error: Call to undefined function plugin_dir_url ()

I can not even set the path of the plugin. Follow the code:

<?php
define('INTEGRADOR_FOLDER_NAME','Integrador');
define('INTEGRADOR_VERSION','0.0.1');
define('INTEGRADOR_PLUGIN_NAME','Integrador Plugin');
define('INTEGRADOR_SLUG','Integrador/integrador.php');

// Plugin Folder URL
define( 'INTEGRADOR_URL', plugin_dir_url( __FILE__ ) );
// Plugin Folder Path
define( 'INTEGRADOR_DIR', plugin_dir_path( __FILE__ ) );

$locale = get_locale();
load_textdomain( 'templatic', plugin_dir_path( __FILE__ ).'languages/'.$locale.'.mo' );



/*if(isset($_POST['notificationType']) && $_POST['notificationType'] == 'transaction'){*/
    //Todo resto do código iremos inserir aqui.     

include_once( ABSPATH . 'wp-admin/includes/plugin.php' 
if ($_REQUEST['codigo_cliente'] != ''){

    echo '<h1>VOU REGISTRAR ESSE USUÁRIO... AGUARDE....</h1>';
    if(file_exists(INTEGRADOR_DIR.'vista/vista_registro.php')){
            include_once(INTEGRADOR_DIR.'vista/vista_registro.php');

            exit;
        }
}

You have a lot more code after this start.

If I access the website first in the browser and send the form everything works (active session). But if I say without entering the site: Error in the basic functions of wordpress.

It's as if wordpress has not loaded.

Can you help me?

    
asked by anonymous 07.03.2017 / 20:17

1 answer

0

Your error is in the form's action:

<form action="http://www.meusite.com/staging/wp-content/plugins/Integrador/integrador.php" >

This path is recognized by the WordPress server as a right access to the file, so only this file is loaded, nothing more.

The form needs to send the POST or GET to a URL recognized in the WordPress rewrite rules, so that the application is loaded first. If your plugin is active, you can even send it to home, although good practices suggest creating endpoints just for this:

<form action="http://www.meusite.com/" >

-

// 'plugins_loaded' é a primeira action disponível para plugins ativos
//  mas pode ser cedo demais, dependendo das outras informações do site que você precisar. 
//  Se não funcionar, tente 'init' ou 'wp'
//  https://codex.wordpress.org/Plugin_API/Action_Reference

add_action( 'plugins_loaded', 'responde_form' );
function responde_form() {
    $request = wp_unslash( $_REQUEST );

    if ( ! isset( $request['codigo_cliente'] ) {
        return;
    }  

    // aqui começa a processar os dados
}
    
08.03.2017 / 03:15