Advertisement
Beee

register acf shortcode

Oct 9th, 2016
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.46 KB | None | 0 0
  1. /**
  2.  * Register link shortcode, example:
  3.  * - [registerlink text="XXX"]
  4.  *
  5.  * @param   array $attr
  6.  * @return  string
  7.  */
  8. function shortcode_acf_form($attributes)
  9. {
  10.     $attr = shortcode_atts(array(
  11.         'id' => ''
  12.     ), $attributes);
  13.     $error      = false;
  14.  
  15.     if ( isset($_GET['updated']) ) {
  16.         if ( $_GET['updated'] == true ) {
  17.  
  18.             // add submission successfull message
  19.             if ( is_page('submit') ) {
  20.                 dvp_errors()->add('ad_submit_success', __('Your ad is successfully submitted. We will review it a.s.a.p.', 'dvp'));
  21.             } else {
  22.                 dvp_errors()->add('ad_update_success', __('Your ad is successfully updated. We will review it a.s.a.p.', 'dvp'));
  23.             }
  24.         }
  25.     }
  26.  
  27.     if ( !isset($_GET['id']) ) {
  28.         $post_id = 0;
  29.     } else {
  30.         $post_id = $_GET['id'];
  31.     }
  32.     if ( $attr['id'] == 0 ) {
  33.         $post_id            = 'new_post';
  34.         $submit_button      = __('Submit profile', 'dvp');
  35.         $updated_message    = false;
  36.     } else {
  37.         $post_id            = $attr['id'];
  38.         $submit_button      = __('Update profile', 'dvp');
  39.         $updated_message    = false;
  40.     }
  41.     $user_id            = get_current_user_id();
  42.     $user_info          = get_userdata($user_id);
  43.     $get_posts          = get_posts(array(
  44.         'post_type'     => DVPPostTypes::POSTTYPE,
  45.         'post_status'   => array('publish','pending','draft'),
  46.         'author'        => $user_id,
  47.     ));
  48.     $user_post_count    = count($get_posts);
  49.     if ( in_array('administrator', $user_info->roles) ) {
  50.         $allowed_ads = 999999;
  51.     } else if ( in_array('agency', $user_info->roles) ) {
  52.         $allowed_ads = 10;
  53.     } else {
  54.         $allowed_ads = 1;
  55.     }
  56.  
  57.     dvp_show_error_messages();
  58.  
  59.     if ( !isset($_GET['updated']) ) {
  60.         if ( is_page('submit') && $user_post_count >= $allowed_ads ) {
  61.             $sorry_message = '<div class="dvp_errors">';
  62.             $sorry_message .= '<div class="error">';
  63.  
  64.             // $sorry_message = '<p>';
  65.             $sorry_message .= __('Sorry, you have reached the maximum allowed ads. Delete your ad to submit a new one.', 'dvp');
  66.             // $sorry_message .= __('If you want to be able to place more ads, <a href="/go-vip/">click here</a>.', 'dvp');
  67.             // $sorry_message .= '</p>';
  68.             $sorry_message .= '</div>';
  69.             $sorry_message .= '</div>';
  70.             $sorry_message .= '<p>';
  71.             $sorry_message .= __('<a href="/profiel/">Click here</a> to go to your profile page.', 'dvp');
  72.             $sorry_message .= '</p>';
  73.             return $sorry_message;
  74.         } else {
  75.  
  76.             return acf_form(array(
  77.                 'post_id'           => $post_id,
  78.                 'submit_value'      => $submit_button,
  79.                 'updated_message'   => $updated_message,
  80.                 'new_post'          => array(
  81.                     'post_type'         => DVPPostTypes::POSTTYPE,
  82.                     'post_status'       => 'pending'
  83.                 ),
  84.             ));
  85.  
  86.         }
  87.     } else { // if post is submitted or new
  88.  
  89.         if ( is_page('edit-advertentie') && isset($_GET['updated']) ) {
  90.             return acf_form(array(
  91.                 'post_id'           => $post_id,
  92.                 'submit_value'      => $submit_button,
  93.                 'updated_message'   => $updated_message
  94.             ));
  95.         }
  96.  
  97.     }
  98.     $errors = dvp_errors()->get_error_messages();
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement