从 Woocommerce 职位列表步骤功能中排除管理员

Excluding admin from Woocommerce job listing steps function

How can I set a conditional to bypass the submit job steps if administrator account is logged in? is there's any possibility to do this?

public static function submit_job_steps( $steps ) {
    if ( self::get_packages() && apply_filters( 'wcpl_enable_paid_job_listing_submission', true ) ) {
        // We need to hijack the preview submission to redirect to WooCommerce and add a step to select a package.
        // Add a step to allow the user to choose a package. Comes after preview.
        $steps['wc-choose-package'] = array(
            'name'     => __( 'Choose a package', 'wp-job-manager-wc-paid-listings' ),
            'view'     => array( __CLASS__, 'choose_package' ),
            'handler'  => array( __CLASS__, 'choose_package_handler' ),
            'priority' => 25,
        );
        // If we instead want to show the package selection FIRST, change the priority and add a new handler.
        if ( 'before' === get_option( 'job_manager_paid_listings_flow' ) ) {
            $steps['wc-choose-package']['priority'] = 5;
            $steps['wc-process-package'] = array(
                'name'     => '',
                'view'     => false,
                'handler'  => array( __CLASS__, 'choose_package_handler' ),
                'priority' => 25,
            );
            // If showing the package step after preview, the preview button text should be changed to show this.
        } elseif ( 'before' !== get_option( 'job_manager_paid_listings_flow' ) ) {
            add_filter( 'submit_job_step_preview_submit_text', array( __CLASS__, 'submit_button_text' ), 10 );
        }

        // We should make sure new jobs are pending payment and not published or pending.
        add_filter( 'submit_job_post_status', array( __CLASS__, 'submit_job_post_status' ), 10, 2 );
    }
    return $steps;
}

这可以通过在函数开头添加这一行来完成:

if(current_user_can('manage_options')) return $step;

由于'manage_options' 功能仅适用于管理员用户角色,当管理员登录时,您的功能将 return $step没有被它处理…

或同时使用:

if( get_current_user_id() == 'administrator' ) return $step;