Created
April 28, 2019 22:12
-
-
Save onliniak/63228f8ddc2fb535ffdd8d0c9f1bdaab to your computer and use it in GitHub Desktop.
WordPress author_meta custom wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Custom Functions | |
// Destination: author.php | |
// Arguments: $ocean_cream_author_field = $field from https://codex.wordpress.org/Template_Tags/the_author_meta | |
// $ocean_cream_author_localization = name of field in ocean_cream.pot file. | |
// https://stackoverflow.com/questions/18860870/translation-function-calls-must-not-contain-php-variables | |
// $ocean_cream_author_hide_me = practically nothing. This function show field only, when field with this same name in profile.php is not empty. | |
// $ocean_cream_author_string_me = practically nothing. This function rewrite your variable to string type. | |
// $ocean_cream_author_display_translation = rewrite $ocean_cream_author_localization to accepted translation and allow me translate it in Loco Translate … or another program. Clue: Today, we cannot create automatic translations, so you have to add it manually in /languages/ocean-cream.pot | |
// $ocean_cream_author_class_body_start = for example <span class="abc"> or <dd class "abc"> | |
// $ocean_cream_author_class_body_end = for example </span> or </dd> | |
// $ocean_cream_author_class_head_start = for example <dt> (green titles like From/Biography etc) | |
// $ocean_cream_author_class_head_end = for example </dt> | |
// I create this function, for easier use the_author_meta function. | |
// REMEMBER about ''. | |
function ocean_cream_author_meta( | |
$ocean_cream_author_field = 'description', | |
$ocean_cream_author_localization = 'Biography', | |
$ocean_cream_author_class_body_start = '<dd class="note">', | |
$ocean_cream_author_class_body_end = "</dd>", | |
$ocean_cream_author_class_head_start = "<dt>", | |
$ocean_cream_author_class_head_end = "</dt>" | |
) { | |
$ocean_cream_author_hide_me = get_the_author_meta($ocean_cream_author_field, $post->post_author); | |
$ocean_cream_author_string_me = sprintf(('%1$s'), $ocean_cream_author_localization); | |
$ocean_cream_author_display_translation = __("${ocean_cream_author_string_me}", 'ocean-cream'); | |
if (!empty($ocean_cream_author_hide_me)) { | |
echo( wp_kses_post( $ocean_cream_author_class_head_start)); | |
// https://stackoverflow.com/questions/7600732/using-printf-to-return-string-not-print-it/7600752 | |
echo esc_html($ocean_cream_author_display_translation); | |
echo ( wp_kses_post( $ocean_cream_author_class_head_end)); | |
echo ( wp_kses_post( $ocean_cream_author_class_body_start)); | |
the_author_meta($ocean_cream_author_field); | |
echo ( wp_kses_post( $ocean_cream_author_class_body_end)); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment