1 2 3 4 |
var el = document.getElementById('YourElementID'); var e = document.createEvent("MouseEvents"); e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); el.dispatchEvent(e); |
This often comes up, when you work with jQuery and try to do a simple $(„#YourElementID“).trigger(„click“); or similar.
Our SSL setup is final fixed, after some back and forth.
The Certificate formatting was broken and failed to load ;) Its all in the detail ….
Simple SSL certificates are easily obtained and installed these days. Here some simple first steps to get a Comodo SSL certificate installed.
1 2 |
openssl genrsa –des3 –out yourdomain_com.key 2048 openssl req -new -key yourdomain_com.key -out yourdomain_com.csr |
1 |
cat yourdomain_com.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt > cacert.pem |
Some options to check your SSL setup:
1 |
openssl s_client -showcerts -connect yourdomain.com:443 |
This can be done manually, as shown above or you can use a shell script, which downloads the certificates for you and combines them. SSL certificate chain resolver – This shell script downloads all intermediate CA certificates for a given SSL server certificate. There is even an online version, but I rather do that on my own machine :) … certificatechain.io
Event registration page for Nutricia de VeranderFabriek 2015 (Danone).
Since version 5.6+ PHP is verifying peer certificates and host names by default when using SSL/TLS. This is causing problems on some servers / websites, where the config has not been setup correctly. If you can not fix the setup yourself, make sure to talk to your server host to fix that issue.
For PHPMailer (Github) there is a workaround:
1 2 3 4 5 6 7 |
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); |
This should only be a workaround until your configuration has been fixed. You are suppressing certificate verification and compromising your security!
As WordPress is using PHPMailer as its main email library, this can be tweaked by using the phpmailer_init hook:
1 2 3 4 5 6 7 8 9 10 11 |
add_action( 'phpmailer_init', 'configure_smtp' ); function configure_smtp( $phpmailer ){ $phpmailer->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); } |
Add this to your themes functions.php.
1 2 3 4 5 6 7 8 9 |
$phpmailer = new PHPMailer(); $phpmailer->isSMTP(); $phpmailer->CharSet = 'UTF-8'; $phpmailer->SMTPSecure = "ssl"; // or tls $phpmailer->SMTPAuth = true; $phpmailer->Username = _APP_EMAIL_FROM; $phpmailer->Password = _APP_EMAIL_PASS; $phpmailer->XMailer =' '; $phpmailer->Host= "correct email host"; |
And here is how phpmailer->smtpOptions should be used, on a properly configured server:
1 2 3 4 5 6 7 8 9 |
phpmailer->smtpOptions = array( 'ssl' => array( 'peer_name' => 'your.domain.com', 'verify_peer_name' => true, 'capath' => '/path/to/authority/certificates/directory' # Usually /etc/ssl/certs or /usr/lib/ssl/certs/ 'local_cert' => '/path/to/your.domain.com.crt', # Should be a combined cert & key in pem format 'verify_peer' => true, ) ); |
SSL changes in PHP 5.6: http://php.net/manual/en/migration56.openssl.php
SSL context options in PHP: http://php.net/manual/en/context.ssl.php
Enjoy coding…
Chrome 45+ is glitching on WordPress admin menus.
1 2 3 4 5 6 7 8 9 |
function chromefix_inline_css() { if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Chrome' ) !== false ) { wp_add_inline_style( 'wp-admin', '#adminmenu { transform: translateZ(0); }' ); } } add_action('admin_enqueue_scripts', 'chromefix_inline_css'); |
Online Course Academy. Video Learning platform for universities in the Netherlands.
WooCommerce provides great functionality, but loads a lot of resources even if not needed.
If a site loads longer than 5-7 seconds, potential customers already loose interest :)
Add this to your functions.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
add_action( 'wp_enqueue_scripts', 'cleanup_woocommerce_includes', 99 ); function cleanup_woocommerce_includes(){ //check that woo exists if ( function_exists( 'is_woocommerce' ) ) { if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {} /*Styles*/ wp_dequeue_style( 'woocommerce_frontend_styles' ); wp_dequeue_style( 'woocommerce_fancybox_styles' ); wp_dequeue_style( 'woocommerce_chosen_styles' ); wp_dequeue_style( 'woocommerce_prettyPhoto_css' ); wp_dequeue_style( 'woocommerce-layout' ); wp_dequeue_style( 'woocommerce-smallscreen' ); wp_dequeue_style( 'woocommerce-general' ); wp_dequeue_style( 'wc-bto-styles' ); /*Scripts*/ wp_dequeue_script( 'wc-cart' ); wp_dequeue_script( 'wc-cart-fragments' ); wp_deregister_script( 'wc-add-to-cart' ); wp_dequeue_script( 'wc-add-to-cart' ); wp_deregister_script( 'wc-add-to-cart-variation' ); wp_dequeue_script( 'wc-add-to-cart-variation' ); wp_dequeue_script( 'wc-checkout' ); wp_dequeue_script( 'wc-single-product' ); wp_dequeue_script( 'jquery-blockui' ); wp_dequeue_script( 'wc_price_slider' ); wp_dequeue_script( 'wc-chosen' ); wp_dequeue_script( 'woocommerce' ); wp_dequeue_script( 'prettyPhoto' ); wp_dequeue_script( 'prettyPhoto-init' ); wp_dequeue_script( 'jquery-placeholder' ); wp_dequeue_script( 'fancybox' ); wp_dequeue_script( 'jqueryui' ); } } } |
Like always, make sure that nothing breaks. If things break or are required by certain pages add an exception for that!
Check WordPress Condional Tags.
Sources:
1 2 |
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) ); remove_action('wp_head', 'wc_generator_tag'); |
Simple add this to your wp-config.php
1 2 |
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); |
Use the MU-Domain-Mapping plugin for that.
With inline content being loaded via ajax, you are loosing a lot of interesting usage data. These can be tracked using Google Analytics Events or by sending a Pageview.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
(function($) { track = { config:{ pageName : "Your Page", eventSelector : ".trackEvent a, .trackEvent", pageviewSelector : ".trackPage a, .trackPage", }, init : function(){ $("body").delegate(this.config.eventSelector ,"click", function(){ // Navigation / Readmore / Apply / FAQ / Contact / Share var cat = $(this).attr("data-track-cat") || "Navigation"; var action = $(this).attr("data-track-action") || "Click"; var label = $(this).attr("data-track-label") || $(this).text() ; this.sendEvent(cat, action, label); }); $("body").delegate(this.config.pageviewSelector, "click", function(){ var label = $(this).text() +" - "+ this.config.pageName var page = "/"+label.split(' ').join('-').toLowerCase()+"/"; this.sendPageview(page,label); }); }, sendEvent: function(cat, action, label){ ga('send', 'event', { 'eventCategory' : cat , 'eventAction' : action, 'eventLabel' : label, 'eventValue' : 1 }); }, sendPageview : function(page,label){ ga('send', { 'hitType': 'pageview', 'page' : page , 'title' : label }); } }; /* INIT */ track.init(); })(jQuery); |
The above allows to automate tracking by attaching simple classes and use HTML5 data attributes to assign category, action and label. Direct tracking is also possible. Lets split it up :)
1 2 3 4 5 6 7 8 9 |
$("body").delegate(".trackEvent a, .trackEvent","click", function(){ // Navigation / Readmore / Apply / FAQ / Contact / Share var cat = $(this).attr("data-track-cat") || "Navigation"; var action = $(this).attr("data-track-action") || "Click"; var label = $(this).attr("data-track-label") || $(this).text() ; this.sendEvent(cat, action, label); }); |
This monitors links with the class .trackEVENT attached and fills the event data using HTML5 data attributes. All attributes have default values assigned.
A possible link would look like this:
1 |
<a href="#" class=".trackEvent" data-track-cat="Subscribe" data-track-action="View" data-track-label="All my news!">Subscribe to my news!</a> |
The sendEvent function than sends this to Google Analytics.
1 2 3 4 5 6 7 8 |
$("body").delegate(".trackPage a, .trackPage", "click", function(){ var label = $(this).text() +" - "+ this.pageName var page = "/"+label.split(' ').join('-').toLowerCase()+"/"; this.sendPageview(page,label); }); |
Much simpler, this just gets the element text and submits the click as a new Pageview. The label gets the pagename attached and the actual page url is constructed from the label. The sendPageview function than sends this to Google Analytics.
1 2 3 |
track.sendEvent(cat, action, label); track.sendPageview(page, label); |
Really simple and effective way within a simple OnePager or a bigger web application. BTW I am using delegation to make sure that also links within AJAX content can be tracked.