<?php
/*
-- This Plugin's Information --------------------------------
Plugin Name: Custom Field Gui Utility
- Site1
Plugin URI: http://www.tinybeans.net/blog/download/wp-plugin/cfg-utility-3.html
Description: WordPress 3.3x用。カスタムフィールドを使いやすくするプラグイン「Custom Field GUI」のカスタマイズ版。オリジナルプラグインの作者は、 <a href="http://rhymedcode.net">Joshua Sigar氏</a>。
Author: Tomohiro Okuwaki
Author URI: http://www.tinybeans.net/blog/
Version: 3.2.7
Customize: Tomohiro Okuwaki (http://www.tinybeans.net/blog/)
Thanks: @hadakadenkyu <http://twitter.com/hadakadenkyu>
-- This Plugin's Information --------------------------------
-- Original Plugin's Information --------------------------------
Original Plugin's Name: rc:custom_field_gui
Original Plugin's URI: http://rhymedcode.net/projects/custom-field-gui
Original Plugin's Description: Automatically adds form element(s) in Write Post panel, which act as a Post's custom field(s). Configuration is thru conf.ini. Instruction is on readme.txt.
Original Plugin's Author: Joshua Sigar
Original Plugin's Version: 1.5
Original Plugin's Author URI: http://rhymedcode.net
-- /Original Plugin's Information --------------------------------
*/
/*
rc:custom_field_gui
Licensed under the MIT License
Copyright (c) 2005 Joshua Sigar
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
require_once (ABSPATH . 'wp-admin/includes/template.php');
add_action ('admin_head','insert_head
_Site1
');
add_action ('add_meta_boxes', 'isert_custom_field_gui
_Site1');
/* edit_post : 投稿記事またはページが更新・編集された際に実行する。これには、コメントが追加・更新された場合(投稿またはページのコメント数が更新される)も含む。 */
add_action('edit_post', 'edit_meta_value
_Site1');
/* save_post : インポート機能の利用、記事・ページ編集フォームの利用、XMLRPCでの投稿、メールでの投稿のうちいずれかの方法で記事・ページが作成・更新された際に実行する。 */
add_action('save_post', 'edit_meta_value
_Site1');
/* publish_post : 投稿記事が公開された際、または公開済みの記事の情報が編集された際に実行する。 */
add_action('publish_post', 'edit_meta_value
_Site1');
/* transition_post_status : 記事・ページが公開された際、またはステータスが「公開」に変更された場合に実行する。 */
add_action('transition_post_status', 'edit_meta_value
_Site1');
/******************
Functions(main)
******************/
/* 管理画面のhead要素でCSSとJavaScriptファイルの読み込み */
function insert_head
_Site1() {
$plugin_url = get_bloginfo('wpurl') . '/wp-content/plugins/custom-field-gui-utility-
Site1/';
$head = <<< EOD
<link rel="stylesheet" href="{$plugin_url}facebox/facebox.css" type="text/css" media="all" />
<link rel="stylesheet" href="{$plugin_url}cfg-utility.css" type="text/css" media="all" />
<link rel="stylesheet" href="{$plugin_url}exValidation/css/exvalidation.css" type="text/css" />
<script type="text/javascript" src="{$plugin_url}facebox/facebox.js"></script>
<script type="text/javascript" src="{$plugin_url}exValidation/js/exvalidation.js"></script>
<script type="text/javascript" src="{$plugin_url}exValidation/js/exchecker-ja.js"></script>
<script type="text/javascript" src="{$plugin_url}cfg-utility.js"></script>
<script type="text/javascript">
jQuery(function($){
$("form#post").exValidation();
});
</script>
EOD;
echo $head;
}
/* add_meta_boxesで実行する関数 */
function isert_custom_field_gui
_Site1 ($post_type = 'post', $post = NULL) {
add_meta_box('cfg_utility', get_field_title($post_type), 'insert_gui', $post_type, 'normal', 'high');
}
function edit_meta_value
_Site1($post_id) {
if ($post_id == 0) {
return $post_id;
}
global $wpdb;
if (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
$nonce = isset($_REQUEST['custom-field-gui-verify-key']) ? $_REQUEST['custom-field-gui-verify-key']: '';
if (!wp_verify_nonce($nonce, 'custom-field-gui')) {
return $post_id;
}
global $post;
$fields = get_conf_ini($post->post_type);
if (!$fields) {
return $post_id;
}
foreach($fields as $meta_key => $data) {
$name = 'cfg_' . sanitize_name($meta_key);
$data_type = isset($data['type']) ? $data['type']: '';
if ($data_type == 'hr' or $meta_key == 'cfgu_setting') {
continue;
}
$meta_value = isset($_REQUEST["$name"]) ? stripslashes(trim($_REQUEST["$name"])): '';
if (isset($meta_value) && !empty($meta_value)) {
delete_post_meta($post_id, $meta_key);
if ($data_type == 'textfield' ||
$data_type == 'imagefield' ||
$data_type == 'filefield' ||
$data_type == 'multi_checkbox' ||
$data_type == 'radio' ||
$data_type == 'select' ||
$data_type == 'textarea') {
add_post_meta($post_id, $meta_key, $meta_value);
} elseif ($data['type'] == 'checkbox') {
add_post_meta($post_id, $meta_key, 'true');
}
} elseif (isset($meta_value) && strval($meta_value) === '0') {
add_post_meta($post_id, $meta_key, '0');
} else {
delete_post_meta($post_id, $meta_key);
}
}
}
?>