• wp-content/plugins/woocommerce/includes/admin/class-wc-admin-assets.php, line #331
    executes current_user_can() at every page under wp-admin, not only for the products page as it’s supposed according to the code and comment:

    
    330 : 	// Product sorting - only when sorting by menu order on the products page
    331 : 	if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) {
    

    Consider to move current_user_can() to the end of this logic expression in order this function (as more resources consuming) was executed for the related page (products list) only:

    
    if ( 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] && current_user_can( 'edit_others_pages' ) ) {
    

    Btw., why ‘edit_others_pages’ is checking here, but not ‘edit_others_products’? Some WooCommerce site owners allows to users to edit products only, and do not grant them access to the pages.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Code enhancement suggestion’ is closed to new replies.