【问题标题】:Excluding admin from Woocommerce job listing steps function从 Woocommerce 工作列表步骤功能中排除管理员
【发布时间】:2018-04-23 03:13:17
【问题描述】:

如果管理员帐户已登录,我如何设置条件以绕过提交作业步骤?有没有可能做到这一点?

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;
}

【问题讨论】:

    标签: php wordpress woocommerce conditional administrator


    【解决方案1】:

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

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

    由于'manage_options'能力仅适用于管理员用户角色,当管理员登录时,您的函数将返回$step而不被它处理......

    或同时使用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-10
      • 1970-01-01
      • 1970-01-01
      • 2020-07-22
      • 2016-10-13
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多