1 | <?php |
1 | <?php |
| |
2 | |
| |
3 | //サイズ指定 |
| |
4 | function thumbnail_size_setup() { |
| |
5 | if(update_option('thumbnail_size_w', 150)) { |
| |
6 | update_option('thumbnail_size_h', 150); |
| |
7 | } |
| |
8 | if(update_option('medium_size_w', 400)) { |
| |
9 | update_option('medium_size_h', auto); |
| |
10 | } |
| |
11 | if(update_option('large_size_w', 546)) { |
| |
12 | update_option('large_size_h', auto); |
| |
13 | } |
| |
14 | } |
| |
15 | add_action('after_setup_theme', 'thumbnail_size_setup'); |
| |
16 | |
| |
17 | /* Name : Resize an image at upload |
| |
18 | * Version: 1.0.0 |
| |
19 | * Author : Otokuni Consulting Co.,Ltd. |
| |
20 | * Author URI: http://www.oto-con.com/ |
| |
21 | * License: GPLv2 or later |
| |
22 | * Description : This function is useful when the user often upload very large size image. |
| |
23 | */ |
| |
24 | |
| |
25 | /* |
| |
26 | This program is free software; you can redistribute it and/or |
| |
27 | modify it under the terms of the GNU General Public License |
| |
28 | as published by the Free Software Foundation; either version 2 |
| |
29 | of the License, or (at your option) any later version. |
| |
30 | |
| |
31 | This program is distributed in the hope that it will be useful, |
| |
32 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
33 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
34 | GNU General Public License for more details. |
| |
35 | |
| |
36 | You should have received a copy of the GNU General Public License |
| |
37 | along with this program; if not, write to the Free Software |
| |
38 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| |
39 | */ |
| |
40 | |
| |
41 | function otocon_resize_at_upload( $file ) { |
| |
42 | // $file contains file, url, type |
| |
43 | // array( 'file' => 'path to the image', 'url' => 'url of the image', 'type' => 'mime type' ) |
| |
44 | |
| |
45 | // resize only if the mime type is image |
| |
46 | if ( $file['type'] == 'image/jpeg' OR $file['type'] == 'image/gif' OR $file['type'] == 'image/png') { |
| |
47 | |
| |
48 | // set width and height |
| |
49 | $w = intval(get_option( 'large_size_w' ) ); // get large size width |
| |
50 | $h = intval(get_option( 'large_size_h' ) ); // get large size height |
| |
51 | |
| |
52 | // get the uploaded image |
| |
53 | $image = wp_get_image_editor( $file['file'] ); |
| |
54 | |
| |
55 | // if no error |
| |
56 | if ( ! is_wp_error( $image ) ){ |
| |
57 | // get image width and height |
| |
58 | $size = getimagesize( $file['file'] ); // $size[0] = width, $size[1] = height |
| |
59 | |
| |
60 | if ( $size[0] > $w || $size[1] > $h ){ // if the width or height is larger than the large-size |
| |
61 | $image->resize( $w, $h, false ); // resize the image |
| |
62 | $final_image = $image->save( $file['file'] ); // save the resized image |
| |
63 | } |
| |
64 | } |
| |
65 | |
| |
66 | } // if mime type |
| |
67 | |
| |
68 | return $file; |
| |
69 | |
| |
70 | } |
| |
71 | add_action( 'wp_handle_upload', 'otocon_resize_at_upload' ); |
| |
72 | |
| |
73 | |
| |
74 | //アイキャッチサムネイル |
| |
75 | add_theme_support('post-thumbnails'); |
| |
76 | add_image_size('thumb100',100,100,true); |
| |
77 | add_image_size('thumb110',110,110,true); |
| |
78 | add_image_size( 'my_thumbnail', '100%', 'auto', true ); |
| |
79 | |
| |
80 | |
| |
81 | //管理画面の不要な表示を削除 |
2 | function example_remove_dashboard_widgets() {global $wp_meta_boxes; |
82 | function example_remove_dashboard_widgets() {global $wp_meta_boxes; |
| | | |
13 | |
93 | |
14 | |
94 | //ENJIからのお知らせ |
15 | function dashboard_widget_function() { |
95 | function dashboard_widget_function() { |
| | | |
33 | add_filter( 'wp_unique_post_slug', 'auto_post_slug', 10, 4 ); |
113 | add_filter( 'wp_unique_post_slug', 'auto_post_slug', 10, 4 ); |
34 | //アイキャッチサムネイル |
114 | |
35 | add_theme_support('post-thumbnails'); |
115 | |
36 | add_image_size('thumb100',100,100,true); |
| |
37 | add_image_size('thumb110',110,110,true); |
| |
38 | //カスタムメニュー |
116 | //カスタムメニュー |
| | | |
51 | |
129 | |
52 | //メディアサイズ追加 |
| |
53 | add_image_size( 'my_thumbnail', '100%', 'auto', true ); |
| |
54 | |
| |
55 | //画像に重ねる文字の色 |
130 | //画像に重ねる文字の色 |
| | | |
62 | get_template_part('functions/create-thread'); |
137 | get_template_part('functions/create-thread'); |
| |
138 | |
63 | //カスタム背景 |
139 | //カスタム背景 |
| | | |
65 | add_theme_support( 'custom-background', array()); |
141 | add_theme_support( 'custom-background', array()); |
66 | //ページャー機能 |
| |
67 | |
| |
68 | |
142 | |
| |
143 | //ページャー機能 |
69 | function pagination($pages = '', $range = 4) |
144 | function pagination($pages = '', $range = 4) |
| | | |
152 | |
227 | |
153 | |
228 | //ウイジェット追加 |
154 | if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(4) ) |
229 | if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(4) ) |
| | | |
178 | )); |
253 | )); |
| |
254 | |
| |
255 | |
| |
256 | |
179 | |
257 | |
| | | |
| |
| |