All in one Background(Custom Background Images & Colors) : 포스트 / 페이지 등에 배경이미지와 색상을 지정할 수 있습니다. Features : 랜덤 슬라이드 메인 배경이미지, 특정일자의 배경이미지, 배경 패턴을 추가할 예정입니다.
Version: 0.9.1
Author: 1eftHander
Author URI: http://www.1efthander.com
*/
//Wordpress Tested up to : 3.4.2
define('AIOB_VERSION', '0.9.0');
define('CRLF', "\n");
//add_meta_boxes라는 hook에 add_aiob_meta_box 함수 등록. add_meta_boxes : Runs when "edit post" page loads. (3.0+)
add_action('add_meta_boxes', 'add_aiob_meta_box');
//admin_enqueue_scripts라는 hook에 load_css_js 함수 등록
//js, css파일을 따로 등록했을 경우 반드시 처리해야 함
add_action('admin_enqueue_scripts', 'load_css_js');
//포스트 / 페이지 저장할 때마다 실행
add_action('save_post', 'save_aiob_meta_box');
//포스트 / 페이지 css
add_action('wp_head', 'add_aiob_css', 99999);
//ajax
add_action('wp_ajax_nopriv_select_aiob_media', 'select_aiob_media');
add_action('wp_ajax_select_aiob_media', 'select_aiob_media');
//post type별 add meta box
function add_aiob_meta_box()
{
if ( function_exists('add_meta_box') )
{
add_meta_box(
'AIOB'
, __('All in one Background')
, 'aiob_meta_box'
, null //post|page|link|custom_post_type|null(current)
, 'normal' //advanced|normal|side
, 'high' //default|high|core|low
);
}
}
//aiob & farbtastic load
function load_css_js()
{
wp_register_style('aiob', plugins_url('/all-in-one-background.css', __FILE__), false, AIOB_VERSION);
wp_enqueue_style('aiob');
wp_register_script('aiob', plugins_url('/all-in-one-background.js', __FILE__), false, AIOB_VERSION);
wp_enqueue_script('aiob');
wp_enqueue_script('farbtastic');
wp_enqueue_style('farbtastic');
}
//aiob meta box save
function save_aiob_meta_box($post_id)
{
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
update_post_meta($post_id, '_aiob_background', $_REQUEST['_aiob_background']);
update_post_meta($post_id, '_aiob_attachment', $_REQUEST['_aiob_attachment']);
update_post_meta($post_id, '_aiob_repeat', $_REQUEST['_aiob_repeat']);
update_post_meta($post_id, '_aiob_color_picker', $_REQUEST['_aiob_color_picker']);
update_post_meta($post_id, '_aiob_image_id', $_REQUEST['_aiob_image_id']);
update_post_meta($post_id, '_aiob_image_url', $_REQUEST['_aiob_image_url']);
}
//meta box layer
function aiob_meta_box()
{
$meta = get_post_meta(get_the_ID());
$attachment_id;
$attach_info;
$file_name;
$file_type;
$upload_date;
$media_dims;
$img_tag;
if ( isset($meta['_aiob_image_id'][0]) && $meta['_aiob_image_id'][0] != '')
{
$attachment_id = $meta['_aiob_image_id'][0];
$attach_info = get_post($attachment_id);
$file_name = esc_html(basename($attach_info->guid));
$file_type = $attach_info->post_mime_type;
$upload_date = mysql2date( get_option('date_format'), $attach_info->post_date );
$attach_meta = wp_get_attachment_metadata($attach_info->ID);
if ( is_array($attach_meta)
&& array_key_exists('width', $attach_meta)
&& array_key_exists('height', $attach_meta) )
{
$media_dims .= "{$attach_meta['width']} × {$attach_meta['height']} ";
}
$media_dims = apply_filters('media_meta', $media_dims, $attach_info);
$img_tag = '';
}
echo CRLF . '