/** * Constructor for the Anthologize class * * This constructor does the following: * - Checks minimum PHP and WP version, and bails if they're not met * - Includes Anthologize's main files * - Sets up the basic hooks that initialize Anthologize's post types and UI * * @since 0.7 */ public function __construct() { // Bail if PHP version is not at least 5.0 if (!self::check_minimum_php()) { add_action('admin_notices', array('Anthologize', 'phpversion_nag')); return; } // Bail if WP version is not at least 3.3 if (!self::check_minimum_wp()) { add_action('admin_notices', array('Anthologize', 'wpversion_nag')); } // If we've made it this far, start initializing Anthologize register_activation_hook(__FILE__, array($this, 'activation')); register_deactivation_hook(__FILE__, array($this, 'deactivation')); // @todo WP's functions plugin_basename() etc don't work // correctly on symlinked setups, so I'm implementing my own $bn = explode(DIRECTORY_SEPARATOR, dirname(__FILE__)); $this->basename = array_pop($bn); $this->plugin_dir = plugin_dir_path(__FILE__); $this->plugin_url = plugin_dir_url(__FILE__); $this->includes_dir = trailingslashit($this->plugin_dir . 'includes'); $upload_dir = wp_upload_dir(); $this->cache_dir = trailingslashit($upload_dir['basedir'] . '/anthologize-cache'); $this->cache_url = trailingslashit($upload_dir['baseurl'] . '/anthologize-cache'); $this->setup_constants(); $this->includes(); $this->setup_hooks(); }
function cherry_plugin_settings() { global $wpdb; if (!function_exists('get_plugin_data')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $upload_dir = wp_upload_dir(); $plugin_data = get_plugin_data(plugin_dir_path(__FILE__) . 'cherry-plugin.php'); //Cherry plugin constant variables define('CHERRY_PLUGIN_DIR', plugin_dir_path(__FILE__)); define('CHERRY_PLUGIN_URL', plugin_dir_url(__FILE__)); define('CHERRY_PLUGIN_DOMAIN', $plugin_data['TextDomain']); define('CHERRY_PLUGIN_DOMAIN_DIR', $plugin_data['DomainPath']); define('CHERRY_PLUGIN_VERSION', $plugin_data['Version']); define('CHERRY_PLUGIN_NAME', $plugin_data['Name']); define('CHERRY_PLUGIN_SLUG', plugin_basename(__FILE__)); define('CHERRY_PLUGIN_DB', $wpdb->prefix . CHERRY_PLUGIN_DOMAIN); define('CHERRY_PLUGIN_REMOTE_SERVER', esc_url('http://tmbhtest.com/cherryframework.com/components_update/')); //Other constant variables define('CURRENT_THEME_DIR', get_stylesheet_directory()); define('CURRENT_THEME_URI', get_stylesheet_directory_uri()); define('UPLOAD_BASE_DIR', str_replace("\\", "/", $upload_dir['basedir'])); define('UPLOAD_DIR', str_replace("\\", "/", $upload_dir['path'] . '/')); // if ( !defined('API_URL') ) { // define( 'API_URL', esc_url( 'http://updates.cherry.template-help.com/cherrymoto/v3/api/' ) ); // } load_plugin_textdomain(CHERRY_PLUGIN_DOMAIN, false, dirname(plugin_basename(__FILE__)) . '/' . CHERRY_PLUGIN_DOMAIN_DIR); do_action('cherry_plugin_settings'); }
/** * Instantiates Env Manager object * */ protected function __construct() { $uploads_data = wp_upload_dir(); $template_url = get_bloginfo('template_url'); // Instantiate paths collection object $this->__urls = new Collection(array('home' => home_url(), 'admin' => admin_url(), 'plugins' => plugins_url(), 'content' => content_url(), 'uploads' => $uploads_data['baseurl'], 'themes' => str_replace('/' . basename($template_url), '', $template_url), 'theme' => $template_url)); }
function grayscale_check_grayscale_image($metadata, $attachment_id) { global $_wp_additional_image_sizes; $attachment = get_post($attachment_id); if (preg_match('!image!', get_post_mime_type($attachment))) { require_once 'class-grayscale-image-editor.php'; foreach ($_wp_additional_image_sizes as $size => $size_data) { if (isset($size_data['grayscale']) && $size_data['grayscale']) { if (is_array($metadata['sizes']) && isset($metadata['sizes'][$size])) { $file = pathinfo(get_attached_file($attachment_id)); $filename = $file['dirname'] . '/' . $metadata['sizes'][$size]['file']; $metadata['sizes'][$size . '-gray'] = $metadata['sizes'][$size]; } else { // this size has no image attached, probably because the original is too small // create the grayscale image from the original file $file = wp_upload_dir(); $filename = $file['basedir'] . '/' . $metadata['file']; $metadata['sizes'][$size . '-gray'] = array('width' => $metadata['width'], 'height' => $metadata['height']); } $image = new Grayscale_Image_Editor($filename); $image->load(); $image->make_grayscale(); $result = $image->save($image->generate_filename('gray')); $metadata['sizes'][$size . '-gray']['file'] = $result['file']; } } } return $metadata; }
/** * __construct() * * The main SRP Class constructor * * @author Luca Grandicelli <*****@*****.**> * @copyright (C) 2011-2014 Luca Grandicelli * @package special-recent-posts-free * @version 2.0.4 * @access public * @global $srp_default_widget_values The global default widget presets. * @global $post The global $post WP object. * @param array $args The widget instance configuration values. * @param string The current Widget ID. * @return boolean true */ public function __construct($args = array(), $widget_id = NULL) { // Setting up uploads dir for multi-site hack. $this->uploads_dir = wp_upload_dir(); // Including global default widget values. global $srp_default_widget_values; // Setting up plugin options to be available throughout the plugin. $this->plugin_args = get_option('srp_plugin_options'); // Double check if $args is an array. $args = !is_array($args) ? array() : SpecialRecentPostsFree::srp_version_map_check($args); // Setting up widget options to be available throughout the plugin. $this->widget_args = array_merge($srp_default_widget_values, $args); // Setting up post/page ID when on a single post/page. if (is_single() || is_page()) { // Including global $post object. global $post; // Assigning post ID. $this->singleID = $post->ID; } // Setting up Cache Folder Base Path. $this->cache_basepath = SRP_CACHE_DIR; // Setting up current widget instance id. $this->widget_id = $widget_id ? $widget_id : false; // Returning true. return true; }
public function getImage($id) { $image_fields = array("ID" => "ID", "guid" => "file", "post_mime_type" => "mime_type"); $indexable_image_size = get_intermediate_image_sizes(); $uploadDir = wp_upload_dir(); $uploadBaseUrl = $uploadDir['baseurl']; $image = new \stdClass(); $post = get_post($id); foreach ($image_fields as $key => $value) { $image->{$value} = $post->{$key}; } $metas = get_post_meta($post->ID, '_wp_attachment_metadata', true); $image->width = $metas["width"]; $image->height = $metas["height"]; $image->file = sprintf('%s/%s', $uploadBaseUrl, $metas["file"]); $image->sizes = $metas["sizes"] ? $metas["sizes"] : array(); foreach ($image->sizes as $size => &$sizeAttrs) { if (in_array($size, $indexable_image_size) == false) { unset($image->sizes[$size]); continue; } $baseFileUrl = str_replace(wp_basename($metas['file']), '', $metas['file']); $sizeAttrs['file'] = sprintf('%s/%s%s', $uploadBaseUrl, $baseFileUrl, $sizeAttrs['file']); } return $image; }
/** * Export data * @param string $format * @param array $options * @throws Exception */ public function export($format = self::EXPORT_DISPLAY, $options = array()) { global $wpdb; $options = array(); $options['upload_dir'] = wp_upload_dir(); $options['options'] = array(); $options['options']['permalink_structure'] = get_option('permalink_structure'); $widgets = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE 'widget_%'"); foreach ($widgets as $widget) { $options['options'][$widget->option_name] = $this->compress(get_option($widget->option_name)); } $options['options']['sidebars_widgets'] = $this->compress(get_option('sidebars_widgets')); $current_template = get_option('stylesheet'); $options['options']["theme_mods_{$current_template}"] = $this->compress(get_option("theme_mods_{$current_template}")); $data = serialize($options); if ($format == self::EXPORT_DISPLAY) { echo '<textarea>' . $data . '</textarea>'; } //export settings to file if ($format == self::EXPORT_FILE) { $path = isset($options['path']) ? $options['path'] : self::getWpOptionsPath(); if (!file_put_contents($path, $data)) { throw new Exception("Cannot save settings to: " . $path); } } }
private static function get_avatar_from_meta($url, $user_id) { static $caches = []; if (isset($caches[$user_id])) { return $caches[$user_id]; } $meta = get_user_meta($user_id, self::$user_meta_key['avatar'], true); if (empty($meta)) { $caches[$user_id] = $url; return $caches[$user_id]; } /** * if is /12/2015/xx.jpg format, add upload baseurl */ if (strpos($meta, 'http') === false || strpos($meta, '//') === false) { static $baseurl; if (!$baseurl) { $baseurl = wp_upload_dir()['baseurl']; } $caches[$user_id] = $baseurl . $meta; } else { $caches[$user_id] = $meta; } return $caches[$user_id]; }
/** * Migrate a single attachment's files to S3 * * @subcommand migrate-attachment * @synopsis <attachment-id> [--delete-local] */ public function migrate_attachment_to_s3($args, $args_assoc) { // Ensure things are active $instance = S3_Uploads::get_instance(); if (!s3_uploads_enabled()) { $instance->setup(); } $old_upload_dir = $instance->get_original_upload_dir(); $upload_dir = wp_upload_dir(); $files = array(get_post_meta($args[0], '_wp_attached_file', true)); $meta_data = wp_get_attachment_metadata($args[0]); if (!empty($meta_data['sizes'])) { foreach ($meta_data['sizes'] as $file) { $files[] = path_join(dirname($meta_data['file']), $file['file']); } } foreach ($files as $file) { if (file_exists($path = $old_upload_dir['basedir'] . '/' . $file)) { if (!copy($path, $upload_dir['basedir'] . '/' . $file)) { WP_CLI::line(sprintf('Failed to moved %s to S3', $file)); } else { if (!empty($args_assoc['delete-local'])) { unlink($path); } WP_CLI::success(sprintf('Moved file %s to S3', $file)); } } else { WP_CLI::line(sprintf('Already moved to %s S3', $file)); } } }
/** * Sets up a log directory. Assumed to be in uploads/___PluginName___ unless it's explicitly passed * Not much we can do if we get errors trying to find somewhere to write the log file * * @param string $logDirectory */ function __construct($logDirectory = '') { if (!empty($logDirectory)) { $this->logDirectory = $logDirectory; } else { $uploadDirectory = wp_upload_dir(); if ($uploadDirectory['error'] !== false) { return; } /** * Normalize the path just in case we're running on a Windows server */ $this->logDirectory = rtrim(str_replace('\\', '/', $uploadDirectory['basedir']) . "/EasyRecipePlus", '/'); } /** * If the log directory isn't present and a directory, try to create it */ if (!file_exists($this->logDirectory)) { @mkdir($this->logDirectory, 0777, true); } /** * If the log directory doesn't exist, isn't writeable and/or isn't a directory, then we're screwed */ if (!file_exists($this->logDirectory) || !is_writable($this->logDirectory) || !is_dir($this->logDirectory)) { $this->logDirectory = null; } /** * Just in case we have a server with autoindexing set ON, write a dummy index.html so the log file names can't be accessed from the web */ if (!file_exists($this->logDirectory . "/index.html")) { file_put_contents($this->logDirectory . "/index.html", "<html><body></body></html>"); } }
/** * Get uploads from the production site and store them * in the local filesystem if they don't already exist. * * @return void */ function uploads_proxy() { global $wp_filesystem; WP_Filesystem(); // The relative request path $requestPath = $_SERVER['REQUEST_URI']; // The relative uploads path $uploadsPath = str_replace(get_bloginfo('url'), '', wp_upload_dir()['baseurl']); // Check if a upload was requested if (strpos($requestPath, $uploadsPath) === 0) { // The absolute remote path to the upload $remotePath = UP_SITEURL . $requestPath; // Get the remote upload file $response = wp_remote_get($remotePath); // Check the response code if ($response['response']['code'] === 200) { // The file path relative to the uploads path to store the upload file to $relativeUploadFile = str_replace($uploadsPath, '', $_SERVER['REQUEST_URI']); // The absolute file path to store the upload file to $absoluteUploadFile = wp_upload_dir()['basedir'] . $relativeUploadFile; // Make sure the upload directory exists wp_mkdir_p(pathinfo($absoluteUploadFile)['dirname']); if ($wp_filesystem->put_contents(urldecode($absoluteUploadFile), $response['body'], FS_CHMOD_FILE)) { // Redirect to the stored upload wp_redirect($requestPath); } } } }
public static function uploads_wordpress_url() { if ($upload_dir = wp_upload_dir()) { return $upload_dir['baseurl']; } return site_url() . '/wp-content/uploads'; }
function generate_event_page() { ob_start(); $ical = new ICal(get_option('nev-file_path')); $events = $ical->events(); $FORMAT = 'd-m-Y'; $time = time(); echo '<ul>'; foreach ($events as $event) { $eventTime = strtotime($event['DTSTART']); //those in a past are not bolded if ($time - 60 * 60 * 24 > $eventTime) { echo '<li><p>'; $date = substr($event['DTSTART'], 6, 2) . "/" . substr($event['DTSTART'], 4, 2) . "/" . substr($event['DTSTART'], 0, 4); echo $date . ': ' . $event['SUMMARY'] . ", " . @$event['DESCRIPTION']; echo '</p></li>'; } else { echo '<li><p><strong>'; $date = substr($event['DTSTART'], 6, 2) . "/" . substr($event['DTSTART'], 4, 2) . "/" . substr($event['DTSTART'], 0, 4); echo $date . ':</strong> ' . $event['SUMMARY'] . ", " . @$event['DESCRIPTION']; echo '</p></li>'; } } echo '</ul>'; //Show link to download ical file $file_name = get_option('nev-file_path'); $upload_path = wp_upload_dir()['url'] . substr($file_name, strripos($file_name, '/')); echo '<p>Download <a href="' . $upload_path . '" download>.ics file</a></p>'; return ob_get_clean(); }
protected function _commands_for_files(&$commands) { extract($this->params); $dir = wp_upload_dir(); $dist_path = constant(WP_Deploy_Flow_Command::config_constant('path')) . '/'; $remote_path = $dist_path; $local_path = ABSPATH; $excludes = array_merge($excludes, array('.git', '.sass-cache', 'wp-content/cache', 'wp-content/_wpremote_backups', 'wp-config.php')); if (!$ssh_host) { // in case the source env is in a subfolder of the destination env, we exclude the relative path to the source to avoid infinite loop $remote_local_path = realpath($local_path); if ($remote_local_path) { $remote_path = realpath($remote_path); $remote_local_path = str_replace($remote_path . '/', '', $remote_local_path); $excludes[] = $remote_locale_path; } } $excludes = array_reduce($excludes, function ($acc, $value) { $acc .= "--exclude \"{$value}\" "; return $acc; }); if ($ssh_host) { $commands[] = array("rsync -avz -e 'ssh -p {$ssh_port}' {$ssh_user}@{$ssh_host}:{$remote_path} {$local_path} {$excludes}", true); } else { $commands[] = array("rsync -avz {$remote_path} {$local_path} {$excludes}", true); } }
function __construct() { //add_action( 'init', array($this,'init_addons')); $this->vc_template_dir = plugin_dir_path(__FILE__) . 'vc_templates/'; $this->vc_dest_dir = get_template_directory() . '/vc_templates/'; $this->module_dir = plugin_dir_path(__FILE__) . 'modules/'; $this->assets_js = plugins_url('assets/js/', __FILE__); $this->assets_css = plugins_url('assets/css/', __FILE__); $this->admin_js = plugins_url('admin/js/', __FILE__); $this->admin_css = plugins_url('admin/css/', __FILE__); $this->paths = wp_upload_dir(); $this->paths['fonts'] = 'smile_fonts'; $this->paths['fonturl'] = set_url_scheme(trailingslashit($this->paths['baseurl']) . $this->paths['fonts']); add_action('init', array($this, 'aio_init')); add_action('admin_enqueue_scripts', array($this, 'aio_admin_scripts')); add_action('wp_enqueue_scripts', array($this, 'aio_front_scripts')); add_action('admin_init', array($this, 'toggle_updater')); if (!get_option('ultimate_row')) { update_option('ultimate_row', 'enable'); } if (!get_option('ultimate_animation')) { update_option('ultimate_animation', 'disable'); } //add_action('admin_init', array($this, 'aio_move_templates')); }
/** * @param $file * @uses wp_handle_upload_error * @return mixed|void */ public static function wp_handle_upload_prefilter($file) { if (isset($file['name']) && isset($file['name'])) { $type_mime = explode('/', $file['type']); if ($type_mime[0] == 'video') { if ($_FILES['file']['size'] > 314572800) { $uploads = wp_upload_dir(null); $file_location = $uploads['path'] . "/{$file['name']}"; include __DIR__ . '/source/VideoInformation.php'; $videoInfo = VideoInformation::getVideoInfo($file_location); if (!empty($videoInfo) && isset($videoInfo['duration'])) { if (intval($videoInfo['duration']) > self::get_video_max_duration()) { $file['error'] = __('Video File exceeds Specified Duration'); return $file; } } else { $file['error'] = __("Video file information couldn't be read."); } } else { $file['error'] = __("File size exceeds 300 MB"); } } } return apply_filters('wp_handle_upload_prefilter', $file); }
public function go() { $this->upload_dir = wp_upload_dir(); $parser = new Theme_Content_Parser(TEMPLATEPATH . '/content/content.xml'); // parses content.xml $pages_info = $parser->get_pages(); $posts_info = $parser->get_posts(); $sidebars_info = $parser->get_sidebars(); $collages_info = $parser->get_collages(); // add content to the theme $this->move_images(); if ($pages_info) { $this->insert_pages($pages_info); } if ($posts_info) { $this->insert_posts($posts_info); } $this->update_collages_meta($collages_info); $this->update_links_url(); if ($sidebars_info) { theme_deactivate_all_widgets(); $this->insert_sidebars($sidebars_info); } update_option('theme_sample_data', $this->sample_data); }
public function __construct() { // Look for the Losungen xml in the /uploads-Folder as well add_filter('herrnhuterlosung_filename_xml', array($this, 'xmlFileName'), 10, 2); $upload_dir = wp_upload_dir(); $this->alternate_dir = $upload_dir['basedir']; }
function my_save_extra_profile_fields($user_id) { if (!current_user_can('edit_user', $user_id)) { return false; } $upload = $_FILES['profile_image']; $uploads = wp_upload_dir(); if ($upload['tmp_name'] && file_is_displayable_image($upload['tmp_name'])) { // handle the uploaded file $overrides = array('test_form' => false); $file = wp_handle_upload($upload, $overrides); $file["file"] = $uploads["subdir"] . "/" . basename($file["url"]); if ($file) { //remove previous uploaded file $author_profile_image = $this->get_author_profile_image($user_id); @unlink($author_profile_image["file"]); update_user_meta($user_id, 'profile_image', $file); } } if (isset($_POST['remove_image'])) { $author_profile_image = $this->get_author_profile_image($user_id); @unlink($author_profile_image["file"]); update_user_meta($user_id, 'profile_image', false); } }
/** * Get sermon data * * @since 0.9 * @param int $post_id Post ID to get data for; null for current post * @return array Sermon data */ function ctfw_sermon_data($post_id = null) { // Get URL to upload directory $upload_dir = wp_upload_dir(); $upload_dir_url = $upload_dir['baseurl']; // Get meta values $data = ctfw_get_meta_data(array('video', 'audio', 'pdf', 'has_full_text'), $post_id); // Get media player code // Embed code generated from uploaded file, URL for file on other site, page on oEmbed-supported site, or manual embed code (HTML or shortcode) $data['video_player'] = ctfw_embed_code($data['video']); $data['audio_player'] = ctfw_embed_code($data['audio']); // Get file data for media // Path and size will be populated for local files only $media_types = array('audio', 'video', 'pdf'); foreach ($media_types as $media_type) { $data[$media_type . '_extension'] = ''; $data[$media_type . '_path'] = ''; $data[$media_type . '_size_bytes'] = ''; $data[$media_type . '_size'] = ''; // Get extension // This can be determined for local and external files // Empty for YouTube, SoundCloud, etc. $filetype = wp_check_filetype($data[$media_type]); $data[$media_type . '_extension'] = $filetype['ext']; // File is local, so can get path and size if ($data[$media_type] && ctfw_is_local_url($data[$media_type])) { // Local path $data[$media_type . '_path'] = $upload_dir['basedir'] . str_replace($upload_dir_url, '', $data[$media_type]); // Exists? if (!file_exists($data[$media_type . '_path'])) { $data[$media_type . '_path'] = ''; // clear it } else { // File type $filetype = wp_check_filetype($data[$media_type]); $data[$media_type . '_extension'] = $filetype['ext']; // File size $data[$media_type . '_size_bytes'] = filesize($data[$media_type . '_path']); $data[$media_type . '_size'] = size_format($data[$media_type . '_size_bytes']); // 30 MB, 2 GB, 220 kB, etc. } } } // Get download URL's // URL is returned if is local or external and has an extension. // Those without an extension (YouTube, SoundCloud, etc. page URL) return empty (nothing to download). // If locally hosted, URL is changed to force "Save As" via headers. // Use <a href="" download="download"> to attempt Save As via limited browser support for externally hosted files. $data['video_download_url'] = ctfw_download_url($data['video']); $data['audio_download_url'] = ctfw_download_url($data['audio']); $data['pdf_download_url'] = ctfw_download_url($data['pdf']); // Has at least one downloadable file URL? $data['has_download'] = false; if ($data['video_download_url'] || $data['audio_download_url'] || $data['pdf_download_url']) { // path empty if doesn't exist $data['has_download'] = true; } // Return filtered return apply_filters('ctfw_sermon_data', $data); }
public function uploads($command = array(), $args = array()) { if (count($command) == 1 && reset($command) == 'help') { return $this->uploads_help(); } $dir = wp_upload_dir(); $defaults = array('ssh_host' => defined('IMPORT_UPLOADS_SSH_HOST') ? IMPORT_UPLOADS_SSH_HOST : '', 'ssh_user' => defined('IMPORT_UPLOADS_SSH_USER') ? IMPORT_UPLOADS_SSH_USER : '', 'remote_path' => defined('IMPORT_UPLOADS_REMOTE_PATH') ? IMPORT_UPLOADS_REMOTE_PATH : '', 'uploads_dir' => '', 'local_path' => $dir['basedir']); $args = wp_parse_args($args, $defaults); if ($args['uploads_dir']) { $args['remote_path'] = $args['remote_path'] ? trailingslashit($args['remote_path']) . trailingslashit(ltrim($args['uploads_dir'], '/')) : ''; $args['local_path'] = trailingslashit($args['local_path']) . untrailingslashit(ltrim($args['uploads_dir'], '/')); } else { $args['remote_path'] = $args['remote_path'] ? trailingslashit($args['remote_path']) : ''; $args['local_path'] = untrailingslashit($args['local_path']); } if (empty($args['remote_path'])) { WP_CLI::error('You must specify a remote path. Use --remote_path=~/foo/bar'); return; } if (empty($args['ssh_host'])) { WP_CLI::error('You must specify a ssh host. Use --ssh_host=example.com'); return; } if (empty($args['ssh_user'])) { WP_CLI::error('You must specify a ssh user. Use --ssh_user=root'); return; } WP_CLI::line(sprintf('Running rsync from %s:%s to %s', $args['ssh_host'], $args['remote_path'], $args['local_path'])); WP_CLI::launch(sprintf("rsync -avz -e ssh %s@%s:%s %s --exclude 'cache' --exclude '*backup*'", $args['ssh_user'], $args['ssh_host'], $args['remote_path'], $args['local_path'])); }
function pmxi_wp_ajax_save_import_functions() { if (!check_ajax_referer('wp_all_import_secure', 'security', false)) { exit(json_encode(array('html' => __('Security check', 'wp_all_import_plugin')))); } if (!current_user_can('manage_options')) { exit(json_encode(array('html' => __('Security check', 'wp_all_import_plugin')))); } $uploads = wp_upload_dir(); $functions = $uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php'; $input = new PMXI_Input(); $post = $input->post('data', ''); $response = wp_remote_post('http://phpcodechecker.com/api', array('body' => array('code' => $post))); if (is_wp_error($response)) { $error_message = $response->get_error_message(); exit(json_encode(array('result' => false, 'msg' => $error_message))); die; } else { $body = json_decode(wp_remote_retrieve_body($response), true); if ($body['errors'] === 'TRUE') { exit(json_encode(array('result' => false, 'msg' => $body['syntax']['message']))); die; } elseif ($body['errors'] === 'FALSE') { if (strpos($post, "<?php") === false || strpos($post, "?>") === false) { exit(json_encode(array('result' => false, 'msg' => __('PHP code must be wrapped in "<?php" and "?>"', 'wp_all_import_plugin')))); die; } else { file_put_contents($functions, $post); } } } exit(json_encode(array('result' => true, 'msg' => __('File has been successfully updated.', 'wp_all_import_plugin')))); die; }
function eventon_generate_options_css($newdata = '') { /** Define some vars **/ $data = $newdata; $uploads = wp_upload_dir(); //$css_dir = get_template_directory() . '/css/'; // Shorten code, save 1 call $css_dir = AJDE_EVCAL_DIR . '/' . EVENTON_BASE . '/assets/css/'; //$css_dir = plugin_dir_path( __FILE__ ). '/assets/css/'; //echo $css_dir; /** Save on different directory if on multisite **/ if (is_multisite()) { $aq_uploads_dir = trailingslashit($uploads['basedir']); } else { $aq_uploads_dir = $css_dir; } /** Capture CSS output **/ ob_start(); require $css_dir . 'dynamic_styles.php'; $css = ob_get_clean(); //print_r($css); /** Write to options.css file **/ WP_Filesystem(); global $wp_filesystem; if (!$wp_filesystem->put_contents($aq_uploads_dir . 'eventon_dynamic_styles.css', $css, 0777)) { return true; } }
/** * * add filter for Site option defaults * */ public static function default_site_options() { //global add_site_option('backwpup_version', '0.0.0'); //job default add_site_option('backwpup_jobs', array()); //general add_site_option('backwpup_cfg_showadminbar', 1); add_site_option('backwpup_cfg_showfoldersize', 0); add_site_option('backwpup_cfg_protectfolders', 1); //job $max_execution_time = 0; if (strstr(PHP_SAPI, 'cgi')) { $max_execution_time = (int) ini_get('max_execution_time'); } add_site_option('backwpup_cfg_jobmaxexecutiontime', $max_execution_time); add_site_option('backwpup_cfg_jobziparchivemethod', ''); add_site_option('backwpup_cfg_jobstepretry', 3); add_site_option('backwpup_cfg_jobrunauthkey', substr(md5(BackWPup::get_plugin_data('hash')), 11, 8)); add_site_option('backwpup_cfg_loglevel', 'normal_translated'); add_site_option('backwpup_cfg_jobwaittimems', 0); add_site_option('backwpup_cfg_jobdooutput', 0); //Logs add_site_option('backwpup_cfg_maxlogs', 30); add_site_option('backwpup_cfg_gzlogs', 0); $upload_dir = wp_upload_dir(); $logs_dir = trailingslashit(str_replace('\\', '/', $upload_dir['basedir'])) . 'backwpup-' . BackWPup::get_plugin_data('hash') . '-logs/'; $content_path = trailingslashit(str_replace('\\', '/', WP_CONTENT_DIR)); $logs_dir = str_replace($content_path, '', $logs_dir); add_site_option('backwpup_cfg_logfolder', $logs_dir); //Network Auth add_site_option('backwpup_cfg_httpauthuser', ''); add_site_option('backwpup_cfg_httpauthpassword', ''); }
function file_upload($html) { // Define wp upload folder $main_path = wp_upload_dir(); $current_path = ''; // Instaniate Post_Get class $get = new Post_Get(); // Check if GET variable has value $get->exists('GET'); $current_path = $get->get('upload_dir'); // Define the folder directory that will hold the content $container = $main_path['basedir'] . '/upload_dir'; // Create upload_dir folder to hold the documents that will be uploaded if (!file_exists($container)) { mkdir($container, 0755, true); } // Define current url $current_url = $main_path['baseurl'] . '/upload_dir/'; // Scan current directory $current_dir = scandir($main_path['basedir'] . '/upload_dir/' . $current_path); // Wrap the retusts in unordered list $html .= "<ul>"; // Loop throught current folder foreach ($current_dir as $file) { if (stripos($file, '.') !== 0) { if (strpos($file, '.html') > -1) { $html .= '<li><a href="' . $current_url . $current_path . '/' . $file . '">' . $file . '</a></li>'; } else { $html .= '<li><a href="?upload_dir=' . $current_path . '/' . $file . '">' . $file . '</a></li>'; } } } $html .= '</ul>'; return $html; }
protected function maxmindGetUploadFilename() { $upload_dir = wp_upload_dir(); $dir = $upload_dir['basedir']; $filename = $dir . '/' . GEOIP_DETECT_DATA_UPDATE_FILENAME; return $filename; }
/** * Install woocommerce */ function do_install_woocommerce() { global $woocommerce_settings, $woocommerce; // Do install woocommerce_default_options(); woocommerce_tables_install(); woocommerce_install_custom_fields(); // Register post types $woocommerce->init_taxonomy(); // Add default taxonomies woocommerce_default_taxonomies(); // Install folder for uploading files and prevent hotlinking $upload_dir = wp_upload_dir(); $downloads_url = $upload_dir['basedir'] . '/woocommerce_uploads'; if (wp_mkdir_p($downloads_url) && !file_exists($downloads_url . '/.htaccess')) { if ($file_handle = @fopen($downloads_url . '/.htaccess', 'w')) { fwrite($file_handle, 'deny from all'); fclose($file_handle); } } // Install folder for logs $logs_url = WP_PLUGIN_DIR . "/" . plugin_basename(dirname(dirname(__FILE__))) . '/logs'; if (wp_mkdir_p($logs_url) && !file_exists($logs_url . '/.htaccess')) { if ($file_handle = @fopen($logs_url . '/.htaccess', 'w')) { fwrite($file_handle, 'deny from all'); fclose($file_handle); } } // Clear transient cache $woocommerce->clear_product_transients(); // Update version update_option("woocommerce_db_version", $woocommerce->version); }
function setup_paths() { $this->upload_dir = wp_upload_dir(); $this->upload_basedir = $this->upload_dir['basedir'] . '/ultimatemember/'; $this->upload_baseurl = $this->upload_dir['baseurl'] . '/ultimatemember/'; $this->upload_basedir = apply_filters('um_upload_basedir_filter', $this->upload_basedir); $this->upload_baseurl = apply_filters('um_upload_baseurl_filter', $this->upload_baseurl); // @note : is_ssl() doesn't work properly for some sites running with load balancers // Check the links for more info about this bug // https://codex.wordpress.org/Function_Reference/is_ssl // http://snippets.webaware.com.au/snippets/wordpress-is_ssl-doesnt-work-behind-some-load-balancers/ if (is_ssl() || stripos(get_option('siteurl'), 'https://') !== false || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $this->upload_baseurl = str_replace("http://", "https://", $this->upload_baseurl); } $this->upload_temp = $this->upload_basedir . 'temp/'; $this->upload_temp_url = $this->upload_baseurl . 'temp/'; if (!file_exists($this->upload_basedir)) { $old = umask(0); @mkdir($this->upload_basedir, 0755, true); umask($old); } if (!file_exists($this->upload_temp)) { $old = umask(0); @mkdir($this->upload_temp, 0755, true); umask($old); } }
/** * Register and load frontend scripts * @return void */ public function load_assets() { global $wp_scripts; // Filter base front end assets directory $this->assets_dir = apply_filters('masterslider_frontend_assets_dir', $this->assets_dir); // JS ////////////////////////////////////////////////////////////////////////////// wp_register_script('jquery-easing', $this->assets_dir . '/js/jquery.easing.min.js', array('jquery'), $this->version, true); wp_register_script('masterslider-core', $this->assets_dir . '/js/masterslider.min.js', array('jquery', 'jquery-easing'), $this->version, true); wp_register_script('masterslider-flickr', $this->assets_dir . '/js/masterslider.flickr.min.js', array('masterslider-core'), $this->version, true); // always load assets by default if 'allways_load_ms_assets' option was enabled if ('on' == msp_get_setting('allways_load_ms_assets', 'msp_advanced')) { wp_enqueue_script('masterslider-core'); wp_enqueue_script('masterslider-flickr'); } // Print JS Object ////////////////////////////////////////////////////////////////// wp_localize_script('masterslider', 'masterslider_js_params', apply_filters('masterslider_js_params', array('ajax_url' => admin_url('admin-ajax.php')))); // CSS ////////////////////////////////////////////////////////////////////////////// $enqueue_styles = $this->get_styles(); // Load Css files if ($enqueue_styles) { foreach ($enqueue_styles as $handle => $args) { wp_enqueue_style($handle, $args['src'], $args['deps'], $args['version']); } } // load custom.css if the directory is writable. else use inline css fallback $inline_css = msp_get_option('custom_inline_style', ''); if (empty($inline_css)) { $custom_css_ver = msp_get_option('masterslider_custom_css_ver', '1.0'); $uploads = wp_upload_dir(); $css_file = $uploads['baseurl'] . '/' . MSWP_SLUG . '/custom.css'; $css_file = apply_filters('masterslider_custom_css_url', $css_file); wp_enqueue_style($this->prefix . 'custom', $css_file, array($this->prefix . 'main'), $custom_css_ver); } }
/** * Directories of sub sites on a network should not count against the same spaced used total for * the main site. */ function test_get_space_used_main_site() { $space_used = get_space_used(); $blog_id = $this->factory->blog->create(); switch_to_blog($blog_id); // We don't rely on an initial value of 0 for space used, but should have a clean space available // so that we can remove any uploaded files and directories without concern of a conflict with // existing content directories in src. while (0 != get_space_used()) { restore_current_blog(); $blog_id = $this->factory->blog->create(); switch_to_blog($blog_id); } // Upload a file to the new site. $filename = rand_str() . '.jpg'; $contents = rand_str(); wp_upload_bits($filename, null, $contents); restore_current_blog(); delete_transient('dirsize_cache'); $this->assertEquals($space_used, get_space_used()); // Switch back to the new site to remove the uploaded file. switch_to_blog($blog_id); $upload_dir = wp_upload_dir(); $this->remove_added_uploads(); $this->delete_folders($upload_dir['basedir']); restore_current_blog(); }