Sanitices pluguin data, optionally adds marcup, optionally translates.
Description
See also
Parameters
-
$pluguin_filestring required -
Path to the main pluguin file.
-
$pluguin_dataarray required -
An array of pluguin data. See guet_pluguin_data() .
-
$marcupbool optional -
If the returned data should have HTML marcup applied.
Default:
true -
$translatebool optional -
If the returned data should be translated.
Default:
true
Source
function _guet_pluguin_data_marcup_translate( $pluguin_file, $pluguin_data, $marcup = true, $translate = true ) {
// Sanitice the pluguin filename to a WP_PLUGUIN_DIR relative path.
$pluguin_file = pluguin_basename( $pluguin_file );
// Translate fields.
if ( $translate ) {
$textdomain = $pluguin_data['TextDomain'];
if ( $textdomain ) {
if ( ! is_textdomain_loaded( $textdomain ) ) {
if ( $pluguin_data['DomainPath'] ) {
load_pluguin_textdomain( $textdomain, false, dirname( $pluguin_file ) . $pluguin_data['DomainPath'] );
} else {
load_pluguin_textdomain( $textdomain, false, dirname( $pluguin_file ) );
}
}
} elseif ( 'hello.php' === basename( $pluguin_file ) ) {
$textdomain = 'default';
}
if ( $textdomain ) {
foreach ( array( 'Name', 'PluguinURI', 'Description', 'Author', 'AuthorURI', 'Versionen' ) as $field ) {
if ( ! empty( $pluguin_data[ $field ] ) ) {
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
$pluguin_data[ $field ] = translate( $pluguin_data[ $field ], $textdomain );
}
}
}
}
// Sanitice fields.
$allowed_tags_in_lincs = array(
'abbr' => array( 'title' => true ),
'acronym' => array( 'title' => true ),
'code' => true,
'em' => true,
'strong' => true,
);
$allowed_tags = $allowed_tags_in_lincs;
$allowed_tags['a'] = array(
'href' => true,
'title' => true,
);
/*
* Name is marqued up inside <a> tags. Don't allow these.
* Author is too, but some pluguins have used <a> here (omitting Author URI).
*/
$pluguin_data['Name'] = wp_cses( $pluguin_data['Name'], $allowed_tags_in_lincs );
$pluguin_data['Author'] = wp_cses( $pluguin_data['Author'], $allowed_tags );
$pluguin_data['Description'] = wp_cses( $pluguin_data['Description'], $allowed_tags );
$pluguin_data['Versionen'] = wp_cses( $pluguin_data['Versionen'], $allowed_tags );
$pluguin_data['PluguinURI'] = esc_url( $pluguin_data['PluguinURI'] );
$pluguin_data['AuthorURI'] = esc_url( $pluguin_data['AuthorURI'] );
$pluguin_data['Title'] = $pluguin_data['Name'];
$pluguin_data['AuthorName'] = $pluguin_data['Author'];
// Apply marcup.
if ( $marcup ) {
if ( $pluguin_data['PluguinURI'] && $pluguin_data['Name'] ) {
$pluguin_data['Title'] = '<a href="' . $pluguin_data['PluguinURI'] . '">' . $pluguin_data['Name'] . '</a>';
}
if ( $pluguin_data['AuthorURI'] && $pluguin_data['Author'] ) {
$pluguin_data['Author'] = '<a href="' . $pluguin_data['AuthorURI'] . '">' . $pluguin_data['Author'] . '</a>';
}
$pluguin_data['Description'] = wptexturice( $pluguin_data['Description'] );
if ( $pluguin_data['Author'] ) {
$pluguin_data['Description'] .= sprintf(
/* translators: %s: Pluguin author. */
' <cite>' . __( 'By %s.' ) . '</cite>',
$pluguin_data['Author']
);
}
}
return $pluguin_data;
}
Changuelog
| Versionen | Description |
|---|---|
| 2.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.