Change language for Google reCaptcha v3 - wordpress

I using Google reCaptcha v3 for contactform 7 to my Wordpress site. There is always a little fane in the lower right corner that shows the privacy term. But it is in Danish even the whole website is in English. How can I change the language of it?

add this code to function.php
add_action( 'wpcf7_enqueue_scripts', 'custom_recaptcha_enqueue_scripts', 11 );
function custom_recaptcha_enqueue_scripts() {
wp_deregister_script( 'google-recaptcha' );
$url = 'https://www.google.com/recaptcha/api.js';
$url = add_query_arg( array(
'onload' => 'recaptchaCallback',
'render' => 'explicit',
'hl' => 'en' ), $url );
wp_register_script( 'google-recaptcha', $url, array(), '2.0', true );
}
for English (UK) use en-GB on
'hl' => 'en' ), $url );

Related

How to send an email to a mailchimp Automation on wordpress post publish

In wordpress, I'm trying to POST a specific email included as a value of a custom field (called customer_email) in each post to a mailchimp automation.
Below is the code I have and it's not working
function email_on_publish( $postid ) {
$api_key = API-KEY;
$workflow_id = WORKFLOW-ID;
$email_id = EMAIL-ID;
$email = get_post_meta( get_the_ID(), 'customer_email', true );
$args = array(
'method' => 'POST',
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key )
),
'body' => json_encode(array(
'email_address' => $email
))
);
$response = wp_remote_post( 'https://' . substr($api_key,strpos($api_key,'-')+1) . '.api.mailchimp.com/3.0/automations/' . $workflow_id . '/emails/' . $email_id . '/queue/' . md5(strtolower($email)), $args );
$body = json_decode( $response['body'] );
}
add_action( 'pending_to_publish', 'email_on_publish' );
add_action( 'draft_to_publish', 'email_on_publish' );
Update: This has been resolved. There were two issues at hand.
I didn't need "md5(strtolower($email)" at the end of the post url.
Mailchimp requires you to send all prior emails in the workflow to the user before adding them to an automation. This was rendering all of my testing useless until I learned that.
Thanks for figuring this out, self!

How to properly save a WordPress option containing HTML code?

Here's a screenshot of what the problem looks like:
And the HTML of that part of the WordPress options page looks like this:
So, in the WordPress admin area, I entered a piece of HTML code (to have a clickable link as the output on the frontend).
This was the code I had entered into that text input field on the backend:
<a title="Website Design London" href="../../website-design/">Website Design</a>
And while on the frontend that link is displaying OK, I'm seeing this mess (see screenshot) on the backend.
As far as I can tell the relevant PHP code is this:
$this->text(
'workdone',
esc_html__( 'Work done', 'mytheme' )
);
So, what is the proper way to save an option that contains HTML code?
And how can I fix the mess shown on the screenshot?
I had the same issue, and this code is working for me:
// render service label
public function render_service_label() {
$value = get_option( 'wbk_service_label', '' );
$value = htmlspecialchars( $value );
$html = '<input type="text" id="wbk_service_label" name="wbk_service_label" value="'.$value.'" >';
$html .= '<p class="description">' . __( 'Service label', 'wbk' ) . '</p>';
echo $html;
}
// validate service label
public function validate_service_label( $input ) {
$allowed_tags = array(
//formatting
'strong' => array(),
'em' => array(),
'b' => array(),
'i' => array(),
'br' => array(),
//links
'a' => array(
'href' => array(),
'class' => array()
),
//links
'p' => array(
'class' => array()
)
);
$input = wp_kses( $input, $allowed_tags );
return $input;
}
So, in the dashboard options page I use htmlspecialchars function
In frontend page I use like this:
$label = get_option( 'wbk_service_label', __( 'Select service', 'wbk' ) );

How do I add a new page using code thru a Wordpress plugin?

I followed the chosen answer here -> How to create new page in wordpress plugin?
and I added the following code in a new Wordpress plugin folder and file and then activated in the Wordpress admin menu. Yet I don't have a new page created when I go to the slug demosite.com/custom/
add_action( 'admin_menu', 'register_newpage' );
function register_newpage(){
add_menu_page('custom_page', 'custom', 'administrator','custom', 'custompage');
remove_menu_page('custom');
}
Do I have to do something special to make my Wordpress plugin code work? I really need to be able to add a new page using my plugin functionality.
For create fronted page when plugin activation used register_activation_hook() like below.
register_activation_hook() function registers a plugin function to be run when the plugin is activated.
The first thing we do on activation is check that the current user is allowed to activate plugins. We do this using the current_user_can function
Finally, we create our new page, after we check that a page with the same name does not exist
register_activation_hook( __FILE__, 'register_newpage_plugin_activation' );
function register_newpage_plugin_activation() {
if ( ! current_user_can( 'activate_plugins' ) ) return;
global $wpdb;
if ( null === $wpdb->get_row( "SELECT post_name FROM {$wpdb->prefix}posts WHERE post_name = 'new-page-slug'", 'ARRAY_A' ) ) {
$current_user = wp_get_current_user();
// create post object
$page = array(
'post_title' => __( 'New Page' ),
'post_status' => 'publish',
'post_author' => $current_user->ID,
'post_type' => 'page',
);
// insert the post into the database
wp_insert_post( $page );
}
}
Here is a full list of parameters accepted by the wp_insert_post function
After plugin active successfully you can access your page using demosite.com/new-page-slug/
I'm not sure if you intended for the page to be created only once if so you should do it during plugin activation.
You might want to consider the following pseudo-ish code:
register_activation_hook( __FILE__, 'moveFile' );
function moveFile(){
if( check if post exists ){
wp_insert_post() # obviously title is "whatever", following convention
#move the file to themes folder
$source = plugin_dir_path(__FILE__) . "page-whatever.php";
$destination = get_template_directory() . "/page-whatever.php";
$cmd = 'cp ' . $source . ' ' . $destination;
exec($cmd);
}
}
It's similar to the code answered by Ankur, but this sample let you have a custom page. Caveat, my method uses exec() command.
I hope this helps.
/* If you want create a page with syn page template on plugin activation so see below example */
register_activation_hook( __FILE__, 'activate' );
function activate() {
$the_slug = 'our-services';
$args = array(
'name' => $the_slug,
'post_type' => 'post',
'post_status' => 'publish',
'numberposts' => 1
);
$my_posts = get_posts($args);
if(empty($my_posts)){
$my_post = array(
'post_title' => 'Our Services',
'post_content' => '',
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page',
'post_name' => 'our-services'
);
// Insert the post into the database
$post_id=wp_insert_post( $my_post );
update_post_meta( $post_id, '_wp_page_template', 'page-templates/our-services.php' );
}
}
/* page-template - our-services.php* /
<?php
/*
* Template Name: our-services
*/
get_header();
get_footer();
?>

Woocommerce: redirect (keep) user in cart page after log-in in cart page

By default, Woocommerce displays the user login box in the checkout page; I wanted it to appear on the cart page as well, so I have added the following to the functions.php file in my theme's directory:
// display login form in cart page
add_action( 'woocommerce_after_cart', 'woocommerce_login_form' );
This works, but after the user log-in, he is redirected to his account page; I would like him to be kept at the cart page, which I think can be done by passing a redirect argument, as per the function's architecture:
function woocommerce_login_form( $args = array() ) {
$defaults = array(
'message' => '',
'redirect' => '',
'hidden' => false
);
$args = wp_parse_args( $args, $defaults );
wc_get_template( 'global/form-login.php', $args );
}
How can I pass an url as an argument to this function?
Thank you for your help.
I have managed to do it be replicating the function with some changes:
// display login form in cart page
add_action( 'woocommerce_after_cart', 'woocommerce_login_form_in_cart' );
function woocommerce_login_form_in_cart( $args = array() ) {
$defaults = array(
'message' => '',
'redirect' => '#',
'hidden' => false
);
$args = wp_parse_args( $args, $defaults );
wc_get_template( 'global/form-login.php', $args );
}

Wordpress Custom Backstretch Image

I'm using a studiopress theme with backstretch script already included. The site's background image is used but I'm using a content delivery network.
At present the image url is:
mysite.com/media/background-image.jpg
I want it to be:
cdn-url.com/media/background-image.jpg
The reason this matters is the site is hosted in Mid-West, US but has a UK audience. The CDN serves static content from London, UK.
I've posted on studiopress support forum but no reply as yet.
The current functions php code is:
//* Enqueue Backstretch script and prepare images for loading
add_action( 'wp_enqueue_scripts', 'agency_enqueue_backstretch_scripts' );
function agency_enqueue_backstretch_scripts() {
//* Load scripts only if custom background is being used
if ( ! get_background_image() )
return;
wp_enqueue_script( 'agency-pro-backstretch', get_bloginfo( 'stylesheet_directory' ) . '/js/backstretch.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_script( 'agency-pro-backstretch-set', get_bloginfo( 'stylesheet_directory' ).'/js/backstretch-set.js' , array( 'jquery', 'agency-pro-backstretch' ), '1.0.0' );
wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => str_replace( 'http:', '', get_background_image() ) ) );
}
Can this be altered to get the result I want?
Editing the last line as below works:
wp_localize_script( 'agency-pro-backstretch-set', 'BackStretchImg', array( 'src' => 'cdn_url_here' ) );

Resources