Fatal error: Call to undefined function wp_insert_post()

If you’d like to use WordPress functions inside your naked PHP file, you’ll have to load the WordPress environment: require_once ‘/path/to/wp-load.php’; That said it’s best practice to NOT handle things via separate PHP files like that outside of WordPress, but use a plugin instead and fire your code on an appropriate action. You can use … Read more

Get wp_current_user_id using PHP and MySQL

Thanks to @Samuel Elh I manage to get this done. I added this to my order-confirmation.php after I included config.php require (‘../wp-blog-header.php’); global $wpdb; global $current_user; get_currentuserinfo(); $skrivID = $current_user->ID; Then the insert query, I added the table I wanted the user ID stored in and used the variable $skrivID as value. $sql = mysqli_query($db_conn, … Read more

How to update user profile custom fields

I use update_user_meta to update the fields. You can add this in functions.php of your child theme. function save_extra_user_profile_fields( $user_id ) { if ( !current_user_can( ‘edit_user’, $user_id ) ) { return false; } update_user_meta( $user_id, ‘telephone’, $_POST[‘telephone’] ); } add_action( ‘personal_options_update’, ‘save_extra_user_profile_fields’ ); add_action( ‘edit_user_profile_update’, ‘save_extra_user_profile_fields’ );

Sending email for the custom form in WordPress

The easy way would install this plugin – https://da.wordpress.org/plugins/contact-form-7/ – It’s super easy to work with, and it will do what you want 🙂 If you don’t want to use a plugin, then you would just code a contact form with html and php. PHP: <?php $firstname = $_POST[‘firstname’]; $lastname = $_POST[‘lastname’]; $from = $_POST[’email’]; … Read more

PHP Contact form

To access array values within a double quoted string use the form: $headers = “From: {$args[‘name’]} <{$args[’email’]}>” . “\r\n”; You are right: your function needs one more } to close it correctly.

Using get_theme_mod in php ajax form doesn’t work

You should never access directly theme files, form submissions, ajax, and even just get requests will be blocked at the server level by some security hardening measure. Ignoring that for a moment, the reason your code fails is because wordpress wasn’t bootstrapped and therefor there are no core functions available. It is actually not 100% … Read more

Saved emails at dashboard

Yes. You can use Contact Form 7 plugin to create a form that will send messages to your email (like gmail, etc) and use another plugin from the same author, Flamingo, to have those messages saved in WordPress database and available in the dashboard. If you prefer to avoid plugins, here’s what you need: Register … Read more