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
Related
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.
I have PHP code like this:
$html .= '<option value="' . esc_attr( $term->slug ) . '" '
. selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>'
. esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) . $price_html )
. '</option>';
I want to add <span class="XXX"> before $price_html variable and closing span tag after that, so on I can style the price. I tried the code below but no success:
$html .= '<option value="' . esc_attr( $term->slug ) . '" '
. selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>'
. esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) . '<span class="XXX">' . $price_html . '</span>')
. '</option>';
Any help?
Edit: the code block i am trying to edit:
// Utility function to get the price of a variation from it's attribute value
function get_the_variation_price_html( $product, $name, $term_slug ){
foreach ( $product->get_available_variations() as $variation ){
if($variation['attributes'][$name] == $term_slug ){
return strip_tags( $variation['price_html'] );
}
}
}
// Add the price to the dropdown options items.
add_filter( 'woocommerce_dropdown_variation_attribute_options_html', 'show_price_in_attribute_dropdown', 10, 2);
function show_price_in_attribute_dropdown( $html, $args ) {
// Only if there is a unique variation attribute (one dropdown)
if( sizeof($args['product']->get_variation_attributes()) == 1 ) :
$options = $args['options'];
$product = $args['product'];
$attribute = $args['attribute'];
$name = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
$id = $args['id'] ? $args['id'] : sanitize_title( $attribute );
$class = $args['class'];
$show_option_none = $args['show_option_none'] ? true : false;
$show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __( 'Choose an option', 'woocommerce' );
if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
$attributes = $product->get_variation_attributes();
$options = $attributes[ $attribute ];
}
$html = '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '" data-show_option_none="' . ( $show_option_none ? 'yes' : 'no' ) . '">';
$html .= '<option value="">' . esc_html( $show_option_none_text ) . '</option>';
if ( ! empty( $options ) ) {
if ( $product && taxonomy_exists( $attribute ) ) {
$terms = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );
foreach ( $terms as $term ) {
if ( in_array( $term->slug, $options ) ) {
// Get and inserting the price
$price_html = get_the_variation_price_html( $product, $name, $term->slug );
$html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) . $price_html ) . '</option>';
}
}
} else {
foreach ( $options as $option ) {
$selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false );
// Get and inserting the price
$price_html = get_the_variation_price_html( $product, $name, $term->slug );
$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) . ' = ' . $price_html ) . '</option>';
}
}
}
$html .= '</select>';
endif;
return $html;
}
The reason why you don't see the desired output is in esc_html() function. Also, <span> tag inside a <option> tag doesn't get any CSS styles. You have to place desired class="XXX" inside the <option> tag.
For now you have something like:
<option value="123">escaped_price_html</option>
Replace lines:
'<option value="' . esc_attr( $term->slug ) . '" '
with
'<option class="XXX" value="' . esc_attr( $term->slug ) . '" '
and
. esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) . '<span class="XXX">' . $price_html . '</span>')
with
. esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) . $price_html)
which will change the structure on:
<option class="XXX" value="123">escaped_price_html</option>
.x{
color: blue;
font-weight: bold;
}
<select>
<option value="1"><span class="x">TEXT1</span></option>
<option class="x" value="2"><span>TEXT2</span></option>
<option value="3"><span class="x">TEXT3</span></option>
</select>
I want to accomplish 2 things in my woocommerce checkout form:
1. Put some text between some groups of fields, for example (h3):
<h3>my custom heading</h3>
<p class="form-row form-row validate-required">
<input type="email">...
</p>
<h3>my other custom heading</h3>
<p class="form-row form-row validate-required">
<input type="text">...
</p>
<p class="form-row form-row validate-required">
<input type="text">...
</p>
2. Display input tag first and label tag as second in html (woocommerce display label before input by default)
I figured out that checkout form is displayed by this code (for billing):
<?php foreach ( $checkout->checkout_fields['billing'] as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
How can I customize it in way I described?
I'm not sure on part 1, but for part 2, you can modify the output of woocommerce_form_field() by filtering woocommerce_form_field_$type.
So your part 2 can be solved like so:
function so_39267627_form_field( $field, $key, $args, $value ){
if ( $args['required'] ) {
$args['class'][] = 'validate-required';
$required = ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>';
} else {
$required = '';
}
$args['maxlength'] = ( $args['maxlength'] ) ? 'maxlength="' . absint( $args['maxlength'] ) . '"' : '';
$args['autocomplete'] = ( $args['autocomplete'] ) ? 'autocomplete="' . esc_attr( $args['autocomplete'] ) . '"' : '';
if ( is_string( $args['label_class'] ) ) {
$args['label_class'] = array( $args['label_class'] );
}
if ( is_null( $value ) ) {
$value = $args['default'];
}
// Custom attribute handling
$custom_attributes = array();
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) {
foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
}
}
$field = '';
$label_id = $args['id'];
$field_container = '<p class="form-row %1$s" id="%2$s">%3$s</p>';
$field .= '<input type="' . esc_attr( $args['type'] ) . '" class="input-text ' . esc_attr( implode( ' ', $args['input_class'] ) ) .'" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" ' . $args['maxlength'] . ' ' . $args['autocomplete'] . ' value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
if ( ! empty( $field ) ) {
$field_html = '';
$field_html .= $field;
if ( $args['description'] ) {
$field_html .= '<span class="description">' . esc_html( $args['description'] ) . '</span>';
}
if ( $args['label'] && 'checkbox' != $args['type'] ) {
$field_html .= '<label for="' . esc_attr( $label_id ) . '" class="' . esc_attr( implode( ' ', $args['label_class'] ) ) .'">' . $args['label'] . $required . '</label>';
}
$container_class = 'form-row ' . esc_attr( implode( ' ', $args['class'] ) );
$container_id = esc_attr( $args['id'] ) . '_field';
$after = ! empty( $args['clear'] ) ? '<div class="clear"></div>' : '';
$field = sprintf( $field_container, $container_class, $container_id, $field_html ) . $after;
}
return $field;
}
add_filter( 'woocommerce_form_field_password', 'so_39267627_form_field', 10, 4 );
add_filter( 'woocommerce_form_field_text', 'so_39267627_form_field', 10, 4 );
add_filter( 'woocommerce_form_field_email', 'so_39267627_form_field', 10, 4 );
add_filter( 'woocommerce_form_field_tel', 'so_39267627_form_field', 10, 4 );
add_filter( 'woocommerce_form_field_number', 'so_39267627_form_field', 10, 4 );
You would need to write a few more functions (mostly I copied and pasted whole swaths of code from WooCommerce and then just swapped the label part around ) for other other field types, but this should serve as an example.
For the first one you can do the following to display single input field
<?php
woocommerce_form_field(
"billing_first_name",
$checkout->checkout_fields['billing']['billing_first_name'],
$checkout->get_value( 'billing_first_name' )
);
?>
where you can replace first_name with any key of the checkout billing fields
So for your example it will be something like this
<h3>my custom heading</h3>
<p class="form-row form-row validate-required">
<?php woocommerce_form_field( "billing_email", $checkout->checkout_fields['billing']['billing_email'], $checkout->get_value( 'billing_email' ) ); ?>
</p>
As for the second I'm not sure how you can achieve that. I needed something similar and i used javascript to reposition the labels.
something like :
jQuery('form.checkout label').each(function(){
jQuery(this).insertAfter(jQuery(this).parent().find('input'));
})
As far as I think, woo commerce does not support html, there's a plugin known as woocommerce checkout field editor, see if it solves your issue.
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;
}
I've been looking and trying different things now for about three days with no success; I've asked on other forums and tried searching on Google, Bing and Yahoo and could not find the answer, and I've looked in WordPress.org and still nothing.
Could someone please put me out of my misery and point to how I may achieve this?
Basically at the moment my code looks like this:
$newlink = strtolower(str_replace(' ', '-', $item->title));
if($item->description == 'blog'){
$attributes = ' title="' . esc_attr( $item->title ) .'"';
$attributes .= ' href="' . esc_attr( '#content' ) .'"';
} elseif($item->description == 'home'){
$attributes = ' title="' . esc_attr( $item->title ) .'"';
$attributes .= ' href="' . esc_attr( site_url() ) .'"';
} elseif($item->description == 'linkout'){
$attributes = ' title="' . esc_attr( $item->title ) .'"';
$attributes .= ' href="' . esc_attr( $item->url ) .'"';
} else {
$attributes = ' title="' . esc_attr( $item->title ) .'"';
$attributes .= ' href="' . esc_attr( site_url() . '/#' . $newlink) .'"';
}
But as you may guess this code becomes bad when using languages which use special chars. This is because I am using $item->title.
How do I get the slug which is automatically created and sanitised to account for the special chars? - I thought it would be as simple as $item->slug but it is not :(