WordPress: Add custom add_filter for custom functions

You can use the apply_filters function: function koku_crm_send_sendgrid($sendgrid_api_key, $to, $subject, $text, $html) { $to = apply_filters( ‘koku_crm_send_to’, $to ); $sendgrid = new \SendGrid($sendgrid_api_key); $mail = new KCSendGrid\Mail(); $from = new KCSendGrid\Email(get_bloginfo( ‘name’ ), get_bloginfo( ‘admin_email’ )); $mail->setFrom($from); $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, ‘UTF-8’)); $content = new KCSendGrid\Content(“text/plain”, $text); $mail->addContent($content); $content = new KCSendGrid\Content(“text/html”, $html); $mail->addContent($content); $personalization = new … Read more

How do I run code every 24 hours?

To run something every 24 hours, you can use the WP Cron system. However, keep in mind: wp-cron is ran/checked after every page load. If nobody visits your site for 2 days no cron jobs can run, it needs visitors to get an opportunity to run Because it needs visitors to the site for the … Read more

Woocommerce – get_items() returns empty array

The solution that was provided here did not work for me. It seems that the order items are assigned to the order after the woocommerce_new_order hook is triggered. I only managed to sort my issues after I changed the hook to woocommerce_checkout_order_processed as per below: add_action( ‘woocommerce_checkout_order_processed’, ‘get_order_items_on_checkout’, 50, 3 ); function get_order_items_on_checkout($order_id, $posted_data, $order){ … Read more

How do you restart php-fpm?

Note: prepend sudo if not root Using SysV Init scripts directly: /etc/init.d/php-fpm restart # typical /etc/init.d/php5-fpm restart # debian-style /etc/init.d/php7.0-fpm restart # debian-style PHP 7 Using service wrapper script service php-fpm restart # typical service php5-fpm restart # debian-style service php7.0-fpm restart # debian-style PHP 7 Using Upstart (e.g. ubuntu): restart php7.0-fpm # typical (ubuntu … Read more

Validate and Sanitize WP REST API Request using WP JSON Schema?

You’re already providing a schema, the parameters in args are their own schemas, but WordPress does not enforce this schema or perform sanitisation/validation by default. You can make WordPress enforce it though by setting the validation and sanitisation callbacks to the following: ‘sanitize_callback’ => ‘rest_sanitize_request_arg’, ‘validate_callback’ => ‘rest_validate_request_arg’, rest_validate_request_arg will look up the parameter in … Read more

How to show every second user different types of banners?

Instead of using the Options API, you’d be better off using the Transients API, however in either case you’ll be polluting the *_options table (even if you use transients with expiration times). I’d possibly recommend using wp-session-manager plugin by EAMann’s which will allow you to use and store $_SESSION data in a dedicated sessions database … Read more