Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Forked from mikejolley/gist:9668782
Last active August 20, 2018 01:50
Show Gist options
  • Select an option

  • Save mikejolley/20d77105f88e54f0c01e to your computer and use it in GitHub Desktop.

Select an option

Save mikejolley/20d77105f88e54f0c01e to your computer and use it in GitHub Desktop.

Revisions

  1. mikejolley revised this gist May 10, 2014. 1 changed file with 13 additions and 11 deletions.
    24 changes: 13 additions & 11 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -27,17 +27,19 @@ function has_active_job_package_or_job_capability_check( $allcaps, $cap, $args )
    }

    // Has active job listing
    $active_jobs = get_posts( array(
    'post_type' => 'job_listing',
    'post_status' => array( 'publish', 'pending' ),
    'ignore_sticky_posts' => 1,
    'posts_per_page' => 1,
    'author' => get_current_user_id(),
    'fields' => 'ids'
    ) );

    if ( sizeof( $active_jobs ) > 0 ) {
    $allcaps[ $cap[0] ] = true;
    if ( is_user_logged_in() ) {
    $active_jobs = get_posts( array(
    'post_type' => 'job_listing',
    'post_status' => array( 'publish', 'pending' ),
    'ignore_sticky_posts' => 1,
    'posts_per_page' => 1,
    'author' => get_current_user_id(),
    'fields' => 'ids'
    ) );

    if ( sizeof( $active_jobs ) > 0 ) {
    $allcaps[ $cap[0] ] = true;
    }
    }

    return $allcaps;
  2. mikejolley revised this gist May 10, 2014. 1 changed file with 17 additions and 3 deletions.
    20 changes: 17 additions & 3 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    // Hook into user_has_cap filter. This assumes you have setup resumes to require the capability 'has_active_job_package'
    add_filter( 'user_has_cap', 'has_active_job_package_capability_check', 10, 3 );
    add_filter( 'user_has_cap', 'has_active_job_package_or_job_capability_check', 10, 3 );

    /**
    * has_active_job_package_capability_check()
    * has_active_job_package_or_job_capability_check()
    *
    * Filter on the current_user_can() function.
    *
    @@ -12,7 +12,7 @@
    * [1] User ID
    * [2] Associated object ID
    */
    function has_active_job_package_capability_check( $allcaps, $cap, $args ) {
    function has_active_job_package_or_job_capability_check( $allcaps, $cap, $args ) {
    // Only interested in has_active_job_package
    if ( empty( $cap[0] ) || $cap[0] !== 'has_active_job_package' || ! function_exists( 'get_user_job_packages' ) ) {
    return $allcaps;
    @@ -26,5 +26,19 @@ function has_active_job_package_capability_check( $allcaps, $cap, $args ) {
    $allcaps[ $cap[0] ] = true;
    }

    // Has active job listing
    $active_jobs = get_posts( array(
    'post_type' => 'job_listing',
    'post_status' => array( 'publish', 'pending' ),
    'ignore_sticky_posts' => 1,
    'posts_per_page' => 1,
    'author' => get_current_user_id(),
    'fields' => 'ids'
    ) );

    if ( sizeof( $active_jobs ) > 0 ) {
    $allcaps[ $cap[0] ] = true;
    }

    return $allcaps;
    }
  3. mikejolley created this gist Mar 20, 2014.
    30 changes: 30 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    // Hook into user_has_cap filter. This assumes you have setup resumes to require the capability 'has_active_job_package'
    add_filter( 'user_has_cap', 'has_active_job_package_capability_check', 10, 3 );

    /**
    * has_active_job_package_capability_check()
    *
    * Filter on the current_user_can() function.
    *
    * @param array $allcaps All the capabilities of the user
    * @param array $cap [0] Required capability
    * @param array $args [0] Requested capability
    * [1] User ID
    * [2] Associated object ID
    */
    function has_active_job_package_capability_check( $allcaps, $cap, $args ) {
    // Only interested in has_active_job_package
    if ( empty( $cap[0] ) || $cap[0] !== 'has_active_job_package' || ! function_exists( 'get_user_job_packages' ) ) {
    return $allcaps;
    }

    $user_id = $args[1];
    $packages = get_user_job_packages( $user_id );

    // Has active package
    if ( is_array( $packages ) && sizeof( $packages ) > 0 ) {
    $allcaps[ $cap[0] ] = true;
    }

    return $allcaps;
    }