Wordpress plugin for course registration - wordpress

I'm building a WordPress Page for course registration. All I want the plugin to do is send the filled in form details to my email ID and send an email to the user that he/she has successfully registered for the course. I don't need users to signup with username and password.
I've tried my luck with WP Forms but it only seems to have the option to forward the email to me and not the user.
Any suggestion on which plugin I should use?

As #Hughes mentioned, you cant use wpcf7, and just hook on it to insert custom post on every query.
// Hook on wpcf7
add_filter( 'wpcf7_mail_components', 'do_on_cf7_submit', 50, 2 );
function do_on_cf7_submit($mail_params, $form = null) {
// Empty post content
$content = '';
// set post content if field not empty
if ($_POST['field-name'] != '') {
$content .= 'Field Name Label: '.$_POST['field-name'] ;
}
// insert post if content not epmty
if ($content != '') {
insertQueryPost($_POST['email'], $content);
}
// allow cf7 to do his stuff
return $mail_params;
}
// insert custom post type "query", don't forget to setup your custom post type first
function insertQueryPost($title, $content) {
// insted of proper post slug, just make a hashed slug, when setting custom post type, set it to not public and not search-able
$t = time();
$thash = md5($t);
$my_query = array(
'post_title' => wp_strip_all_tags( $title ),
'post_content' => $content,
'post_type' => 'query',
'post_name' => $thash,
'post_status' => 'publish',
'post_author' => 1
);
$data = wp_insert_post( $my_query );
}

Related

How update ACF field in savepost hook and wp remote post

How I can update post meta or ACF fields by wp_remote_post or other method by using exists API ?
function publish_content($post_id, $post, $update)
{
// If this is just a revision, don't send the email.
if (wp_is_post_revision($post_id)) {
return;
}
$full_content = get_field('full_content', $post_id);
$login = 'username';
$password = 'password';
$response = wp_remote_post(
'https://example.com/wp-json/wp/v2/posts/12',
array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode("$login:$password")
)
)
);
//I need Update ACF Field Value in example.com site
}
add_action('save_post', 'publish_content', 11, 3);
I don't want to develop new API on the destination site and I want to use the existing (wp/v2/posts/{id}) WordPress API.

Wordpress wp_insert_post in post type doesnt work

I created a custom post type with CPT plugin. It's works fine and did the job.
I can create post, publish the post and i can see on the site.
But when i create a post from frontend via wp_insert_post it's creates the post but i can't see on site. It gives me 404.
$postId = "" . getUserCompanyId() . $menuId . "";
$m = array(
'insert_id' => intval($postId),
'post_title' => $menuName . ' | ' . $postId,
'post_name' => ''.$postId.'',
'post_content' => '',
'post_status' => 'draft',
'post_author' => get_current_user_id(),
'post_type' => 'm',
);
$insert = wp_insert_post( $m );
When i create a post:
When i publish and see on site:
Note: wp_insert_post works just fine when change post_type to post
insert_id is not allowed in post arguments array($m in your code) it must be ID.
But as you mentioned you need to create a post then ID is not required it is only needed when you wish to update an existing post.
Refer here for wp_insert_post(...)
Also, validate whether the post is created on not
$post_args = array('post_type' => 'your_custom_post',
/*other default parameters you want to set*/
);
$post_id = wp_insert_post($post_args);
if(!is_wp_error($post_id)){
//the post is valid
} else {
//there was an error in the post insertion,
echo $post_id->get_error_message();
}

Automatically create a post for each user on wordpress site

I'm trying to automatically great a custom post (users) upon registering a new user to my site. I'm just barely familar with php, but I've been working off another question from stackoverflow: Automatically create a post for each user using wp_insert_post
I would ideally love to create a page upon registering or updating user information that carries over custom fields. I've used ACF to create custom fields associated with users (listed in the code as lowercase variables) and custom fields associated with the to be created custom posts (listed in the code as uppercase variables).
Thank you for any help you can offer!
function create_authors_page( $user_id ) {
$the_user = get_userdata( $user_id );
$new_user_name = $the_user->user_login;
$PostSlug = $user_id;
$PostGuid = home_url() . "/" . $PostSlug;
$member_bio = get_field('member_bio');
$contact_info = get_field('contact_info');
$member_affiliation = get_field('member_affiliation');
$my_post = array( 'post_title' => $new_user_name,
'post_type' => 'users',
'post_content' => '',
'post_status' => 'publish',
'post_theme' => 'user-profile',
'guid' => $PostGuid );
$NewPostID = wp_insert_post( $my_post );
$Member_Bio = $member_bio;
$Contact_Info = $contact_info;
$Member_Affiliation = $member_affiliation;
update_post_meta( $NewPostID, $Member_Bio, $Contact_Info, $Member_Affiliation );
return $NewPostID;
}
add_action('publish_members', 'create_authors_page');
Your hook is incorrect, use user_register action hook which fires after a user has registered and passes $user_id as a variable:
add_action('user_register', 'create_authors_page');
function create_authors_page( $user_id ) {
// do your stuff
}
You can also use profile_update hook that trigger each time user update profile.

Vimeo api to wordpress posts

I have listed the vimeo videos from a channel using vimeo api using php
Now i want to upload all the videos as a post to wordpress custom postype how to do that?
each time a new video i published it should add the videos as a post to custom postype
To create a post in WordPress, you can use the below code.
Step1:
Look for the Vimeo webhooks option, which will let you know when a new Vimeo video is published. By doing so, you can get the details of the video and then use that information to create a post in WordPress.
Vimeo API link: https://developer.vimeo.com/help
Zapier Vimeo Integration Link: https://zapier.com/apps/vimeo/integrations/webhook
Step2:
/**
* A function used to programmatically create a post in WordPress. The slug, author ID, and title
* are defined within the context of the function.
*
* #returns -1 if the post was never created, -2 if a post with the same title exists, or the ID
* of the post if successful.
*/
function programmatically_create_post() {
// Initialize the page ID to -1. This indicates no action has been taken.
$post_id = -1;
// Setup the author, slug, and title for the post
$author_id = 1;
$slug = 'example-post';
$title = 'My Example Post';
// If the page doesn't already exist, then create it
if( null == get_page_by_title( $title ) ) {
// Set the post ID so that we know the post was created successfully
$post_id = wp_insert_post(
array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => $author_id,
'post_name' => $slug,
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'post'
)
);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
} // end if
} // end programmatically_create_post
add_filter( 'after_setup_theme', 'programmatically_create_post' );

Wordpress - Create a page when creating a user

I would like to create a function that creates a page in wordpress that uses a specific page title, specific URL, and is under an already exisiting parent page, when ever a new user is created.
An example:
Creating a new user call user1, will also create a new page called User1's Page with a slug of user1s-page under a specified parent page ID.
I didn't test this while writing but it should do the trick. Make sure you set $post_parent to the ID of the page you want to use as the parent. It's currently set to 0 so no parent.
function wpse_user_registration_create_page( $user_id ) {
// Get the new user by their ID.
$new_user = get_user_by( 'id', $user_id );
// Check a user was found.
if ( ! $new_user )
return;
// Create the post title. E.g. User1's Page
$post_title = ucfirst( $new_user->display_name ) . "'s Page";
// SET THE ID OF THE PARENT PAGE HERE!!!
$post_parent = 0;
$post_args = array(
"post_name" => sanitize_title( $post_title ),
"post_title" => $post_title,
"post_type" => "page",
"post_status" => "publish",
"post_author" => $new_user->ID,
"post_parent" => $post_parent,
);
wp_insert_post( $post_args );
}
add_action( 'user_register', 'wpse_user_registration_create_page' );
You will need to hook into the register user hook, here;
http://codex.wordpress.org/Plugin_API/Action_Reference/user_register
Then build a function which inserts a post (page) using this;
http://codex.wordpress.org/Function_Reference/wp_insert_post

Resources