This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nginx_flush_cache( $url ) { | |
global $nginx_servers; | |
static $urls = array(); | |
if ( !$url ) | |
return; | |
if ( isset($urls[md5($url)]) ) | |
return; | |
$urls[md5($url)] = $url; | |
$log_file = '/tmp/nginx_flush_cache.log'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('/path/to/wordpress/wp-load.php'); | |
require_once('class-wp_post_helper.php'); | |
// 初期化 | |
$post = new wp_post_helper(array( | |
'post_name' => 'slug' , // スラッグ | |
'post_author' => 1 , // 投稿者のID | |
'post_date' => '2012/11/15 20:00:00' , // 投稿時刻 | |
'post_type' => 'posts' , // 投稿タイプ(カスタム投稿タイプも指定できるよ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function thumbnail_noimage($html, $post_id, $post_thumbnail_id, $size, $attr) { | |
if (!empty($html)) | |
return $html; | |
$post_thumbnail_id = 1234; // default thumbnail image id | |
$html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); | |
return $html; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- カテゴリー 4 の投稿を、カスタム投稿タイプ photo に | |
update wp_posts | |
set post_type = 'photo' | |
where post_type = 'post' | |
and exists | |
(select object_id | |
from wp_term_taxonomy as t | |
inner join wp_relationships as r on t.term_taxonomy_id = r.term_taxonomy_id | |
where t.term_id = 4 | |
and r.object_id = wp_posts.ID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function attachment_link_convert($content){ | |
global $wpdb; | |
$upload_dir = wp_upload_dir(); | |
$pattern = '#(<a [^>]*href=[\'"])('.preg_quote($upload_dir['baseurl']).'/)([^\'"]*)([\'"][^>]*><img [^>]*></a>)#uism'; | |
if ( preg_match_all($pattern, $content, $matches, PREG_SET_ORDER) ) { | |
foreach ( $matches as $match ) { | |
$attachment_id = $wpdb->get_var($wpdb->prepare(" | |
select p.ID | |
from {$wpdb->posts} as p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
sed -e 's/\(EXISTS\|TABLES\?\|INSERT INTO\) `wp_/\1 `wp_other_/ig' dump.sql > dump_new.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
delete from wp_posts | |
where post_status in ('auto-draft', 'trash') | |
or post_type = 'revision'; | |
delete from wp_postmeta | |
where not exists (select 'x' from wp_posts where wp_posts.ID = wp_postmeta.post_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter('query_vars', function($vars){ | |
array_push($vars, 'my_meta_key'); | |
return $vars; | |
}); | |
add_action('restrict_manage_posts', function(){ | |
printf( | |
'<input type="text" id="%1$s" name="%1$s" value="%2$s" />', | |
'my_meta_key', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wp_embed_handler_image( $matches, $attr, $url, $rawattr ) { | |
$embed = sprintf( | |
'<img src="%1$s" alt="" />', | |
esc_attr($matches[0]) | |
); | |
return apply_filters( 'embed_image', $embed, $matches, $attr, $url, $rawattr ); | |
} | |
wp_embed_register_handler( 'image', '/^https?(:\/\/[-_\.!~*\'()a-zA-Z0-9;\/:\@=+\$,%#]+)(\.jpe?g|\.gif|\.png)$/', 'wp_embed_handler_image', 10, 4 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_attachment_title($title, $id) { | |
if ( is_admin() ) | |
return $title; | |
$post = is_object($id) | |
? $id | |
: $post = get_post($id); | |
if ( !$post || $post->post_type !== 'attachment' ) |