From f1cb3ebb7394e5f7b257d69ac287ca3d4c0862ac Mon Sep 17 00:00:00 2001 From: eoxia-amandine Date: Thu, 11 Apr 2024 14:53:36 +0200 Subject: [PATCH] #41 Add: Beflex URL registration redirect --- acf-json/group_6617dbb4efcd8.json | 65 +++++++++++++++++++++++++++++++ functions.php | 14 +++++++ inc/blocks/bfs-login/view.php | 11 ++++-- sensei/functions.php | 13 +++++++ 4 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 acf-json/group_6617dbb4efcd8.json diff --git a/acf-json/group_6617dbb4efcd8.json b/acf-json/group_6617dbb4efcd8.json new file mode 100644 index 0000000..5cb0116 --- /dev/null +++ b/acf-json/group_6617dbb4efcd8.json @@ -0,0 +1,65 @@ +{ + "key": "group_6617dbb4efcd8", + "title": "Beflex Settings", + "fields": [ + { + "key": "field_6617dbb50e861", + "label": "Réglages généraux", + "name": "", + "aria-label": "", + "type": "tab", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "placement": "left", + "endpoint": 0 + }, + { + "key": "field_6617dbdb0e862", + "label": "Page d'inscription \/ connexion", + "name": "page_url_register", + "aria-label": "", + "type": "page_link", + "instructions": "A utiliser pour modifier la page d'inscription par défaut de Sensei LMS", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "post_type": [ + "page" + ], + "post_status": "", + "taxonomy": "", + "allow_archives": 1, + "multiple": 0, + "allow_null": 0 + } + ], + "location": [ + [ + { + "param": "options_page", + "operator": "==", + "value": "theme-general-settings" + } + ] + ], + "menu_order": 0, + "position": "normal", + "style": "default", + "label_placement": "top", + "instruction_placement": "label", + "hide_on_screen": "", + "active": true, + "description": "", + "show_in_rest": 0, + "modified": 1712839735 +} diff --git a/functions.php b/functions.php index 7240221..3cd9ccb 100644 --- a/functions.php +++ b/functions.php @@ -81,6 +81,20 @@ function beflex_add_custom_classes_to_body( $classes ) { } add_filter( 'body_class', 'beflex_add_custom_classes_to_body' ); +/** + * Création admin page for theme settings + */ +if( function_exists('acf_add_options_page') ) { + + acf_add_options_page( array( + 'page_title' => esc_html__('BeFlex Settings', 'beflex'), + 'menu_title' => esc_html__('BeFlex Settings', 'beflex'), + 'menu_slug' => 'theme-general-settings', + 'parent_slug' => 'themes.php', + 'capability' => 'edit_pages', + )); + +} // Block patterns. require_once 'inc/block-patterns.php'; diff --git a/inc/blocks/bfs-login/view.php b/inc/blocks/bfs-login/view.php index afaf880..6b2274d 100644 --- a/inc/blocks/bfs-login/view.php +++ b/inc/blocks/bfs-login/view.php @@ -27,13 +27,16 @@ settings->settings['my_course_page'] ); - $my_courses_url = get_permalink( $my_account_page_id ); + $beflex_registration_url = get_field( 'page_url_register', 'options' ); + if ( empty( $beflex_registration_url ) ) : + $my_account_page_id = intval( Sensei()->settings->settings['my_course_page'] ); + $beflex_registration_url = get_permalink( $my_account_page_id ); + endif; - if ( ! empty( $my_courses_url ) ) : + if ( ! empty( $beflex_registration_url ) ) : ?>
- + diff --git a/sensei/functions.php b/sensei/functions.php index 901f99e..b2aa948 100644 --- a/sensei/functions.php +++ b/sensei/functions.php @@ -178,3 +178,16 @@ function myplugin_user_register( $user_id ) { update_user_meta( $user_id, 'last_name', trim( $_POST['last_name'] ) ); } } + +/** + * Change the redirect of login page + */ +add_filter( 'sensei_registration_url', 'beflex_registration_url', 10, 2 ); +function beflex_registration_url( $registration_url, $redirect) { + $beflex_registration_url = get_field( 'page_url_register', 'options' ); + if ( ! empty( $beflex_registration_url ) ) { + $registration_url = esc_url( $beflex_registration_url ); + } + + return $registration_url; +}