post_type !== EPPRO_Popup_CPT::POST_TYPE ) return;
wp_enqueue_style(
'eppro-admin-ui',
EPPRO_URL . 'assets/css/eppro-admin.css',
[],
eppro_asset_ver( 'assets/css/eppro-admin.css' )
);
wp_enqueue_script(
'eppro-admin-ui',
EPPRO_URL . 'assets/js/eppro-admin.js',
[ 'jquery' ],
eppro_asset_ver( 'assets/js/eppro-admin.js' ),
true
);
wp_localize_script( 'eppro-admin-ui', 'epproAdmin', [
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'eppro_admin_nonce' ),
'i18n' => [
'confirmDuplicate' => __( 'Duplicate this template? A draft copy will be created.', 'admore-widgets-suite' ),
],
] );
}
// =========================================================================
// Render
// =========================================================================
public static function render( \WP_Post $post ): void {
$m = self::get( $post->ID );
wp_nonce_field( self::NONCE, self::NONCE );
$active_t = (array) ( $m['triggers'] ?? [] );
$sel_devs = (array) ( $m['devices'] ?? [ 'desktop', 'tablet', 'mobile' ] );
?>
! empty( $raw['active'] ),
'triggers' => array_map( 'sanitize_key', (array) ( $raw['triggers'] ?? [] ) ),
'page_load_delay' => absint( $raw['page_load_delay'] ?? 0 ),
'scroll_depth' => min( 100, absint( $raw['scroll_depth'] ?? 50 ) ),
'click_selector' => sanitize_text_field( $raw['click_selector'] ?? '' ),
'inactivity_time' => absint( $raw['inactivity_time'] ?? 30 ),
'condition_scope' => sanitize_key( $raw['condition_scope'] ?? 'entire_site' ),
'condition_page_ids' => sanitize_text_field( $raw['condition_page_ids'] ?? '' ),
'condition_post_types' => array_map( 'sanitize_key', (array) ( $raw['condition_post_types'] ?? [] ) ),
'condition_categories' => array_map( 'absint', (array) ( $raw['condition_categories'] ?? [] ) ),
'condition_tags' => array_map( 'absint', (array) ( $raw['condition_tags'] ?? [] ) ),
'condition_exclude_ids' => sanitize_text_field( $raw['condition_exclude_ids'] ?? '' ),
'condition_url_contains' => sanitize_text_field( $raw['condition_url_contains'] ?? '' ),
'condition_url_param' => sanitize_key( $raw['condition_url_param'] ?? '' ),
'user_condition' => sanitize_key( $raw['user_condition'] ?? 'all' ),
'user_roles' => array_map( 'sanitize_key', (array) ( $raw['user_roles'] ?? [] ) ),
'visitor_type' => sanitize_key( $raw['visitor_type'] ?? 'all' ),
'schedule_start' => sanitize_text_field( $raw['schedule_start'] ?? '' ),
'schedule_end' => sanitize_text_field( $raw['schedule_end'] ?? '' ),
'schedule_days' => array_map( 'sanitize_key', (array) ( $raw['schedule_days'] ?? [] ) ),
'schedule_time_from' => sanitize_text_field( $raw['schedule_time_from'] ?? '' ),
'schedule_time_to' => sanitize_text_field( $raw['schedule_time_to'] ?? '' ),
'show_once' => ! empty( $raw['show_once'] ),
'show_once_session' => ! empty( $raw['show_once_session'] ),
'cookie_days' => absint( $raw['cookie_days'] ?? 30 ),
'max_per_session' => ! empty( $raw['max_per_session'] ) ? absint( $raw['max_per_session'] ) : null,
'after_page_views' => ! empty( $raw['after_page_views'] ) ? absint( $raw['after_page_views'] ) : null,
'lifetime_cap' => ! empty( $raw['lifetime_cap'] ) ? absint( $raw['lifetime_cap'] ) : null,
'close_overlay' => ! empty( $raw['close_overlay'] ),
'close_esc' => ! empty( $raw['close_esc'] ),
'show_close_btn' => ! empty( $raw['show_close_btn'] ),
'close_position' => sanitize_key( $raw['close_position'] ?? 'top-right' ),
'hide_close_for' => absint( $raw['hide_close_for'] ?? 0 ),
'auto_close_after' => absint( $raw['auto_close_after'] ?? 0 ),
'position' => self::sanitize_position( $raw['position'] ?? 'center' ),
'animation' => self::sanitize_animation( $raw['animation'] ?? 'fade' ),
'max_width' => absint( $raw['max_width'] ?? 600 ),
'popup_width' => absint( $raw['popup_width'] ?? 600 ),
'popup_width_unit' => in_array( $raw['popup_width_unit'] ?? 'px', [ 'px', '%', 'vw' ], true ) ? sanitize_key( $raw['popup_width_unit'] ) : 'px',
'popup_height' => ! empty( $raw['popup_height'] ) ? absint( $raw['popup_height'] ) : null,
'popup_height_unit' => in_array( $raw['popup_height_unit'] ?? 'px', [ 'px', 'vh' ], true ) ? sanitize_key( $raw['popup_height_unit'] ) : 'px',
'devices' => array_map( 'sanitize_key', (array) ( $raw['devices'] ?? [ 'desktop', 'tablet', 'mobile' ] ) ),
'overlay_color' => sanitize_hex_color( $raw['overlay_color'] ?? '#000000' ) ?: '#000000',
'overlay_opacity' => min( 100, absint( $raw['overlay_opacity'] ?? 55 ) ),
'container_bg' => sanitize_hex_color( $raw['container_bg'] ?? '#ffffff' ) ?: '#ffffff',
'border_radius' => min( 50, absint( $raw['border_radius'] ?? 8 ) ),
'content_padding' => min( 80, absint( $raw['content_padding'] ?? 0 ) ),
'anim_speed' => min( 1000, max( 100, absint( $raw['anim_speed'] ?? 300 ) ) ),
'z_index' => absint( $raw['z_index'] ?? 999999 ),
'body_scroll_lock' => ! empty( $raw['body_scroll_lock'] ),
'close_btn_size' => min( 60, max( 20, absint( $raw['close_btn_size'] ?? 32 ) ) ),
'close_btn_color' => sanitize_hex_color( $raw['close_btn_color'] ?? '#334155' ) ?: '#334155',
'close_btn_bg' => sanitize_hex_color( $raw['close_btn_bg'] ?? '#f1f5f9' ) ?: '#f1f5f9',
'close_btn_shape' => in_array( $raw['close_btn_shape'] ?? 'circle', [ 'circle', 'rounded', 'square' ], true ) ? sanitize_key( $raw['close_btn_shape'] ) : 'circle',
'overlay_blur' => min( 20, absint( $raw['overlay_blur'] ?? 0 ) ),
'shadow_preset' => in_array( $raw['shadow_preset'] ?? 'lg', [ 'none', 'sm', 'md', 'lg', 'xl' ], true ) ? sanitize_key( $raw['shadow_preset'] ) : 'lg',
'border_width' => min( 5, absint( $raw['border_width'] ?? 0 ) ),
'border_color' => sanitize_hex_color( $raw['border_color'] ?? '#e2e8f0' ) ?: '#e2e8f0',
'form_selector' => sanitize_text_field( $raw['form_selector'] ?? '' ),
'condition_referrer' => sanitize_text_field( $raw['condition_referrer'] ?? '' ),
'redirect_on_close' => esc_url_raw( $raw['redirect_on_close'] ?? '' ),
];
update_post_meta( $post_id, self::META_KEY, $data );
}
// =========================================================================
// Getter
// =========================================================================
public static function get( int $post_id ): array {
$meta = get_post_meta( $post_id, self::META_KEY, true );
return is_array( $meta ) ? $meta : [];
}
private static function sanitize_animation( string $value ): string {
$allowed = [ 'fade', 'slide_up', 'slide_down', 'slide_left', 'slide_right', 'zoom', 'bounce', 'flip', 'newspaper', 'none' ];
$value = sanitize_key( str_replace( '-', '_', $value ) );
return in_array( $value, $allowed, true ) ? $value : 'fade';
}
private static function sanitize_position( string $value ): string {
$allowed = [ 'center', 'top_bar', 'bottom_bar', 'slide_right', 'slide_left', 'full_screen', 'side_left', 'side_right' ];
$value = sanitize_key( str_replace( '-', '_', $value ) );
return in_array( $value, $allowed, true ) ? $value : 'center';
}
}