Giter VIP home page Giter VIP logo

wpml-rest-api's Introduction

WPML REST API

Contributors: shooper
Donate link: http://shawnhooper.ca/
Tags: wpml, api, rest
Requires at least: 5.2
Tested up to: 6.4.2 Requires PHP: 7.4
Stable tag: trunk
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Get translations details with the WP REST API on sites running WordPress & WPML

Description

This plugin adds links to pages and posts in other languages into the results of a WP REST API query for sites running the WPML plugin.

It adds a "wpml_current_locale" string containing the locale code of the current response, and a "wpml_translations" array containing the available translations for this plugin.

Screenshots

  1. This screenshot shows an excerpt of the JSON returned by the WP REST API when a page has translations available

Changelog

2.0.1 (2024-01-07)

  • Fixed: Some posts without translations would return a random post when no translation was available

2.0.0 (2022-10-27)

  • Fixed: Permalink style /yyyy/mm/dd/post_name/ returns slug without the dates (reported by @lukas-hablitzel)
  • Change: array keys in the wpml_translations response are now the locale code instead of an integer
  • Updated PHP Style: Short array syntax
  • Updated PHP Style: Added return types to all methods
  • Updated PHP Style: Added types to all parameters
  • Updated PHP Style: replaced str_pos with str_contains and str_ends_with

1.1.4 (2022-05-31)

  • Update build tool dependencies to fix CVE-2022-1537, CVE-2022-0436 and CVE-2020-7729

1.1.3 (2022-03-18)

  • Returns the post slug (post_name column) in the return value (thanks @mags1317)

1.1.2 (2021-06-27)

  • Fixed child page URL handling
  • Adds 'wpmlrestapi_get_translation' filter immediately before adding translation to array (thanks @elskwid)

1.1.1 (2021-01-10)

  • Fix: Refactored into a class and namesapce (thanks @szepeviktor)
  • Changed minimum required version to 5.2 (for PHP 7 support)

1.1 (2021-01-05)

  • Fix: properly renders URLs for pages that have parent parents (Thank you @rburgst)
  • Fix: Respect home and allow filtering of language url (Thank you ghost contributor)
  • Fix: Updated WPML filters/functions to replace deprecated ones.
  • Fix: No longer returns draft translations
  • Fix: When adding new posts - PHP Fatal error: Uncaught Error: Cannot use object of type WP_Error as array (Thanks @darenzammit!)

1.0.5

  • Allows language switching by specifying 'lang' or 'wpml_lang' parameters on the query string.
  • Typos in code fixed.

1.0

  • First release.

wpml-rest-api's People

Contributors

darenzammit avatar joperron avatar mags1317 avatar maximejobin avatar rburgst avatar shawnhooper avatar szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wpml-rest-api's Issues

nested pages still not handled correctly

Hey! Thank you for this wonderful extension. I've found you fix targeting the nested pages issue – but it's still not working on my side. What do I miss? Thanks for your help!

Plugin doesn't work on PHP 7.1.9

Hi Shawn,

Thank you for the great plugin. I have used before your plugin, but now I moved to newer PHP version, and I'm trying to figure out the problem why doesn't show the languages (wpml) on the json output.
Can you help me to figure out the problem I'm facing right now.

best regards
Riat

Non-Translated Posts referencing random other translated post

Hi, thanks for building this. Was trying this out to solve my issue about getting my post data via API where WPML doesn't expose post unless I use the lang parameter. Trying to get everything all at once rather than combining data sets.

What I'm seeing unfortunately is when there is not actually a translations for my post, it 'makes one up' it seems as shown below. The 3 posts below do not have translations but it wants to attach id: 5834 to each of them.

{
    "title": {
        "rendered": "How to heat a tent during winter camping?"
    },
    "wpml_current_locale": "en_US",
    "wpml_translations": {
        "es_ES": {
            "locale": "es_ES",
            "id": 5834,
            "slug": "butano-vs-propano-cual-es-el-mejor-combustible-para-una-estufa-de-camping",
            "post_title": "Butano vs Propano – ¿Cuál es el mejor combustible para una estufa de camping?",
            "href": "https://trucampers.com/es/butano-vs-propano-cual-es-el-mejor-combustible-para-una-estufa-de-camping/"
        }
    }
},
{
    "title": {
        "rendered": "How To Avoid Frostbite During Winter Camping?"
    },
    "wpml_current_locale": "en_US",
    "wpml_translations": {
        "es_ES": {
            "locale": "es_ES",
            "id": 5834,
            "slug": "butano-vs-propano-cual-es-el-mejor-combustible-para-una-estufa-de-camping",
            "post_title": "Butano vs Propano – ¿Cuál es el mejor combustible para una estufa de camping?",
            "href": "https://trucampers.com/es/butano-vs-propano-cual-es-el-mejor-combustible-para-una-estufa-de-camping/"
        }
    }
},
{
    "title": {
        "rendered": "How to keep water from freezing during winter camping?"
    },
    "wpml_current_locale": "en_US",
    "wpml_translations": {
        "es_ES": {
            "locale": "es_ES",
            "id": 5834,
            "slug": "butano-vs-propano-cual-es-el-mejor-combustible-para-una-estufa-de-camping",
            "post_title": "Butano vs Propano – ¿Cuál es el mejor combustible para una estufa de camping?",
            "href": "https://trucampers.com/es/butano-vs-propano-cual-es-el-mejor-combustible-para-una-estufa-de-camping/"
        }
    }
},

Plugin activation problem

Hi, I installed the plugin on WP but when I have to activate it, it gives a 500 error page. Could you help me?
Thanks
Andrea

Bug when using a different post base

Hi,

first of all, thank you so much for the work you put into this, this plugin really helped me when working with WP in a headless setup.

Unfortunately there is one issue, when the permalink structure is set to something other than %postname% (in my case news/%postname%). In that case the link returned by the plugin is incorrect (as if the setting was still %postname%).

Ideas for extending this: wp menus

Hey, thanks a lot for publishing this plugin, it helps a lot!

Now, I wonder what has to be done in order to extend the functionality to the wp-menus, so that they also link to the corresponding translation when accessed via /wp-json/wp-api-menus/v2/menus/[id] ?

Note: I'm using https://wordpress.org/plugins/wp-api-menus/ since as of today there's no way to get those menus using the built-in REST API in WP.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.