• I would like to implement the wp-api-swaggerui in my project, but I noticed that the WPML parameter uses wpml_language instead of lang, which would better align with the REST API structure.

    Is there a solution to remove or replace wpml_language with lang?

    Thank you in advance for your assistance!

Viewing 1 replies (of 1 total)
  • Hey hey, this is my solution:

    <?php
    // add to functions.php
    include_once('class-wpml-rest-extend-args.php');
    ?>

    <?php
    // file create in your theme class-wpml-rest-extend-args.php
    class Fix_WPML_REST_Extend_Args extends WPML_REST_Extend_Args {

    // Prefix of endpoints from which need remove param REST_LANGUAGE_ARGUMENT
    // Here example: /wp/v means all endpoint which started from wp/v1, wp/v2, wp/vqwr, ...
    private $excluded_prefix = '/wp/p';

    public function rest_endpoints( array $endpoints ) {
    foreach ( $endpoints as $route => &$endpoint ) {
    if ( strpos($route, $this->excluded_prefix) === 0 ) { // Проверяем, начинается ли маршрут с /wapi/v
    foreach ( $endpoint as $key => &$data ) {
    if ( is_numeric( $key ) && isset($data['args'][self::REST_LANGUAGE_ARGUMENT])) {
    unset($data['args'][self::REST_LANGUAGE_ARGUMENT]);
    }
    }
    }
    }

    return $endpoints;
    }
    }

    // Replace original object
    global $sitepress;
    $custom_wpml = new Fix_WPML_REST_Extend_Args($sitepress);
    $custom_wpml->add_hooks();
    ?>
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.