This repository was archived by the owner on Apr 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
171 lines (142 loc) · 6.21 KB
/
functions.php
File metadata and controls
171 lines (142 loc) · 6.21 KB
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
<?php
require_once "lib/walker.class.php";
require_once "lib/settings.php";
require_once "lib/metabox.class.php";
require_once "lib/widgets.php";
require_once "lib/scripts.php";
function wordstrap_register_menus() {
register_nav_menus(
array(
'primary' => __( 'Primary menu')
)
);
}
add_action( 'init', 'wordstrap_register_menus' );
// call the metabox class
function wordstrap_load_meta_boxClass() {
return new wordstrap_meta_box();
}
if( is_admin() ) {
add_action( 'load-post.php', 'wordstrap_load_meta_boxClass' );
}
function wordstrap_after_setup_theme() {
add_theme_support( 'post-thumbnails' );
//register the thumbnails we want created on upload.
add_image_size( 'hero-unit-xlarge', 1170, 9999 );
add_image_size( 'hero-unit-large', 940, 9999 );
add_image_size( 'hero-unit-medium', 724, 9999 );
add_image_size( 'hero-unit-small', 360, 9999 );
add_editor_style( 'editor-style.css' );
}
add_action( 'after_setup_theme', 'wordstrap_after_setup_theme' );
function wordstrap_body_classes( $classes ) {
global $wp_query;
$wordstrap_options = get_option( 'theme_wordstrap_options' );
if( is_page() ) {
$classes[] = "page-slug-{$wp_query->post->post_name}";
}
if( "fixed" === $wordstrap_options['menu']['type'] ) {
$classes[] = "fixed-nav-bar";
}
return $classes;
}
add_filter( 'body_class', 'wordstrap_body_classes' );
function wordstrap_compile_stylesheets() {
$css_folder = __DIR__."/lib/bootstrap/css";
//parse the variables from the database.
$bootstrap_options = "";
$wordstrap_options = get_option("theme_wordstrap_options");
//open variables file and read it line by line
$variables_handle = fopen(__DIR__."/lib/bootstrap/less/variables.less", "r+");
$variables_content = "";
if($variables_handle) {
while( ($line = fgets($variables_handle)) !== FALSE ) {
if(preg_match('/^@([a-zA-Z]+):(.*);/', $line, $matches)) {
if(array_key_exists($matches[1], $wordstrap_options['bootstrap'])) {
$variables_content .= "@{$matches[1]}: {$wordstrap_options['bootstrap'][$matches[1]]};".PHP_EOL;
} else {
$variables_content .= $line;
}
} else {
$variables_content .= $line;
}
}
} else {
//unable to find the variables file
add_settings_error('error', 'settings_updated', __('Unable to locate Bootstrap, please make sure that it is installed properly..'), 'error');
set_transient('settings_errors', get_settings_errors(), 30);
wp_redirect("{$_SERVER['PHP_SELF']}?page=wordstrap-options&tab=stylesheet&settings-updated=true");
exit;
}
//write the new variables file
if( fwrite($variables_handle, $variables_content) === FALSE ) {
//unable to write file
add_settings_error('error', 'settings_updated', __('Unable to write to the variables file, please make sure that the filesystem is writeable.'), 'error');
set_transient('settings_errors', get_settings_errors(), 30);
wp_redirect("{$_SERVER['PHP_SELF']}?page=wordstrap-options&tab=stylesheet&settings-updated=true");
exit;
}
//does the bootstrap css folder exist, if not create it.
if( !is_dir($css_folder) && !is_file($css_folder) ) {
$dir_made = mkdir($css_folder);
if(!$dir_made) {
add_settings_error('error', 'settings_updated', __('Unable to create stylesheets folder, please make sure that the filesystem is writeable.'), 'error');
set_transient('settings_errors', get_settings_errors(), 30);
wp_redirect("{$_SERVER['PHP_SELF']}?page=wordstrap-options&tab=stylesheet&settings-updated=true");
exit;
}
}
$lessLibraryPath = __DIR__."/lib/less.php/lib/";
// Register an autoload function
spl_autoload_register(function($className) use ($lessLibraryPath) {
$fileName = $lessLibraryPath.str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
if (file_exists($fileName)) {
require_once $fileName;
}
});
$bootstrap_parser = new \Less\Parser();
$bootstrap_parser->getEnvironment()->setCompress(false);
$responsive_parser = new \Less\Parser();
$responsive_parser->getEnvironment()->setCompress(false);
//$parser->parse($bootstrap_options); //Options not working yet
try {
$bootstrapLess = $bootstrap_parser->parseFile(__DIR__."/lib/bootstrap/less/bootstrap.less"); //, true);
$responsiveLess = $responsive_parser->parseFile(__DIR__."/lib/bootstrap/less/responsive.less"); //, true);
} catch (Exception $e) {
add_settings_error('error', 'settings_updated', __('Unable to parse stylesheets. Message returned was: ').$e->getMessage(), 'error');
set_transient('settings_errors', get_settings_errors(), 30);
wp_redirect("{$_SERVER['PHP_SELF']}?page=wordstrap-options&tab=stylesheet&settings-updated=true");
exit;
}
//parse the variables from the database.
$wordstrap_options = get_option("theme_wordstrap_options");
foreach($wordstrap_options['bootstrap'] as $key => $value) {
//$bootstrapLess->parse("@{$key}: {$value};");
//$responsiveLess->parse("@{$key}: {$value};");
}
$bootstrapCss = $bootstrapLess->getCss();
$responsiveCss = $responsiveLess->getCss();
//time to save to file
$bootstrapHandle = @fopen(__DIR__."/lib/bootstrap/css/bootstrap.css", "w");
$responsiveHandle = @fopen(__DIR__."/lib/bootstrap/css/responsive.css", "w");
if(!$bootstrapHandle || !$responsiveHandle) {
add_settings_error('error', 'settings_updated', __('Unable to open stylesheets, please make sure that the files are writeable.'), 'error');
set_transient('settings_errors', get_settings_errors(), 30);
wp_redirect("{$_SERVER['PHP_SELF']}?page=wordstrap-options&tab=stylesheet&settings-updated=true");
exit;
}
$bootstrapWritten = fwrite($bootstrapHandle, $bootstrapCss);
$responsiveWritten = fwrite($responsiveHandle, $responsiveCss);
if(!$bootstrapWritten || !$responsiveWritten) {
add_settings_error('error', 'settings_updated', __('Unable to save stylesheets, please make sure that the files are writeable.'), 'error');
set_transient('settings_errors', get_settings_errors(), 30);
wp_redirect("{$_SERVER['PHP_SELF']}?page=wordstrap-options&tab=stylesheet&settings-updated=true");
exit;
}
fclose($bootstrapHandle);
fclose($responsiveHandle);
add_settings_error('general', 'settings_updated', __('Stylesheets compiled.'), 'updated');
set_transient('settings_errors', get_settings_errors(), 30);
wp_redirect("{$_SERVER['PHP_SELF']}?page=wordstrap-options&tab=stylesheet&settings-updated=true");
exit;
}