ADDED logic to create profil post if logged in user doesnt exist as profil post

This commit is contained in:
Daniel Reintanz 2025-11-24 14:18:55 +01:00
commit 807b1d5796

56
efabi_net_core.php Normal file
View file

@ -0,0 +1,56 @@
<?php
/**
* Plugin Name: Efabi.net Core Plugin
* Plugin URI: https://github.com/rpi-virtuell/rpi-newsletter
* Description: Efabi.net Hauptplugin
* Version: 1.0
* Author: reintanz
* Author URI: https://github.com/FreelancerAMP
* License: GPL2 or later
*
*/
class EfabiNetCore
{
public function __construct()
{
add_action('wp_login', array($this, 'register_new_user_on_login'));
}
public function register_new_user_on_login()
{
if (is_user_logged_in()) {
$user = wp_get_current_user();
$args = array(
'post_type' => 'profil',
'numberposts' => -1,
'meta_query' =>
array(
'key' => 'user_id',
'value' => $user->ID,
'compare' => '='
)
);
$profil = get_posts($args);
if (count($profil) == 0) {
// Kein Profil gefunden, neues Profil erstellen
$new_profil = array(
'post_title' => $user->user_login,
'post_status' => 'publish',
'post_type' => 'profil',
);
$new_profil = wp_insert_post($new_profil);
add_post_meta($new_profil, 'user_id', $user->ID);
add_post_meta($new_profil, 'email', $user->user_email);
add_post_meta($new_profil, 'first_name', $user->first_name);
add_post_meta($new_profil, 'last_name', $user->last_name);
}
}
}
}
new EfabiNetCore();