本文整理汇总了PHP中wp_mkdir_p函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_mkdir_p函数的具体用法?PHP wp_mkdir_p怎么用?PHP wp_mkdir_p使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_mkdir_p函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_image
static function add_image($image_url)
{
if (empty($image_url)) {
return FALSE;
}
// Add Featured Image to Post
$upload_dir = wp_upload_dir();
// Set upload folder
$image_data = file_get_contents($image_url);
// Get image data
$filename = basename($image_url);
// Create image file name
// Check folder permission and define file location
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
// Create the image file on the server
file_put_contents($file, $image_data);
// Check image file type
$wp_filetype = wp_check_filetype($filename, NULL);
// Set attachment data
$attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($filename), 'post_content' => '', 'post_status' => 'inherit');
// Create the attachment
$attach_id = wp_insert_attachment($attachment, $file);
// Include image.php
require_once ABSPATH . 'wp-admin/includes/image.php';
// Define attachment metadata
$attach_data = wp_generate_attachment_metadata($attach_id, $file);
// Assign metadata to attachment
wp_update_attachment_metadata($attach_id, $attach_data);
return $attach_id;
}
示例2: setUp
/**
* Setup the backup object and create the tmp directory
*
*/
public function setUp()
{
HM\BackUpWordPress\Path::get_instance()->set_path(dirname(__FILE__) . '/tmp');
$this->backup = new HM\BackUpWordPress\Backup();
$this->backup->set_root(dirname(__FILE__) . '/test-data/');
wp_mkdir_p(hmbkp_path());
}
示例3: folders
public function folders()
{
global $mf_domain;
$dir_list = "";
$dir_list2 = "";
wp_mkdir_p(MF_FILES_DIR);
wp_mkdir_p(MF_CACHE_DIR);
if (!is_dir(MF_CACHE_DIR)) {
$dir_list2 .= "<li>" . MF_CACHE_DIR . "</li>";
} elseif (!is_writable(MF_CACHE_DIR)) {
$dir_list .= "<li>" . MF_CACHE_DIR . "</li>";
}
if (!is_dir(MF_FILES_DIR)) {
$dir_list2 .= "<li>" . MF_FILES_DIR . "</li>";
} elseif (!is_writable(MF_FILES_DIR)) {
$dir_list .= "<li>" . MF_FILES_DIR . "</li>";
}
if ($dir_list2 != "") {
echo "<div id='magic-fields-install-error-message' class='error'><p><strong>" . __('Magic Fields is not ready yet.', $mf_domain) . "</strong> " . __('must create the following folders (and must chmod 777):', $mf_domain) . "</p><ul>";
echo $dir_list2;
echo "</ul></div>";
}
if ($dir_list != "") {
echo "<div id='magic-fields-install-error-message-2' class='error'><p><strong>" . __('Magic Fields is not ready yet.', $mf_domain) . "</strong> " . __('The following folders must be writable (usually chmod 777 is neccesary):', $mf_domain) . "</p><ul>";
echo $dir_list;
echo "</ul></div>";
}
}
示例4: __construct
/**
* Sets defaults like cache, compile and template directory paths.
*
* @throws Exception When cache path cannot be used.
*/
public function __construct()
{
$upload_dir = wp_upload_dir();
$current_theme = wp_get_theme();
$theme_slug = $current_theme->get_stylesheet();
/**
* Make the upload folder the root for changing files, this is the place
* that is most likely writable.
*
* Keeping the theme name as container prevents accidental problems with
* caching or compiling files when switching themes.
*/
$root = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . $theme_slug;
$this->cache_path = implode(DIRECTORY_SEPARATOR, array($root, 'cache', ''));
$this->compile_path = implode(DIRECTORY_SEPARATOR, array($root, 'compiled', ''));
/**
* Filter: views directory
*/
$views_path = Stencil_Environment::filter('path-views', 'views');
/**
* Get all directories (root + optional child theme)
*/
$this->template_path = Stencil_File_System::get_potential_directories($views_path);
/**
* Attempt to make the directories
*/
if (!wp_mkdir_p($this->cache_path)) {
throw new Exception('Cache path could not be created.');
}
if (!wp_mkdir_p($this->compile_path)) {
throw new Exception('Compile path could not be created.');
}
}
示例5: update
function update($file)
{
$response = array();
$result = 0;
// Create a temporary directory for all the files
wp_mkdir_p($file . '.tmp');
exec("{$this->command} export {$this->url} {$file}.tmp --force", $response, $result);
if ($result === 0) {
// Check if this is a plugin by scanning for a plugin header
$files = glob($file . '.tmp/*.php');
if (count($files) > 0) {
foreach ($files as $tmp) {
$data = file_get_contents($tmp);
if (strpos($data, 'Plugin Name:') !== false) {
if (preg_match('/Version:\\s*(.*)/', $data, $matches) > 0) {
$this->version = trim($matches[1]);
}
break;
}
}
if (count($files) > 1) {
// Zip the directory
$zip = new zipfile();
$this->zip($zip, $file . '.tmp', $file . '.tmp');
$fd = fopen($file, 'w');
fwrite($fd, $zip->file());
fclose($fd);
}
}
$this->cleanup($file . '.tmp');
}
}
示例6: bigboom_generate_custom_color_scheme
/**
* Generate custom color scheme css
*
* @since 1.0
*/
function bigboom_generate_custom_color_scheme()
{
parse_str($_POST['data'], $data);
if (!isset($data['custom_color_scheme'])) {
return;
}
if (!$data['custom_color_scheme']) {
return;
}
$color_1 = $data['custom_color_1'];
if (!$color_1) {
return;
}
// Prepare LESS to compile
$less = file_get_contents(THEME_DIR . '/css/color-schemes/mixin.less');
$less .= ".custom-color-scheme { .color-scheme({$color_1}); }";
// Compile
require THEME_DIR . '/inc/libs/lessc.inc.php';
$compiler = new lessc();
$compiler->setFormatter('compressed');
$css = $compiler->compile($less);
// Get file path
$upload_dir = wp_upload_dir();
$dir = path_join($upload_dir['basedir'], 'custom-css');
$file = $dir . '/color-scheme.css';
// Create directory if it doesn't exists
wp_mkdir_p($dir);
@file_put_contents($file, $css);
wp_send_json_success();
}
示例7: get_image_url
function get_image_url($path, $id, $width, $height)
{
$image_path = $path;
$upload_directory = wp_upload_dir();
$modified_image_directory = $upload_directory["basedir"] . "/blog/" . $id . "/";
if (!file_exists($modified_image_directory)) {
wp_mkdir_p($modified_image_directory);
}
$file_name_with_ending = explode("/", $image_path);
$file_name_with_ending = $file_name_with_ending[count($file_name_with_ending) - 1];
$file_name_without_ending = explode(".", $file_name_with_ending);
$file_ending = $file_name_without_ending[count($file_name_without_ending) - 1];
$file_name_without_ending = $file_name_without_ending[count($file_name_without_ending) - 2];
$modified_image_path = $modified_image_directory . md5($file_name_without_ending) . "." . $file_ending;
if (!file_exists($modified_image_path)) {
$image = wp_get_image_editor($image_path);
if (!is_wp_error($image)) {
$rotate = 180;
$modified_file_name_without_ending = $file_name_without_ending . "-" . $width . "x" . $height . "-" . $rotate . "dg";
$image->resize($width, $height);
$image->rotate($rotate);
$image->save($modified_file_name_without_ending);
}
}
$modified_image_url = $upload_directory["url"] . "/" . $modified_file_name_without_ending . "." . $file_ending;
return $modified_image_url;
}
示例8: install
function install()
{
global $wpdb;
$table_name = $wpdb->prefix . "egcl_certificates";
//if($wpdb->get_var("show tables like '".$table_name."'") != $table_name)
//{
$upload_dir = wp_upload_dir();
if (!file_exists($upload_dir["basedir"] . '/egiftcardlite')) {
wp_mkdir_p($upload_dir["basedir"] . '/egiftcardlite');
}
$sourcelocation = plugin_dir_path(__FILE__) . 'defaultimages/';
$targetlocation = $upload_dir["basedir"] . '/egiftcardlite/';
copy($sourcelocation . 'smallimage_sample.png', $targetlocation . 'smallimage_sample.png');
copy($sourcelocation . 'bigimage_sample.png', $targetlocation . 'bigimage_sample.png');
copy($sourcelocation . 'certimage_sample.jpg', $targetlocation . 'certimage_sample.jpg');
$sql = "CREATE TABLE " . $table_name . " (\r\n\t\t\t\tid int(11) NOT NULL auto_increment,\r\n\t\t\t\ttx_str varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tcode varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\trecipient varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\temail varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tprice float NOT NULL,\r\n\t\t\t\tcurrency varchar(15) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tstatus int(11) NOT NULL,\r\n\t\t\t\tregistered int(11) NOT NULL,\r\n\t\t\t\tblocked int(11) NOT NULL,\r\n\t\t\t\tdeleted int(11) NULL,\r\n\t\t\t\tecard tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\tUNIQUE KEY id (id)\r\n\t\t\t);";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta($sql);
//}
$table_name = $wpdb->prefix . "egcl_transactions";
if ($wpdb->get_var("show tables like '" . $table_name . "'") != $table_name) {
$sql = "CREATE TABLE " . $table_name . " (\r\n\t\t\t\tid int(11) NOT NULL auto_increment,\r\n\t\t\t\ttx_str varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tpayer_name varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tpayer_email varchar(255) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tgross float NOT NULL,\r\n\t\t\t\tcurrency varchar(15) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tpayment_status varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\ttransaction_type varchar(31) collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tdetails text collate utf8_unicode_ci NOT NULL,\r\n\t\t\t\tcreated int(11) NOT NULL,\r\n\t\t\t\tUNIQUE KEY id (id)\r\n\t\t\t);";
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta($sql);
}
}
示例9: save_woff_fonts_css
public static function save_woff_fonts_css()
{
$fonts_dir = WP_CONTENT_DIR . '/uploads/fpd_fonts';
//create fancy product orders directory
if (!file_exists($fonts_dir)) {
wp_mkdir_p($fonts_dir);
}
$fonts_css = WP_CONTENT_DIR . '/uploads/fpd_fonts/jquery.fancyProductDesigner-fonts.css';
chmod($fonts_css, 0775);
$handle = @fopen($fonts_css, 'w') or print 'Cannot open file: ' . $fonts_css;
$files = scandir($fonts_dir);
$data = '';
if (is_array($files)) {
foreach ($files as $file) {
if (preg_match("/.woff/", $file)) {
$new_file = str_replace(' ', '_', $file);
rename($fonts_dir . '/' . $file, $fonts_dir . '/' . $new_file);
$data .= '@font-face {' . "\n";
$data .= ' font-family: "' . preg_replace("/\\.[^.\\s]{3,4}\$/", "", str_replace('_', ' ', $file)) . '";' . "\n";
$data .= ' src: local("#"), url("' . content_url('/uploads/fpd_fonts/' . $new_file) . '") format("woff");' . "\n";
$data .= ' font-weight: normal;' . "\n";
$data .= ' font-style: normal;' . "\n";
$data .= '}' . "\n\n\n";
}
}
}
fwrite($handle, $data);
fclose($handle);
}
示例10: do_install_woocommerce
/**
* 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);
}
示例11: install
function install($last_modified)
{
global $wp_version;
// Add / update the version number
if (get_option('k2version') === false) {
add_option('k2version', K2_CURRENT, 'This option stores K2\'s version number');
} else {
update_option('k2version', K2_CURRENT);
}
// Add / update the last modified timestamp
if (get_option('k2lastmodified') === false) {
add_option('k2lastmodified', $last_modified, 'This option stores K2\'s last application modification. Used for version checking');
} else {
update_option('k2lastmodified', $last_modified);
}
if (get_option('k2active') === false) {
add_option('k2active', 0, 'This option stores if K2 has been activated');
} else {
update_option('k2active', 0);
}
// Create support folders for WordPressMU
if (K2_MU) {
if (!is_dir(ABSPATH . UPLOADS . 'k2support/')) {
wp_mkdir_p(ABSPATH . UPLOADS . 'k2support/');
}
if (!is_dir(K2_STYLES_PATH)) {
wp_mkdir_p(K2_STYLES_PATH);
}
if (!is_dir(K2_HEADERS_PATH)) {
wp_mkdir_p(K2_HEADERS_PATH);
}
}
// Call the install handlers
do_action('k2_install');
}
示例12: edd_create_protection_files
/**
* Creates blank index.php and .htaccess files
*
* This function runs approximately once per month in order
* to ensure all folders have their necessary protection files
*
* @access private
* @since 1.1.5
* @return void
*/
function edd_create_protection_files()
{
if (false === get_transient('edd_check_protection_files')) {
$wp_upload_dir = wp_upload_dir();
$upload_path = $wp_upload_dir['basedir'] . '/edd';
wp_mkdir_p($upload_path);
// top level blank index.php
if (!file_exists($upload_path . '/index.php')) {
@file_put_contents($upload_path . '/index.php', '<?php' . PHP_EOL . '// silence is golden');
}
// top level .htaccess file
$rules = 'Options -Indexes';
if (file_exists($upload_path . '/.htaccess')) {
$contents = @file_get_contents($upload_path . '/.htaccess');
if (false === strpos($contents, 'Options -Indexes') || !$contents) {
@file_put_contents($upload_path . '/.htaccess', $rules);
}
}
// now place index.php files in all sub folders
$folders = edd_scan_folders($upload_path);
foreach ($folders as $folder) {
// create index.php, if it doesn't exist
if (!file_exists($folder . 'index.php')) {
@file_put_contents($folder . 'index.php', '<?php' . PHP_EOL . '// silence is golden');
}
}
// only have this run the first time. This is just to create .htaccess files in existing folders
set_transient('edd_check_protection_files', true, 2678400);
}
}
示例13: _handle_logo_upload
function _handle_logo_upload()
{
if (!isset($_FILES['wdeb_logo'])) {
return false;
}
$name = $_FILES['wdeb_logo']['name'];
if (!$name) {
return false;
}
$allowed = array('jpg', 'jpeg', 'png', 'gif');
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
if (!in_array($ext, $allowed)) {
wp_die(__('This file type is not supported', 'wdeb'));
}
$wp_upload_dir = wp_upload_dir();
$logo_dir = $wp_upload_dir['basedir'] . '/wdeb';
$logo_path = $wp_upload_dir['baseurl'] . '/wdeb';
if (!file_exists($logo_dir)) {
wp_mkdir_p($logo_dir);
}
while (file_exists("{$logo_dir}/{$name}")) {
$name = rand(0, 9) . $name;
}
if (move_uploaded_file($_FILES['wdeb_logo']['tmp_name'], "{$logo_dir}/{$name}")) {
if (defined('WP_NETWORK_ADMIN') && WP_NETWORK_ADMIN) {
$opts = $this->data->get_options('wdeb');
$opts['wdeb_logo'] = "{$logo_path}/{$name}";
$this->data->set_options($opts, 'wdeb');
} else {
update_option('wdeb_logo', "{$logo_path}/{$name}");
}
}
}
示例14: edd_create_protection_files
/**
* Creates blank index.php and .htaccess files
*
* This function runs approximately once per month in order to ensure all folders
* have their necessary protection files
*
* @since 1.1.5
*
* @param bool $force
* @param bool $method
*/
function edd_create_protection_files($force = false, $method = false)
{
if (false === get_transient('edd_check_protection_files') || $force) {
$upload_path = edd_get_upload_dir();
// Make sure the /edd folder is created
wp_mkdir_p($upload_path);
// Top level .htaccess file
$rules = edd_get_htaccess_rules($method);
if (edd_htaccess_exists()) {
$contents = @file_get_contents($upload_path . '/.htaccess');
if ($contents !== $rules || !$contents) {
// Update the .htaccess rules if they don't match
@file_put_contents($upload_path . '/.htaccess', $rules);
}
} elseif (wp_is_writable($upload_path)) {
// Create the file if it doesn't exist
@file_put_contents($upload_path . '/.htaccess', $rules);
}
// Top level blank index.php
if (!file_exists($upload_path . '/index.php') && wp_is_writable($upload_path)) {
@file_put_contents($upload_path . '/index.php', '<?php' . PHP_EOL . '// Silence is golden.');
}
// Now place index.php files in all sub folders
$folders = edd_scan_folders($upload_path);
foreach ($folders as $folder) {
// Create index.php, if it doesn't exist
if (!file_exists($folder . 'index.php') && wp_is_writable($folder)) {
@file_put_contents($folder . 'index.php', '<?php' . PHP_EOL . '// Silence is golden.');
}
}
// Check for the files once per day
set_transient('edd_check_protection_files', true, 3600 * 24);
}
}
示例15: do_install_woocommerce
/**
* Install woocommerce
*/
function do_install_woocommerce()
{
global $woocommerce_settings, $woocommerce;
// Do install
woocommerce_default_options();
woocommerce_tables_install();
woocommerce_default_taxonomies();
woocommerce_populate_custom_fields();
// 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 (if this is an upgrade then woocommerce_class will be defined)
if ($woocommerce instanceof woocommerce) {
$woocommerce->clear_product_transients();
}
// Update version
update_option("woocommerce_db_version", $woocommerce->version);
}