I'm looking to create a custom function page which is a non WordPress PHP file. I have created a template with a form in my theme and I am looking to post the form to this custom function PHP file. The function is to add a new row into the WordPress database.
I have the this working via the main functions file of my theme however I want to create my own custom file to call that has the function within it. Please the below my code of the working with the main functions file were i use isset to tigger to when submit button is selected in form..
function register_user() {
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$options = [
'cost' => 11,
];
$passwordFromPost = $_POST['password'];
$hash = password_hash($passwordFromPost, PASSWORD_BCRYPT, $options);
global $wpdb;
$table_name = $wpdb->prefix . "yuenergy_users";
$wpdb->insert($table_name, array(
'name' => $name,
'email' => $email,
'password' => $hash
),array(
'%s',
'%s',
'%s')
);
}
if( isset($_POST['registerSubmit']) ) register_user();
Instead of using the main functions file to put ALL my functions in i have create a registerProcess.php in my theme in same directory as functions and use to wp-load.php to be able to use this file however no error appeaers but form isnt being post to database.
<?php
require_once("../../..wp-load.php");
function register_user() {
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$options = [
'cost' => 11,
];
$passwordFromPost = $_POST['password'];
$hash = password_hash($passwordFromPost, PASSWORD_BCRYPT, $options);
global $wpdb;
$table_name = $wpdb->prefix . "yuenergy_users";
$wpdb->insert($table_name, array(
'name' => $name,
'email' => $email,
'password' => $hash
),array(
'%s',
'%s',
'%s')
);
}
if( isset($_POST['registerSubmit']) ) register_user();
I'm new to wordpress and trying tohave a better understanding of how this all works.. go easy on me please.