Making WordPress.org

Changeset 4259


Ignore:
Timestamp:
10/19/2016 02:27:58 AM (10 years ago)
Author:
tellyworth
Message:

Add readme-validator shortcode class, and tweak the Validator class a little to work on the front-end as well.

Fixes #2128

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
1 added
2 edited

Legend:

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

    r4224 r4259  
    336336                add_shortcode( 'wporg-plugins-screenshots', array( __NAMESPACE__ . '\Shortcodes\Screenshots', 'display' ) );
    337337                add_shortcode( 'wporg-plugins-reviews',     array( __NAMESPACE__ . '\Shortcodes\Reviews',     'display' ) );
     338                add_shortcode( 'readme-validator',          array( __NAMESPACE__ . '\Shortcodes\Readme_Validator',     'display' ) );
    338339        }
    339340
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php

    r4223 r4259  
    7272
    7373                $readme    = '';
    74                 $temp_file = Filesystem::temp_directory() . '/readme.txt';
    75                 $warnings  = array();
    76                 $notes     = array();
    7774
    7875                if ( ! empty( $_REQUEST['readme_url'] ) ) {
    … …  
    9895                }
    9996
     97                return $this->validate_content( $readme );
     98        }
     99
     100        /**
     101         * Validates content via a string paramater and adds feedback.
     102         */
     103        public function validate_content( $readme ) {
     104
     105                $temp_file = Filesystem::temp_directory() . '/readme.txt';
     106                $errors    = array();
     107                $warnings  = array();
     108                $notes     = array();
     109
    100110                file_put_contents( $temp_file, $readme );
    101111                $readme = new Parser( $temp_file );
    … …  
    105115                        /* Translators: Plugin header tag; */
    106116                        add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( "Fatal Error:\nNo plugin name detected. Plugin names look like: %s", 'wporg-plugins' ), '<code>=== Plugin Name ===</code>' ) );
    107                         return;
     117                        $errors[] = array( 'error', sprintf( __( "Fatal Error:\nNo plugin name detected.    Plugin names look like: %s", 'wporg-plugins' ), '<code>=== Plugin Name ===</code>' ) );
     118                        return $errors;
    108119                }
    109120
    … …  
    133144                        $message .= "</ul>\n</div>";
    134145
    135                         add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-warning' );
    136                         return;
     146                        if ( function_exists( 'add_settings_error' ) ) {
     147                                add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-warning' );
     148                        }
     149                        return $message;
    137150                }
    138151
    … …  
    165178                        $message .= "</ul>\n</div>";
    166179
    167                         add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-info' );
    168                         return;
     180                        if ( function_exists( 'add_settings_error' ) ) {
     181                                add_settings_error( 'wporg-plugins-readme', 'readme-validator', $message, 'notice-info' );
     182                        }
     183                        return $message;
    169184                }
    170185
    171186                /* Translators: File name; */
    172                 add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( 'Your %s rocks.  Seriously.  Flying colors.', 'wporg-plugins' ), '<code>readme.txt</code>' ), 'updated' );
    173         }
     187                if ( function_exists( 'add_settings_error' ) ) {
     188                        add_settings_error( 'wporg-plugins-readme', 'readme-validator', sprintf( __( 'Your %s rocks.  Seriously.  Flying colors.', 'wporg-plugins' ), '<code>readme.txt</code>' ), 'updated' );
     189                }
     190        }
     191
    174192
    175193        /**
Note: See TracChangeset for help on using the changeset viewer.