-
How to remove notices in wp-admin
function pr_disable_admin_notices() { global $wp_filter; if ( is_user_admin() ) { if ( isset( $wp_filter[‘user_admin_notices’] ) ) { unset( $wp_filter[‘user_admin_notices’] ); } } elseif ( isset( $wp_filter[‘admin_notices’] ) ) { unset( $wp_filter[‘admin_notices’] ); } if ( isset( $wp_filter[‘all_admin_notices’] ) ) { unset( $wp_filter[‘all_admin_notices’] ); } } add_action( ‘admin_print_scripts’, ‘pr_disable_admin_notices’ ); I would wrap parts of it using current_user_can(‘administrator’). Reference: https://www.quora.com/How-do-you-remove-WordPress-admin-messages
-
Add menu item to WordPress admin bar
function custom_node_example($wp_admin_bar){ $args = array( ‘id’ => ‘custom-node’, ‘title’ => ‘Custom Node’, ‘href’ => ‘http://example.com/page/’, ‘meta’ => array( ‘class’ => ‘custom-node-class’ ) ); $wp_admin_bar->add_node($args); } add_action(‘admin_bar_menu’, ‘custom_node_example’, 50); http://natko.com/custom-menu-item-position-in-wordpress-admin-bar-toolbar/
-
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; }
-
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
-
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 }
-
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’); }
-
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
-
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) ); } }
-
How to Clean up WordPress Header Section without any Plugin?
https://crunchify.com/how-to-clean-up-wordpress-header-section-without-any-plugin/