Plugin Directory


Ignore:
Timestamp:
10/25/2026 06:29:16 AM (39 hours ago)
Author:
avakodeforge
Message:

Release 1.3.0 (trunk + tag; see readme changelog)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • langforge/trunk/includes/class-rest-api.php

    r3732047 r3764005  
    111111        ];
    112112
     113        // BUG-LANG-GLOSS-02: the glossary terms a saved translation does not follow. Read-only and for the edit
     114        // context (the response of a save, the editor): a warning never refuses or changes a save.
     115        $glossary_field = [
     116            'get_callback' => [$this, 'get_post_glossary_warnings_field'],
     117            'schema' => [
     118                'description' => 'Warnings of the glossary check of a translation: the terms it does not follow',
     119                'type' => 'array',
     120                'items' => ['type' => 'string'],
     121                'context' => ['edit'],
     122                'readonly' => true,
     123            ],
     124        ];
     125
    113126        foreach ($post_types as $post_type) {
    114127            // Canonical prefixed REST fields.
    115128            register_rest_field($post_type, 'langforge_language', $language_field);
    116129            register_rest_field($post_type, 'langforge_translations', $translations_field);
     130            register_rest_field($post_type, 'langforge_glossary_warnings', $glossary_field);
    117131            // Deprecated lf_ aliases — kept so the block-editor sidebar and any
    118132            // existing headless client that reads/writes the old field names
    … …  
    340354    }
    341355
     356    /** @return string The glossary warnings of a translation, for who may edit it (LANGFORGE_Post_Translation::glossary_warnings). */
     357    public function get_post_glossary_warnings_field($post) {
     358        $post_id = $this->rest_object_id($post);
     359        if ($post_id <= 0 || !current_user_can('edit_post', $post_id)) {
     360            return [];
     361        }
     362        return LANGFORGE_Post_Translation::instance()->glossary_warnings($post_id);
     363    }
     364
    342365    public function update_post_language_field($value, $post) {
    343366        if (!current_user_can('edit_post', $post->ID)) {
    … …  
    364387        // asked about: current_user_can('read_post') for such a post is a _doing_it_wrong in
    365388        // map_meta_cap and judged by another capability. No type, no right to read.
     389        // A published translation is public, and a visitor who is not signed in has no capability
     390        // at all, `read` included: current_user_can('read_post') is false for him even for a
     391        // published post. So a published member is listed for everyone, the way core's own
     392        // WP_REST_Posts_Controller::check_read_permission lets a visitor read a published post;
     393        // a draft, a pending, a scheduled or a private member only for who may read it
     394        // (BUG-LANG-REST-01).
     395
     396        // And only a member of the type of the post asked about: a group links posts of one type
     397        // (the metabox and the link command refuse the rest), so a member of another type is a
     398        // migrated or hand-edited row, and its id is not handed out to anyone, with whatever status.
    366399        $pt      = LANGFORGE_Post_Translation::instance();
     400        $type    = get_post_type($post_id);
    367401        $visible = [];
    368402        foreach ($translations as $lang => $tid) {
    369             if ($pt->translation_type_is_registered((int) $tid) && current_user_can('read_post', (int) $tid)) {
     403            if (get_post_type((int) $tid) !== $type) {
     404                continue;
     405            }
     406            if (!$pt->translation_type_is_registered((int) $tid)) {
     407                continue;
     408            }
     409            if (current_user_can('read_post', (int) $tid) || get_post_status((int) $tid) === 'publish') {
    370410                $visible[$lang] = $tid;
    371411            }
Note: See TracChangeset for help on using the changeset viewer.