Replies
- maimaimemain on January 31, 2019 at 2:07 am in reply to: [Resolved] I want to execute the action only the first time #20595
Thank you for the quick response.
The code you presented did not work.
I wrote it in “wordpress\wp-content\plugins\bp-custom.php”.
I confirmed the topic list at the timing when the user registered and logged in the first time.
There seems to be no error in particular.
Regards.
- This reply was modified 5 years, 9 months ago by maimaimemain.
- maimaimemain on January 30, 2019 at 7:23 pm in reply to: [Resolved] I want to execute the action only the first time #20590
Although it will work, but since it is executed with the number of times to access the login screen before logging in, articles are posted many times.
function first_login_check( $redirect_to, $not_used, $user ) { // After the second time actions if( bp_get_user_last_activity( $user->ID ) !== '' ) { // nothing much } // First time actions else{ // get user name $user_data = get_user_by( 'id', bp_loggedin_user_id() )->data; $user_nicename = = $user_data->user_nicename; // create slug $new_slug = 'first-topic-' . $user_nicename; // create topic $post_value = array( 'post_name' => $new_slug, 'post_type' => 'topic', 'post_author' => $userid, 'post_title' => 'first topic', 'post_content' => 'This topic was created when you registered.', 'post_category' => array(1,5), 'tags_input' => array('tag1','tag2'), 'post_status' => 'publish' ); wp_insert_post($post_value); } exit(); } add_filter( 'login_redirect', 'first_login_check', 20, 3 );
- This reply was modified 5 years, 9 months ago by maimaimemain.
- maimaimemain on January 30, 2019 at 7:16 pm in reply to: [Resolved] I want to execute the action only the first time #20589
Or I tried the code below, but it did not work.
function buddydev_create_post_on_activation( $user_id, $key, $user ) { // get user name $user_data = get_user_by( 'id', bp_loggedin_user_id() )->data; $user_nicename = = $user_data->user_nicename; // create slug $new_slug = 'first-topic-' . $user_nicename; // create topic $post_value = array( 'post_name' => $new_slug, 'post_type' => 'topic', 'post_author' => $userid, 'post_title' => 'first topic', 'post_content' => 'This topic was created when you registered.', 'post_category' => array(1,5), 'tags_input' => array('tag1','tag2'), 'post_status' => 'publish' ); wp_insert_post($post_value); } add_action( 'bp_core_activated_user', 'buddydev_create_post_on_activation', 10, 3 );