Anbieter Login (/anbieter-login/): - Add auth-forms.css with styles matching the Mentor Login reference (navy pill buttons, bold #333 labels at 18px, consistent input sizing) - Enqueue CSS only on the login page via stored page ID - Strip legacy inline styles from page content via the_content filter - Inject "Passwort vergessen?" link after login form - Pixel-perfect field alignment between registration and login columns (matching Formidable's 97px field spacing, label padding, and margins) - Override Formidable's flex-row submit wrapper for full-width button Jobangebot (single job_offer): - Display company name next to provider logo in a flex .job-header container - Graceful fallback when logo or org name is missing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
217 lines
6.0 KiB
PHP
217 lines
6.0 KiB
PHP
<?php
|
|
/**
|
|
* Pages Class
|
|
*
|
|
* Handles creation of plugin pages during activation
|
|
*
|
|
* @package DDHH_Job_Manager
|
|
*/
|
|
|
|
// Exit if accessed directly.
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
/**
|
|
* Pages functionality
|
|
*/
|
|
class DDHH_JM_Pages {
|
|
|
|
/**
|
|
* Setup hooks
|
|
*/
|
|
public static function setup_hooks() {
|
|
// Redirect logged-in providers from login page to dashboard
|
|
add_action( 'template_redirect', array( __CLASS__, 'maybe_redirect_logged_in_from_login' ) );
|
|
|
|
// Enqueue auth form styles on anbieter-login page
|
|
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_auth_styles' ) );
|
|
|
|
// Clean up legacy inline styles and inject missing elements on login page
|
|
add_filter( 'the_content', array( __CLASS__, 'filter_login_page_content' ) );
|
|
}
|
|
|
|
/**
|
|
* Enqueue auth form styles on the anbieter-login page
|
|
*/
|
|
public static function enqueue_auth_styles() {
|
|
$login_page_id = get_option( 'ddhh_jm_login_page_id' );
|
|
if ( ! $login_page_id || ! is_page( $login_page_id ) ) {
|
|
return;
|
|
}
|
|
|
|
wp_enqueue_style(
|
|
'ddhh-jm-auth-forms',
|
|
DDHH_JM_PLUGIN_URL . 'assets/css/auth-forms.css',
|
|
array(),
|
|
DDHH_JM_VERSION
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Filter login page content to remove legacy inline styles and inject missing elements
|
|
*
|
|
* @param string $content Page content.
|
|
* @return string Filtered content.
|
|
*/
|
|
public static function filter_login_page_content( $content ) {
|
|
$login_page_id = get_option( 'ddhh_jm_login_page_id' );
|
|
if ( ! $login_page_id || ! is_page( $login_page_id ) ) {
|
|
return $content;
|
|
}
|
|
|
|
// Strip legacy inline <style> blocks baked into the page content
|
|
$content = preg_replace( '/<style[^>]*>.*?<\/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 = '<p class="login-lost-password"><a href="' . esc_url( wp_lostpassword_url() ) . '">Passwort vergessen?</a></p>';
|
|
|
|
// Insert after the closing </form> inside the login section
|
|
$pos = strrpos( $content, '</form>' );
|
|
if ( false !== $pos ) {
|
|
$content = substr_replace( $content, '</form>' . $lost_pw_html, $pos, strlen( '</form>' ) );
|
|
}
|
|
}
|
|
|
|
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 .= '<div class="ddhh-auth-container">';
|
|
|
|
// Registration section
|
|
$content .= '<div class="ddhh-register-section">';
|
|
$content .= '<h2>Neu registrieren</h2>';
|
|
if ( $registration_form_id ) {
|
|
$content .= '[formidable id=' . $registration_form_id . ']';
|
|
} else {
|
|
$content .= '<p>Registrierungsformular wird geladen...</p>';
|
|
}
|
|
$content .= '</div>';
|
|
|
|
// Login section
|
|
$content .= '<div class="ddhh-login-section">';
|
|
$content .= '<h2>Bereits registriert?</h2>';
|
|
|
|
// Build wp_login_form args for German labels
|
|
$login_args = array(
|
|
'echo' => false,
|
|
'redirect' => home_url( '/anbieter-dashboard/' ),
|
|
'label_username' => 'E-Mail oder Benutzername',
|
|
'label_password' => 'Passwort',
|
|
'label_remember' => 'Angemeldet bleiben',
|
|
'label_log_in' => 'Anmelden',
|
|
);
|
|
|
|
$content .= wp_login_form( $login_args );
|
|
$content .= '<p class="login-lost-password"><a href="' . esc_url( wp_lostpassword_url() ) . '">Passwort vergessen?</a></p>';
|
|
$content .= '</div>';
|
|
|
|
$content .= '</div>'; // .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 );
|
|
}
|
|
}
|
|
}
|