get_header(); $edit_id = isset( $_GET['edit'] ) ? intval( $_GET['edit'] ) : 0; $message = ''; if ( $edit_id && get_post_field( 'post_author', $edit_id ) != get_current_user_id() && ! current_user_can( 'manage_options' ) ) { $edit_id = 0; } if ( isset( $_POST['mddir_submit_listing'] ) && check_admin_referer( 'mddir_submit' ) ) { $title = sanitize_text_field( wp_unslash( $_POST['listing_title'] ) ); $content = wp_kses_post( wp_unslash( $_POST['listing_content'] ) ); $category = intval( $_POST['listing_category'] ); $location = intval( $_POST['listing_location'] ); $phone = sanitize_text_field( wp_unslash( $_POST['listing_phone'] ) ); $email = sanitize_email( wp_unslash( $_POST['listing_email'] ) ); $website = esc_url_raw( wp_unslash( $_POST['listing_website'] ) ); $address = sanitize_text_field( wp_unslash( $_POST['listing_address'] ) ); $zip = sanitize_text_field( wp_unslash( $_POST['listing_zip'] ) ); $post_data = array( 'post_title' => $title, 'post_content' => $content, 'post_status' => get_option( 'mddir_paid_enabled' ) === '1' ? 'pending' : 'publish', 'post_type' => 'rtcl_listing', 'post_author' => get_current_user_id(), ); if ( $edit_id && ( get_post_field( 'post_author', $edit_id ) == get_current_user_id() || current_user_can( 'manage_options' ) ) ) { $post_data['ID'] = $edit_id; $post_id = wp_update_post( $post_data ); } else { $post_id = wp_insert_post( $post_data ); } if ( $post_id && ! is_wp_error( $post_id ) ) { if ( $category ) { wp_set_post_terms( $post_id, array( $category ), 'rtcl_category' ); } if ( $location ) { wp_set_post_terms( $post_id, array( $location ), 'rtcl_location' ); } update_post_meta( $post_id, 'phone', $phone ); update_post_meta( $post_id, 'email', $email ); update_post_meta( $post_id, 'website', $website ); update_post_meta( $post_id, 'address', $address ); update_post_meta( $post_id, 'zipcode', $zip ); if ( ! empty( $_FILES['listing_image']['name'] ) ) { require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; $attachment_id = media_handle_upload( 'listing_image', $post_id ); if ( ! is_wp_error( $attachment_id ) ) { set_post_thumbnail( $post_id, $attachment_id ); } } if ( get_option( 'mddir_paid_enabled' ) === '1' && ! $edit_id ) { wp_redirect( home_url( '/payment/?listing=' . $post_id ) ); exit; } $message = '
Listing saved.
'; $edit_id = $post_id; } } $current_title = $edit_id ? get_the_title( $edit_id ) : ''; $current_content = $edit_id ? get_post_field( 'post_content', $edit_id ) : ''; $current_phone = $edit_id ? get_post_meta( $edit_id, 'phone', true ) : ''; $current_email = $edit_id ? get_post_meta( $edit_id, 'email', true ) : ''; $current_website = $edit_id ? get_post_meta( $edit_id, 'website', true ) : ''; $current_address = $edit_id ? get_post_meta( $edit_id, 'address', true ) : ''; $current_zip = $edit_id ? get_post_meta( $edit_id, 'zipcode', true ) : ''; ?>