Make WordPress Themes

source: lightning/15.28.1/functions.php

Last change on this file was 249543, checked in by themedropbox, 12 months ago

New version of Lightning - 15.28.0

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