introducing api features
This commit is contained in:
parent
a1197b69b8
commit
396831c4a5
|
|
@ -6,6 +6,8 @@ require_once(__DIR__ . '/includes/blocks.php');
|
|||
require_once(__DIR__ . '/includes/post_types.php');
|
||||
require_once(__DIR__ . '/includes/admin.php');
|
||||
require_once(__DIR__ . '/includes/logos.php');
|
||||
require_once(__DIR__ . '/includes/api.php');
|
||||
require_once(__DIR__ . '/includes/dashboard.php');
|
||||
|
||||
// require_once(__DIR__ . '/includes/widget.php');
|
||||
// require_once( __DIR__ . '/includes/taxonomy.php');
|
||||
|
|
|
|||
112
includes/api.php
Normal file
112
includes/api.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
|
||||
add_action('rest_api_init', function () {
|
||||
register_rest_route('lhoist-datas/interface-content', '/welcome', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => 'get_interface_welcome_screen',
|
||||
'permission_callback' => '__return_true',
|
||||
|
||||
));
|
||||
|
||||
// ################ POST ################
|
||||
register_rest_route('lhoist-datas/statistics', '/post', array(
|
||||
'methods' => 'POST',
|
||||
'callback' => 'wp_learn_create_database_table',
|
||||
'permission_callback' => 'lhoist_datas_permission_callback',
|
||||
|
||||
));
|
||||
});
|
||||
function wp_learn_create_database_table(WP_REST_Request $request)
|
||||
{
|
||||
$data = $request->get_json_params(); // Récupération des données envoyées avec la requête POST
|
||||
$user_name = $data['user_name'] ?? null;
|
||||
$user_locale = $data['user_locale'] ?? null;
|
||||
$user_country = $data['user_country'] ?? null;
|
||||
$level_post_id = $data['level_post_id'] ?? null;
|
||||
$level_is_completed = $data['level_is_completed'] ?? null;
|
||||
$level_completion_time = $data['level_completion_time'] ?? null;
|
||||
$level_score = $data['level_score'] ?? null;
|
||||
|
||||
if (!$data) {
|
||||
return rest_ensure_response(array('success' => false, 'message' => 'Erreur lors de l\'enregistrement des données.'));
|
||||
exit;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$table_name = 'wp_app_users_statistics';
|
||||
$post_id = uniqid();
|
||||
write_log("user_locale : " . $user_locale);
|
||||
|
||||
$result_check = $wpdb->insert(
|
||||
$table_name,
|
||||
array(
|
||||
'session_ID' => $post_id,
|
||||
'user_name' => $user_name,
|
||||
'user_locale' => $user_locale,
|
||||
'user_country' => $user_country,
|
||||
'level_post_id' => $level_post_id,
|
||||
'level_is_completed' => $level_is_completed,
|
||||
'level_completion_time' => $level_completion_time,
|
||||
'level_score' => $level_score,
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
if ($result_check) {
|
||||
return rest_ensure_response(array('success' => true, 'message' => 'Données enregistrées avec succès.'));
|
||||
} else {
|
||||
return rest_ensure_response(array('success' => false, 'message' => 'Erreur lors de l\'enregistrement des données.'));
|
||||
}
|
||||
}
|
||||
|
||||
function lhoist_datas_permission_callback()
|
||||
{
|
||||
if (is_user_logged_in() && current_user_can('administrator')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ################ WELCOME SCREEN ################
|
||||
|
||||
function get_interface_welcome_screen($request)
|
||||
{
|
||||
// $language = sanitize_text_field($request['language']);
|
||||
$currentLanguage = $request->get_param('current-page-language') ?? 'fr';
|
||||
|
||||
|
||||
$option_id = icl_object_id('option_id', 'option', false, $currentLanguage);
|
||||
|
||||
do_action('wpml_switch_language', $currentLanguage);
|
||||
function acf_set_language()
|
||||
{
|
||||
return apply_filters('wpml_current_language', null);
|
||||
}
|
||||
add_filter('acf/settings/current_language', 'acf_set_language');
|
||||
$args = array(
|
||||
'post_type' => 'search-and-find',
|
||||
'posts_per_page' => -1,
|
||||
);
|
||||
$posts = new WP_Query($args);
|
||||
|
||||
$applicationTitle = get_field('application_title', 'option');
|
||||
$applicationSubtitle = get_field('application_subtitle', 'option');
|
||||
$applicationDescription = get_field('application_description', 'option');
|
||||
// write_log("current language : " . $currentLanguage);
|
||||
// write_log($posts->posts[0]->post_title);
|
||||
// write_log($applicationDescription);
|
||||
|
||||
$response_data = array(
|
||||
'applicationTitle' => $applicationTitle,
|
||||
'applicationSubtitle' => $applicationSubtitle,
|
||||
'applicationDescription' => $applicationDescription,
|
||||
);
|
||||
|
||||
$response = new WP_REST_Response($response_data);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
|
@ -4,3 +4,56 @@
|
|||
#menu-posts {
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.2) !important;
|
||||
}
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
font-size: revert;
|
||||
font-weight: revert;
|
||||
}
|
||||
|
||||
#menu-posts-search-and-find {
|
||||
margin-bottom: 12px !important;
|
||||
padding-bottom: 8px !important;
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important;
|
||||
}
|
||||
|
||||
#toplevel_page_theme-general-settings {
|
||||
margin-top: 12px !important;
|
||||
padding-top: 8px !important;
|
||||
padding-bottom: 0px !important;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.2) !important;
|
||||
}
|
||||
|
||||
.toplevel_page_session-datas-options {
|
||||
/* @apply bg-white; */
|
||||
}
|
||||
.wrap {
|
||||
.page-title {
|
||||
@apply text-5xl font-semibold text-neutral-800 pb-16;
|
||||
}
|
||||
@apply py-12 text-base max-w-screen-xl mx-auto px-4;
|
||||
p,
|
||||
li {
|
||||
@apply text-lg;
|
||||
}
|
||||
h2 {
|
||||
@apply text-blue-700 font-medium text-2xl my-0;
|
||||
}
|
||||
h3 {
|
||||
@apply font-medium text-blue-500 my-0;
|
||||
}
|
||||
|
||||
.geography,
|
||||
.game {
|
||||
@apply grid grid-cols-2 overflow-hidden;
|
||||
}
|
||||
.section-title {
|
||||
@apply col-span-2 mb-4;
|
||||
}
|
||||
.data-label {
|
||||
@apply font-semibold;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user