Thời gian tiếp theo cho một sự kiện. Retrieve the next timestamp for an event. wp_next_scheduled (ok
https://developer.wordpress.org/reference/functions/wp_next_scheduled/
if ( ! wp_next_scheduled( 'resend_code_api_error' ) ) {
wp_schedule_event( time(), 'hourly', 'resend_code_api_error' );
}
add_action( 'resend_code_api_error', 'resend_code_api_error' );
function resend_code_api_error() {
global $wpdb;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,API_OEC_ERROR_URL);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
$server_output = json_decode($server_output, true);
if($server_output['done']) {
$records = $server_output['records'];
if(count($records) > 0) {
foreach ($records as $record) {
$course = get_post($record['course_id']);
// Kiểm tra xem record đã tạo thành công trước đó chưa
$sql = "SELECT * FROM wp_log_api WHERE course_id = " . $record['course_id'] . " AND order_id = " . $record['order_id'];
$temp = $wpdb->get_row($sql);
if(!$temp || $temp->status != 2) {
// Gen lại code
do {
$code = wccg_get_random_coupon();
// Kiểm tra mã kích hoạt đã được tạo trước đó chưa
$checkSql = "SELECT id FROM wp_codes WHERE code = '" . $code . "'";
$codes = $wpdb->get_results($checkSql);
if(count($codes) > 0) {
$end = false;
} else {
$end = true;
}
} while ($end == false);
// Insert mã kích hoạt vào DB
$today = date('Y-m-d H:i:s');
if($code) {
$data = array(
'code' => $code,
'course_id' => $record['course_id'],
'is_active' => 0,
'status' => 1,
'customer_email' => $record['customer_email'],
'created_at' => $today,
'order_id' => $record['order_id'],
'source' => 'API'
);
$wpdb->insert('wp_codes', $data);
if($wpdb->insert_id) {
if($temp) {
// Cập nhật log
$wpdb->update('wp_log_api', array('api_status' => 1, 'code' => $code), array('id' => $temp['id']));
} else {
// Lưu log TMDT call API
$dataApi = array(
'customer_email' => $record['customer_email'],
'customer_name' => $record['customer_name'],
'course_id' => $record['course_id'],
'order_id' => $record['order_id'],
'created_at' => date('Y-m-d :H:i:s'),
'api_status' => 1,
'source' => 'API',
);
$wpdb->insert('wp_log_api', $dataApi);
}
$subject = 'MÃ KÍCH HOẠT KHÓA HỌC';
$customer_name = $record['customer_name'];
$customer_email = $record['customer_email'];
$body = '<b>MÃ KÍCH HOẠT KHÓA HỌC ' . wc_strtoupper($course->post_title) . '</b><br/>';
$body .= 'Thân gửi học viên <b>' . $customer_name .'</b><br/>';
$body .= 'Vinmec xin xác nhận đã thanh toán thành công khóa học <b>' . $course->post_title . '</b> tại <a href="' . home_url() . '">songkhoe.vinmec.com</a> <br/>';
$body .= 'Mã kích hoạt khóa học của bạn là: <b>' . $code . '</b><br/>';
$body .= 'Hướng dẫn kích hoạt khóa học: <br/>';
$body .= '<b>(Lưu ý: chỉ kích hoạt một lần duy nhất) </b><br/>';
$body .= '<b>Bước 1:</b> Truy cập vào link: <a href="' . home_url() . '">songkhoe.vinmec.com</a> <br/>';
$body .= '<b>Bước 2:</b> Chọn nút "Đăng nhập" và nhập thông tin tài khoản của bạn <br/>';
$body .= '<b>Bước 3:</b> Chọn mục “Khóa học”, xem thông tin khóa học <br/>';
$body .= '<b>Bước 4:</b> Chọn nút “Kích hoạt khóa học” <br/>';
$body .= '<b>Bước 5:</b> Nhập mã kích hoạt thành công và bắt đầu học ngay <br/><br/>';
$body .= 'Cảm ơn sự quan tâm và ủng hộ của bạn. <br/>';
$body .= 'Chúc các bạn có những trải nghiệm thú vị cùng <a href="' . home_url() .'">songkhoe.vinmec.com</a> <br/><br/>';
$body .= '<a href="#">Câu hỏi thường gặp</a> <br/>';
$body .= '<a href="#">Chính sách bảo mật thông tin</a> <br/><br/>';
$body .= '<b>Chú ý:</b> Đây là email tự động từ Hệ thống Y tế Vinmec. Quý khách vui lòng, không trả lời email này. <br/><br/>';
$body .= '<b>CÔNG TY CỔ PHẦN BỆNH VIỆN ĐA KHOA QUỐC TẾ VINMEC </b><br/>';
$body .= 'Địa chỉ: số 458 Minh Khai, phường Vĩnh Tuy, quận Hai Bà Trung, Hà Nội <br/>';
$body .= 'Liên hệ: <a href="mailto: info@vinmec.com">info@vinmec.com</a><br/>';
$headers = array('Content-Type: text/html; charset=UTF-8');
$result = wp_mail($customer_email, $subject, $body, $headers);
if($result) {
// Cập nhật log
$wpdb->update('wp_log_api', array('api_status' => 2), array('id' => $temp['id']));
$response['error'] = 200;
$response['message'] = 'Tạo mã kích hoạt và gửi email thành công';
wp_send_json_success( $response );
} else {
$response['error'] = 400;
$response['message'] = 'Gửi email không thành công';
wp_send_json_success( $response );
}
} else {
$response['error'] = 400;
$response['message'] = 'Tạo mã kích hoạt không thành công';
wp_send_json_success( $response );
}
} else {
$response['error'] = 400;
$response['message'] = 'Không thể tạo mã kích hoạt';
wp_send_json_success( $response );
}
}
}
}
}
}Tham khảo:
PHP wp_next_scheduled Examples
PHP wp_next_scheduled - 30 examples found. These are the top rated real world PHP examples of wp_next_scheduled extracted from open source projects. You can rate examples to help us improve the quality of examples.Programming Language: PHPMethod/Function: wp_next_scheduledExamples at hotexamples.com: 30RELATEDThemeMockImprovementsBuildingsActualUsesBasePageHelperGOTMLS_update_statusGroupQuerydatabase_addldap_get_optionyii\widgets\PjaxReceiptLineRELATED IN LANGSBitTreeDecoder (C#)DeleteBandwidthRateLimitRequestMarshaller (C#)block_write_full_page (C++)elf_begin (C++)LogError (Go)LoggingHandler (Go)UnitPrinter (Java)ReplyContext (Java)Cookie (Python)cbcdecrypt (Python)Google BookmarkFacebookTwitterPrintEmailMoreEXAMPLE #11 Show fileFile: class.fileaway_cleanup.php Project: Nguyenkain/strida.vn
EXAMPLE #21 Show fileFile: class-itsec-logger.php Project: helloworld-digital/insightvision
EXAMPLE #31 Show fileFile: tracking.php Project: dreadfra/superba
EXAMPLE #40 Show fileFile: sandbox-functionality.php Project: diddledan/meta-environment
EXAMPLE #50 Show fileFile: ClientTest.php Project: 10up/wp-gears
EXAMPLE #60 Show fileFile: class-itsec-file-change.php Project: jfbelisle/magexpress
EXAMPLE #70 Show fileFile: class-itsec-file-change.php Project: Garth619/Femi9
EXAMPLE #80 Show fileFile: wpmudev-dash-notification.php Project: olechka1505/hungrylemur
EXAMPLE #90 Show fileFile: functions-scrape.php Project: CityOfPrescott/tabula-rasa_city-of-prescott
EXAMPLE #100 Show fileFile: class-poller.php Project: ibericode/boxzilla-wp
EXAMPLE #110 Show fileFile: WsdScheduler.php Project: yarwalker/ecobyt
EXAMPLE #120 Show fileFile: cbrobot.php Project: pratikparmar111/cblogger-robot
EXAMPLE #130 Show fileFile: fp_rac_cron.php Project: bear12345678/keylessoption
EXAMPLE #140 Show fileFile: class_eab_scheduler.php Project: nayabbukhari/circulocristiano
EXAMPLE #150 Show fileFile: custom-fonts.php Project: renatodex/submundo-blogstore
EXAMPLE #160 Show fileFile: wordpress-slack.php Project: barzik/Slack-Notifications
EXAMPLE #170 Show fileFile: gateway.paypal-chained-payments.php Project: nikwin333/pcu_project
EXAMPLE #180 Show fileFile: remove-duplicate-posts.php Project: rrasco09/remove-duplicate-posts
EXAMPLE #190 Show fileFile: class-wpmudev-dashboard-api.php Project: developmentDM2/Whohaha
EXAMPLE #200 Show fileFile: cachehelper.class.php Project: geminorum/gmember
EXAMPLE #210 Show fileFile: plugin-update-checker.class.php Project: Andysean/agilephilippines.org
EXAMPLE #220 Show fileFile: import-stream.php Project: antoniorequenalorente/Fanpage-import
EXAMPLE #230 Show fileFile: cron.php Project: Born1988/WordPress
EXAMPLE #240 Show fileFile: class-itsec-lockout.php Project: Haydt45/justinhaydt.com
EXAMPLE #250 Show fileFile: class-wc-square-inventory-poll.php Project: lilweirdward/blofishwordpress
EXAMPLE #260 Show fileFile: cron.php Project: alons182/4energy
EXAMPLE #270 Show fileFile: wp-google-authenticator.php Project: dishuostec/WP-Google-Authenticator
EXAMPLE #280 Show fileFile: class-itsec-lockout.php Project: jacko5/bjj
EXAMPLE #290 Show fileFile: class-wp-user-avatar-admin.php Project: tuanlibra/thptxuanang
EXAMPLE #300 Show fileFile: github-embed.php Project: pattyland/wp-github-oembed
Last updated
Was this helpful?