Building automatic landing page when new user signs up functionality

This is a bit of a confusing task, but I think I nearly have it figured out and need some help to get it over the finish line.

I’m using GoAffPro (API documentation: https://api.goaffpro.com/docs/admin/) to manage our affiliate network.

Members sign up on goaffpro and I’d like them to get a duplicated landing page on our main WordPress site with their referral link placed inside.

This is the code that I have so far in functions.php and it isn’t working.

// Add custom endpoint
add_action('init', 'custom_add_endpoint'); function custom_add_endpoint() {
add_rewrite_rule('^goaffpro-webhook/?', 'index.php?goaffpro_webhook=1', 'top'); }
// Add query var for the endpoint

 add_filter('query_vars', 'custom_add_query_vars'); function custom_add_query_vars($vars) {
$vars[] = 'goaffpro_webhook';
return $vars; }
// Flush rewrite rules on activation function custom_flush_rewrite_rules() {
custom_add_endpoint();
flush_rewrite_rules(); }
register_activation_hook(__FILE__, 'custom_flush_rewrite_rules'); register_deactivation_hook(__FILE__, 'flush_rewrite_rules');
// Handle the endpoint
add_action('template_redirect', 'custom_handle_webhook'); function custom_handle_webhook() {
if (get_query_var('goaffpro_webhook')) { $payload = file_get_contents('php://input'); $data = json_decode($payload, true);
if ($data && isset($data['affiliate_id'])) {
$affiliate_id = $data['affiliate_id']; create_landing_page_for_goaffpro_member($affiliate_id);
}
wp_die(); }
}
function get_goaffpro_affiliate_details($affiliate_id) { $access_token =
'APIACCESSTOKEN'; // Consider storing this securely
$response = wp_remote_get("https://api.goaffpro.com/v1/admin/affiliates/{$affiliate_id}", array(
'headers' => array(
'Authorization' => 'Bearer ' . $access_token
) ));
if (is_wp_error($response)) {
error_log('API request error: ' . print_r($response->get_error_message(), true)); return false;

 }
$affiliate_details = json_decode(wp_remote_retrieve_body($response), true);
if (isset($affiliate_details['affiliate'])) { return $affiliate_details['affiliate'];
}
return false; }
function create_landing_page_for_goaffpro_member($affiliate_id) { // Retrieve affiliate details from GoAffPro API
$affiliate_details = get_goaffpro_affiliate_details($affiliate_id);
if ($affiliate_details) {
$user_email = $affiliate_details['email'];
$user_login = $affiliate_details['name'];
$referral_code = $affiliate_details['ref_code'];
$network_link = "https://mqaz0jeik52e.goaffpro.com/create-account?ref=" . $referral_code;
// Create a new landing page $post_id = wp_insert_post(array(
'post_title' => 'Landing Page for ' . $user_login,
'post_content' => '[elementor-template id="affiliate-auto"]', // Adjust this if needed 'post_status' => 'publish',
'post_type' => 'page', // Change to your specific post type if different
));
// Update post meta with the network link update_post_meta($post_id, 'network_link', $network_link);
// Send email to the user
send_landing_page_email($user_email, $post_id); }
}
function send_landing_page_email($user_email, $post_id) { $landing_page_url = get_permalink($post_id);
$subject = 'Your New Landing Page';
$message = 'Hi, your new landing page is ready: ' . $landing_page_url; wp_mail($user_email, $subject, $message);
}

 // Shortcode to display network link function network_link_shortcode($atts) {
$network_link = get_post_meta(get_the_ID(), 'network_link', true);
return '<a href="' . esc_url($network_link) . '" class="elementor-button-link elementor-button elementor-size-md">Sign Up Here</a>';
}
add_shortcode('network_link_button', 'network_link_shortcode');

I expected this to work but it didn’t.

New contributor

Jack Bontatibus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật