index.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . '/wpml.php'; |
| 4 | require_once __DIR__ . '/polylang.php'; |
| 5 | |
| 6 | |
| 7 | add_action( |
| 8 | 'rest_api_init', |
| 9 | function () { |
| 10 | $namespace = 'kubio/v1'; |
| 11 | |
| 12 | register_rest_route( |
| 13 | $namespace, |
| 14 | '/get-language-selector-html', |
| 15 | array( |
| 16 | 'methods' => 'GET', |
| 17 | 'callback' => 'kubio_api_get_language_selector_html', |
| 18 | 'permission_callback' => function () { |
| 19 | return current_user_can( 'edit_theme_options' ); |
| 20 | }, |
| 21 | ) |
| 22 | ); |
| 23 | } |
| 24 | ); |
| 25 | |
| 26 | function kubio_api_get_language_selector_html() { |
| 27 | |
| 28 | $content = ''; |
| 29 | if ( kubio_polylang_is_active() ) { |
| 30 | $content = kubio_get_polylang_selector_html( true ); |
| 31 | } elseif ( kubio_wpml_is_active() ) { |
| 32 | $content = kubio_get_wpml_selector_html( true ); |
| 33 | } |
| 34 | |
| 35 | return array( |
| 36 | 'content' => $content, |
| 37 | ); |
| 38 | } |
| 39 |