• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_tempnam函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中wp_tempnam函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_tempnam函数的具体用法?PHP wp_tempnam怎么用?PHP wp_tempnam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了wp_tempnam函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: save_temp_image

 /**
  * Save the submitted image as a temporary file.
  *
  * @todo Revisit file handling.
  *
  * @param string $img Base64 encoded image.
  * @return false|string File name on success, false on failure.
  */
 protected function save_temp_image($img)
 {
     // Strip the "data:image/png;base64," part and decode the image.
     $img = explode(',', $img);
     $img = isset($img[1]) ? base64_decode($img[1]) : base64_decode($img[0]);
     if (!$img) {
         return false;
     }
     // Upload to tmp folder.
     $filename = 'user-feedback-' . date('Y-m-d-H-i');
     $tempfile = wp_tempnam($filename);
     if (!$tempfile) {
         return false;
     }
     // WordPress adds a .tmp file extension, but we want .png.
     if (rename($tempfile, $filename . '.png')) {
         $tempfile = $filename . '.png';
     }
     if (!WP_Filesystem(request_filesystem_credentials(''))) {
         return false;
     }
     /**
      * WordPress Filesystem API.
      *
      * @var \WP_Filesystem_Base $wp_filesystem
      */
     global $wp_filesystem;
     $success = $wp_filesystem->put_contents($tempfile, $img);
     if (!$success) {
         return false;
     }
     return $tempfile;
 }
开发者ID:kreapress,项目名称:user-feedback,代码行数:41,代码来源:AjaxHandler.php


示例2: download_url

 function download_url($url)
 {
     /*
     	http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/file.php?rev=17928#L467
     	changes:  
     		- wanted a timeout < 5 min
     		- SSL fails when trying to access github
     */
     if (!$url) {
         return new WP_Error('http_no_url', __('Invalid URL Provided.'));
     }
     $tmpfname = wp_tempnam($url);
     if (!$tmpfname) {
         return new WP_Error('http_no_file', __('Could not create Temporary file.'));
     }
     $handle = @fopen($tmpfname, 'wb');
     if (!$handle) {
         return new WP_Error('http_no_file', __('Could not create Temporary file.'));
     }
     // This! is the one line I wanted to get at
     $response = wp_remote_get($url, array('sslverify' => false, 'timeout' => 30));
     if (is_wp_error($response)) {
         fclose($handle);
         unlink($tmpfname);
         return $response;
     }
     if ($response['response']['code'] != '200') {
         fclose($handle);
         unlink($tmpfname);
         return new WP_Error('http_404', trim($response['response']['message']));
     }
     fwrite($handle, $response['body']);
     fclose($handle);
     return $tmpfname;
 }
开发者ID:nmedia82,项目名称:rotary,代码行数:35,代码来源:assets.php


示例3: is_win_paths_exception

 public function is_win_paths_exception($repository_id)
 {
     if (!isset($this->is_win_paths_exception[$repository_id])) {
         $this->is_win_paths_exception[$repository_id] = false;
         if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
             $windows_max_path_length = 256;
             $longest_path['wpml'] = 109;
             $longest_path['toolset'] = 99;
             $margin = 15;
             $upgrade_path_length = strlen(WP_CONTENT_DIR . '/upgrade');
             $installer_settings = WP_Installer()->settings;
             if (is_array($installer_settings['repositories'][$repository_id]['data']['downloads']['plugins'])) {
                 $a_plugin = current($installer_settings['repositories'][$repository_id]['data']['downloads']['plugins']);
                 $url = WP_Installer()->append_site_key_to_download_url($a_plugin['url'], 'xxxxxx', $repository_id);
                 $tmpfname = wp_tempnam($url);
                 $tmpname_length = strlen(basename($tmpfname)) - 4;
                 // -.tmp
                 if ($upgrade_path_length + $tmpname_length + $longest_path[$repository_id] + $margin > $windows_max_path_length) {
                     $this->is_win_paths_exception[$repository_id] = true;
                 }
             }
         }
     }
     return $this->is_win_paths_exception[$repository_id];
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:25,代码来源:class-installer-dependencies.php


示例4: synved_option_item_addon_install

 function synved_option_item_addon_install($id, $name, $item)
 {
     $return = null;
     $type = synved_option_item_type($item);
     $target = synved_option_item_property($item, 'target');
     $folder = synved_option_item_property($item, 'folder');
     $field_name = synved_option_name_default($id);
     $path = null;
     if (file_exists($target)) {
         $path = $target;
     }
     if ($type != 'addon' || $path == null) {
         return false;
     }
     $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
     if (substr($path, -1) != DIRECTORY_SEPARATOR) {
         $path .= DIRECTORY_SEPARATOR;
     }
     if (isset($_FILES[$field_name])) {
         foreach ($_FILES[$field_name]["error"] as $key => $error) {
             if ($key == $name && $error == UPLOAD_ERR_OK) {
                 $tmp_name = $_FILES[$field_name]["tmp_name"][$key];
                 $name = $_FILES[$field_name]["name"][$key];
                 $tmpfname = wp_tempnam($name . '.zip');
                 if (move_uploaded_file($tmp_name, $tmpfname)) {
                     global $wp_filesystem;
                     $unzip_path = realpath($path);
                     $dirs = glob($path . '*', GLOB_ONLYDIR);
                     if ($wp_filesystem != null) {
                         $unzip_path = $wp_filesystem->find_folder($unzip_path);
                     }
                     wp_mkdir_p(realpath($path));
                     $return = unzip_file($tmpfname, $unzip_path);
                     if ($wp_filesystem != null) {
                         $wp_filesystem->delete($tmpfname);
                     }
                     $dirs_new = glob($path . '*', GLOB_ONLYDIR);
                     $dirs_diff = array_values(array_diff($dirs_new, $dirs));
                     $addon_path = $path;
                     if ($dirs_diff != null) {
                         $folder_path = null;
                         foreach ($dirs_diff as $dir) {
                             if (basename($dir) == $folder) {
                                 $folder_path = $dir;
                             }
                         }
                         // XXX no correct path, was unzip successful?
                         if ($folder_path == null) {
                             $folder_path = $dirs_diff[0];
                         }
                         $addon_path = $folder_path;
                     }
                     synved_option_set($id, $name, $addon_path);
                 }
             }
         }
     }
     return $return;
 }
开发者ID:nihrain,项目名称:accelerate,代码行数:59,代码来源:option-type-addon.php


示例5: dumpTable

 private function dumpTable($table)
 {
     global $wpdb;
     $fileName = wp_tempnam();
     $handle = fopen($fileName, 'w');
     $create = $wpdb->get_row("SHOW CREATE TABLE `{$table}`", ARRAY_N);
     @fwrite($handle, "{$create[1]};\n\n");
     $rowCount = $wpdb->get_var("SELECT Count(*) FROM `{$table}`");
     if ($rowCount > $this->qryLimit) {
         $batches = ceil($rowCount / $this->qryLimit);
     } else {
         if ($rowCount > 0) {
             $batches = 1;
         }
     }
     for ($i = 0; $i < $batches; $i++) {
         $sql = "";
         $limit = $i * $this->qryLimit;
         $query = "SELECT * FROM `{$table}` LIMIT {$limit}, {$this->qryLimit}";
         $rows = $wpdb->get_results($query, ARRAY_A);
         if (is_array($rows)) {
             foreach ($rows as $row) {
                 $sql .= "INSERT INTO `{$table}` VALUES(";
                 $values = array();
                 foreach ($row as $value) {
                     if (is_null($value) || !isset($value)) {
                         $values[] = 'NULL';
                     } else {
                         $values[] = '"' . @esc_sql($value) . '"';
                     }
                 }
                 $sql .= join(',', $values);
                 $sql .= ");\n";
             }
             fwrite($handle, $sql);
         }
     }
     $sql = "\nSET FOREIGN_KEY_CHECKS = 1; \n\n";
     fwrite($handle, $sql);
     fclose($handle);
     $zip = new \ZipArchive();
     $zipFile = wp_tempnam();
     $zip->open($zipFile, \ZipArchive::OVERWRITE);
     $zip->addFile($fileName, 'sql');
     $zip->close();
     unlink($fileName);
     return $zipFile;
 }
开发者ID:eriktorsner,项目名称:wp-bootstrap-test,代码行数:48,代码来源:WpMirrorHelperDb.php


示例6: download_wpcom_theme_to_file

 protected static function download_wpcom_theme_to_file($theme)
 {
     $wpcom_theme_slug = preg_replace('/-wpcom$/', '', $theme);
     $file = wp_tempnam('theme');
     if (!$file) {
         return new WP_Error('problem_creating_theme_file', __('Problem creating file for theme download', 'jetpack'));
     }
     $url = "themes/download/{$theme}.zip";
     $args = array('stream' => true, 'filename' => $file);
     $result = Jetpack_Client::wpcom_json_api_request_as_blog($url, '1.1', $args);
     $response = $result['response'];
     if ($response['code'] !== 200) {
         unlink($file);
         return new WP_Error('problem_fetching_theme', __('Problem downloading theme', 'jetpack'));
     }
     return $file;
 }
开发者ID:netmagik,项目名称:netmagik,代码行数:17,代码来源:class.jetpack-json-api-themes-install-endpoint.php


示例7: download_url

 function download_url($url, $timeout = 300)
 {
     //WARNING: The file is not automatically deleted, The script must unlink() the file.
     if (!$url) {
         return new WP_Error('http_no_url', __('Invalid URL Provided.', 'themify-flow'));
     }
     $tmpfname = wp_tempnam($url);
     if (!$tmpfname) {
         return new WP_Error('http_no_file', __('Could not create Temporary file.', 'themify-flow'));
     }
     $response = wp_safe_remote_get($url, array('cookies' => $this->cookies, 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname));
     if (is_wp_error($response)) {
         unlink($tmpfname);
         return $response;
     }
     if (200 != wp_remote_retrieve_response_code($response)) {
         unlink($tmpfname);
         return new WP_Error('http_404', trim(wp_remote_retrieve_response_message($response)));
     }
     return $tmpfname;
 }
开发者ID:jhostetter,项目名称:wp_intern_themes,代码行数:21,代码来源:class-tf-upgrader.php


示例8: wpqi_download_url

/**
 * Downloads a url to a local file using the Snoopy HTTP Class.
 *
 * @since unknown
 * @todo Transition over to using the new HTTP Request API (jacob).
 *
 * @param string $url the URL of the file to download
 * @return mixed WP_Error on failure, string Filename on success.
 */
function wpqi_download_url($url)
{
    //WARNING: The file is not automatically deleted, The script must unlink() the file.
    if (!$url) {
        return new WP_Error('http_no_url', __('Invalid URL Provided'));
    }
    $tmpfname = wp_tempnam($url);
    if (!$tmpfname) {
        return new WP_Error('http_no_file', __('Could not create Temporary file'));
    }
    $response = wp_remote_get($url, array('timeout' => 60, 'stream' => true, 'filename' => $tmpfname));
    if (is_wp_error($response)) {
        unlink($tmpfname);
        return $response;
    }
    if ($response['response']['code'] != 200) {
        unlink($tmpfname);
        return new WP_Error('http_404', trim($response['response']['message']));
    }
    return array($tmpfname, $response);
}
开发者ID:rmccue,项目名称:wpqi,代码行数:30,代码来源:file.php


示例9: download

 protected static function download($url, $timeout = 300)
 {
     //WARNING: The file is not automatically deleted, The script must unlink() the file.
     if (!$url) {
         return new WP_Error('http_no_url', __('Invalid URL Provided.', 'wp-e-commerce'));
     }
     $tmpfname = wp_tempnam($url);
     if (!$tmpfname) {
         return new WP_Error('http_no_file', __('Could not create Temporary file.', 'wp-e-commerce'));
     }
     $args = array('timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname, 'headers' => array('X-WP-Domain' => Sputnik_API::domain()), 'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION);
     Sputnik_API::sign_download($url, $args);
     $response = wp_safe_remote_get($url, $args);
     if (is_wp_error($response)) {
         unlink($tmpfname);
         return $response;
     }
     if (200 != wp_remote_retrieve_response_code($response)) {
         unlink($tmpfname);
         return new WP_Error('http_404', trim(wp_remote_retrieve_response_message($response)));
     }
     return $tmpfname;
 }
开发者ID:ashik968,项目名称:digiplot,代码行数:23,代码来源:Upgrader.php


示例10: download_url

/**
 * Downloads a url to a local temporary file using the WordPress HTTP Class.
 * Please note, That the calling function must unlink() the file.
 *
 * @since 2.5.0
 *
 * @param string $url the URL of the file to download
 * @param int $timeout The timeout for the request to download the file default 300 seconds
 * @return mixed WP_Error on failure, string Filename on success.
 */
function download_url( $url, $timeout = 300 ) {
	//WARNING: The file is not automatically deleted, The script must unlink() the file.
	if ( ! $url )
		return new WP_Error('http_no_url', __('Invalid URL Provided.'));

	$tmpfname = wp_tempnam($url);
	if ( ! $tmpfname )
		return new WP_Error('http_no_file', __('Could not create Temporary file.'));

	$response = wp_safe_remote_get( $url, array( 'timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname ) );

	if ( is_wp_error( $response ) ) {
		unlink( $tmpfname );
		return $response;
	}

	if ( 200 != wp_remote_retrieve_response_code( $response ) ){
		unlink( $tmpfname );
		return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
	}

	$content_md5 = wp_remote_retrieve_header( $response, 'content-md5' );
	if ( $content_md5 ) {
		$md5_check = verify_file_md5( $tmpfname, $content_md5 );
		if ( is_wp_error( $md5_check ) ) {
			unlink( $tmpfname );
			return $md5_check;
		}
	}

	return $tmpfname;
}
开发者ID:ShankarVellal,项目名称:WordPress,代码行数:42,代码来源:file.php


示例11: put_contents

 /**
  * @param string $file
  * @param string $contents
  * @param bool|int $mode
  * @return bool
  */
 public function put_contents($file, $contents, $mode = false)
 {
     $tempfile = wp_tempnam($file);
     $temp = fopen($tempfile, 'wb+');
     if (!$temp) {
         return false;
     }
     mbstring_binary_safe_encoding();
     $data_length = strlen($contents);
     $bytes_written = fwrite($temp, $contents);
     reset_mbstring_encoding();
     if ($data_length !== $bytes_written) {
         fclose($temp);
         unlink($tempfile);
         return false;
     }
     fseek($temp, 0);
     // Skip back to the start of the file being written to
     $ret = @ftp_fput($this->link, $file, $temp, FTP_BINARY);
     fclose($temp);
     unlink($tempfile);
     $this->chmod($file, $mode);
     return $ret;
 }
开发者ID:kuryerov,项目名称:portfolio,代码行数:30,代码来源:class-wp-filesystem-ftpext.php


示例12: put_contents

 function put_contents($file, $contents, $type = '')
 {
     if (empty($type)) {
         $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
     }
     $this->ftp->SetType($type);
     $temp = wp_tempnam($file);
     if (!($temphandle = fopen($temp, 'w+'))) {
         unlink($temp);
         return false;
     }
     fwrite($temphandle, $contents);
     fseek($temphandle, 0);
     //Skip back to the start of the file being written to
     $ret = $this->ftp->fput($file, $temphandle);
     fclose($temphandle);
     unlink($temp);
     return $ret;
 }
开发者ID:bluedanbob,项目名称:wordpress,代码行数:19,代码来源:class-wp-filesystem-ftpsockets.php


示例13: upload_from_data

 /**
  * Handles an upload via raw POST data.
  *
  * @since 4.7.0
  * @access protected
  *
  * @param array $data    Supplied file data.
  * @param array $headers HTTP headers from the request.
  * @return array|WP_Error Data from wp_handle_sideload().
  */
 protected function upload_from_data($data, $headers)
 {
     if (empty($data)) {
         return new WP_Error('rest_upload_no_data', __('No data supplied.'), array('status' => 400));
     }
     if (empty($headers['content_type'])) {
         return new WP_Error('rest_upload_no_content_type', __('No Content-Type supplied.'), array('status' => 400));
     }
     if (empty($headers['content_disposition'])) {
         return new WP_Error('rest_upload_no_content_disposition', __('No Content-Disposition supplied.'), array('status' => 400));
     }
     $filename = self::get_filename_from_disposition($headers['content_disposition']);
     if (empty($filename)) {
         return new WP_Error('rest_upload_invalid_disposition', __('Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.'), array('status' => 400));
     }
     if (!empty($headers['content_md5'])) {
         $content_md5 = array_shift($headers['content_md5']);
         $expected = trim($content_md5);
         $actual = md5($data);
         if ($expected !== $actual) {
             return new WP_Error('rest_upload_hash_mismatch', __('Content hash did not match expected.'), array('status' => 412));
         }
     }
     // Get the content-type.
     $type = array_shift($headers['content_type']);
     /** Include admin functions to get access to wp_tempnam() and wp_handle_sideload() */
     require_once ABSPATH . 'wp-admin/includes/admin.php';
     // Save the file.
     $tmpfname = wp_tempnam($filename);
     $fp = fopen($tmpfname, 'w+');
     if (!$fp) {
         return new WP_Error('rest_upload_file_error', __('Could not open file handle.'), array('status' => 500));
     }
     fwrite($fp, $data);
     fclose($fp);
     // Now, sideload it in.
     $file_data = array('error' => null, 'tmp_name' => $tmpfname, 'name' => $filename, 'type' => $type);
     $overrides = array('test_form' => false);
     $sideloaded = wp_handle_sideload($file_data, $overrides);
     if (isset($sideloaded['error'])) {
         @unlink($tmpfname);
         return new WP_Error('rest_upload_sideload_error', $sideloaded['error'], array('status' => 500));
     }
     return $sideloaded;
 }
开发者ID:johnpbloch,项目名称:wordpress,代码行数:55,代码来源:class-wp-rest-attachments-controller.php


示例14: launch_editor_for_input

/**
 * Launch system's $EDITOR to edit text
 *
 * @param [string] $input Text to be put into the temp file for changing
 * @param [string] $title Name for the temporary file
 * @return [string] $output Output string if input has changed, false otherwise
 */
function launch_editor_for_input($input, $title = 'Terminus')
{
    $tmpfile = wp_tempnam($title);
    if (!$tmpfile) {
        \Terminus::error('Error creating temporary file.');
    }
    $output = '';
    file_put_contents($tmpfile, $input);
    $editor = getenv('EDITOR');
    if (!$editor) {
        if (isset($_SERVER['OS']) && strpos($_SERVER['OS'], 'indows') !== false) {
            $editor = 'notepad';
        } else {
            $editor = 'vi';
        }
    }
    \Terminus::launch("{$editor} " . escapeshellarg($tmpfile));
    $output = file_get_contents($tmpfile);
    unlink($tmpfile);
    if ($output == $input) {
        return false;
    }
    return $output;
}
开发者ID:reynoldsalec,项目名称:cli,代码行数:31,代码来源:utils.php


示例15: get_google_drive_backup

 function get_google_drive_backup($args)
 {
     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Google/Client.php';
     require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/Google/Service/Drive.php';
     //refresh token
     $client = new IWP_google_Client();
     $client->setClientId($args['clientID']);
     $client->setClientSecret($args['clientSecretKey']);
     $client->setRedirectUri($args['redirectURL']);
     $client->setScopes(array('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'));
     //$client->setUseObjects(true);
     $accessToken = $args['token'];
     $refreshToken = $accessToken['refresh_token'];
     try {
         $client->refreshToken($refreshToken);
     } catch (Exception $e) {
         echo 'google Error ', $e->getMessage(), "\n";
         return array("error" => $e->getMessage(), "error_code" => "google_error_refresh_token");
     }
     //downloading the file
     $service = new IWP_google_Service_Drive($client);
     $file = $service->files->get($args['backup_file']);
     $downloadUrl = $file->getDownloadUrl();
     $temp = wp_tempnam('iwp_temp_backup.zip');
     try {
         if ($downloadUrl) {
             $request = new IWP_google_Http_Request($downloadUrl, 'GET', null, null);
             $signHttpRequest = $client->getAuth()->sign($request);
             $httpRequest = $client->getIo()->makeRequest($signHttpRequest);
             if ($httpRequest->getResponseHttpCode() == 200) {
                 file_put_contents($temp, $httpRequest->getResponseBody());
                 return $temp;
             } else {
                 // An error occurred.
                 return array("error" => "There is some error.", "error_code" => "google_error_bad_response_code");
             }
         } else {
             // The file doesn't have any content stored on Drive.
             return array("error" => "Google Drive file doesnt have nay content.", "error_code" => "google_error_download_url");
         }
     } catch (Exception $e) {
         echo 'google Error ', $e->getMessage(), "\n";
         return array("error" => $e->getMessage(), "error_code" => "google_error_download_url_catch_excep");
     }
 }
开发者ID:Trideon,项目名称:gigolo,代码行数:45,代码来源:backup.class.multicall.php


示例16: test_mime_overrides_filename

 /**
  * Test that a passed mime type overrides the extension in the filename
  * @ticket 6821
  */
 public function test_mime_overrides_filename()
 {
     if (!extension_loaded('fileinfo')) {
         $this->markTestSkipped('The fileinfo PHP extension is not loaded.');
     }
     // Test each image editor engine
     $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick');
     foreach ($classes as $class) {
         // If the image editor isn't available, skip it
         if (!call_user_func(array($class, 'test'))) {
             continue;
         }
         $img = new $class(DIR_TESTDATA . '/images/canola.jpg');
         $loaded = $img->load();
         // Save the file
         $mime_type = 'image/gif';
         $file = wp_tempnam('tmp.jpg');
         $ret = $img->save($file, $mime_type);
         // Make assertions
         $this->assertNotEmpty($ret);
         $this->assertNotInstanceOf('WP_Error', $ret);
         $this->assertEquals($mime_type, $this->get_mime_type($ret['path']));
         // Clean up
         unlink($file);
         unlink($ret['path']);
         unset($img);
     }
 }
开发者ID:CompositeUK,项目名称:clone.WordPress-Develop,代码行数:32,代码来源:functions.php


示例17: test_media_handle_upload_sets_post_excerpt

 /**
  * @ticket 22768
  */
 public function test_media_handle_upload_sets_post_excerpt()
 {
     $iptc_file = DIR_TESTDATA . '/images/test-image-iptc.jpg';
     // Make a copy of this file as it gets moved during the file upload
     $tmp_name = wp_tempnam($iptc_file);
     copy($iptc_file, $tmp_name);
     $_FILES['upload'] = array('tmp_name' => $tmp_name, 'name' => 'test-image-iptc.jpg', 'type' => 'image/jpeg', 'error' => 0, 'size' => filesize($iptc_file));
     $post_id = media_handle_upload('upload', 0, array(), array('action' => 'test_iptc_upload', 'test_form' => false));
     unset($_FILES['upload']);
     $post = get_post($post_id);
     // Clean up.
     wp_delete_attachment($post_id);
     $this->assertEquals('This is a comment. / Это комментарий. / Βλέπετε ένα σχόλιο.', $post->post_excerpt);
 }
开发者ID:nkeat12,项目名称:dv,代码行数:17,代码来源:media.php


示例18: _s

 /**
  * Generate starter code for a theme.
  *
  * ## OPTIONS
  *
  * <slug>
  * : The slug for the new theme, used for prefixing functions.
  *
  * [--activate]
  * : Activate the newly downloaded theme.
  *
  * [--enable-network]
  * : Enable the newly downloaded theme for the entire network.
  *
  * [--theme_name=<title>]
  * : What to put in the 'Theme Name:' header in style.css
  *
  * [--author=<full-name>]
  * : What to put in the 'Author:' header in style.css
  *
  * [--author_uri=<uri>]
  * : What to put in the 'Author URI:' header in style.css
  *
  * [--sassify]
  * : Include stylesheets as SASS
  */
 function _s($args, $assoc_args)
 {
     $theme_slug = $args[0];
     $theme_path = WP_CONTENT_DIR . "/themes";
     $url = "http://underscores.me";
     $timeout = 30;
     $data = wp_parse_args($assoc_args, array('theme_name' => ucfirst($theme_slug), 'author' => "Me", 'author_uri' => ""));
     $theme_description = "Custom theme: " . $data['theme_name'] . " developed by, " . $data['author'];
     $body = array();
     $body['underscoresme_name'] = $data['theme_name'];
     $body['underscoresme_slug'] = $theme_slug;
     $body['underscoresme_author'] = $data['author'];
     $body['underscoresme_author_uri'] = $data['author_uri'];
     $body['underscoresme_description'] = $theme_description;
     $body['underscoresme_generate_submit'] = "Generate";
     $body['underscoresme_generate'] = "1";
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'sassify')) {
         $body['underscoresme_sass'] = 1;
     }
     $tmpfname = wp_tempnam($url);
     $response = wp_remote_post($url, array('timeout' => $timeout, 'body' => $body, 'stream' => true, 'filename' => $tmpfname));
     if (is_wp_error($response)) {
         WP_CLI::error($response);
     }
     $response_code = wp_remote_retrieve_response_code($response);
     if (200 != $response_code) {
         WP_CLI::error("Couldn't create theme (received {$response_code} response).");
     }
     $this->maybe_create_themes_dir();
     $this->init_wp_filesystem();
     $unzip_result = unzip_file($tmpfname, $theme_path);
     unlink($tmpfname);
     if (true === $unzip_result) {
         WP_CLI::success("Created theme '{$data['theme_name']}'.");
     } else {
         WP_CLI::error("Could not decompress your theme files ('{$tmpfname}') at '{$theme_path}': {$unzip_result->get_error_message()}");
     }
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'activate')) {
         WP_CLI::run_command(array('theme', 'activate', $theme_slug));
     } else {
         if (\WP_CLI\Utils\get_flag_value($assoc_args, 'enable-network')) {
             WP_CLI::run_command(array('theme', 'enable', $theme_slug), array('network' => true));
         }
     }
 }
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:71,代码来源:scaffold.php


示例19: respond_to_process_chunk

 /**
  * Handler for the ajax request to process a chunk of data (e.g. SQL inserts).
  *
  * @return bool|null
  */
 function respond_to_process_chunk()
 {
     add_filter('wpmdb_before_response', array($this, 'scramble'));
     $key_rules = array('action' => 'key', 'remote_state_id' => 'key', 'table' => 'string', 'chunk_gzipped' => 'positive_int', 'sig' => 'string');
     $this->set_post_data($key_rules, 'remote_state_id');
     $filtered_post = $this->filter_post_elements($this->state_data, array('action', 'remote_state_id', 'table', 'chunk_gzipped'));
     $gzip = isset($this->state_data['chunk_gzipped']) && $this->state_data['chunk_gzipped'];
     $tmp_file_name = 'chunk.txt';
     if ($gzip) {
         $tmp_file_name .= '.gz';
     }
     $tmp_file_path = wp_tempnam($tmp_file_name);
     if (!isset($_FILES['chunk']['tmp_name']) || !move_uploaded_file($_FILES['chunk']['tmp_name'], $tmp_file_path)) {
         $result = $this->end_ajax(__('Could not upload the SQL to the server. (#135)', 'wp-migrate-db'));
         return $result;
     }
     if (false === ($chunk = file_get_contents($tmp_file_path))) {
         $result = $this->end_ajax(__('Could not read the SQL file we uploaded to the server. (#136)', 'wp-migrate-db'));
         return $result;
     }
     // TODO: Use WP_Filesystem API.
     @unlink($tmp_file_path);
     $filtered_post['chunk'] = $chunk;
     if (!$this->verify_signature($filtered_post, $this->settings['key'])) {
         $error_msg = $this->invalid_content_verification_error . ' (#130)';
         $this->log_error($error_msg, $filtered_post);
         $result = $this->end_ajax($error_msg);
         return $result;
     }
     if ($this->settings['allow_push'] != true) {
         $result = $this->end_ajax(__('The connection succeeded but the remote site is configured to reject push connections. You can change this in the "settings" tab on the remote site. (#139)', 'wp-migrate-db'));
         return $result;
     }
     if ($gzip) {
         $filtered_post['chunk'] = gzuncompress($filtered_post['chunk']);
     }
     $process_chunk_result = $this->process_chunk($filtered_post['chunk']);
     $result = $this->end_ajax($process_chunk_result);
     return $result;
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:45,代码来源:wpmdbpro.php


示例20: put_contents

 function put_contents($file, $contents, $type = '')
 {
     if (empty($type)) {
         $extension = substr(strrchr($file, '.'), 1);
         $type = isset($this->filetypes[$extension]) ? $this->filetypes[$extension] : FTP_AUTOASCII;
     }
     $this->ftp->SetType($type);
     $temp = wp_tempnam($file);
     if (!($temphandle = fopen($temp, 'w+'))) {
         unlink($temp);
         return false;
     }
     fwrite($temphandle, $contents);
     fseek($temphandle, 0);
     //Skip back to the start of the file being written to
     $ret = $this->ftp->fput($file, $temphandle);
     fclose($temphandle);
     unlink($temp);
     return $ret;
 }
开发者ID:nurpax,项目名称:saastafi,代码行数:20,代码来源:class-wp-filesystem-ftpsockets.php



注:本文中的wp_tempnam函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_terms_checklist函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_templating_constants函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap