[WordPress]ショートコード#1
function sc_get_template($atts) { $param = shortcode_atts( array( 'file' => '', ), $atts ); $param['file'] = ltrim($param['file'],'/.'); $file = TEMPLATEPATH . DIRECTORY_SEPARATOR . $param['file']; if(!file_exists($file))return ''; ob_start(); include($file); $contents = ob_get_contents(); ob_end_clean(); return $contents; } add_shortcode('get_template', 'sc_get_template');
[get_template file="module/_head.php"]
[MySQL]AES_ENCRYPT
CREATE TABLE `users` ( `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARBINARY(100) NULL DEFAULT NULL, `email` VARBINARY(200) NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE INDEX `id` (`id`) ) ENGINE=InnoDB ;
crypto_saltは任意の文字列
SET @key_str = SHA2('crypto_salt',512); INSERT INTO users(name,email) VALUES(AES_ENCRYPT('佐藤鈴木',@key_str),AES_ENCRYPT('satosuzuki@nullmail.com',@key_str));
SET @key_str = SHA2('crypto_salt',512); SELECT id,AES_DECRYPT(`name`,@key_str) AS name,AES_DECRYPT(`email`,@key_str) AS email FROM users;
[PHP]idiorm #1
require_once 'idiorm.php'; ORM::configure('mysql:host=localhost;dbname=dev_db'); ORM::configure('username', 'root'); ORM::configure('password', ''); ORM::configure('driver_options', [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, ]); function echo_json($data) { header("Content-Type: application/json; charset=utf-8"); echo json_encode($data); } $words = mb_split('[\s, ]',addcslashes(trim($_POST['keywords']),'\_%')); try{ $orm = ORM::for_table('entries')->select('id')->where_equal('deleted','0')->order_by_asc('id'); foreach ($words as $w) { $w = trim($w); if($w !== '') $orm->where_like('search', "%{$w}%"); } $recipes = $orm->find_many(); }catch (PDOException $e){ } $result_data = array(); if(!empty($recipes)){ foreach ($recipes as $recipe) $result_data[] = $recipe->html_id; } echo_json($result_data); exit;
[PHP]remove_protocol
public function remove_protocol($url) { return preg_replace('/^https?:\/\/[^\/]+/', '', $url); }
[WordPress]初期設定
update wp_options set option_value='/manage' where option_name = 'siteurl'; update wp_options set option_value='/' where option_name = 'home'; update wp_options set option_value='/uploads' where option_name = 'upload_url_path'; update wp_options set option_value='../uploads' where option_name = 'upload_path'; update wp_options set option_value='' where option_name = 'blogdescription'; update wp_options set option_value='0' where option_name = 'start_of_week'; update wp_options set option_value='Y/m/d' where option_name = 'date_format'; update wp_options set option_value='H:i' where option_name = 'time_format'; update wp_options set option_value='closed' where option_name = 'default_comment_status'; update wp_options set option_value='closed' where option_name = 'default_ping_status'; update wp_options set option_value='0' where option_name = 'thumbnail_size_w'; update wp_options set option_value='0' where option_name = 'thumbnail_size_h'; update wp_options set option_value='0' where option_name = 'medium_size_w'; update wp_options set option_value='0' where option_name = 'medium_size_h'; update wp_options set option_value='0' where option_name = 'large_size_w'; update wp_options set option_value='0' where option_name = 'large_size_h'; update wp_options set option_value='0' where option_name = 'medium_large_size_w'; update wp_options set option_value='0' where option_name = 'medium_large_size_h'; update wp_options set option_value='0' where option_name = 'uploads_use_yearmonth_folders'; update wp_options set option_value='/%postname%/' where option_name = 'permalink_structure';
plugin require
Advanced Custom Fields PRO Custom Post Type UI Scheduled Post Trigger User Role Editor WP Term Order Duplicate Post
plugin option
Radio Buttons for Taxonomies Parent Category Toggler Adjust Admin Categories
[PHP]download_file
function download_file($filePath) { header("Content-Disposition: inline; filename=\"" . basename($filePath) . "\""); header("Content-Length: " . filesize($filePath)); header("Content-Type: application/octet-stream"); readfile($filePath); }
[IE]IE11で特定のファイルをダウンロードしようとすると文字化けタブが開く時
.htaccessへ下記を追記
AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document .docx AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet .xlsx AddType application/vnd.openxmlformats-officedocument.presentationml.presentation .pptx
[PHP]get_image_rgb
public function get_image_rgb($image_path,$x=0,$y=0) { if(!is_readable($image_path)) return false; $im = imagecreatefrompng($image_path); $rgb = imagecolorat($im, $x, $y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; return array( 'r' => $r, 'g' => $g, 'b' => $b, ); }