Changeset 1395 for sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php
- Timestamp:
- 03/11/2015 10:55:10 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php
r1392 r1395 24 24 include_once plugin_dir_path( __FILE__ ) . 'themes-api.php'; 25 25 26 register_activation_hook( __FILE__, 'flush_rewrite_rules' ); 27 register_deactivation_hook( __FILE__, 'flush_rewrite_rules' ); 26 // Load adjustments to the edit.php screen for repopackage posts. 27 include_once plugin_dir_path( __FILE__ ) . 'admin-edit.php'; 28 29 30 /** 31 * Things to change on activation. 32 */ 33 function wporg_themes_activate() { 34 flush_rewrite_rules(); 35 36 do_action( 'wporg_themes_activation' ); 37 } 38 register_activation_hook( __FILE__, 'wporg_themes_activate' ); 39 40 /** 41 * Things to change on deactivation. 42 */ 43 function wporg_themes_deactivate() { 44 flush_rewrite_rules(); 45 46 do_action( 'wporg_themes_deactivation' ); 47 } 48 register_deactivation_hook( __FILE__, 'wporg_themes_deactivate' ); 28 49 29 50 /** … … 193 214 194 215 /** 195 * Capability mapping for custom caps.196 *197 * @param array $caps Returns the user's actual capabilities.198 * @param string $cap Capability name.199 * @param int $user_id The user ID.200 * @param array $args Adds the context to the cap. Typically the object ID.201 * @return array202 */203 function wporg_themes_map_meta_cap( $caps, $cap, $user_id, $args ) {204 switch ( $cap ) {205 case 'delete_categories':206 case 'edit_categories':207 case 'manage_categories':208 209 if ( ! is_super_admin() ) {210 $caps[] = 'do_not_allow';211 }212 break;213 }214 215 return $caps;216 }217 add_filter( 'map_meta_cap', 'wporg_themes_map_meta_cap', 10, 4 );218 219 /**220 216 * Checks if ther current users is a super admin before allowing terms to be added. 221 217 * … … 503 499 } 504 500 } 505 506 /* REPOPACKAGE EDITOR ENHANCEMENTS */507 508 /**509 * Use theme screen shot for post thumbnails.510 *511 * @param string $html512 * @param int $post_id513 * @return string514 */515 function wporg_themes_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size ) {516 $post = get_post( $post_id );517 if ( 'repopackage' == $post->post_type ) {518 $theme = new WPORG_Themes_Repo_Package( $post );519 $src = add_query_arg( array( 'w' => $size, 'strip' => 'all' ), $theme->screenshot_url() );520 521 $html = '<img src="' . esc_url( $src ) . '"/>';522 }523 524 return $html;525 }526 add_filter( 'post_thumbnail_html', 'wporg_themes_post_thumbnail_html', 10, 5 );527 528 /**529 * Prevents repopackages from being deleted.530 *531 * @param int $post_id532 */533 function wporg_theme_no_delete_repopackage( $post_id ) {534 if ( 'repopackage' == get_post( $post_id )->post_type ) {535 wp_die( __( 'Repopackages can not be deleted.', 'wporg-themes' ), '', array(536 'back_link' => true,537 ) );538 }539 }540 add_filter( 'before_delete_post', 'wporg_theme_no_delete_repopackage' );541 542 /**543 * Better view in the Packages screen.544 *545 * @param array $columns546 * @return array547 */548 function wporg_themes_repopackage_columns( $columns ) {549 $columns = array_merge( $columns, array(550 'version' => __( 'Version', 'wporg-themes' ),551 'theme-url' => __( 'Theme URL', 'wporg-themes' ),552 'author-url' => __( 'Author URL', 'wporg-themes' ),553 'ticket' => __( 'Ticket ID', 'wporg-themes' ),554 ) );555 unset( $columns['categories'] );556 557 return $columns;558 }559 add_filter( 'manage_repopackage_posts_columns', 'wporg_themes_repopackage_columns' );560 561 /**562 * Custom columns for the admin screen.563 *564 * @param string $column565 * @param int $post_id566 */567 function wporg_themes_repopackage_custom_columns( $column, $post_id ) {568 $theme = new WPORG_Themes_Repo_Package( $post_id );569 570 switch ( $column ) {571 case 'ticket':572 if ( $theme->ticket ) {573 printf( '<a href="%1$s">%2$s</a>', esc_url( 'https://themes.trac.wordpress.org/ticket/' . $theme->ticket ), '#' . $theme->ticket );574 }575 break;576 case 'theme-url':577 case 'author-url':578 echo make_clickable( $theme->$column );579 break;580 default:581 echo $theme->$column;582 }583 }584 add_action( 'manage_repopackage_posts_custom_column', 'wporg_themes_repopackage_custom_columns', 10, 2 );585 586 /**587 * Meta box to choose which version is live.588 */589 function wporg_themes_add_meta_box() {590 add_meta_box(591 'wporg_themes_versions',592 __( 'Theme Versions', 'wporg-themes' ),593 'wporg_themes_meta_box_callback',594 'repopackage',595 'side',596 'high'597 );598 }599 add_action( 'add_meta_boxes', 'wporg_themes_add_meta_box' );600 601 /**602 * Displays the content of the `_status` meta box.603 *604 * @param WP_Post $post605 */606 function wporg_themes_meta_box_callback( $post ) {607 $versions = get_post_meta( $post->ID, '_status', true );608 609 if ( empty( $versions ) ) {610 return;611 }612 613 // Add an nonce field so we can check for it later.614 wp_nonce_field( 'wporg_themes_meta_box', 'wporg_themes_meta_box_nonce' );615 616 foreach ( $versions as $version => $status ) :617 ?>618 <p><?php echo $version; ?> -619 <select name="wporg_themes_status[<?php echo base64_encode( $version ); // base64 because version numbers don't work so well as parts of keys ?>]">620 <option value="new" <?php selected( $status, 'new' ); ?>><?php esc_html_e( 'New', 'wporg-themes' ); ?></option>621 <option value="live" <?php selected( $status, 'live' ); ?>><?php esc_html_e( 'Live', 'wporg-themes' ); ?></option>622 <option value="old" <?php selected( $status, 'old' ); ?>><?php esc_html_e( 'Old', 'wporg-themes' ); ?></option>623 </select>624 </p>625 <?php626 endforeach;627 }628 629 /**630 * Sanitizes and saves meta box settings.631 *632 * @param int $post_id633 */634 function wporg_themes_save_meta_box_data( $post_id ) {635 // All the safety checks.636 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {637 return;638 }639 if ( ! isset( $_POST['wporg_themes_meta_box_nonce'] ) ) {640 return;641 }642 if ( ! wp_verify_nonce( $_POST['wporg_themes_meta_box_nonce'], 'wporg_themes_meta_box' ) ) {643 return;644 }645 // TODO should this be a post type specific capability?646 if ( ! current_user_can( 'edit_post', $post_id ) ) {647 return;648 }649 650 $new_status = array();651 foreach ( $_POST['wporg_themes_status'] as $version => $status ) {652 // We could check of the passed status is valid, but wporg_themes_update_version_status() handles that beautifully.653 $new_status[ base64_decode( $version ) ] = $status;654 }655 uksort( $new_status, 'version_compare' );656 657 // Update the statuses.658 foreach ( $new_status as $version => $status ) {659 wporg_themes_update_version_status( $post_id, $version, $status );660 }661 }662 add_action( 'save_post', 'wporg_themes_save_meta_box_data' );
Note: See TracChangeset
for help on using the changeset viewer.