-
core
WordPress 5.4
https://www.wp-plugin-api.com/version/wordpress-5-4/ https://wordpress.org/news/2020/03/adderley/ https://ja.wordpress.org/2020/04/01/adderley/ -
woocommerce_checkout_process
WooCommerce Get Order Product Details Before Payment in Plugin
The woocommerce_checkout_process hook is very useful when you want to validate anything before the order is processed. add_action(‘woocommerce_checkout_process’, ‘woocommerce_get_data’, 10); function woocommerce_get_data(){ $cart = array(); $items = WC()->cart->get_cart(); foreach($items as $i=>$fetch){ $item = $fetch[‘data’]->post; $cart[]=array( ‘code’ => $fetch[‘product_id’], ‘name’ => $item->post_title, ‘description’ => $item->post_content, ‘quantity’ => $fetch[‘quantity’], ‘amount’ => get_post_meta($fetch[‘product_id’], ‘_price’, true) ); } $user = wp_get_current_user(); $data = array( ‘total’ => WC()->cart->total, ‘cart’ => $cart, ‘user’ => array( ‘id’ => $user->ID, ‘name’ => join(‘ ‘,array_filter(array($user->user_firstname, $user->user_lastname))), ‘mail’ => $user->user_email, ) ); $_SESSION[‘woo_data’]=json_encode($data); } https://stackoverflow.com/questions/42784075/woocommerce-get-order-product-details-before-payment-in-plugin -
Change comment author
When you don’t want to show the comment author’s email, you would want to replace it with something else. add_filter( ‘comment_author’, ‘wpa_custom_comment_author’, 10, 2 ); function wpa_custom_comment_author( $author, $commentID ) { $comment = get_comment( $commentID ); $user = get_user_by( ’email’, $comment->comment_author_email ); if( !$user ): return $author; else: return substr( $comment->comment_author_email, 0,2 ) . ‘****’; endif; } -
woocommerce_is_purchasable
How to disable cart functionality from Woocommerce
tested on WordPress 5.3.2 WooCommerce 3.9.3 // DISABLING PURCHASE FUNCTIONALITY AND REMOVING ADD TO CART BUTTON FROM NORMAL PRODUCTS add_filter( ‘woocommerce_is_purchasable’, ‘__return_false’); // REMOVING PRICE FROM VARIATIONS remove_action(‘woocommerce_single_variation’, ‘woocommerce_single_variation’, 10); // REMOVING ADD TO CART BUTTON FROM VARIATIONS remove_action(‘woocommerce_single_variation’, ‘woocommerce_single_variation_add_to_cart_button’, 20); Reference: https://stackoverflow.com/questions/29314168/how-to-disable-cart-functionality-from-woocommerce -
cron_schedules
How to run wp-cron every x minutes
add_filter( ‘cron_schedules’, ‘cron_add_5min’ ); function cron_add_5min( $schedules ) { $schedules[‘5min’] = array( ‘interval’ => 5*60, ‘display’ => __( ‘Once every five minutes’ ) ); return $schedules; } if ( ! wp_next_scheduled( ‘my_task_hook’ ) ) { wp_schedule_event( time(), ‘5min’, ‘my_task_hook’ ); } add_action( ‘my_task_hook’, ‘do_stuff’ ); function do_stuff(){ // do stuff } -
admin_head
Remove content editor for front page
add_action(‘admin_head’, ‘remove_frontpage_content_editor’); function remove_frontpage_content_editor(){ if( is_front_page() ) remove_post_type_support(‘page’, ‘editor’); } -
admin_init
Disable non-admin users’ access to wp-admin, but allow admin-ajax
function redirect_non_admin_user(){ if ( !defined( ‘DOING_AJAX’ ) && !current_user_can(‘administrator’) ){ wp_redirect( site_url() ); exit; } } add_action( ‘admin_init’, ‘redirect_non_admin_user’ ); Reference: https://stackoverflow.com/questions/9408334/wordpress-admin-ajax-results-in-error-302-redirect https://stackoverflow.com/questions/9408334/wordpress-admin-ajax-results-in-error-302-redirect -
manage_posts_columns
How to add a column with Featured Thumbnail to wp-admin
How to add a column with Featured Thumbnail to wp-admin without using plugins. You can specify the size of the thumbnail using the_post_thumbnail(). add_filter(‘manage_posts_columns’, ‘posts_columns’, 5); add_action(‘manage_posts_custom_column’, ‘posts_custom_columns’, 5, 2); function posts_columns($defaults){ $defaults[‘show_post_thumbnail’] = __(‘Thumbnail’); return $defaults; } function posts_custom_columns($column_name, $id){ if($column_name === ‘show_post_thumbnail’){ // echo the_post_thumbnail( ‘thumbnail’ ); echo the_post_thumbnail( array(50,50) ); } } -
script_loader_src
How to Clean up WordPress Header Section without any Plugin?
https://crunchify.com/how-to-clean-up-wordpress-header-section-without-any-plugin/ -
shutdown
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[] […]