Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Register link shortcode, example:
- * - [registerlink text="XXX"]
- *
- * @param array $attr
- * @return string
- */
- function shortcode_acf_form($attributes)
- {
- $attr = shortcode_atts(array(
- 'id' => ''
- ), $attributes);
- $error = false;
- if ( isset($_GET['updated']) ) {
- if ( $_GET['updated'] == true ) {
- // add submission successfull message
- if ( is_page('submit') ) {
- dvp_errors()->add('ad_submit_success', __('Your ad is successfully submitted. We will review it a.s.a.p.', 'dvp'));
- } else {
- dvp_errors()->add('ad_update_success', __('Your ad is successfully updated. We will review it a.s.a.p.', 'dvp'));
- }
- }
- }
- if ( !isset($_GET['id']) ) {
- $post_id = 0;
- } else {
- $post_id = $_GET['id'];
- }
- if ( $attr['id'] == 0 ) {
- $post_id = 'new_post';
- $submit_button = __('Submit profile', 'dvp');
- $updated_message = false;
- } else {
- $post_id = $attr['id'];
- $submit_button = __('Update profile', 'dvp');
- $updated_message = false;
- }
- $user_id = get_current_user_id();
- $user_info = get_userdata($user_id);
- $get_posts = get_posts(array(
- 'post_type' => DVPPostTypes::POSTTYPE,
- 'post_status' => array('publish','pending','draft'),
- 'author' => $user_id,
- ));
- $user_post_count = count($get_posts);
- if ( in_array('administrator', $user_info->roles) ) {
- $allowed_ads = 999999;
- } else if ( in_array('agency', $user_info->roles) ) {
- $allowed_ads = 10;
- } else {
- $allowed_ads = 1;
- }
- dvp_show_error_messages();
- if ( !isset($_GET['updated']) ) {
- if ( is_page('submit') && $user_post_count >= $allowed_ads ) {
- $sorry_message = '<div class="dvp_errors">';
- $sorry_message .= '<div class="error">';
- // $sorry_message = '<p>';
- $sorry_message .= __('Sorry, you have reached the maximum allowed ads. Delete your ad to submit a new one.', 'dvp');
- // $sorry_message .= __('If you want to be able to place more ads, <a href="/go-vip/">click here</a>.', 'dvp');
- // $sorry_message .= '</p>';
- $sorry_message .= '</div>';
- $sorry_message .= '</div>';
- $sorry_message .= '<p>';
- $sorry_message .= __('<a href="/profiel/">Click here</a> to go to your profile page.', 'dvp');
- $sorry_message .= '</p>';
- return $sorry_message;
- } else {
- return acf_form(array(
- 'post_id' => $post_id,
- 'submit_value' => $submit_button,
- 'updated_message' => $updated_message,
- 'new_post' => array(
- 'post_type' => DVPPostTypes::POSTTYPE,
- 'post_status' => 'pending'
- ),
- ));
- }
- } else { // if post is submitted or new
- if ( is_page('edit-advertentie') && isset($_GET['updated']) ) {
- return acf_form(array(
- 'post_id' => $post_id,
- 'submit_value' => $submit_button,
- 'updated_message' => $updated_message
- ));
- }
- }
- $errors = dvp_errors()->get_error_messages();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement