Changeset 2621 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
- Timestamp:
- 02/25/2016 10:49:24 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r2611 r2621 5 5 * The main Plugin Directory class, it handles most of the bootstrap and basic operations of the plugin. 6 6 * 7 * @package WordPressdotorg _Plugin_Directory7 * @package WordPressdotorg\Plugin_Directory 8 8 */ 9 9 class Plugin_Directory { … … 14 14 public static function instance( $plugin_file = null ) { 15 15 static $instance = null; 16 16 17 return ! is_null( $instance ) ? $instance : $instance = new Plugin_Directory( $plugin_file ); 17 18 } 18 19 20 /** 21 * @param string $plugin_file 22 */ 19 23 private function __construct( $plugin_file ) { 20 24 add_action( 'init', array( $this, 'init' ) ); … … 25 29 add_filter( 'the_content', array( $this, 'filter_post_content_to_correct_page' ), 1 ); 26 30 27 // Load all Admin-specific items 28 add_action( 'admin_init', array( __NAMESPACE__ . '\\Admin\\ Admin_Customizations', 'instance' ) );31 // Load all Admin-specific items. 32 add_action( 'admin_init', array( __NAMESPACE__ . '\\Admin\\Customizations', 'instance' ) ); 29 33 30 34 register_activation_hook( $plugin_file, array( $this, 'activate' ) ); … … 95 99 // When this plugin is used in the context of a Rosetta site, handle it gracefully 96 100 if ( 'wordpress.org' != $_SERVER['HTTP_HOST'] && defined( 'WPORG_PLUGIN_DIRECTORY_BLOGID' ) ) { 97 $this->add_rosetta_network_filters(); 101 add_filter( 'option_home', array( $this, 'rosetta_network_localize_url' ) ); 102 add_filter( 'option_siteurl', array( $this, 'rosetta_network_localize_url' ) ); 98 103 } 99 104 } … … 109 114 110 115 /** 111 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.116 * @global \WP_Rewrite $wp_rewrite WordPress rewrite component. 112 117 */ 113 118 public function activate() { … … 151 156 152 157 /** 158 * Filter the URLs to use the current localized domain name, rather than WordPress.org. 159 * 153 160 * The Plugin Directory is available at multiple URLs (internationalised domains), this method allows 154 161 * for the one blog (a single blog_id) to be presented at multiple URLs yet have correct localised links. 155 */ 156 public function add_rosetta_network_filters() { 157 // Filter the URLs to use the current localised domain name, rather than WordPress.org. 158 foreach ( array( 'option_home', 'option_siteurl' ) as $filter ) { 159 add_filter( $filter, function( $url ) { 160 static $localized_url = null; 161 if ( is_null( $localized_url ) ) { 162 $localized_url = 'https://' . preg_replace( '![^a-z.-]+!', '', $_SERVER['HTTP_HOST'] ); 163 } 164 165 return preg_replace( '!^[https]+://wordpress\.org!i', $localized_url, $url ); 166 } ); 167 } 168 169 /* 170 // This method works in conjuction with a filter in sunrise.php, duplicated here for transparency: 171 172 // Make the Plugin Directory available at /plugins/ on all rosetta sites. 173 function wporg_plugins_on_rosetta_domains( $site, $domain, $path, $segments ) { 174 // All non-rosetta networks define DOMAIN_CURRENT_SITE in wp-config.php 175 if ( ! defined( 'DOMAIN_CURRENT_SITE' ) && 'wordpress.org' != $domain && '/plugins/' == substr( $path . '/', 0, 9 ) ) { 176 $site = get_blog_details( WPORG_PLUGIN_DIRECTORY_BLOGID ); 177 if ( $site ) { 178 $site = clone $site; 179 // 6 = The Rosetta network, this causes the site to be loaded as part of the Rosetta network 180 $site->site_id = 6; 181 return $site; 182 } 183 } 184 185 return $site; 186 } 187 add_filter( 'pre_get_site_by_path', 'wporg_plugins_on_rosetta_domains', 10, 4 ); 188 */ 162 * 163 * This method works in conjunction with a filter in sunrise.php, duplicated here for transparency: 164 * 165 * // Make the Plugin Directory available at /plugins/ on all rosetta sites. 166 * function wporg_plugins_on_rosetta_domains( $site, $domain, $path, $segments ) { 167 * // All non-rosetta networks define DOMAIN_CURRENT_SITE in wp-config.php 168 * if ( ! defined( 'DOMAIN_CURRENT_SITE' ) && 'wordpress.org' != $domain && '/plugins/' == substr( $path . '/', 0, 9 ) ) { 169 * $site = get_blog_details( WPORG_PLUGIN_DIRECTORY_BLOGID ); 170 * if ( $site ) { 171 * $site = clone $site; 172 * // 6 = The Rosetta network, this causes the site to be loaded as part of the Rosetta network 173 * $site->site_id = 6; 174 * return $site; 175 * } 176 * } 177 * 178 * return $site; 179 * } 180 * add_filter( 'pre_get_site_by_path', 'wporg_plugins_on_rosetta_domains', 10, 4 ); 181 * 182 * @param string $url The URL to be localized. 183 * @return string 184 */ 185 public function rosetta_network_localize_url( $url ) { 186 static $localized_url = null; 187 188 if ( is_null( $localized_url ) ) { 189 $localized_url = 'https://' . preg_replace( '![^a-z.-]+!', '', $_SERVER['HTTP_HOST'] ); 190 } 191 192 return preg_replace( '!^[https]+://wordpress\.org!i', $localized_url, $url ); 189 193 } 190 194 … … 192 196 * Filter the permalink for the Plugins to be /plugin-name/. 193 197 * 194 * @param string $link The generated permalink.195 * @param WP_Post $post The Plugin post object.198 * @param string $link The generated permalink. 199 * @param \WP_Post $post The Plugin post object. 196 200 * @return string 197 201 */ … … 208 212 * 209 213 * @param string $term The term to add or update. 210 * @return string| WP_Error The term to add or update or WP_Error on failure.214 * @return string|\WP_Error The term to add or update or WP_Error on failure. 211 215 */ 212 216 public function pre_insert_term_prevent( $term ) { 213 217 if ( ! is_super_admin() ) { 214 $term = new WP_Error( 'not-allowed', __( 'You are not allowed to add terms.', 'wporg-plugins' ) );218 $term = new \WP_Error( 'not-allowed', __( 'You are not allowed to add terms.', 'wporg-plugins' ) ); 215 219 } 216 220 … … 219 223 220 224 /** 221 * @param WP_Query $wp_query The WordPress Query object.225 * @param \WP_Query $wp_query The WordPress Query object. 222 226 */ 223 227 public function use_plugins_in_query( $wp_query ) { … … 299 303 */ 300 304 public function split_post_content_into_pages( $content ) { 301 $_pages = preg_split( "#<!--section=(.+?)-->#", $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );305 $_pages = preg_split( "#<!--section=(.+?)-->#", $content, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); 302 306 $content_pages = array( 303 307 'screenshots' => '[wporg-plugins-screenshots]', … … 318 322 319 323 /** 320 * Retrieve the WP_Post object representing a given plugin.321 *322 * @param $plugin_slug string|WP_Post The slug of the plugin to retrieve.323 * @return WP_Post|WP_Error324 */324 * Retrieve the WP_Post object representing a given plugin. 325 * 326 * @param $plugin_slug string|\WP_Post The slug of the plugin to retrieve. 327 * @return \WP_Post|\WP_Error 328 */ 325 329 public function get_plugin_post( $plugin_slug ) { 326 330 if ( $plugin_slug instanceof \WP_Post ) { … … 332 336 'post_type' => 'plugin', 333 337 'name' => $plugin_slug, 334 'post_status' => 'any' 338 'post_status' => 'any', 335 339 ) ); 336 340 if ( ! $posts ) { … … 338 342 } 339 343 340 $plugin = reset( $posts ); 341 return $plugin; 342 } 343 344 /** 345 * Create a new post entry for a given plugin slug. 346 * 344 return reset( $posts ); 345 } 346 347 /** 348 * Create a new post entry for a given plugin slug. 349 * 347 350 * @param array $plugin_info { 348 351 * Array of initial plugin post data, all fields are optional. 349 *352 * 350 353 * @type string $title The title of the plugin. 351 354 * @type string $slug The slug of the plugin. … … 354 357 * @type string $description The short description of the plugin. 355 358 * } 356 * @return WP_Post|WP_Error357 */359 * @return \WP_Post|\WP_Error 360 */ 358 361 public function create_plugin_post( array $plugin_info ) { 359 362 $title = !empty( $plugin_info['title'] ) ? $plugin_info['title'] : ''; … … 377 380 } 378 381 379 $plugin = get_post( $id ); 380 return $plugin; 382 return get_post( $id ); 381 383 } 382 384 }
Note: See TracChangeset
for help on using the changeset viewer.