1470 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says

Hi guys, I am developing a plugin that includes a form for submitting content. Because of that, I need WP functions available in that file.

What is the best practice to do that? Note that I will include ajax in a form and will use the proper, WordPress way of doing that, but I am building this as a fallback for users that do not have JavaScript enabled.

This is the way I am doing it currently, I believe it should always return a proper relative path.

First, I store plugin url and wordpress url in a session (you will notice session variables). The rest is self explanatory.

$fng_relative_include = '';
$fng_includepath = str_replace($_SESSION['fng-wp'], '', $_SESSION['fng-plugin']);
$fng_includepath = explode('/', $fng_includepath);
foreach ($fng_includepath as $fng_add_one){
    $fng_relative_include .= '../';
require_once(realpath( $fng_relative_include . 'wp-blog-header.php'));
echo home_url('/#it-worked');

Is there a better way to do this?