Skip to content

Instantly share code, notes, and snippets.

View torounit's full-sized avatar

Hiroshi Urabe torounit

View GitHub Profile
@torounit
torounit / gist:3765200
Created September 22, 2012 05:11
WordPressのマルチサイトでブログが追加されたときに、フロントページ・投稿ページを自動追加するクラス
class Mu_Set_Front {
public function __construct() {
add_action( 'wpmu_new_blog', array(&$this, 'create_front_page'), 10 ,2 );
}
public function create_front_page( $blog_id, $user_id ) {
switch_to_blog( $blog_id );
if( !get_page_by_path('front-page') ) {
update_option( 'show_on_front', 'page' );
@torounit
torounit / HOW to Use
Created November 13, 2012 09:37
子サイトの一覧を持って来るクラス
<?php
$child_blog = new Child_Blog();
$child_blog->count= 5;//5サイトずつ持って来る。デフォルトは3つ。
$blogs = $child_blog->get_blog_ids(get_query_var('paged'));
foreach ($blogs as $key => $blog) {
if($blog->blog_id != 1) {
switch_to_blog( $blog->blog_id );
@torounit
torounit / gist:5106240
Created March 7, 2013 07:38
Wordpressで指定したカテゴリーの年別アーカイブを作成する | webOpixel http://www.webopixel.net/wordpress/236.html の改造版。プラグイン有効時にflush_rules()か、パーマリンク設定の更新が必要。
<?php
function extend_date_archives_add_rewrite_rules() {
add_rewrite_rule( 'category/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]&feed=$matches[4]', 'top' );
add_rewrite_rule( 'category/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$', 'index.php?category_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]', 'top' );
add_rewrite_rule( 'category/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?category_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]', 'top' );
add_rewrite_rule( 'category/([^/]+)/date/([0-9]{4})/?$', 'index.php?category_name=$matches[1]&year=$matches[2]', 'top' );
}
add_action('wp_loaded', 'extend_date_archives_add_rewrite_rules');
@torounit
torounit / batch-category-import-fix.php
Last active December 15, 2015 02:29
Batch categories import http://wordpress.org/extend/plugins/batch-category-import/ をハックしてカスタムタクソノミーにも対応させる。
<?php
/*
Plugin Name: Batch Term Import
Version: 1.1
Description: Batch Term Import forked by Batch categories Import cerated by Guy Maliar.(http://www.egstudio.biz/)
*/
if(!class_exists("CategoryImport")) {
class CategoryImport{
@torounit
torounit / location-field.php
Last active January 29, 2021 16:04
Fixed Repeater x location fields.
<?php
/*
* Plugin Name: Advanced Custom Fields - Location Field add-on
* Plugin URI: https://github.com/julienbechade/acf-location-field
* Description: This plugin is an add-on for Advanced Custom Fields. It allows you to find coordinates and/or address of a location with Google Maps.
* Author: Julien Bechade
* Author URI: http://julienbechade.com/
* Version: 1.0
* Text Domain: acf-location-field
* Domain Path: /lang/
@torounit
torounit / mu-blog-util.php
Created March 29, 2013 03:18
WordPressのマルチサイト用のユーティリティ ブログパスからblog_id取得とか。サブディレクトリ用。
<?php
/*
Plugin Name: MU Blog Util
Description: マルチサイト用のユーティリティ
Author: Toro-Unit
*/
class MU_Blog_Util {
@torounit
torounit / gist:5368443
Created April 12, 2013 00:56
WordPressの投稿をJSONで吐き出す。
Class WP_JSON_API {
public function __construct() {
add_action( "init", array( &$this, "add_query_var" ),10);
add_action( "init", array( &$this, "json_actions" ),11);
}
public function add_query_var() {
@torounit
torounit / current_hierarchical.php
Last active December 17, 2015 01:49
WordPressの階層のある投稿タイプで、最上位の親投稿のIDを返す。階層の無い投稿タイプの場合 falseを返す。
<?php
function current_hierarchical() {
global $post;
$post_type_object = get_post_type_object( get_post_type() );
if ( $post_type_object->hierarchical ) {
if ( $post->post_parent ) { // is child page
$ancestors = get_post_ancestors( $post->ID );
$root_ID = array_pop( $ancestors );
}
@torounit
torounit / Ms_Body_Class.php
Created May 11, 2013 17:51
WordPressマルチサイトで、body_classに"site-hoge"を出力するクラス。
<?php
class Ms_Body_Class {
public function __construct() {
add_filter( "body_class", array( $this, "body_class" ));
}
public function get_blog_path() {
$blog_details = get_blog_details($GLOBALS['blog_id']);
<?php
if ( ! class_exists( 'PM_Schedule_Post' ) ) {
class PM_Schedule_Post {
protected $from = '';
protected $to = '';
protected $label = '';
public function __construct( $from, $to, $label = 'expired' ) {
$this->from = $from;
$this->to = $to;