-
WordPress 4.7 – first beta available
Today, WordPress development team has announced first beta release of WordPress 4.7. Final release is slated on Dec 6th, good time to release new WordPress thoug. Biggest thing for common users is new default theme. Guess the name… yes, you are right – Twenty Seventeen 🙂 What else? Multi-language support for administrators, video headers, PDF thumbnails, expanded Settings Registration API, post type templates and many many more. You have to see it!
-
Google Analytics
Some of you know, that I wrote Google Analytics Head plugin for WordPress (freely available in WordPress repository). Of course I use it on my webpages, and today I look at its results. Well, I was impressed! Almost 22% from India! Second place – Canada (over 10%) and third – USA (about 5%). Well, I heard a lot about programmers in India, thank you for using my blog! Most popular article is, no surprises here, Insert new woocommerce product programmatically. I like it, too. I hope we will meet in the future!
-
Add woocommerce category programmatically
As I promised in this article Assign woocommerce product categories programmatically, I will explain how to create woocommerce category programmatically. It is very easy, just use this code: [crayon-66dc9e8a53c96464249743/] You should get something like this: [crayon-66dc9e8a53c9c448163035/] However, sometimes you may get WP_Error. Sometimes, category may already exists. You must check the result, if it isn’t WP_Error object. So, if you need to add category or get existing category ID, use this: [crayon-66dc9e8a53c9f528537061/] This code uses PHP7 construction (?? – null coalesce operator), you may substitute it with isset when using earlier PHP version (or much better – upgrade your PHP or your hosting operator!) Remember to wrote this code in…
-
Assign woocommerce product categories programmatically
How to assign categories for your Woocommerce products programmatically? Well, it isn’t that hard. First of all, you must know the ID of your product. If you insert your product programmatically, it is easy, you got it. If not, you can see ID for many ways, for example in your edit screen (something like http://example.com/wp-admin/post.php?post=123&action=edit – 123 is your product ID). Let’s assume you’ve got your product ID in the $product_id variable. Now, you must decide if you want to assign product to existing category or create category by yourself? Well, if you already got category, you need your term ID. How to get it? Go to product categories list…
-
Deleting non empty directory
I assume that you are aware of the rmdir function. This is very useful function, however it has its own limitations. The biggest one is that you are not able to delete non empty folders. We need to build our own function. First, we will use recursion and second – this actually won’t be a function. We will write a method instead. Of course you may translate it into function, it is very easy (just remove $this->). [crayon-66dc9e8a65020163430716/] Please remember – this is a method, part of the class.
-
Different value and label of the input submit
Once upon a time (today), I stuck into this problem: I needed GET form with a few submit inputs. However, I needed numeric GET values (1-5) but I wanted to keep it simple for users – and I needed different labels than values… After some thinking, I figured it out. I can’t use input submit, I must use button! And here we are: [crayon-66dc9e8a655f0862089261/] A piece of cake.
-
Showing all errors, warnings, notices…
Why would you like to show all errors, warnings, notices, etc? Well, this is the first and easiest way to debug your PHP script. Of course there is a bunch of scripts and debug tools out there, but we do not need sledgehammer to crack a nut, don’t we? So, first thing is to turn this on on your local or staging server. Second thing, but even more important!, is to turn it off on your production server! You don’t want your users to see what is wrong this way. OK, let’s go to code: [crayon-66dc9e8a65a25397227914/] And that’s all! Of course you may need it more complicated way. Something like:…