Advertisement
arsh999cg

Current Author has published any post in any of mentioned post types

May 10th, 2023
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2. add_action( 'init', 'arsh_oxy_condition_author_has_cpt_entry' );
  3. function arsh_oxy_condition_author_has_cpt_entry() {
  4.     if ( function_exists( 'oxygen_vsb_register_condition' ) ) {
  5.  
  6.         oxygen_vsb_register_condition(
  7.             'Author has any entry published',
  8.             array(
  9.                 'options' => array('true', 'false'),
  10.                 'custom' => false
  11.             ),
  12.             array('=='),
  13.             'is_user_has_published_post',
  14.             'User'
  15.         );
  16.  
  17.     }
  18. }
  19.  
  20. function is_user_has_published_post( $value, $operator ) {
  21.     $current_user = wp_get_current_user();
  22.     $args = array(
  23.         'author' => $current_user->ID,
  24.         'post_type' => array('opdrachten_personeel', 'opdracht_loonwerk', 'dienstverlen_machver', 'dienstverle_loonwerk', 'dienstverleners_zzp'),
  25.         'post_status' => 'publish'
  26.     );
  27.     $posts = get_posts($args);
  28.  
  29.     if ('true' === $value) {
  30.         if ($posts) { return true; }
  31.     }
  32.     if ('false' === $value) {
  33.         if (!$posts) { return true; }
  34.     }
  35. }
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement