Make WordPress Themes

source: lightning/15.31.1/functions.php

Last change on this file was 275423, checked in by themedropbox, 6 months ago

New version of Lightning - 15.29.9

File size: 6.6 KB
Line 
1<?php
2
3define( 'LIG_G3_DIR', '_g3' );
4define( 'LIG_G2_DIR', '_g2' );
5
6define( 'LIG_DEBUG', false );
7
8require_once __DIR__ . '/vendor/autoload.php';
9
10if ( true === LIG_DEBUG ) {
11        function lightning_debug_mode() {
12                $options = lightning_get_theme_options();
13                // $options = get_option( 'lightning_theme_options' );
14                // unset( $options['layout'] );
15                // update_option( 'lightning_theme_options', $options );
16                print '<pre style="text-align:left">';
17                print_r( $options );
18                print '</pre>';
19        }
20        add_action( 'lightning_site_header_after', 'lightning_debug_mode' );
21}
22
23/**
24 * Check is G3
25 *
26 * @return bool
27 */
28function lightning_is_g3() {
29
30        $return = true;
31        $g       = get_option( 'lightning_theme_generation' );
32        $options = get_option( 'lightning_theme_options' );
33
34        if ( '1' === get_option( 'fresh_site' ) ) {
35                // 新規サイトの場合はG3に指定.
36                update_option( 'lightning_theme_generation', 'g3' );
37                $return = true;
38        } else if ( 'g3' === $g ) {
39                $return = true;
40        } elseif ( 'g2' === $g ) {
41                $return = false;
42        } else {
43                $skin    = get_option( 'lightning_design_skin' );
44                if ( 'origin2' === $skin ) {
45                        update_option( 'lightning_theme_generation', 'g2' );
46                        $return = false;
47                } elseif ( 'origin3' === $skin ) {
48                        update_option( 'lightning_theme_generation', 'g3' );
49                        $return = true;
50                } elseif ( empty( $options ) ) {
51                        // 後から Lightning をインストールした場合は G3 にする
52                        // (新規サイトではない && lightning_theme_options が存在しない)
53                        update_option( 'lightning_theme_generation', 'g3' );
54                        $return = true;
55                } else {
56                        // これ以外は旧ユーザー(Lightning Pro)の可能性が高いのでG2.
57                        update_option( 'lightning_theme_generation', 'g2' );
58                        $return = false;
59                }
60        }
61        return apply_filters( 'lightning_is_g3', $return );
62}
63
64require __DIR__ . '/inc/class-ltg-template-redirect.php';
65
66/**
67 * 最終的に各Gディレクトリに移動
68 */
69if ( ! function_exists( 'lightning_get_template_part' ) ) {
70        function lightning_get_template_part( $slug, $name = null, $args = array() ) {
71
72                if ( lightning_is_g3() ) {
73                        $g_dir = '_g3';
74                } else {
75                        $g_dir = '_g2';
76                }
77
78                /**
79                 * 読み込み優先度
80                 *
81                 * 1.child g階層 nameあり
82                 * 2.child 直下 nameあり
83                 * 3.parent g階層 nameあり
84                 *
85                 * 4.child g階層 nameなし
86                 * 5.child 直下 nameなし
87                 * 6.parent g階層 nameなし
88                 */
89
90                /* Almost the same as the core */
91                $template_path_array = array();
92                $name                = (string) $name;
93
94                // Child theme G directory
95                if ( preg_match( '/^' . $g_dir . '/', $slug ) ) {
96                        // 1. g階層がもともと含まれている場合
97                        if ( '' !== $name ) {
98                                $template_path_array[] = get_stylesheet_directory() . "/{$slug}-{$name}.php";
99                        }
100                } else {
101                        // g階層が含まれていない場合
102
103                        // 1. g階層付きのファイルパス
104                        if ( '' !== $name ) {
105                                $template_path_array[] = get_stylesheet_directory() . '/' . $g_dir . "/{$slug}-{$name}.php";
106                        }
107                        // 2. 直下のファイルパス
108                        if ( '' !== $name ) {
109                                $template_path_array[] = get_stylesheet_directory() . "/{$slug}-{$name}.php";
110                        }
111                }
112
113                if ( preg_match( '/^' . $g_dir . '/', $slug ) ) {
114                        // 3. g階層がもともと含まれている場合
115                        if ( '' !== $name ) {
116                                $template_path_array[] = get_template_directory() . "/{$slug}-{$name}.php";
117                        }
118                } else {
119                        // 3. g階層がもともと含まれていない場合
120                        if ( '' !== $name ) {
121                                $template_path_array[] = get_template_directory() . '/' . $g_dir . "/{$slug}-{$name}.php";
122                        }
123                }
124
125                // Child theme G directory
126                if ( preg_match( '/^' . $g_dir . '/', $slug ) ) {
127                        // 4. g階層がもともと含まれている場合
128                        $template_path_array[] = get_stylesheet_directory() . "/{$slug}.php";
129                } else {
130                        // g階層が含まれていない場合
131                        // 4. g階層付きのファイルパス
132                        $template_path_array[] = get_stylesheet_directory() . '/' . $g_dir . "/{$slug}.php";
133                        // 5. 直下のファイルパス
134                        $template_path_array[] = get_stylesheet_directory() . "/{$slug}.php";
135                }
136
137                if ( preg_match( '/^' . $g_dir . '/', $slug ) ) {
138                        // g階層がもともと含まれている場合
139                        // 6. 親のg階層
140                        $template_path_array[] = get_template_directory() . "/{$slug}.php";
141                } else {
142                        // 6. 親のg階層
143                        $template_path_array[] = get_template_directory() . '/' . $g_dir . "/{$slug}.php";
144                }
145
146                foreach ( (array) $template_path_array as $template_path ) {
147                        if ( file_exists( $template_path ) ) {
148                                $require_once = false;
149                                load_template( $template_path, $require_once );
150                                break;
151                        }
152                }
153        }
154}
155
156if ( lightning_is_g3() ) {
157        require __DIR__ . '/' . LIG_G3_DIR . '/functions.php';
158} else {
159        require __DIR__ . '/' . LIG_G2_DIR . '/functions.php';
160}
161
162require __DIR__ . '/inc/customize-basic.php';
163require __DIR__ . '/inc/tgm-plugin-activation/tgm-config.php';
164require __DIR__ . '/inc/vk-old-options-notice/vk-old-options-notice-config.php';
165require __DIR__ . '/inc/admin-mail-checker.php';
166require __DIR__ . '/inc/functions-compatible.php';
167require __DIR__ . '/inc/font-awesome/font-awesome-config.php';
168require __DIR__ . '/inc/old-page-template.php';
169
170require __DIR__ . '/inc/class-ltg-theme-json-activator.php';
171new LTG_Theme_Json_Activator();
172
173/**
174 * 世代切り替えした時に同時にスキンも変更する処理
175 *
176 * 世代は lightning_theme_generation で管理している。
177 *
178 *      generetionに変更がある場合
179 *          今の世代でのスキン名を lightning_theme_options の配列の中に格納しておく
180 *          lightning_theme_option の中に格納されている新しい世代のスキンを取得
181 *          スキンをアップデートする *
182 */
183
184function lightning_change_generation( $old_value, $value, $option ) {
185        // 世代変更がある場合
186        if ( $value !== $old_value ) {
187
188                // 現状のスキンを取得
189                $current_skin = get_option( 'lightning_design_skin' );
190
191                if ( $current_skin ) {
192                        // オプションを取得
193                        $options = get_option( 'lightning_theme_options' );
194                        if ( ! $options || ! is_array( $options ) ) {
195                                $options = array();
196                        }
197                        $options[ 'previous_skin_' . $old_value ] = $current_skin;
198                        // 既存のスキンをオプションに保存
199                        update_option( 'lightning_theme_options', $options );
200                }
201
202                // 前のスキンが保存されている場合
203                if ( ! empty( $options[ 'previous_skin_' . $value ] ) ) {
204                        $new_skin = esc_attr( $options[ 'previous_skin_' . $value ] );
205
206                        // 前のスキンが保存されていない場合
207                } elseif ( 'g3' === $value ) {
208                                $new_skin = 'origin3';
209                } else {
210                        $new_skin = 'origin2';
211                }
212                update_option( 'lightning_design_skin', $new_skin );
213        }
214}
215add_action( 'update_option_lightning_theme_generation', 'lightning_change_generation', 10, 3 );
Note: See TracBrowser for help on using the repository browser.