Self-Host Your Static Assets

One of the quickest wins—and one of the first things I recommend my clients do—to make websites faster can at first seem counter-intuitive: you should self-host all of your static assets, forgoing others’ CDNs/infrastructure. In this short and hopefully very straightforward post, I want to outline the disadvantages of hosting your static assets ‘off-site’, and the overwhelming benefits of hosting them on your own origin. What Am I Talking About? It’s not uncommon for developers to link to static assets such as libraries or plugins that are hosted at a…

Web Design Weekly #355

Headlines What Does it Mean to Be “Full Stack”? If you are confused about the term “Full Stack” this post by Chris Coyier might shed some light on what it means in this day and age. (css-tricks.com) Google Fonts is Adding Font-Display (zachleat.com) Articles Unraveling the JPEG JPEG images are everywhere in our digital lives, but behind the veil of familiarity lie algorithms that remove details that are imperceptible to the human eye. This produces the highest visual quality with the smallest file size, but what does that look like?…

php preg_match with multiple patterns

I am trying to combine two preg_match patterns separate with ,|,. /blog/page/[0-9]+/?$/ with /tag/ skip in /blog/page/ and /tag/ /page/[0-9]+/?$/ with /[0-9]+/?$/ ex. /page/2/ and only /2/ /(page/[0-9]+/?)$/ with /([0-9]+/?)$/ function redirect_pagination() { if(!preg_match(‘/blog/page/[0-9]+/?$/,|,/tag/’, $_SERVER[‘REQUEST_URI’])) { if(preg_match(‘/page/[0-9]+/?$/,|,/[0-9]+/?$/’, $_SERVER[‘REQUEST_URI’])) { $new_url = preg_replace(‘/(page/[0-9]+/?)$/,|,/([0-9]+/?)$/’,  », $_SERVER[‘REQUEST_URI’]); wp_redirect($new_url, 301); exit; } } } add_action( ‘init’, ‘redirect_pagination’, 1 ); Source: https://wordpress.stackexchange.com/feeds

Make authorization mandatory on custom routes

I’m setting up multiple custom api routes in my wordpress theme and I would like that to require a JWT token to access. So I have followed the steps in order to get the JWT Authentication for WP Rest API plugin and I am able to successfully get a token and use it on default routes. However, on custom routes it is not needed and if no Authorization header is specified I successfully get the data from route. If I provide an Authorization with a bad bearer token then the…

How to keep HTML form field that is conditional hidden with javasript hidden after page reload?

I have an html form in which I conditionally hide a field with javascript if an option is selected in the dropdown. The javascript condition works fine but when the page is reloaded the condition is lost even though the right option is still selected. Steps to recreate: I have a js code to store user input in session storage because my users might sometimes have to go to another page and come back to the form later. I have a js code to conditionally hide a field named price_input_div…

Updating Custom WordPress User Meta Field via REST API

I have created an empty user meta field for a user called phone_number via the add_user_meta() function. When I use the get_user_meta function, I can see an empty string for the meta field which is what I would expect. But when I access the endpoint for the user via the REST API e.g. /wp-json/wp/v2/users/8, there is an empty meta array, why? How do I update the phone_number empty meta field I created earlier via the REST API? Source: https://wordpress.stackexchange.com/feeds

Web Design Weekly #354

Headlines What is design? Berlin based designer, Koos Looijesteijn does a pretty great job at looking at the different angles and coming up with a concise answer in this post. (kooslooijesteijn.net) Inside Microsoft’s surprise decision to work with Google (theverge.com) Articles Implementing a Mockup: CSS Layout Step by Step In this post, Dave Ceddia shows us a way to approach layouts wholistically, as a cohesive problem to be solved. Top notch post. (daveceddia.com) Technical debt — leverage or liquidate? It’s not always a case of debt = bad. Used intelligently, technical debt…

Update coupon amount after checkout

I have created custom coupons per logged in customers and set their initial amount to 0. After that by continuing customers to buy more they get i.e 10$ coupon amount increase that can be used in their next purchases. this way every custom coupon that belongs to that customer should be updated in every usage. In order to make them special per customer, I used customer email and also woocommerce_coupon_is_valid hook as follow: add_filter( ‘woocommerce_coupon_is_valid’, ‘coupon_is_valid’, 10, 2); function coupon_is_valid($result, $coupon){ $restricted_emails = $coupon->get_email_restrictions(); return ( in_array( wp_get_current_user()->user_email, $restricted_emails )…