-
How to Log MySQL Errors in WordPress
https://brightbrightgreat.com/2016/03/24/how-to-log-mysql-errors-in-wordpress/ //————————————————- // Database logging – query errors // // email database query errors to the contact // specified // // @param n/a // @return n/a function db_debug_log(){ //WP already stores query errors in this obscure //global variable, so we can see what we’ve ended //up with just before shutdown global $EZSQL_ERROR; try { //proceed if there were MySQL errors during runtime if(is_array($EZSQL_ERROR) && count($EZSQL_ERROR)) { //build a log entry $xout = array(); //let’s start with some environmental information $xout[] = “DATE: ” . current_time(‘r’); $xout[] = “SITE: ” . site_url(); $xout[] = “IP: ” . $_SERVER[‘REMOTE_ADDR’]; $xout[] = “UA: ” . $_SERVER[‘HTTP_USER_AGENT’]; $xout[] = “SCRIPT: ” . $_SERVER[‘SCRIPT_NAME’]; $xout[] […]
-
Disable page’s “page templates” in page attributes
function hoge_remove_page_templates( $templates ) { // use unset() if you want to remove specific template // unset( $templates[‘page-templates/contributors.php’] ); // return $templates; // or just return empty array to remove the entire page templates input return array(); } add_filter( ‘theme_page_templates’, ‘hoge_remove_page_templates’ );
-
Disable Comments
https://gist.github.com/mattclements/eab5ef656b2f946c4bfb
-
Edit oembedded contents
Change excerpt length function wpa_oembed_excerpt_length() { return 20; } add_filter( ‘rest_oembed_output_excerpt_length’, ‘wpa_oembed_excerpt_length’, 9 ); Change oembedded content style function wpa_oembed_output() { ?> <style> .wp-embed { font-family: serif !important; } </style> <?php } add_action( ‘rest_oembed_output’, ‘wpa_oembed_output’, 11 );
-
Add customized fields in Contact Form 7
Add a field in Contact Form 7. In the form, insert [favorite_posts post_titles] In the email content, use [post_titles] In functions.php, add_action( ‘wpcf7_init’, ‘custom_add_form_tag_form_seminars’ ); function custom_add_form_tag_form_seminars() { wpcf7_add_form_tag( ‘favorite_posts’, ‘your_form_shortcode’, array(‘name-attr’ => true) ); // “form_seminars” is the type of the form-tag } function your_form_shortcode( $tag ) { if (!is_object($tag)) return ”; $name = $tag->{‘name’}; if (empty($name)) return ”; ob_start(); $args = array(‘post_type’ => ‘post’, ‘numberposts’ => -1 ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { ?> <table class=”table table-bordered”> <?php while ( $the_query->have_posts() ) { $the_query->the_post(); ?> <tr> <td style=”width:40px;”> <input type=”checkbox” id=”hoge_<?php the_ID(); ?>” name=”<?php echo $name; ?>[]” class=”wpcf7-form-control” value=”<?php echo esc_attr( get_the_title() […]
-
Show Custom Post Types in archive page
Change ‘your-custom-post-type’ to your desired custom post type. You should use $query->is_main_query() to only show these in your archive page (if you don’t, your custom post type posts may show up in your sidebar widget, etc.). function hoge_show_cpt_archives( $query ) { if( is_tag() && $query->is_main_query() ) { $query->set( ‘post_type’, array( ‘post’, ‘your-custom-post-type’ )); return $query; } } add_filter( ‘pre_get_posts’, ‘hoge_show_cpt_archives’ );
-
WooCommerce BCC emails to specific email address
function add_bcc_all_emails( $headers, $object ) { $headers = array( $headers, ‘Bcc: Me <my@mail.net>’ .”\r\n”, ); return $headers; } add_filter( ‘woocommerce_email_headers’, ‘add_bcc_all_emails’, 10, 2 ); https://stackoverflow.com/questions/52924180/woocommerce-bcc-all-mails
-
Remove WooCommerce shipping calculator fields
When calculating the shipping fees, usually the City / Post Code / State fields are not necessary; Country is sufficient. To remove these fields, use the following snippet: add_filter( ‘woocommerce_shipping_calculator_enable_city’, ‘__return_false’ ); add_filter( ‘woocommerce_shipping_calculator_enable_postcode’, ‘__return_false’ ); add_filter( ‘woocommerce_shipping_calculator_enable_state’, ‘__return_false’ );
-
Automatically generate random Post Slug for specific post type
add_filter( ‘wp_unique_post_slug’, ‘custom_unique_post_slug’, 10, 4 ); function custom_unique_post_slug( $slug, $post_ID, $post_status, $post_type ) { if ( $custom_post_type == $post_type ) { $post = get_post($post_ID); if ( empty($post->post_name) || $slug != $post->post_name ) { $slug = md5( time() ); } } return $slug; } Specify $custom_post_type to make it work for a specific post type. https://stackoverflow.com/questions/4518527/customize-the-auto-generation-of-post-slug-in-wordpress
-
Add Privacy Policy Acceptance Checkbox @ WooCommerce Checkout
/** * @snippet Add privacy policy tick box at checkout * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055 * @sourcecode https://businessbloomer.com/?p=19854 * @author Rodolfo Melogli * @testedwith WooCommerce 3.3.4 */ add_action( ‘woocommerce_review_order_before_submit’, ‘bbloomer_add_checkout_privacy_policy’, 9 ); function bbloomer_add_checkout_privacy_policy() { woocommerce_form_field( ‘privacy_policy’, array( ‘type’ => ‘checkbox’, ‘class’ => array(‘form-row privacy’), ‘label_class’ => array(‘woocommerce-form__label woocommerce-form__label-for-checkbox checkbox’), ‘input_class’ => array(‘woocommerce-form__input woocommerce-form__input-checkbox input-checkbox’), ‘required’ => true, ‘label’ => ‘I\’ve read and accept the <a href=”/privacy-policy”>Privacy Policy</a>’, )); } // Show notice if customer does not tick add_action( ‘woocommerce_checkout_process’, ‘bbloomer_not_approved_privacy’ ); function bbloomer_not_approved_privacy() { if ( ! (int) isset( $_POST[‘privacy_policy’] ) ) { wc_add_notice( __( ‘Please acknowledge the Privacy Policy’ ), ‘error’ ); } } https://businessbloomer.com/woocommerce-additional-acceptance-checkbox-checkout/