public function upload_post_image() { if (!ap_user_can_upload_image()) { $this->result = array('message' => 'no_permission'); return; } $user_id = get_current_user_id(); $file = $_FILES['post_upload_image']; if ($file['size'] > ap_opt('max_upload_size')) { $this->result = array('message_type' => 'error', 'message' => sprintf(__('File cannot be uploaded, size is bigger then %d Byte'), ap_opt('max_upload_size'))); return; } if (ap_user_upload_limit_crossed($user_id)) { $this->result = array('message' => 'upload_limit_crossed'); return; } if (!is_user_logged_in()) { $this->result = array('message' => 'no_permission'); return; } if (!isset($_POST['__nonce']) || !wp_verify_nonce($_POST['__nonce'], 'upload_image_' . $user_id)) { ap_send_json(ap_ajax_responce('something_wrong')); } if (!empty($file) && is_array($file) && $file['error'] == 0) { $attachment_id = ap_upload_user_file($file); if ($attachment_id !== false) { ap_send_json(ap_ajax_responce(array('action' => 'upload_post_image', 'html' => wp_get_attachment_image($attachment_id, 'full'), 'message' => 'post_image_uploaded', 'attachment_id' => $attachment_id))); } } ap_send_json(ap_ajax_responce('something_wrong')); }
function ap_post_upload_form($post_id = false) { $html = ' <div class="ap-post-upload-form"> <div class="ap-btn ap-upload-o ' . ap_icon('image') . '"> <span>' . __('Add image to editor', 'ap') . '</span>'; if (ap_user_can_upload_image()) { $html .= ' <a class="ap-upload-link" href="#" data-action="ap_post_upload_field"> ' . __('upload', 'ap') . ' </a> ' . __('or', 'ap'); } $html .= '<span class="ap-upload-remote-link"> ' . __('add image from link', 'ap') . ' </span> <div class="ap-upload-link-rc"> <input type="text" name="post_remote_image" class="ap-form-control" placeholder="' . __('Enter images link', 'ap') . '" data-action="post_remote_image"> <a data-action="post_image_ok" class="apicon-check ap-btn" href="#"></a> <a data-action="post_image_close" class="apicon-x ap-btn" href="#"></a> </div> <input type="hidden" name="attachment_ids[]" value="" /> </div>'; $html .= '</div>'; return $html; }