To convert Place Holder Value in another language in Wordpress - php

I have used Contact Form 7 plugin in Worpress and I also used Gtranslate Plugin to translate content of my Wordpress site into another language.
Issue is that Placholder values for Example Name, Email etc. is not getting converted into another language via Gtranslate plugin.It remains in default English.
Can please anyone assist me to fix this issue?
public static function form() {
$template =
'<p>' . __( 'Your Name', 'contact-form-7' )
. ' ' . __( '(required)', 'contact-form-7' ) . '<br />' . "\n"
. ' [text* your-name] </p>' . "\n\n"
. '<p>' . __( 'Your Email', 'contact-form-7' )
. ' ' . __( '(required)', 'contact-form-7' ) . '<br />' . "\n"
. ' [email* your-email] </p>' . "\n\n"
. '<p>' . __( 'Subject', 'contact-form-7' ) . '<br />' . "\n"
. ' [text your-subject] </p>' . "\n\n"
. '<p>' . __( 'Your Message', 'contact-form-7' ) . '<br />' . "\n"
. ' [textarea your-message] </p>' . "\n\n"
. '<p>[submit "' . __( 'Send', 'contact-form-7' ) . '"]</p>';
return $template;
}

Related

disable media wordpress and use the browser file uploader to upload

I use the One User Avatar plugin, Inside the settings, there is a check box with the title "Always use the browser file uploader to upload avatars". I tick it. But when I try to change the default avatar, it still uses WordPress media, I came across the following code in the file below :
path : /plugins/one-user-avatar/includes/class-wp-user-avatar-admin.php
public function wpua_add_default_avatar() {
global $avatar_default, $mustache_admin, $mustache_medium, $wpua_avatar_default, $wpua_disable_gravatar, $wpua_functions;
// Remove get_avatar filter
remove_filter( 'get_avatar', array( $wpua_functions, 'wpua_get_avatar_filter' ) );
// Set avatar_list variable
$avatar_list = '';
// Set avatar defaults
$avatar_defaults = array(
'mystery' => __( 'Mystery Man', 'one-user-avatar'),
'blank' => __( 'Blank', 'one-user-avatar'),
'gravatar_default' => __( 'Gravatar Logo', 'one-user-avatar'),
'identicon' => __( 'Identicon (Generated)', 'one-user-avatar'),
'wavatar' => __( 'Wavatar (Generated)', 'one-user-avatar'),
'monsterid' => __( 'MonsterID (Generated)', 'one-user-avatar'),
'retro' => __( 'Retro (Generated)', 'one-user-avatar')
);
$avatar_defaults = apply_filters( 'avatar_defaults', $avatar_defaults );
// No Default Avatar, set to Mystery Man
if ( empty( $avatar_default ) ) {
$avatar_default = 'mystery';
}
// Take avatar_defaults and get examples for unknown#gravatar.com
foreach ( $avatar_defaults as $default_key => $default_name ) {
$avatar = get_avatar( 'unknown#gravatar.com', 32, $default_key );
$selected = ( $avatar_default == $default_key ) ? ' checked="checked" ' : '';
$avatar_list .= sprintf(
'<label><input type="radio" name="avatar_default" id="avatar_%1$s" value="%1$s" %2$s/> ',
esc_attr( $default_key ),
$selected
);
$avatar_list .= preg_replace( "/src='(.+?)'/", "src='\$1&forcedefault=1'", $avatar );
$avatar_list .= ' ' . $default_name . '</label>';
$avatar_list .= '<br />';
}
// Show remove link if custom Default Avatar is set
if ( ! empty( $wpua_avatar_default ) && $wpua_functions->wpua_attachment_is_image( $wpua_avatar_default ) ) {
$avatar_thumb_src = $wpua_functions->wpua_get_attachment_image_src( $wpua_avatar_default, array( 32, 32 ) );
$avatar_thumb = $avatar_thumb_src[0];
$hide_remove = '';
} else {
$avatar_thumb = $mustache_admin;
$hide_remove = ' class="wpua-hide"';
}
// Default Avatar is wp_user_avatar, check the radio button next to it
$selected_avatar = ( 1 == (bool) $wpua_disable_gravatar || 'wp_user_avatar' == $avatar_default ) ? ' checked="checked" ' : '';
// Wrap WPUA in div
$avatar_thumb_img = sprintf( '<div id="wpua-preview"><img src="%s" width="32" /></div>', esc_url( $avatar_thumb ) );
// Add WPUA to list
$wpua_list = sprintf(
'<label><input type="radio" name="avatar_default" id="wp_user_avatar_radio" value="wp_user_avatar" %s /> ',
$selected_avatar
);
$wpua_list .= preg_replace( "/src='(.+?)'/", "src='\$1'", $avatar_thumb_img );
$wpua_list .= ' ' . __( 'One User Avatar', 'one-user-avatar' ) . '</label>';
$wpua_list .= '<p id="wpua-edit"><button type="button" class="button" id="wpua-add" name="wpua-add" data-avatar_default="true" data-title="' . __( 'Choose Image', 'one-user-avatar' ) . ': ' . __( 'Default Avatar', 'one-user-avatar' ) . '">' . __( 'Choose Image', 'one-user-avatar' ) . '</button>';
$wpua_list .= '<span id="wpua-remove-button"' . $hide_remove . '>' . __( 'Remove', 'one-user-avatar' ) . '</span><span id="wpua-undo-button">' . __( 'Undo', 'one-user-avatar' ) . '</span></p>';
$wpua_list .= '<input type="hidden" id="wp-user-avatar" name="avatar_default_wp_user_avatar" value="' . $wpua_avatar_default . '">';
$wpua_list .= '<div id="wpua-modal"></div>';
if ( 1 != (bool) $wpua_disable_gravatar ) {
return $wpua_list . '<div id="wp-avatars">' . $avatar_list . '</div>';
} else {
return $wpua_list . '<div id="wp-avatars" style="display:none;">' . $avatar_list . '</div>';
}
}
How can I disable WordPress media and choose and upload a file from my computer?
I found the following code :
$wpua_list .= '<p id="wpua-edit"><button type="button" class="button" id="wpua-add" name="wpua-add" data-avatar_default="true" data-title="' . __( 'Choose Image', 'one-user-avatar' ) . ': ' . __( 'Default Avatar', 'one-user-avatar' ) . '">' . __( 'Choose Image', 'one-user-avatar' ) . '</button>';
I replaced it with the following code :
$wpua_list .= '<p id="wpua-edit"><input name="wpua-file" id="wpua-file" type="file"><button type="submit" class="button" id="wpua-upload" name="wpua-upload" data-avatar_default="true" data-title="' . __( 'Upload', 'one-user-avatar' ) . ': ' . __( 'Default Avatar', 'one-user-avatar' ) . '">' . __( 'Upload', 'one-user-avatar' ) . '</button>';
But when I go to wp-admin/options-discussion.php address and select and upload a photo from the computer, nothing is uploaded.
Where am I doing wrong? Thank you for taking the time to read my question.

adding php code inside html in wordpress

I am having event organizer and event venues need to add one line code in html file for displaying if it is venue to show as venue and it is organizer to show as organizer.as i have tried that by adding like below format but got an error as
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\live\wp-content\plugins\the-events-calendar\src\Tribe\Linked_Posts.php on line 943
This is the code:
echo '<input
type="hidden"
class="tribe-dropdown linked-post-dropdown"
name="' . esc_attr( $name ) . '"
id="saved_' . esc_attr( $post_type ) . '"
data-placeholder="' . $placeholder . '"
data-search-placeholder="' . $search_placeholder . '" ' .
( $creation_enabled ?
'data-freeform
data-sticky-search
data-create-choice-template="' . __( 'Click to create new "' . <?php printf( esc_html__( '%s:', 'the-events-calendar' ), $this->singular_name ); ?> . '": <b><%= term %></b>', 'the-events-calendar' ) . '"
data-allow-html ' : '' ) .
'data-options="' . esc_attr( json_encode( $data ) ) . '"' .
( empty( $current ) ? '' : ' value="' . esc_attr( $current ) . '"' ) .
'>';
i have this line code to display that
<?php printf( esc_html__( '%s:', 'the-events-calendar' ), $this->singular_name ); ?>
remove php code in printf( esc_html__( '%s:', 'the-events-calendar' ), $this->singular_name );
<?php
echo '<input
type="hidden"
class="tribe-dropdown linked-post-dropdown"
name="' . esc_attr( $name ) . '"
id="saved_' . esc_attr( $post_type ) . '"
data-placeholder="' . $placeholder . '"
data-search-placeholder="' . $search_placeholder . '" ' .
( $creation_enabled ?
'data-freeform
data-sticky-search
data-create-choice-template="' . __( 'Click to create new "' .printf( esc_html__( '%s:', 'the-events-calendar' ), $this->singular_name ). '": <b><%= term %></b>', 'the-events-calendar' ) . '"
data-allow-html ' : '' ) .
'data-options="' . esc_attr( json_encode( $data ) ) . '"' .
( empty( $current ) ? '' : ' value="' . esc_attr( $current ) . '"' ) .
'>';
?>
if ($post_type == 'tribe_venue'){
echo '<input
type="hidden"
class="tribe-dropdown linked-post-dropdown"
name="' . esc_attr( $name ) . '"
id="saved_' . esc_attr( $post_type ) . '"
data-placeholder="' . $placeholder . '"
data-search-placeholder="' . $search_placeholder . '" ' .
( $creation_enabled ?
'data-freeform
data-sticky-search
data-create-choice-template="' . __( 'Click to create new venue: <b><%= term %></b>', 'the-events-calendar' ) . '"
data-allow-html ' : '' ) .
'data-options="' . esc_attr( json_encode( $data ) ) . '"' .
( empty( $current ) ? '' : ' value="' . esc_attr( $current ) . '"' ) .
'>';
}else{
echo '<input
type="hidden"
class="tribe-dropdown linked-post-dropdown"
name="' . esc_attr( $name ) . '"
id="saved_' . esc_attr( $post_type ) . '"
data-placeholder="' . $placeholder . '"
data-search-placeholder="' . $search_placeholder . '" ' .
( $creation_enabled ?
'data-freeform
data-sticky-search
data-create-choice-template="' . __( 'Click to create new organizer: <b><%= term %></b>', 'the-events-calendar' ) . '"
data-allow-html ' : '' ) .
'data-options="' . esc_attr( json_encode( $data ) ) . '"' .
( empty( $current ) ? '' : ' value="' . esc_attr( $current ) . '"' ) .
'>';
}
This solution worked fine

Wordpress - using variable in menu URL

Is it possible to use php variable in menu URL, that I defined in function.php?
This is actually not working:
For example, in variable $path I store username of every user so they can visit their own profile.
You can use a hook and add the PHP programmatically.
add_filter( 'wp_get_nav_menu_items','nav_items', 11, 3 );
function nav_items( $items, $menu, $args ) {
if( is_admin() )
return $items;
foreach( $items as $item ) {
if( 'profil' == $item->post_title ) {
$current_user = wp_get_current_user();
$username = $current_user->user_login;
$item->url .= '/' . $username;
}
}
return $items;
}
I found this code from another answer on this community.
In Wordpress You Can Do Direct Like this for get the current user details:
<?php
$current_user = wp_get_current_user();
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User email: ' . $current_user->user_email . '<br />';
echo 'User first name: ' . $current_user->user_firstname . '<br />';
echo 'User last name: ' . $current_user->user_lastname . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
echo 'User ID: ' . $current_user->ID . '<br />';
?>
Reference: https://codex.wordpress.org/Function_Reference/wp_get_current_user

How to calculate time range between sale start and sale end including the second?

Let me say about the condition I need to ask:
I display the start sale and end sale for a product on WooCommerce. The code on loop like this:
<?php $thepostid = get_the_ID();
if ( $date = get_post_meta( $thepostid, '_sale_price_dates_from', true ) ) {
$sale_price_dates_from =
'<div class="fromsale">' .
'<span class="promodesc">' . esc_html__( 'Sale start:', 'mytheme' ). '</span>' .
'<span class="m">' . date_i18n( 'M', $date ) . '</span> ' .
'<span class="d">' . date_i18n( 'j', $date ) . '</span> ' .
'</div>'
;
} else {
$sale_price_dates_from =
'<div class="endsale">' .
'<span class="promodesc">' . esc_html__( 'No Schedule', 'mytheme' ). '</span> ' .
'</div>'
; }
echo $sale_price_dates_from ;
?>
<?php $thepostid = get_the_ID();
if ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) {
$sale_price_dates_to =
'<div class="endsale">' .
'<span class="promodesc">' . esc_html__( 'Sale end:', 'mytheme' ). '</span>' .
'<span class="m">' . date_i18n( 'M', $date ) . '</span> ' .
'<span class="d">' . date_i18n( 'j', $date ) . '</span> ' .
'</div>'
;
} else {
$sale_price_dates_to =
'<div class="endsale">' .
'<span class="promodesc">' . esc_html__( 'No Schedule', 'mytheme' ). '</span> ' .
'</div>'
; }
echo $sale_price_dates_to ;
?>
The result is like this:
Sale start: May 13
Sale end: May 22
I am curious, how to get times range between the start and the end? In this case I want to display the countdown like this (for example):
Sale will be end: 7days 20hours 33minutes 22seconds.
Can anyone help me?
Thank for any kind of helps.

wordpress menu link function

I have added the code below to my functions.php to add a "Login" Link to my wp menu.
$newlink = '<li>' . $args->before . '<a title="Login" href="'. wp_login_url('index.php') .'">' . $args->link_before . 'Login' . $args->link_after . '</a>' . $args->after;
how can i change wp_login_url function to use another page? For example, I'm using the mingle plugin which creates a custom login page.
code below from wp-includes/general-template.php
function wp_login_url($redirect = '', $force_reauth = false) {
$login_url = site_url('wp-login.php', 'login');
if ( !empty($redirect) )
$login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
if ( $force_reauth )
$login_url = add_query_arg('reauth', '1', $login_url);
return apply_filters('login_url', $login_url, $redirect);
}
I would not recommend changing the core code of WordPress as you will likely break the install.
Can you not just update your functions.php file line of code to be something like:
$newlink = '<li>' . $args->before . '<a title="Login" href="/login/">' . $args->link_before . 'Login' . $args->link_after . '</a>' . $args->after;

Categories