Contact Form 7 – Replace database configured form template with a static file

I answered this question on Stackoverflow, and reposting the answer here. We would never edit it there though, it’d be impossible, quite, the CF7 plugin was never conceived for anything more complex than a contact form unfortunately. You may want to play around with the Smart Grid-layout extension which was specifically designed for creating and … Read more

Warning: in_array() null given in PHP function

Well first you have this code // no matter what the value here, you can forget about it (because in the next line of code you assing a new value to the same variable) $post_types = apply_filters( ‘sortable_wordpress_gallery_post_types’, array( ‘post’ ) ); // only this really matters $post_types = apply_filters( ‘sortable_wordpress_gallery_’ . $this->id . ‘_post_types’, … Read more

How to optimize update_post_meta?

To achieve what you want you’re better creating an associative array and then walking over it with a foreach loop as shown below : $data = array( ‘_shipping_first_name’ => $order->get_billing_first_name(), ‘_shipping_last_name’ => $order->get_billing_last_name(), ‘_shipping_company’ => $order->get_billing_company(), ‘_shipping_address_1’ => $order->get_billing_address_1(), ‘_shipping_address_2’ => $order->get_billing_address_2(), ‘_shipping_postcode’ => $order->get_billing_postcode(), ‘_shipping_city’ => $order->get_billing_city(), ‘_shipping_state’ => $order->get_billing_state(), ‘_shipping_country’ => $order->get_billing_country() ); … Read more

Verify if a category is the child of another category

Yes, there are two functions you can use: For the default category taxonomy, you can use cat_is_ancestor_of(): // Retrieve category object by slug: $parent_cat = get_category_by_slug( ‘clothes’ ); // term object $child_cat = get_category_by_slug( ‘t-shirts’ ); // term object /* Or retrieve category ID by name: $parent_cat = get_cat_ID( ‘Clothes’ ); // term ID $child_cat … Read more

How to update and save user metadata on page visits?

There are lots of actions you can hook into to do this, I think the best once to use would be wp or template_redirect. Using either of those actions the code would be like this, this code goes into the functions.php add_action(‘wp’, ‘bt_update_user_homepage_meta’); function bt_update_user_homepage_meta () { // get user id, if user is not … Read more

Save Custom CSS file in the upload folder dynamically?

Please use this method: // Lets create some test CSS code $css=”/* Some test CSS */ body {background:red;}”; // Stash CSS in uploads directory require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); // We will probably need to load this file global $wp_filesystem; $upload_dir = wp_upload_dir(); // Grab uploads folder array $dir = trailingslashit( $upload_dir[‘basedir’] ) . ‘some-folder/’; … Read more