Puddinq.com sharing knowledge

php storm remove exmpty lines

php storm remove exmpty lines

^ asserts position at start of a line Non-capturing group (?:[\t ]*(?:\r?\n|\r)){1,} {1,} matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy) Match a single character present in the list below [\t ] * matches the previous token between zero and unlimited times, as many […]

Format bytes

Regex cheatsheet

Links testing (link) negative lookbehind Find space not precede bij \ Dynamically replace countries with code

Using isset() empty() and is_null()

Validating the input is very important, but you want te write lean code. So if you are in doubt about using !empty only, or !empty && isset here’s the difference: Value of variable ($var) isset($var) empty($var) is_null($var) “” (an empty string) bool(true) bool(true) bool(false) ” ” (space) bool(true) bool(false) bool(false) FALSE bool(true) bool(true) bool(false) TRUE […]

How can you allow editors to clear (manage) the WP Rocket cache

First of, you should look at the official documentation customize-access WP Rocket. This article uses the same technique but adds a trick. When you use the init hook, the function runs every time the hook fires. To reduce this, we have added an option and before we run the full function we check if that […]

WooCommerce add attribute to multiple products (programmatically)

This snippets was used in winkel-centrum.nl, I needed to adjust an import and add colors found in the title as attributes. I had imported the products and wanted to extract a word from the title to add as attribute in the product. I used a shortcode because I wanted to visualize the products I was […]

Insert extra link in yoast breadcrumb

There are a few filters in WordPress to give you the oppertunity to change an aspect, but the variable is an array the has a cetrain order. Yoast breadcrums is a filter like that. If you want to add an extra link to the main blog at the second position it is not as simple […]

PHP use a function in HereDoc

Heredocs are amazing ( under the right circumstances ), using ling strings with variables without endless echo’s or quotes and line endings. But using functions is a bit less convenient. I found the following made it work for me. (example uses the wordpress translation function)