_get_plugin_data_markup_translate

Sanitizes plugin data, optionally adds markup, optionally translates.

Description

_get_plugin_data_markup_translate( $plugin_file, $plugin_data, (constant) $markup = true, (bool) $translate = true ); 

Parameters (4)

0. $plugin_file
The plugin file.
1. $plugin_data
The plugin data.
2. $markup — Optional. (constant) => true
The markup.
3. $translate — Optional. (bool) => true
The translate.

Usage

  1. if ( !function_exists( '_get_plugin_data_markup_translate' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/plugin.php'; 
  3.  
  4. // The plugin file. 
  5. $plugin_file = null; 
  6.  
  7. // The plugin data. 
  8. $plugin_data = null; 
  9.  
  10. // The markup. 
  11. $markup = true; 
  12.  
  13. // The translate. 
  14. $translate = true; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup, $translate); 
  18.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/plugin.php  
  1. function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup = true, $translate = true ) { 
  2.  
  3. // Sanitize the plugin filename to a WP_PLUGIN_DIR relative path 
  4. $plugin_file = plugin_basename( $plugin_file ); 
  5.  
  6. // Translate fields 
  7. if ( $translate ) { 
  8. if ( $textdomain = $plugin_data['TextDomain'] ) { 
  9. if ( ! is_textdomain_loaded( $textdomain ) ) { 
  10. if ( $plugin_data['DomainPath'] ) { 
  11. load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] ); 
  12. } else { 
  13. load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) ); 
  14. } elseif ( 'hello.php' == basename( $plugin_file ) ) { 
  15. $textdomain = 'default'; 
  16. if ( $textdomain ) { 
  17. foreach ( array( 'Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version' ) as $field ) 
  18. $plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain ); 
  19.  
  20. // Sanitize fields 
  21. $allowed_tags = $allowed_tags_in_links = array( 
  22. 'abbr' => array( 'title' => true ),  
  23. 'acronym' => array( 'title' => true ),  
  24. 'code' => true,  
  25. 'em' => true,  
  26. 'strong' => true,  
  27. ); 
  28. $allowed_tags['a'] = array( 'href' => true, 'title' => true ); 
  29.  
  30. // Name is marked up inside <a> tags. Don't allow these. 
  31. // Author is too, but some plugins have used <a> here (omitting Author URI). 
  32. $plugin_data['Name'] = wp_kses( $plugin_data['Name'], $allowed_tags_in_links ); 
  33. $plugin_data['Author'] = wp_kses( $plugin_data['Author'], $allowed_tags ); 
  34.  
  35. $plugin_data['Description'] = wp_kses( $plugin_data['Description'], $allowed_tags ); 
  36. $plugin_data['Version'] = wp_kses( $plugin_data['Version'], $allowed_tags ); 
  37.  
  38. $plugin_data['PluginURI'] = esc_url( $plugin_data['PluginURI'] ); 
  39. $plugin_data['AuthorURI'] = esc_url( $plugin_data['AuthorURI'] ); 
  40.  
  41. $plugin_data['Title'] = $plugin_data['Name']; 
  42. $plugin_data['AuthorName'] = $plugin_data['Author']; 
  43.  
  44. // Apply markup 
  45. if ( $markup ) { 
  46. if ( $plugin_data['PluginURI'] && $plugin_data['Name'] ) 
  47. $plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>'; 
  48.  
  49. if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] ) 
  50. $plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>'; 
  51.  
  52. $plugin_data['Description'] = wptexturize( $plugin_data['Description'] ); 
  53.  
  54. if ( $plugin_data['Author'] ) 
  55. $plugin_data['Description'] .= ' <cite>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</cite>'; 
  56.  
  57. return $plugin_data;