1479 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
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.

if(!session_id()){
    session_start();
}
$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?

by
by
by
by
by
by