Exceptions
1 week ago
Frontend
1 week ago
Language
1 week ago
Store
1 week ago
Wrapper
1 week ago
Functions.php
1 week ago
Generic.php
1 week ago
Hooks.php
2 years ago
ProductSaveActions.php
1 week ago
Generic.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Rest; |
| 4 | |
| 5 | use WPML\FP\Fns; |
| 6 | use WPML\FP\Obj; |
| 7 | use WPML\API\Sanitize; |
| 8 | |
| 9 | class Generic { |
| 10 | |
| 11 | public static function preventDefaultLangUrlRedirect() { |
| 12 | $exp = explode( '?', $_SERVER['REQUEST_URI'] ); |
| 13 | if ( ! empty( $exp[1] ) ) { |
| 14 | parse_str( $exp[1], $vars ); |
| 15 | if ( isset( $vars['lang'] ) && $vars['lang'] === wpml_get_default_language() ) { |
| 16 | unset( $vars['lang'] ); |
| 17 | $_SERVER['REQUEST_URI'] = $exp[0] . '?' . http_build_query( $vars ); |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | public static function autoAdjustIncludedIds( \WP_Query $wp_query ) { |
| 23 | $lang = Sanitize::string( (string) Obj::prop( 'lang', $_GET ) ); |
| 24 | $include = $wp_query->get( 'post__in' ); |
| 25 | if ( empty( $lang ) && ! empty( $include ) ) { |
| 26 | $filtered_include = []; |
| 27 | foreach ( $include as $id ) { |
| 28 | $filtered_include[] = wpml_object_id_filter( $id, get_post_type( $id ), true ); |
| 29 | } |
| 30 | $wp_query->set( 'post__in', $filtered_include ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | public static function removeHomeUrlFilterOnRestAuthentication() { |
| 35 | $returnTrue = Fns::always( true ); |
| 36 | |
| 37 | add_filter( 'determine_current_user', Fns::tap( function() use ( $returnTrue ) { |
| 38 | add_filter( 'wpml_skip_convert_url_string', $returnTrue ); |
| 39 | } ), 10 ); |
| 40 | |
| 41 | add_filter( 'determine_current_user', Fns::tap( function() use ( $returnTrue ) { |
| 42 | remove_filter( 'wpml_skip_convert_url_string', $returnTrue ); |
| 43 | } ), 20 ); |
| 44 | } |
| 45 | |
| 46 | } |
| 47 |