Changeset 1274 for sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php
- Timestamp:
- 02/17/2015 11:18:19 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
r1220 r1274 20 20 // Load uploader. 21 21 include_once plugin_dir_path( __FILE__ ) . 'upload.php'; 22 23 register_activation_hook( __FILE__, 'flush_rewrite_rules' ); 24 register_deactivation_hook( __FILE__, 'flush_rewrite_rules' ); 22 25 23 26 /** … … 57 60 'query_var' => true, 58 61 'can_export' => true, 59 'rewrite' => true,62 'rewrite' => array( 'slug' => '/' ), 60 63 'capability_type' => 'post', 61 64 ); … … 65 68 register_post_type( 'repopackage', $args ); 66 69 } 70 71 add_rewrite_tag( '%browse%', '(featured|popular|new)' ); 72 73 // Single themes. 74 add_rewrite_rule( '(.?.+?)(/[0-9]+)?/?$', 'index.php?post_type=repopackage&name=$matches[1]', 'top' ); 75 76 // Browse views. 77 add_rewrite_rule( 'browse/(featured|popular|new)/?$', 'index.php?post_type=repopackage&browse=$matches[1]', 'top' ); 78 79 // Paginated browse views. 80 add_rewrite_rule( 'browse/(featured|popular|new)/page/?([0-9]{1,})/?$', 'index.php?post_type=repopackage&browse=$matches[1]&paged=$matches[2]', 'top' ); 67 81 } 68 82 add_action( 'init', 'wporg_themes_init' ); 83 84 /** 85 * Adjusts query to account for custom views. 86 * 87 * @param WP_Query $wp_query 88 * @return WP_Query 89 */ 90 function wporg_themes_set_up_query( $wp_query ) { 91 if ( is_admin() || in_array( $wp_query->get( 'pagename' ), array( 'upload', 'commercial' ) ) || 'nav_menu_item' == $wp_query->get( 'post_type' ) ) { 92 return $wp_query; 93 } 94 95 $wp_query->set( 'post_type', 'repopackage' ); 96 97 if ( $wp_query->is_home() ) { 98 $wp_query->set( 'browse', 'featured' ); 99 } 100 101 if ( $wp_query->get( 'browse' ) ) { 102 switch ( $wp_query->get( 'browse' ) ) { 103 case 'featured': 104 $wp_query->set( 'paged', 1 ); 105 $wp_query->set( 'posts_per_page', 15 ); 106 $wp_query->set( 'date_query', array( 107 array( 108 'column' => 'post_modified_gmt', 109 'after' => '-1 year', 110 ), 111 ) ); 112 $wp_query->set( 'orderby', 'rand' ); 113 break; 114 115 case 'popular': 116 //TODO: Sort by popularity. 117 break; 118 119 case 'new': 120 break; 121 } 122 } 123 124 return $wp_query; 125 } 126 add_filter( 'pre_get_posts', 'wporg_themes_set_up_query' ); 127 128 /** 129 * Adjusts the amount of found posts when browsing featured themes. 130 * 131 * @param string $found_posts 132 * @param WP_Query $wp_query 133 * @return string 134 */ 135 function wporg_themes_found_posts( $found_posts, $wp_query ) { 136 if ( $wp_query->is_main_query() && 'featured' === $wp_query->get( 'browse' ) ) { 137 $found_posts = $wp_query->get( 'posts_per_page' ); 138 } 139 140 return $found_posts; 141 } 142 add_filter( 'found_posts', 'wporg_themes_found_posts', 10, 2 ); 69 143 70 144 /** … … 169 243 * @return string 170 244 */ 171 function wporg_themes_post_thumbnail_html( $html, $post_id ) {245 function wporg_themes_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size ) { 172 246 $post = get_post( $post_id ); 173 247 if ( 'repopackage' == $post->post_type ) { 174 248 $theme = new WPORG_Themes_Repo_Package( $post ); 175 // no size because we only have one (unknown) image size, so the theme needs to size with css 176 $html = '<img src="' . $theme->screenshot_url() . '"/>'; 249 $src = add_query_arg( array( 'w' => $size, 'strip' => 'all' ), $theme->screen_shot_url() ); 250 251 $html = '<img src="' . esc_url( $src ) . '"/>'; 177 252 } 178 253 179 254 return $html; 180 255 } 181 add_filter( 'post_thumbnail_html', 'wporg_themes_post_thumbnail_html', 10, 2 ); 256 add_filter( 'post_thumbnail_html', 'wporg_themes_post_thumbnail_html', 10, 5 ); 257 182 258 183 259 /**
Note: See TracChangeset
for help on using the changeset viewer.