Making WordPress.org

Changeset 1844


Ignore:
Timestamp:
08/24/2015 07:59:04 AM (9 years ago)
Author:
dd32
Message:

Themes Directory: When a theme is suspended, or it reaches 2 years old, mark the translate.wordpress.org project as inactive.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r1840 r1844  
    791791
    792792/**
     793 * Hooks into the Suspend process to mark a theme as inactive in GlotPress.
     794 *
     795 * @param int  $post_id The post ID being suspended
     796 */
     797function wporg_themes_glotpress_mark_as_inactive_on_suspend( $post_id ) {
     798    $post = get_post( $post_id );
     799    if ( ! $post || 'repopackage' != $post->post_type ) {
     800        return;
     801    }
     802
     803    wporg_themes_glotpress_import( $post, 'inactve' );
     804}
     805add_action( 'suspend_repopackage', 'wporg_themes_glotpress_mark_as_inactive_on_suspend' );
     806
     807/**
    793808 * Import theme strings to GlotPress on approval.
    794809 *
    795810 * @param WP_Post|int $theme_post The WP_Post (or post_id) representing the theme.
    796  * @param string      $version    The version of the theme to import.
     811 * @param string      $version    The version of the theme to import, or 'inactive' to mark the translation project inactive.
    797812 */
    798813function wporg_themes_glotpress_import( $theme_post, $version ) {
     
    809824add_action( 'wporg_themes_update_version_live', 'wporg_themes_glotpress_import', 100, 2 );
    810825
     826/**
     827 * A Daily cron task to mark any themes which are now older than 2 years inactive in GlotPress.
     828 */
     829function wporg_themes_check_for_old_themes() {
     830    $too_old = strtotime( '-2 years' );
     831
     832    $query = new WP_Query( array(
     833        'post_type' => 'repopackage',
     834        'post_status' => 'publish',
     835        'date_query' => array(
     836            'column' => 'post_modified',
     837            'before' => date( 'Y-m-d 00:00:00', $too_old ),
     838            'after' => date( 'Y-m-d 00:00:00', $too_old - DAY_IN_SECONDS ),
     839            'inclusive' => true
     840        )
     841    ) );
     842    $posts = $query->get_posts();
     843
     844    foreach ( $posts as $post ) {
     845        wporg_themes_glotpress_import( $post, 'inactive' );
     846    }   
     847}
     848add_action( 'wporg_themes_check_for_old_themes', 'wporg_themes_check_for_old_themes' );
     849
     850/**
     851 * Sets up the daily cron tasks for the Themes Directory
     852 */
     853function wporg_themes_maybe_schedule_daily_job() {
     854    if ( ! wp_next_scheduled( 'wporg_themes_check_for_old_themes' ) ) {
     855        wp_schedule_event( time(), 'daily', 'wporg_themes_check_for_old_themes' );
     856    }
     857}
     858add_action( 'admin_init', 'wporg_themes_maybe_schedule_daily_job' );
Note: See TracChangeset for help on using the changeset viewer.