-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfunctions.php
302 lines (276 loc) · 9.29 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
/*
-------------------------------------------
Load Module
Theme setup
Load Theme CSS & JS
Load Admin CSS & JS
WidgetArea initiate
Add Post Type Client
Remove_post_editor_support
Replace Post Label
Replace Document Title
ログイン画面のロゴ
-------------------------------------------
*/
$theme_opt = wp_get_theme( get_template() );
define( 'BILLVEKTOR_THEME_VERSION', $theme_opt->Version );
/**
* Composer Autoload
*/
$autoload_path = plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
// vendor ディレクトリがない状態で誤配信された場合に Fatal Error にならないようにファイルの存在確認.
if ( file_exists( $autoload_path ) ) {
// Composer のファイルを読み込み ( composer install --no-dev )
require_once $autoload_path;
}
// Update Checker
if ( class_exists( 'YahnisElsts\PluginUpdateChecker\v5\PucFactory' ) ){
$my_update_checker = YahnisElsts\PluginUpdateChecker\v5\PucFactory::buildUpdateChecker(
'https://github.com/vektor-inc/bill-vektor',
__FILE__,
'bill-vektor'
);
$my_update_checker->getVcsApi()->enableReleaseAssets();
}
/**
* 存在する消費税率の配列
*
* 消費税率の高い順に並べた配列。2番目以降は軽減税率フラグが立つ
* @return $tax_array : 10%, 8%, 0%
*/
function bill_vektor_tax_array() {
$tax_array = array( '10%', '8%', '0%' );
return $tax_array;
}
/*
-------------------------------------------
Load Module
-------------------------------------------
*/
require_once dirname( __FILE__ ) . '/inc/custom-field-builder-config.php';
require_once dirname( __FILE__ ) . '/inc/custom-field/custom-field-normal-bill.php';
require_once dirname( __FILE__ ) . '/inc/custom-field/custom-field-normal-estimate.php';
require_once dirname( __FILE__ ) . '/inc/custom-field/custom-field-normal-client.php';
require_once dirname( __FILE__ ) . '/inc/custom-field/custom-field-table.php';
require_once dirname( __FILE__ ) . '/inc/custom-field/custom-field-table-bill.php';
require_once dirname( __FILE__ ) . '/inc/setting-page/setting-page.php';
require_once dirname( __FILE__ ) . '/inc/duplicate-doc/duplicate-doc.php';
require_once dirname( __FILE__ ) . '/inc/export/class.csv-export.php';
get_template_part( 'inc/template-tags' );
get_template_part( 'inc/functions-limit-view' );
get_template_part( 'inc/functions-pre-get-posts' );
/*
-------------------------------------------
Theme setup
-------------------------------------------
*/
function bill_theme_title() {
// title tag
add_theme_support( 'title-tag' );
// custom menu
register_nav_menus( array( 'Header Navigation' => 'Header Navigation' ) );
}
add_action( 'after_setup_theme', 'bill_theme_title' );
/*
-------------------------------------------
Load Theme CSS & JS
-------------------------------------------
*/
function bill_theme_scripts() {
// 静的HTMLで読み込んでいたCSSを読み込む
wp_enqueue_style( 'bill-css-bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '3.3.6' );
wp_enqueue_style( 'bill-css', get_template_directory_uri() . '/assets/css/style.css', array( 'bill-css-bootstrap' ), BILLVEKTOR_THEME_VERSION );
// テーマディレクトリ直下にある style.css を出力
wp_enqueue_style( 'bill-theme-style', get_stylesheet_uri(), array( 'bill-css' ), BILLVEKTOR_THEME_VERSION );
// テーマ用のjsを読み込む
wp_enqueue_script( 'bill-js-bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array( 'jquery' ), BILLVEKTOR_THEME_VERSION, true );
wp_register_script( 'datepicker', get_template_directory_uri() . '/inc/custom-field-builder/js/datepicker.js', array( 'jquery', 'jquery-ui-datepicker' ), BILLVEKTOR_THEME_VERSION, true );
wp_enqueue_script( 'datepicker' );
}
add_action( 'wp_enqueue_scripts', 'bill_theme_scripts' );
/*
-------------------------------------------
Load Admin CSS & JS
-------------------------------------------
*/
function bill_admin_scripts() {
// 管理画面用のcss
wp_enqueue_style( 'bill-admin-css', get_template_directory_uri() . '/assets/css/admin-style.css', BILLVEKTOR_THEME_VERSION, null );
}
add_action( 'admin_enqueue_scripts', 'bill_admin_scripts' );
/*
-------------------------------------------
WidgetArea initiate
-------------------------------------------
*/
function bill_widgets_init() {
register_sidebar(
array(
'name' => 'Sidebar',
'id' => 'sidebar-widget-area',
'before_widget' => '<aside class="sub-section section %2$s" id="%1$s">',
'after_widget' => '</aside>',
'before_title' => '<h4 class="sub-section-title">',
'after_title' => '</h4>',
)
);
}
add_action( 'widgets_init', 'bill_widgets_init' );
/*
-------------------------------------------
Add Post Type Client
-------------------------------------------
*/
add_action( 'init', 'bill_add_post_type_client', 0 );
function bill_add_post_type_client() {
register_post_type(
'client', /* カスタム投稿タイプのスラッグ */
array(
'labels' => array(
'name' => '取引先・送付状',
'view_item' => '送付状を表示',
'edit_item' => '送付状を編集',
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'has_archive' => false,
'supports' => array( 'title' ),
'menu_icon' => 'dashicons-building',
'menu_position' => 3,
)
);
}
/*
-------------------------------------------
Add Post Type Estimate
-------------------------------------------
*/
add_action( 'init', 'bill_add_post_type_estimate', 0 );
function bill_add_post_type_estimate() {
register_post_type(
'estimate',
array(
'labels' => array(
'name' => '見積書',
'edit_item' => '見積書の編集',
'add_new_item' => '見積書の作成',
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'has_archive' => true,
'supports' => array( 'title' ),
'menu_icon' => 'dashicons-media-spreadsheet',
'menu_position' => 5,
)
);
register_taxonomy(
'estimate-cat',
'estimate',
array(
'hierarchical' => true,
'update_count_callback' => '_update_post_term_count',
'label' => '見積書カテゴリー',
'singular_label' => '見積書カテゴリー',
'public' => true,
'show_ui' => true,
)
);
}
/*
-------------------------------------------
Remove_post_editor_support
-------------------------------------------
*/
function bill_remove_post_editor_support() {
remove_post_type_support( 'post', 'editor' );
}
add_action( 'init', 'bill_remove_post_editor_support' );
/*
-------------------------------------------
Replace Post Label
-------------------------------------------
*/
function bill_change_post_type_args_post( $args ) {
if ( isset( $args['rest_base'] ) && $args['rest_base'] == 'posts' ) {
$args['labels']['name_admin_bar'] = '請求書';
$args['labels']['name'] = '請求書';
$args['labels']['edit_item'] = '請求書の編集';
$args['labels']['add_new_item'] = '請求書の作成';
}
return $args;
}
add_filter( 'register_post_type_args', 'bill_change_post_type_args_post' );
/*
-------------------------------------------
Replace Document Title
-------------------------------------------
*/
function bill_title_custom( $title ) {
$target_post_types = array( 'post', 'estimate', 'receipt' );
if ( is_single() ) {
global $post;
setup_postdata( $post );
$post_type = bill_get_post_type();
if ( in_array( $post_type['slug'], $target_post_types ) ) {
// 書類種別
$title = $post_type['name'] . '_';
// 取引先名
$title .= bill_get_client_name( $post );
// 敬称
$client_honorific = esc_html( get_post_meta( $post->bill_client, 'client_honorific', true ) );
if ( $client_honorific ) {
$title .= $client_honorific . '_';
} else {
$title .= '御中_';
}
// 件名
$title .= get_the_title() . '_';
$title .= get_the_date( 'Ymd' );
}
}
return strip_tags( $title );
}
add_filter( 'wp_title', 'bill_title_custom', 11 );
add_filter( 'pre_get_document_title', 'bill_title_custom', 11 );
/*
-------------------------------------------
未来の投稿の公開
-------------------------------------------
*/
// 予約投稿機能を無効化
add_action( 'save_post', 'bill_future_publish', 99 );
add_action( 'edit_post', 'bill_future_publish', 99 );
function bill_future_publish() {
global $wpdb;
$sql = 'UPDATE `' . $wpdb->prefix . 'posts` ';
$sql .= 'SET post_status = "publish" ';
$sql .= 'WHERE post_status = "future"';
$wpdb->get_results( $sql );
}
function bill_immediately_publish( $id ) {
global $wpdb;
$q = 'UPDATE ' . $wpdb->posts . " SET post_status = 'publish' WHERE ID = " . (int) $id;
$wpdb->get_results( $q );
}
add_action( 'future_event', 'bill_immediately_publish' );
/*
-------------------------------------------
ログイン画面のロゴ
-------------------------------------------
*/
function custom_login_logo() { ?>
<style>
.login #login h1 a {
width: 300px;
height: 65px;
background: url(<?php echo get_template_directory_uri(); ?>/assets/images/head_logo.png) no-repeat 0 0;
}
</style>
<?php
}
add_action( 'login_enqueue_scripts', 'custom_login_logo' );