Wordpress plugin does not work called external FORM

Asked

Viewed 66 times

1

I am trying to respond 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 reaches the address, but when the result is:

Fatal error: Call to Undefined Function plugin_dir_url()

I can’t even set the plugin path. 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;
        }
}

There are a lot more codes after this start.

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

It is as if wordpress has not loaded.

Can you help me?

1 answer

0

Your error is in the form 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 must send the POST or GET to a recognized URL in 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
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.