Making WordPress.org


Ignore:
Timestamp:
12/19/2017 04:22:37 PM (6 years ago)
Author:
obenland
Message:

PLugins: Clean up formatting with phpcbf

File:
1 edited

Legend:

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

    r6217 r6287  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory;
     3
    34use WordPressdotorg\Plugin_Directory\Admin\Customizations;
    45use WordPressdotorg\Plugin_Directory\Admin\Tools\Author_Cards;
     
    5960
    6061        // Load the API routes.
    61         add_action( 'rest_api_init', array( __NAMESPACE__ . '\API\Base', 'load_routes' ) );
     62        add_action( 'rest_api_init', array( __NAMESPACE__ . '\API\Base', 'init' ) );
    6263
    6364        // Allow post_modified not to be modified when we don't specifically bump it.
     
    6566
    6667        // Work around caching issues
    67         add_filter( 'pre_option_jetpack_sync_full__started' , array( $this, 'bypass_options_cache' ), 10, 2 );
     68        add_filter( 'pre_option_jetpack_sync_full__started', array( $this, 'bypass_options_cache' ), 10, 2 );
    6869        add_filter( 'default_option_jetpack_sync_full__started', '__return_null' );
    69         add_filter( 'pre_option_jetpack_sync_full__params' , array( $this, 'bypass_options_cache' ), 10, 2 );
     70        add_filter( 'pre_option_jetpack_sync_full__params', array( $this, 'bypass_options_cache' ), 10, 2 );
    7071        add_filter( 'default_option_jetpack_sync_full__params', '__return_null' );
    71         add_filter( 'pre_option_jetpack_sync_full__queue_finished' , array( $this, 'bypass_options_cache' ), 10, 2 );
     72        add_filter( 'pre_option_jetpack_sync_full__queue_finished', array( $this, 'bypass_options_cache' ), 10, 2 );
    7273        add_filter( 'default_option_jetpack_sync_full__queue_finished', '__return_null' );
    73         add_filter( 'pre_option_jetpack_sync_full__send_started' , array( $this, 'bypass_options_cache' ), 10, 2 );
     74        add_filter( 'pre_option_jetpack_sync_full__send_started', array( $this, 'bypass_options_cache' ), 10, 2 );
    7475        add_filter( 'default_option_jetpack_sync_full__send_started', '__return_null' );
    75         add_filter( 'pre_option_jetpack_sync_full__finished' , array( $this, 'bypass_options_cache' ), 10, 2 );
     76        add_filter( 'pre_option_jetpack_sync_full__finished', array( $this, 'bypass_options_cache' ), 10, 2 );
    7677        add_filter( 'default_option_jetpack_sync_full__finished', '__return_null' );
    7778
     
    8889            Stats_Report::instance();
    8990
    90             add_action( 'wp_insert_post_data',    array( __NAMESPACE__ . '\Admin\Status_Transitions', 'can_change_post_status' ), 10, 2 );
     91            add_action( 'wp_insert_post_data', array( __NAMESPACE__ . '\Admin\Status_Transitions', 'can_change_post_status' ), 10, 2 );
    9192            add_action( 'transition_post_status', array( __NAMESPACE__ . '\Admin\Status_Transitions', 'instance' ) );
    9293        }
     
    124125        register_post_type( 'plugin', array(
    125126            'labels'       => array(
    126                 'name'               => __( 'Repo Plugins',              'wporg-plugins' ),
    127                 'singular_name'      => __( 'Repo Plugin',               'wporg-plugins' ),
    128                 'menu_name'          => __( 'Repo Plugins',              'wporg-plugins' ),
    129                 'add_new'            => __( 'Add New',                   'wporg-plugins' ),
    130                 'add_new_item'       => __( 'Add New Plugin',            'wporg-plugins' ),
    131                 'new_item'           => __( 'New Plugin',                'wporg-plugins' ),
    132                 'view_item'          => __( 'View Plugin',               'wporg-plugins' ),
    133                 'search_items'       => __( 'Search Plugins',            'wporg-plugins' ),
    134                 'not_found'          => __( 'No plugins found',          'wporg-plugins' ),
     127                'name'               => __( 'Repo Plugins', 'wporg-plugins' ),
     128                'singular_name'      => __( 'Repo Plugin', 'wporg-plugins' ),
     129                'menu_name'          => __( 'Repo Plugins', 'wporg-plugins' ),
     130                'add_new'            => __( 'Add New', 'wporg-plugins' ),
     131                'add_new_item'       => __( 'Add New Plugin', 'wporg-plugins' ),
     132                'new_item'           => __( 'New Plugin', 'wporg-plugins' ),
     133                'view_item'          => __( 'View Plugin', 'wporg-plugins' ),
     134                'search_items'       => __( 'Search Plugins', 'wporg-plugins' ),
     135                'not_found'          => __( 'No plugins found', 'wporg-plugins' ),
    135136                'not_found_in_trash' => __( 'No plugins found in Trash', 'wporg-plugins' ),
    136137
     
    138139                'edit_item'          => is_admin() ? __( 'Editing Plugin: %s', 'wporg-plugins' ) : __( 'Edit Plugin', 'wporg-plugins' ),
    139140            ),
    140             'description'     => __( 'A Repo Plugin', 'wporg-plugins' ),
    141             'supports'        => array( 'comments', 'author', 'custom-fields' ),
    142             'public'          => true,
    143             'show_ui'         => true,
    144             'show_in_rest'    => true,
    145             'has_archive'     => true,
    146             'rewrite'         => false,
    147             'menu_icon'       => 'dashicons-admin-plugins',
    148             'capabilities'    => array(
     141            'description'  => __( 'A Repo Plugin', 'wporg-plugins' ),
     142            'supports'     => array( 'comments', 'author', 'custom-fields' ),
     143            'public'       => true,
     144            'show_ui'      => true,
     145            'show_in_rest' => true,
     146            'has_archive'  => true,
     147            'rewrite'      => false,
     148            'menu_icon'    => 'dashicons-admin-plugins',
     149            'capabilities' => array(
    149150                'edit_post'          => 'plugin_edit',
    150151                'read_post'          => 'read',
     
    184185            'labels'            => array(
    185186                'name'          => __( 'Plugin Categories', 'wporg-plugins' ),
    186                 'singular_name' => __( 'Plugin Category',   'wporg-plugins' ),
    187                 'edit_item'     => __( 'Edit Category',     'wporg-plugins' ),
    188                 'update_item'   => __( 'Update Category',   'wporg-plugins' ),
    189                 'add_new_item'  => __( 'Add New Category',  'wporg-plugins' ),
     187                'singular_name' => __( 'Plugin Category', 'wporg-plugins' ),
     188                'edit_item'     => __( 'Edit Category', 'wporg-plugins' ),
     189                'update_item'   => __( 'Update Category', 'wporg-plugins' ),
     190                'add_new_item'  => __( 'Add New Category', 'wporg-plugins' ),
    190191                'new_item_name' => __( 'New Category Name', 'wporg-plugins' ),
    191192                'search_items'  => __( 'Search Categories', 'wporg-plugins' ),
     
    237238            'rewrite'           => false,
    238239            'labels'            => array(
    239                 'name' => __( 'Contributors', 'wporg-plugins' ),
     240                'name'          => __( 'Contributors', 'wporg-plugins' ),
    240241                'singular_name' => __( 'Contributor', 'wporg-plugins' ),
    241242            ),
     
    253254            'rewrite'           => false,
    254255            'labels'            => array(
    255                 'name' => __( 'Committers', 'wporg-plugins' ),
     256                'name'          => __( 'Committers', 'wporg-plugins' ),
    256257                'singular_name' => __( 'Committer', 'wporg-plugins' ),
    257258            ),
     
    269270            'rewrite'           => false,
    270271            'labels'            => array(
    271                 'name' => __( 'Support Reps', 'wporg-plugins' ),
     272                'name'          => __( 'Support Reps', 'wporg-plugins' ),
    272273                'singular_name' => __( 'Support Rep', 'wporg-plugins' ),
    273274            ),
     
    291292            'labels'            => array(
    292293                'name'          => __( 'Plugin Tags', 'wporg-plugins' ),
    293                 'singular_name' => __( 'Plugin Tag',   'wporg-plugins' ),
    294                 'edit_item'     => __( 'Edit Tag',     'wporg-plugins' ),
    295                 'update_item'   => __( 'Update Tag',   'wporg-plugins' ),
    296                 'add_new_item'  => __( 'Add New Tag',  'wporg-plugins' ),
     294                'singular_name' => __( 'Plugin Tag', 'wporg-plugins' ),
     295                'edit_item'     => __( 'Edit Tag', 'wporg-plugins' ),
     296                'update_item'   => __( 'Update Tag', 'wporg-plugins' ),
     297                'add_new_item'  => __( 'Add New Tag', 'wporg-plugins' ),
    297298                'new_item_name' => __( 'New Tag Name', 'wporg-plugins' ),
    298299                'search_items'  => __( 'Search Tags', 'wporg-plugins' ),
     
    352353
    353354        register_meta( 'post', 'rating', array(
    354             'type'              => 'number',
    355             'description'       => __( 'Overall rating of the plugin.', 'wporg-plugins' ),
    356             'single'            => true,
     355            'type'         => 'number',
     356            'description'  => __( 'Overall rating of the plugin.', 'wporg-plugins' ),
     357            'single'       => true,
    357358            // todo 'sanitize_callback' => 'absint',
    358             'show_in_rest'      => true,
     359            'show_in_rest' => true,
    359360        ) );
    360361
     
    376377
    377378        register_meta( 'post', 'tested', array(
    378             'description'       => __( 'The version of WordPress the plugin was tested with.', 'wporg-plugins' ),
    379             'single'            => true,
     379            'description'  => __( 'The version of WordPress the plugin was tested with.', 'wporg-plugins' ),
     380            'single'       => true,
    380381            // TODO 'sanitize_callback' => 'absint',
    381             'show_in_rest'      => true,
     382            'show_in_rest' => true,
    382383        ) );
    383384
    384385        register_meta( 'post', 'requires', array(
    385             'description'       => __( 'The minimum version of WordPress the plugin needs to run.', 'wporg-plugins' ),
    386             'single'            => true,
     386            'description'  => __( 'The minimum version of WordPress the plugin needs to run.', 'wporg-plugins' ),
     387            'single'       => true,
    387388            // TODO 'sanitize_callback' => 'absint',
    388             'show_in_rest'      => true,
     389            'show_in_rest' => true,
    389390        ) );
    390391
    391392        register_meta( 'post', 'requires_php', array(
    392             'description'       => __( 'The minimum version of PHP the plugin needs to run.', 'wporg-plugins' ),
    393             'single'            => true,
     393            'description'  => __( 'The minimum version of PHP the plugin needs to run.', 'wporg-plugins' ),
     394            'single'       => true,
    394395            // TODO 'sanitize_callback' => 'absint',
    395             'show_in_rest'      => true,
     396            'show_in_rest' => true,
    396397        ) );
    397398
    398399        register_meta( 'post', 'stable_tag', array(
    399             'description'       => __( 'Stable version of the plugin.', 'wporg-plugins' ),
    400             'single'            => true,
     400            'description'  => __( 'Stable version of the plugin.', 'wporg-plugins' ),
     401            'single'       => true,
    401402            // TODO 'sanitize_callback' => 'absint',
    402             'show_in_rest'      => true,
     403            'show_in_rest' => true,
    403404        ) );
    404405
     
    411412
    412413        register_meta( 'post', 'version', array(
    413             'description'       => __( 'Current stable version.', 'wporg-plugins' ),
    414             'single'            => true,
     414            'description'  => __( 'Current stable version.', 'wporg-plugins' ),
     415            'single'       => true,
    415416            // TODO 'sanitize_callback' => 'esc_url_raw',
    416             'show_in_rest'      => true,
     417            'show_in_rest' => true,
    417418        ) );
    418419
    419420        register_meta( 'post', 'header_name', array(
    420             'description'       => __( 'Name of the plugin.', 'wporg-plugins' ),
    421             'single'            => true,
     421            'description'  => __( 'Name of the plugin.', 'wporg-plugins' ),
     422            'single'       => true,
    422423            // TODO 'sanitize_callback' => 'esc_url_raw',
    423             'show_in_rest'      => true,
     424            'show_in_rest' => true,
    424425        ) );
    425426
     
    432433
    433434        register_meta( 'post', 'header_name', array(
    434             'description'       => __( 'Name of the plugin.', 'wporg-plugins' ),
    435             'single'            => true,
     435            'description'  => __( 'Name of the plugin.', 'wporg-plugins' ),
     436            'single'       => true,
    436437            // TODO 'sanitize_callback' => 'esc_url_raw',
    437             'show_in_rest'      => true,
     438            'show_in_rest' => true,
    438439        ) );
    439440
    440441        register_meta( 'post', 'header_author', array(
    441             'description'       => __( 'Name of the plugin author.', 'wporg-plugins' ),
    442             'single'            => true,
     442            'description'  => __( 'Name of the plugin author.', 'wporg-plugins' ),
     443            'single'       => true,
    443444            // TODO 'sanitize_callback' => 'esc_url_raw',
    444             'show_in_rest'      => true,
     445            'show_in_rest' => true,
    445446        ) );
    446447
     
    453454
    454455        register_meta( 'post', 'header_description', array(
    455             'description'       => __( 'Description of the plugin.', 'wporg-plugins' ),
    456             'single'            => true,
     456            'description'  => __( 'Description of the plugin.', 'wporg-plugins' ),
     457            'single'       => true,
    457458            // TODO 'sanitize_callback' => 'esc_url_raw',
    458             'show_in_rest'      => true,
     459            'show_in_rest' => true,
    459460        ) );
    460461
    461462        register_meta( 'post', 'assets_icons', array(
    462             'type'              => 'array',
    463             'description'       => __( 'Icon images of the plugin.', 'wporg-plugins' ),
    464             'single'            => true,
     463            'type'         => 'array',
     464            'description'  => __( 'Icon images of the plugin.', 'wporg-plugins' ),
     465            'single'       => true,
    465466            // TODO 'sanitize_callback' => 'esc_url_raw',
    466             'show_in_rest'      => true,
     467            'show_in_rest' => true,
    467468        ) );
    468469
    469470        register_meta( 'post', 'assets_banners_color', array(
    470             'description'       => __( 'Fallback color for the plugin.', 'wporg-plugins' ),
    471             'single'            => true,
     471            'description'  => __( 'Fallback color for the plugin.', 'wporg-plugins' ),
     472            'single'       => true,
    472473            // TODO 'sanitize_callback' => 'esc_url_raw',
    473             'show_in_rest'      => true,
     474            'show_in_rest' => true,
    474475        ) );
    475476
     
    510511
    511512        // If changing capabilities around, uncomment this.
    512         //Capabilities::add_roles();
     513        // Capabilities::add_roles();
    513514
    514515        // Remove the /admin$ redirect to wp-admin
     
    523524        if ( class_exists( 'Jetpack' ) && \Jetpack::get_option( 'id' ) && ! class_exists( 'Jetpack_Search' )
    524525            && ! isset( $_GET['s'] ) ) { // Don't run the ES query if we're going to redirect to the pretty search URL
    525                 require_once( __DIR__ . '/libs/site-search/jetpack-search.php' );
     526                require_once __DIR__ . '/libs/site-search/jetpack-search.php';
    526527                \Jetpack_Search::instance();
    527528        }
     
    532533     */
    533534    public function register_shortcodes() {
    534         add_shortcode( 'wporg-plugins-developers',  array( __NAMESPACE__ . '\Shortcodes\Developers', 'display' ) );
    535         add_shortcode( 'wporg-plugin-upload',       array( __NAMESPACE__ . '\Shortcodes\Upload',      'display' ) );
     535        add_shortcode( 'wporg-plugins-developers', array( __NAMESPACE__ . '\Shortcodes\Developers', 'display' ) );
     536        add_shortcode( 'wporg-plugin-upload', array( __NAMESPACE__ . '\Shortcodes\Upload', 'display' ) );
    536537        add_shortcode( 'wporg-plugins-screenshots', array( __NAMESPACE__ . '\Shortcodes\Screenshots', 'display' ) );
    537         add_shortcode( 'wporg-plugins-reviews',     array( __NAMESPACE__ . '\Shortcodes\Reviews',    'display' ) );
    538         add_shortcode( 'readme-validator',          array( __NAMESPACE__ . '\Shortcodes\Readme_Validator',    'display' ) );
     538        add_shortcode( 'wporg-plugins-reviews', array( __NAMESPACE__ . '\Shortcodes\Reviews', 'display' ) );
     539        add_shortcode( 'readme-validator', array( __NAMESPACE__ . '\Shortcodes\Readme_Validator', 'display' ) );
    539540    }
    540541
     
    552553            'wporg-plugins-screenshots',
    553554            'wporg-plugins-reviews',
    554             'readme-validator'
     555            'readme-validator',
    555556        );
    556557
     
    568569     */
    569570    public function register_widgets() {
    570         register_widget( __NAMESPACE__ . '\Widgets\Donate'        );
    571         register_widget( __NAMESPACE__ . '\Widgets\Meta'          );
    572         register_widget( __NAMESPACE__ . '\Widgets\Ratings'       );
    573         register_widget( __NAMESPACE__ . '\Widgets\Support'       );
    574         register_widget( __NAMESPACE__ . '\Widgets\Committers'    );
    575         register_widget( __NAMESPACE__ . '\Widgets\Contributors'  );
    576         register_widget( __NAMESPACE__ . '\Widgets\Support_Reps'  );
     571        register_widget( __NAMESPACE__ . '\Widgets\Donate' );
     572        register_widget( __NAMESPACE__ . '\Widgets\Meta' );
     573        register_widget( __NAMESPACE__ . '\Widgets\Ratings' );
     574        register_widget( __NAMESPACE__ . '\Widgets\Support' );
     575        register_widget( __NAMESPACE__ . '\Widgets\Committers' );
     576        register_widget( __NAMESPACE__ . '\Widgets\Contributors' );
     577        register_widget( __NAMESPACE__ . '\Widgets\Support_Reps' );
    577578    }
    578579
     
    669670    /**
    670671     * Filter content to make links rel=nofollow on plugin pages only
    671      * @param string    $content    The content.
     672     *
     673     * @param string $content    The content.
    672674     * @return string
    673675     */
     
    675677        if ( get_post_type() == 'plugin' ) {
    676678            // regex copied from wp_rel_nofollow(). Not calling that function because it messes with slashes.
    677             $content = preg_replace_callback('|<a (.+?)>|i', 'wp_rel_nofollow_callback', $content);
     679            $content = preg_replace_callback( '|<a (.+?)>|i', 'wp_rel_nofollow_callback', $content );
    678680        }
    679681        return $content;
     
    706708                $wp_query->query_vars['order']    = 'DESC';
    707709                break;
     710
    708711            case 'favorites':
    709712                $favorites_user = wp_get_current_user();
     
    723726
    724727                    $wp_query->query_vars['orderby'] = 'post_title';
    725                     $wp_query->query_vars['order'] = 'ASC';
     728                    $wp_query->query_vars['order']   = 'ASC';
    726729                }
    727730
     
    766769                array(
    767770                    'taxonomy' => 'plugin_contributors',
    768                     'field' => 'slug',
    769                     'terms' => $user
    770                 )
     771                    'field'    => 'slug',
     772                    'terms'    => $user,
     773                ),
    771774            );
    772775
     
    776779                $wp_query->query_vars['tax_query'][] = array(
    777780                    'taxonomy' => 'plugin_committers',
    778                     'field' => 'slug',
    779                     'terms' => $user
     781                    'field'    => 'slug',
     782                    'terms'    => $user,
    780783                );
    781784            }
    782785
    783786            $wp_query->query_vars['orderby'] = 'post_title';
    784             $wp_query->query_vars['order'] = 'ASC';
     787            $wp_query->query_vars['order']   = 'ASC';
    785788
    786789            // Treat it as a taxonomy query now, not the author archive.
    787790            $wp_query->is_author = false;
    788             $wp_query->is_tax = true;
     791            $wp_query->is_tax    = true;
    789792
    790793            unset( $wp_query->query_vars['author_name'], $wp_query->query_vars['author'] );
     
    796799            $wp_query->query_vars['post_status'] = array( 'approved', 'publish', 'closed', 'disabled' );
    797800
    798             add_filter( 'posts_results', function( $posts, $this_wp_query ) use( $wp_query ) {
     801            add_filter( 'posts_results', function( $posts, $this_wp_query ) use ( $wp_query ) {
    799802                if ( $this_wp_query != $wp_query ) {
    800803                    return $posts;
     
    825828        // Allow anyone to view a closed plugin directly from its page. It won't show in search results or lists.
    826829        if ( $wp_query->is_main_query() && ! empty( $wp_query->query_vars['name'] ) ) {
    827             $wp_query->query_vars['post_status'] = (array) $wp_query->query_vars['post_status'];
     830            $wp_query->query_vars['post_status']   = (array) $wp_query->query_vars['post_status'];
    828831            $wp_query->query_vars['post_status'][] = 'closed';
    829832            $wp_query->query_vars['post_status'][] = 'disabled';
    830             $wp_query->query_vars['post_status'] = array_unique( $wp_query->query_vars['post_status'] );
     833            $wp_query->query_vars['post_status']   = array_unique( $wp_query->query_vars['post_status'] );
    831834        }
    832835
     
    856859    public function bypass_options_cache( $value, $option ) {
    857860        global $wpdb;
    858         $value = $wpdb->get_var(
    859             $wpdb->prepare(
    860                 "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1",
    861                 $option
    862             )
    863         );
     861        $value = $wpdb->get_var( $wpdb->prepare(
     862            "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1",
     863            $option
     864        ) );
    864865        $value = maybe_unserialize( $value );
    865866
     
    874875    public function fix_login_url( $login_url, $redirect, $force_reauth ) {
    875876        // modify the redirect_to for the support forums to point to the current page
    876         if ( 0 === strpos($_SERVER['REQUEST_URI'], '/plugins' ) ) {
     877        if ( 0 === strpos( $_SERVER['REQUEST_URI'], '/plugins' ) ) {
    877878            // Note that this is not normal because of the code in /mu-plugins/wporg-sso/class-wporg-sso.php.
    878879            // The login_url function there expects the redirect_to as the first parameter passed into it instead of the second
     
    884885            // parse_url is used here to remove any additional query args from the REQUEST_URI before redirection
    885886            // The SSO code handles the urlencoding of the redirect_to parameter
    886             $url_parts = parse_url('https://wordpress.org'.$_SERVER['REQUEST_URI']);
    887             $constructed_url = $url_parts['scheme'] . '://' . $url_parts['host'] . (isset($url_parts['path'])?$url_parts['path']:'');
    888             $login_url = $constructed_url;
     887            $url_parts       = parse_url( 'https://wordpress.org' . $_SERVER['REQUEST_URI'] );
     888            $constructed_url = $url_parts['scheme'] . '://' . $url_parts['host'] . ( isset( $url_parts['path'] ) ? $url_parts['path'] : '' );
     889            $login_url       = $constructed_url;
    889890        }
    890891        return $login_url;
     
    940941     * @global string $locale Current locale.
    941942     *
    942      * @param int   $post_id    Post ID to update.
    943      * @param int   $min_translated Translations below this % threshold will not be synced to meta, to save space.
     943     * @param int $post_id    Post ID to update.
     944     * @param int $min_translated Translations below this % threshold will not be synced to meta, to save space.
    944945     * @return array
    945946     */
    946     public function sync_all_translations_to_meta( $post_id, $min_translated = 40, $skip_pfx = array('en_') ) {
     947    public function sync_all_translations_to_meta( $post_id, $min_translated = 40, $skip_pfx = array( 'en_' ) ) {
    947948
    948949        $locales_to_sync = array();
    949         $post = get_post( $post_id );
     950        $post            = get_post( $post_id );
    950951        if ( $post ) {
    951952            $translations = Plugin_I18n::instance()->find_all_translations_for_plugin( $post->post_name, 'stable-readme', $min_translated ); // at least $min_translated % translated
     
    953954                // Eliminate translations that start with unwanted prefixes, so we don't waste space on near-duplicates like en_AU, en_CA etc.
    954955                foreach ( $translations as $i => $_locale ) {
    955                     foreach ( $skip_pfx as $pfx )
    956                         if ( substr( $_locale, 0, strlen( $pfx ) ) === $pfx )
     956                    foreach ( $skip_pfx as $pfx ) {
     957                        if ( substr( $_locale, 0, strlen( $pfx ) ) === $pfx ) {
    957958                            unset( $translations[ $i ] );
     959                        }
     960                    }
    958961                }
    959962                $locales_to_sync = array_unique( $translations );
     
    961964        }
    962965
    963         if ( count($locales_to_sync) > 0 ) {
     966        if ( count( $locales_to_sync ) > 0 ) {
    964967            foreach ( $locales_to_sync as $locale ) {
    965968                $this->sync_translation_to_meta( $post_id, $locale );
     
    975978     * @global string $locale Current locale.
    976979     *
    977      * @param int   $post_id    Post ID to update.
    978      * @param string   $locale  Locale to translate.
     980     * @param int    $post_id    Post ID to update.
     981     * @param string $locale  Locale to translate.
    979982     */
    980983    public function sync_translation_to_meta( $post_id, $_locale ) {
     
    983986        $old_locale = $locale;
    984987        // Keep track of the original untranslated strings
    985         $orig_title = get_the_title( $post_id );
     988        $orig_title   = get_the_title( $post_id );
    986989        $orig_excerpt = get_the_excerpt( $post_id );
    987990        $orig_content = get_post_field( 'post_content', $post_id );
    988         $locale = $_locale;
     991        $locale       = $_locale;
    989992
    990993        // Update postmeta values for the translated title, excerpt, and content, if they are available and different from the originals.
    991994        // There is a bug here, in that no attempt is made to remove old meta values for translations that do not have new translations.
    992 
    993995        $the_title = Plugin_I18n::instance()->translate( 'title', $orig_title, [ 'post_id' => $post_id ] );
    994996        if ( $the_title && $the_title != $orig_title ) {
     
    10031005        // Split up the content to translate it in sections.
    10041006        $the_content = array();
    1005         $sections = $this->split_post_content_into_pages( $orig_content );
     1007        $sections    = $this->split_post_content_into_pages( $orig_content );
    10061008        foreach ( $sections as $section => $section_content ) {
    10071009            $translated_section = $this->translate_post_content( $section_content, $section, $post_id );
     
    10121014        }
    10131015
    1014         if ( !empty( $the_content ) ) {
     1016        if ( ! empty( $the_content ) ) {
    10151017            update_post_meta( $post_id, 'content_' . $locale, implode( $the_content ) );
    10161018        }
     
    11091111
    11101112            if ( 'tags' === $path[2] ) {
    1111                 if ( isset( $path[3] ) && !empty( $path[3] ) ) {
     1113                if ( isset( $path[3] ) && ! empty( $path[3] ) ) {
    11121114                    wp_safe_redirect( home_url( '/search/' . urlencode( $path[3] ) . '/' ) );
    11131115                    die();
     
    11451147            }
    11461148
    1147             //Otherwise, let's redirect to the search page
    1148             if ( isset( $path[2] ) && !empty( $path[2] ) ) {
     1149            // Otherwise, let's redirect to the search page
     1150            if ( isset( $path[2] ) && ! empty( $path[2] ) ) {
    11491151                wp_safe_redirect( home_url( '/search/' . urlencode( $path[2] ) . '/' ) );
    11501152                die();
     
    12051207     */
    12061208    public function split_post_content_into_pages( $content ) {
    1207         $_pages        = preg_split( "#<!--section=(.+?)-->#", $content, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
     1209        $_pages        = preg_split( '#<!--section=(.+?)-->#', $content, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
    12081210        $content_pages = array(
    12091211            'screenshots' => '[wporg-plugins-screenshots]',
     
    13181320    public static function create_plugin_post( array $args ) {
    13191321        $title = $args['post_title'] ?: $args['post_name'];
    1320         $slug  = $args['post_name']  ?: sanitize_title( $title );
     1322        $slug  = $args['post_name'] ?: sanitize_title( $title );
    13211323
    13221324        $args = wp_parse_args( $args, array(
Note: See TracChangeset for help on using the changeset viewer.