blocks baked into the page content $content = preg_replace( '/]*>.*?<\/style>/s', '', $content ); // Inject "Passwort vergessen?" link after the login form if not already present if ( strpos( $content, 'login-lost-password' ) === false ) { $lost_pw_html = '

Passwort vergessen?

'; // Insert after the closing inside the login section $pos = strrpos( $content, '' ); if ( false !== $pos ) { $content = substr_replace( $content, '' . $lost_pw_html, $pos, strlen( '' ) ); } } return $content; } /** * Redirect logged-in providers from login page to dashboard */ public static function maybe_redirect_logged_in_from_login() { // Only check on the login page $login_page_id = get_option( 'ddhh_jm_login_page_id' ); if ( ! $login_page_id || ! is_page( $login_page_id ) ) { return; } // If user is logged in and is a provider, redirect to dashboard if ( is_user_logged_in() ) { $user = wp_get_current_user(); if ( in_array( 'ddhh_provider', $user->roles, true ) ) { $dashboard_page_id = get_option( 'ddhh_jm_dashboard_page_id' ); if ( $dashboard_page_id ) { $dashboard_url = get_permalink( $dashboard_page_id ); if ( $dashboard_url ) { wp_safe_redirect( $dashboard_url ); exit; } } } } } /** * Create provider pages on plugin activation */ public static function create_provider_pages() { // Create Anbieter Dashboard page self::create_dashboard_page(); // Create Anbieter Login page self::create_login_page(); } /** * Create provider dashboard page */ private static function create_dashboard_page() { // Check if page already exists $existing_page_id = get_option( 'ddhh_jm_dashboard_page_id' ); if ( $existing_page_id && get_post( $existing_page_id ) ) { // Page already exists return; } // Create the dashboard page $page_data = array( 'post_title' => 'Anbieter Dashboard', 'post_name' => 'anbieter-dashboard', 'post_content' => '[ddhh_provider_dashboard]', 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, // Admin user ); $page_id = wp_insert_post( $page_data ); if ( $page_id && ! is_wp_error( $page_id ) ) { // Store page ID in options update_option( 'ddhh_jm_dashboard_page_id', $page_id ); } } /** * Create login/registration page */ private static function create_login_page() { // Check if page already exists by slug $existing_page = get_page_by_path( 'anbieter-login' ); if ( $existing_page ) { // Page already exists, store ID if not stored $stored_page_id = get_option( 'ddhh_jm_login_page_id' ); if ( ! $stored_page_id ) { update_option( 'ddhh_jm_login_page_id', $existing_page->ID ); } return; } // Get registration form ID $registration_form_id = DDHH_JM_Formidable::get_registration_form_id(); // Build page content — styles are loaded via enqueued auth-forms.css $content = ''; $content .= '
'; // Registration section $content .= '
'; $content .= '

Neu registrieren

'; if ( $registration_form_id ) { $content .= '[formidable id=' . $registration_form_id . ']'; } else { $content .= '

Registrierungsformular wird geladen...

'; } $content .= '
'; // Login section $content .= ''; $content .= '
'; // .ddhh-auth-container // Create the login/registration page $page_data = array( 'post_title' => 'Anbieter Login', 'post_name' => 'anbieter-login', 'post_content' => $content, 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1, // Admin user ); $page_id = wp_insert_post( $page_data ); if ( $page_id && ! is_wp_error( $page_id ) ) { // Store page ID in options update_option( 'ddhh_jm_login_page_id', $page_id ); } } }