Making WordPress.org


Ignore:
Timestamp:
02/04/2018 02:34:02 PM (7 years ago)
Author:
ocean90
Message:

Translate, Plugin Directory: Update project status (active/inactive) on plugin status (publish/closed) changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php

    r6287 r6534  
    140140            case 'publish':
    141141                $this->clean_closed_date( $post->ID );
     142                $this->set_translation_status( $post, 'active' );
    142143                break;
    143144
     
    145146            case 'closed':
    146147                $this->save_close_reason( $post->ID );
     148                $this->set_translation_status( $post, 'inactive' );
    147149                break;
    148150        }
     
    150152        // Record the time a plugin was transitioned into a specific status.
    151153        update_post_meta( $post->ID, "_{$new_status}", strtotime( $post->post_modified_gmt ) );
     154    }
     155
     156    /**
     157     * Updates project status of the plugin on translate.wordpress.org.
     158     *
     159     * @param \WP_Post $post Post object.
     160     * @param string   $status Project status. Accepts 'active' or 'inactive'.
     161     */
     162    public function set_translation_status( $post, $status ) {
     163        if ( ! defined( 'TRANSLATE_API_INTERNAL_BEARER_TOKEN' ) ) {
     164            return;
     165        }
     166
     167        wp_remote_post( 'https://translate.wordpress.org/wp-json/translate/v1/jobs', array(
     168            'body'       => json_encode(
     169                array(
     170                    'timestamp'  => time() + 2 * 60,
     171                    'recurrence' => 'once',
     172                    'hook'       => 'wporg_translate_update_plugin_status',
     173                    'args'       => array(
     174                        array(
     175                            'plugin' => $post->post_name,
     176                            'status' => $status,
     177                        ),
     178                    ),
     179                )
     180            ),
     181            'headers'    => array(
     182                'Content-Type'  => 'application/json',
     183                'Authorization' => 'Bearer ' . TRANSLATE_API_INTERNAL_BEARER_TOKEN,
     184            ),
     185            'blocking'   => false,
     186            'user-agent' => 'WordPress.org Plugin Status',
     187        ) );
    152188    }
    153189
Note: See TracChangeset for help on using the changeset viewer.