How to pass a GET request to a file that does not belong to wordpress

2

Wordpress does not recognize files that do not belong to it, even though it's there in the theme folder, which is my case. How can I make an external file receive this information?

For example: I am in .page and there exists a button with parâmetro via GET , through link . The page is at:

www.meusite.com.br/tema/page.php

The target file, which will receive the parameter is:

www.meusite.com.br/tema/src/arquivo.php

This arquivo.php was only placed there and there is no link with wordpress, but it has a capture function via $ _GET .

  

DETAIL :   I do not want to access the file through the front, that is, present it in the browse, but only make it execute its conditions.

    
asked by anonymous 26.05.2015 / 19:11

1 answer

1

Assuming you are overwriting your permalinks , you will not be able to do this even though the file is inside the theme folder . This is due to the fact that WordPress, when with permalinks enabled, treats its routes through RewriteRule s in .htaccess . Assuming you go into the admin panel and set your URLs to be for example based on the post name, the following .htaccess is created (I removed examples from an instance of WP that I have running in http://localhost/wp_testes/) :

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp_testes/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp_testes/index.php [L]
</IfModule>

# END WordPress

This answer in the gringo OS gives an excellent explanation of how these rules work. Adding this to WP's Hierarchy of Templates , it is easy to conclude that all requests made within your WP instance (in my case, /wp_testes/ forward), will be routed according to these rules, preventing direct access. If your teste.php file does not conform to the template rules, the house will fall.

Solutions

  • Do not use permalinks.

    It's dirty, I know. Your URLs will look awful, but this will allow you to have direct access to your file. In my case, I disabled the permalinks, and I made a direct access in http://localhost/wp_testes/wp-content/themes/twentyfifteen/teste.php?teste=123 , where teste.php contained this complicated instruction:

    <?php echo $_GET['teste']; ?>
    

    and the result, as expected, was

      

    123

  • Put your root file in WordPress

    Placing the teste.php file in the folder where the WP files are located (in my case, within the /wp_testes folder), the permalink rules should not affect your requests. In this case, I made the request http://localhost/wp_testes/teste.php?teste=123 (with permalinks enabled) and got the expected result.

  • I do not know if you are developing a necessarily a theme, and whether or not you can include files in the WP root. I believe you are limited to these two solutions. But the sum of the two (permalinks with the in of the theme), I think there is no way.

        
    01.10.2015 / 21:37