Ticket #1691: 1691.2.patch
File 1691.2.patch, 5.4 KB (added by , 9 years ago) |
---|
-
trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-i18n.php
9 9 class i18n { 10 10 11 11 /** 12 * Translate a Term Name.12 * Translates a term name. 13 13 * 14 14 * @param \WP_Term $term The Term object to translate. 15 15 * @return \WP_Term The term object with a translated `name` field. … … 27 27 } 28 28 29 29 /** 30 * Retrieves the translated version of a plugin. 31 * 32 * @param int $post_id The post ID of a plugin. 33 * @return \WP_Post|null WP_Post object on success, null on failure. 34 */ 35 static function get_translated_plugin_post( $post_id, $locale = null ) { 36 if ( null === $locale ) { 37 $locale = get_locale(); 38 } 39 40 if ( ! $locale || 'en_US' === $locale ) { 41 return null; 42 } 43 44 $posts = get_posts( array( 45 'post_type' => 'plugin_translated', 46 'name' => $locale, 47 'post_parent' => $post_id, 48 'post_status' => array( 'publish' ), 49 'numberposts' => 1, 50 ) ); 51 52 if ( ! $posts ) { 53 return null; 54 } 55 56 $plugin = reset( $posts ); 57 return $plugin; 58 } 59 60 /** 61 * Translates the title of a plugin. 62 * 63 * @param string $title The post title. 64 * @param int $post_id The post ID. 65 * @return string Filtered title. 66 */ 67 static function translate_title( $title, $post_id ) { 68 $post = get_post( $post_id ); 69 if ( ! $post || 'plugin' !== $post->post_type ) { 70 return $title; 71 } 72 73 $translated_plugin = self::get_translated_plugin_post( $post->ID ); 74 if ( ! $translated_plugin ) { 75 return $title; 76 } 77 78 return $translated_plugin->post_title; 79 } 80 81 /** 82 * Translates the title of a plugin. 83 * 84 * @param string $content The post content. 85 * @return string Filtered content. 86 */ 87 static function translate_content( $content ) { 88 $post = get_post(); 89 if ( ! $post || 'plugin' !== $post->post_type ) { 90 return $content; 91 } 92 93 $translated_plugin = self::get_translated_plugin_post( $post->ID ); 94 if ( ! $translated_plugin ) { 95 return $content; 96 } 97 98 return $translated_plugin->post_content; 99 } 100 101 /** 102 * Translates the excerpt of a plugin. 103 * 104 * @param string $excerpt The post excerpt. 105 * @param int $post_id The post ID. 106 * @return string Filtered excerpt. 107 */ 108 static function translate_excerpt( $excerpt, $post_id ) { 109 $post = get_post( $post_id ); 110 if ( ! $post || 'plugin' !== $post->post_type ) { 111 return $excerpt; 112 } 113 114 $translated_plugin = self::get_translated_plugin_post( $post->ID ); 115 if ( ! $translated_plugin ) { 116 return $excerpt; 117 } 118 119 return $translated_plugin->post_excerpt; 120 } 121 122 /** 30 123 * A private method to hold a list of the strings contained within the Database. 31 124 * 32 125 * This function is never called, and only exists so that out pot tools can detect the strings. -
trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
91 91 'read_private_posts' => 'do_not_allow', 92 92 'delete_posts' => 'do_not_allow', 93 93 'create_posts' => 'do_not_allow', 94 ) 94 ), 95 95 ) ); 96 96 97 register_post_type( 'plugin_translated', array( 98 'public' => false, 99 'rewrite' => false, 100 'query_var' => false, 101 'can_export' => false, 102 'hierarchical' => true, 103 ) ); 104 97 105 register_taxonomy( 'plugin_section', 'plugin', array( 98 106 'hierarchical' => true, 99 107 'query_var' => 'plugin_section', … … 216 224 217 225 if ( 'en_US' != get_locale() ) { 218 226 add_filter( 'get_term', array( __NAMESPACE__ . '\i18n', 'translate_term' ) ); 227 add_filter( 'the_title', array( __NAMESPACE__ . '\i18n', 'translate_title' ), 10, 2 ); 228 add_filter( 'wporg_plugins_content', array( __NAMESPACE__ . '\i18n', 'translate_content' ) ); // @todo get_the_content 229 add_filter( 'get_the_excerpt', array( __NAMESPACE__ . '\i18n', 'translate_excerpt', 10, 2 ) ); 219 230 } 220 231 221 232 // Instantiate our copy of the Jetpack_Search class. -
trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-plugins/template-parts/plugin-single.php
11 11 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 12 12 use WordPressdotorg\Plugin_Directory\Template; 13 13 14 $content = call_user_func( array( Plugin_Directory::instance(), 'split_post_content_into_pages' ), get_the_content() ); 14 $content = apply_filters( 'wporg_plugins_content', get_the_content() ); 15 $content = call_user_func( array( Plugin_Directory::instance(), 'split_post_content_into_pages' ), $content ); 15 16 16 17 $widget_args = array( 17 18 'before_title' => '<h4 class="widget-title">', … … 59 60 ?> 60 61 61 62 </div><!-- .entry-meta --> 62 </article><!-- #post-## --> 63 No newline at end of file 63 </article><!-- #post-## -->