Example #1
0
 function handle_upload($response, $data)
 {
     $files_base = $data['files']['file'];
     /** Add SVG and other new types */
     add_filter('upload_mimes', array($this, 'tmp_mime_overide'));
     $arr_file_type = wp_check_filetype(basename($files_base['name']));
     $uploaded_file_type = $arr_file_type['type'];
     // Set an array containing a list of acceptable formats
     $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/x-icon', 'image/svg+xml');
     if (in_array($uploaded_file_type, $allowed_file_types)) {
         $files_base['name'] = preg_replace('/[^a-zA-Z0-9._\\-]/', '', $files_base['name']);
         $override['test_form'] = false;
         $override['action'] = 'wp_handle_upload';
         $uploaded_file = wp_handle_upload($files_base, $override);
         $name = sprintf('%s%s', apply_filters('pl_up_image_prefix', 'PageLines-'), addslashes($files_base['name']));
         $attachment = array('guid' => $uploaded_file['url'], 'post_mime_type' => $uploaded_file_type, 'post_title' => $name, 'post_content' => '', 'post_status' => 'inherit');
         $attach_id = wp_insert_attachment($attachment, $uploaded_file['file']);
         $attach_data = wp_generate_attachment_metadata($attach_id, $uploaded_file['file']);
         wp_update_attachment_metadata($attach_id, $attach_data);
         do_action('after_pl_up_image', $attach_id, $attach_data);
     } else {
         $uploaded_file['error'] = __('Unsupported file type!', 'pl-platform');
     }
     /** if there was an error...  */
     if (!empty($uploaded_file['error'])) {
         $error = sprintf(__('Upload Error: %s', 'pl-platform'), $uploaded_file['error']);
         $response = wp_parse_args(array('error' => $error), $response);
     } else {
         /** SIZE - If a specific crop is requested */
         if (isset($data['size']) && $data['size'] != '') {
             $image_array = wp_get_attachment_image_src($attach_id, $data['size']);
             $url = $image_array[0];
         } else {
             $url = $uploaded_file['url'];
         }
         /** SHORTCODE - Replace with path shortcodes */
         $url = pl_uploads_shortcode_url($url);
         /** Set the return response */
         $response = wp_parse_args(array('url' => $url, 'success' => TRUE, 'attach_id' => $attach_id), $response);
     }
     remove_filter('upload_mimes', 'pl_tmp_mime_overide');
     return $response;
 }
Example #2
0
 /**
  * Replace default attachment actions with "Set as header" link.
  *
  * @since 3.4.0
  */
 function attachment_fields_to_edit($form_fields, $post)
 {
     $form_fields = array();
     $attach_id = $post->ID;
     $image_url = wp_get_attachment_url($attach_id);
     $short_img_url = pl_uploads_shortcode_url($image_url);
     $form_fields['buttons'] = array('tr' => sprintf('<tr class="submit"><td></td>
           <td>
           <span class="pl-frame-button admin-blue button" data-selector="%s" data-imgurl="%s" data-short-img-url="%s">%s</span>
           </td></tr>', esc_attr($this->option_id), $image_url, $short_img_url, __('Select This For Option', 'pl-platform')));
     $form_fields['context'] = array('input' => 'hidden', 'value' => 'pl-custom-attach');
     $form_fields['oid'] = array('input' => 'hidden', 'value' => $this->option_id);
     return $form_fields;
 }
Example #3
0
function pl_get_site_logo($shortcode = true)
{
    if (pl_user_setting('site_logo')) {
        $logo = do_shortcode(pl_user_setting('site_logo'));
    } elseif (file_exists(get_template_directory() . '/logo.png')) {
        $logo = get_template_directory_uri() . '/logo.png';
    } else {
        $logo = pl_framework_url('images') . '/leaf.png';
    }
    if ($shortcode) {
        return pl_uploads_shortcode_url($logo);
    } else {
        return $logo;
    }
}