public function __construct() { $this->templates = array(); $theme_path = untrailingslashit(get_template_directory()); $theme_path .= '/page-templates'; $this->theme_template_path = $theme_path; SB_PHP::create_folder($theme_path); }
public static function fetch_media($image_url) { $attach_id = 0; if (empty($image_url)) { return $attach_id; } $wp_upload_dir = wp_upload_dir(); $base_dir = trailingslashit($wp_upload_dir['basedir']) . 'sb-media'; $base_url = trailingslashit($wp_upload_dir['url']) . 'sb-media'; SB_PHP::create_folder($base_dir); $parts = pathinfo($image_url); $random = rand(); $random = md5($random); $file_name = 'sb-media-' . $parts['filename'] . '-' . $random . '.' . $parts['extension']; $file_path = trailingslashit($base_dir) . $file_name; $file_url = trailingslashit($base_url) . $file_name; if (SB_PHP::copy($image_url, $file_path)) { $attachment = array('guid' => $file_url); $attach_id = self::insert_attachment($attachment, $file_path); } return $attach_id; }