Making WordPress.org


Ignore:
Timestamp:
02/25/2016 05:03:19 AM (11 years ago)
Author:
dd32
Message:

Plugin Directory: Switch to using namespaces instead of implemeting them through classnames.
This change introduces an autoloader and relies upon it for most file inclusions, this should encourage us to keep a standard naming schema and writing more component classes going forward.
See #1584

File:
1 moved

Legend:

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

    r2561 r2611  
    11<?php
     2namespace WordPressdotorg\Plugin_Directory;
     3
    24/**
    3  * @package WPorg_Plugin_Directory
     5 * The main Plugin Directory class, it handles most of the bootstrap and basic operations of the plugin.
     6 *
     7 * @package WordPressdotorg_Plugin_Directory
    48 */
    5 
    6 /**
    7  * Class WPorg_Plugin_Directory
    8  */
    9 class WPorg_Plugin_Directory {
    10 
    11         /**
    12          * Constructor.
    13          */
    14         public function __construct() {
     9class Plugin_Directory {
     10
     11        /**
     12         * Fetch the instance of the Plugin_Directory class.
     13         */
     14        public static function instance( $plugin_file = null ) {
     15                static $instance = null;
     16                return ! is_null( $instance ) ? $instance : $instance = new Plugin_Directory( $plugin_file );
     17        }
     18
     19        private function __construct( $plugin_file ) {
    1520                add_action( 'init', array( $this, 'init' ) );
     21                add_action( 'init', array( $this, 'register_shortcodes' ) );
    1622                add_filter( 'post_type_link', array( $this, 'package_link' ), 10, 2 );
    1723                add_filter( 'pre_insert_term', array( $this, 'pre_insert_term_prevent' ) );
    1824                add_action( 'pre_get_posts', array( $this, 'use_plugins_in_query' ) );
    1925                add_filter( 'the_content', array( $this, 'filter_post_content_to_correct_page' ), 1 );
    20         }
    21 
    22         /**
    23          * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
    24          */
    25         public function activate() {
    26                 global $wp_rewrite;
    27 
    28                 // Setup the environment.
    29                 $this->init();
    30 
    31                 // %postname% is required.
    32                 $wp_rewrite->set_permalink_structure( '/%postname%/' );
    33 
    34                 // /tags/%slug% is required for tags.
    35                 $wp_rewrite->set_tag_base( '/tags' );
    36 
    37                 // We require the WordPress.org Ratings plugin also be active.
    38                 if ( ! is_plugin_active( 'wporg-ratings/wporg-ratings.php' ) ) {
    39                         activate_plugin( 'wporg-ratings/wporg-ratings.php' );
    40                 }
    41 
    42                 // Enable the WordPress.org Plugin Repo Theme.
    43                 foreach ( wp_get_themes() as $theme ) {
    44                         if ( $theme->get( 'Name' ) === 'WordPress.org Plugins' ) {
    45                                 switch_theme( $theme->get_stylesheet() );
    46                                 break;
    47                         }
    48                 }
    49 
    50                 flush_rewrite_rules();
    51 
    52                 do_action( 'wporg_plugins_activation' );
    53         }
    54 
    55         /**
    56          *
    57          */
    58         public function deactivate() {
    59                 flush_rewrite_rules();
    60 
    61                 do_action( 'wporg_plugins_deactivation' );
     26
     27                // Load all Admin-specific items
     28                add_action( 'admin_init', array( __NAMESPACE__ . '\\Admin\\Admin_Customizations', 'instance' ) );
     29
     30                register_activation_hook( $plugin_file, array( $this, 'activate' ) );
     31                register_deactivation_hook( $plugin_file, array( $this, 'deactivate' ) );
    6232        }
    6333
    … …  
    130100
    131101        /**
     102         * Register the Shortcodes used within the content.
     103         */
     104        public function register_shortcodes() {
     105                add_shortcode( 'wporg-plugins-screenshots', array( __NAMESPACE__ . '\\Shortcodes\\Screenshots', 'display' ) );
     106        //      add_shortcode( 'wporg-plugins-stats',       array( __NAMESPACE__ . '\\Shortcodes\\Stats',       'display' ) );
     107        //      add_shortcode( 'wporg-plugins-developer',   array( __NAMESPACE__ . '\\Shortcodes\\Developer',   'display' ) );
     108        }
     109
     110        /**
     111         * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
     112         */
     113        public function activate() {
     114                global $wp_rewrite;
     115
     116                // Setup the environment.
     117                $this->init();
     118
     119                // %postname% is required.
     120                $wp_rewrite->set_permalink_structure( '/%postname%/' );
     121
     122                // /tags/%slug% is required for tags.
     123                $wp_rewrite->set_tag_base( '/tags' );
     124
     125                // We require the WordPress.org Ratings plugin also be active.
     126                if ( ! is_plugin_active( 'wporg-ratings/wporg-ratings.php' ) ) {
     127                        activate_plugin( 'wporg-ratings/wporg-ratings.php' );
     128                }
     129
     130                // Enable the WordPress.org Plugin Repo Theme.
     131                foreach ( wp_get_themes() as $theme ) {
     132                        if ( $theme->get( 'Name' ) === 'WordPress.org Plugins' ) {
     133                                switch_theme( $theme->get_stylesheet() );
     134                                break;
     135                        }
     136                }
     137
     138                flush_rewrite_rules();
     139
     140                do_action( 'wporg_plugins_activation' );
     141        }
     142
     143        /**
     144         *
     145         */
     146        public function deactivate() {
     147                flush_rewrite_rules();
     148
     149                do_action( 'wporg_plugins_deactivation' );
     150        }
     151
     152        /**
    132153         * The Plugin Directory is available at multiple URLs (internationalised domains), this method allows
    133154         * for the one blog (a single blog_id) to be presented at multiple URLs yet have correct localised links.
    … …  
    303324         */
    304325        public function get_plugin_post( $plugin_slug ) {
    305                 if ( $plugin_slug instanceof WP_Post ) {
     326                if ( $plugin_slug instanceof \WP_Post ) {
    306327                        return $plugin_slug;
    307328                }
Note: See TracChangeset for help on using the changeset viewer.