Changeset 2561
- Timestamp:
- 02/24/2016 06:44:33 AM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-wporg-plugin-directory-template.php
r2556 r2561 150 150 static function get_plugin_icon( $plugin, $output = 'raw' ) { 151 151 global $wporg_plugin_directory; 152 $plugin = $wporg_plugin_directory->get_ or_create_plugin_post( $plugin );153 if ( is_wp_error( $plugin )) {152 $plugin = $wporg_plugin_directory->get_plugin_post( $plugin ); 153 if ( ! $plugin ) { 154 154 return false; 155 155 } … … 219 219 static function get_plugin_banner( $plugin, $output = 'raw' ) { 220 220 global $wporg_plugin_directory; 221 $plugin = $wporg_plugin_directory->get_ or_create_plugin_post( $plugin );222 if ( is_wp_error( $plugin )) {221 $plugin = $wporg_plugin_directory->get_plugin_post( $plugin ); 222 if ( ! $plugin ) { 223 223 return false; 224 224 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-wporg-plugin-directory.php
r2558 r2561 278 278 */ 279 279 public function split_post_content_into_pages( $content ) { 280 $_pages 280 $_pages = preg_split( "#<!--section=(.+?)-->#", $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); 281 281 $content_pages = array( 282 282 'screenshots' => '[wporg-plugins-screenshots]', … … 302 302 * @return WP_Post|WP_Error 303 303 */ 304 public function get_ or_create_plugin_post( $plugin_slug ) {304 public function get_plugin_post( $plugin_slug ) { 305 305 if ( $plugin_slug instanceof WP_Post ) { 306 306 return $plugin_slug; … … 308 308 309 309 // get_post_by_slug(); 310 $posts = get_posts( array( 'post_type' => 'plugin', 'name' => $plugin_slug, 'post_status' => 'any', 'fields' => 'ids' ) ); 311 312 if ( $posts ) { 313 $id = reset( $posts ); 314 } else { 315 $id = wp_insert_post( array( 316 'post_type' => 'plugin', 317 'post_status' => 'pending', 318 'post_name' => $plugin_slug, 319 'post_title' => $plugin_slug, 320 'post_content' => '', 321 ), true ); 322 323 if ( is_wp_error( $id ) ) { 324 return $id; 325 } 310 $posts = get_posts( array( 311 'post_type' => 'plugin', 312 'name' => $plugin_slug, 313 'post_status' => 'any' 314 ) ); 315 if ( ! $posts ) { 316 return false; 317 } 318 319 $plugin = reset( $posts ); 320 return $plugin; 321 } 322 323 /** 324 * Create a new post entry for a given plugin slug. 325 * 326 * @param array $plugin_info { 327 * Array of initial plugin post data, all fields are optional. 328 * 329 * @type string $title The title of the plugin. 330 * @type string $slug The slug of the plugin. 331 * @type string $status The status of the plugin ( 'publish', 'pending', 'disabled', 'closed' ). 332 * @type int $author The ID of the plugin author. 333 * @type string $description The short description of the plugin. 334 * } 335 * @return WP_Post|WP_Error 336 */ 337 public function create_plugin_post( array $plugin_info ) { 338 $title = !empty( $plugin_info['title'] ) ? $plugin_info['title'] : ''; 339 $slug = !empty( $plugin_info['slug'] ) ? $plugin_info['slug'] : sanitize_title( $title ); 340 $status = !empty( $plugin_info['status'] ) ? $plugin_info['status'] : 'pending'; 341 $author = !empty( $plugin_info['author'] ) ? $plugin_info['author'] : 0; 342 $desc = !empty( $plugin_info['description'] ) ? $plugin_info['description'] : ''; 343 344 $id = wp_insert_post( array( 345 'post_type' => 'plugin', 346 'post_status' => $status, 347 'post_name' => $slug, 348 'post_title' => $title ?: $slug, 349 'post_author' => $author, 350 'post_content' => '', 351 'post_excerpt' => $desc, 352 ), true ); 353 354 if ( is_wp_error( $id ) ) { 355 return $id; 326 356 } 327 357
Note: See TracChangeset
for help on using the changeset viewer.