-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
243 lines (217 loc) · 8.97 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
<?php
function getStyle() {
wp_enqueue_style('normalize', get_template_directory_uri() . '/css/normalize.min.css');
wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;700&family=Space+Grotesk:wght@400;700&display=swap', false );
wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css', false);
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'getStyle' );
function my_enqueue_scripts() {
wp_enqueue_script( 'jquery_3.4.1', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js', array(), '3.4.1', true);
wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom-script.js', array(), null, true);
$translation_array = array( 'templateUrl' => get_template_directory_uri());
wp_localize_script( 'custom-script', 'customScriptVar', $translation_array );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );
// Theme setup
function rapsooSetup() {
}
add_action('after_setup_theme', 'rapsooSetup');
add_theme_support( 'post-thumbnails' );
// Theme path
if (!defined('THEME_IMG_PATH')) {
define('THEME_IMG_PATH', get_stylesheet_directory_uri() . '/img');
};
// Carbon fields
use Carbon_Fields\Container;
use Carbon_Fields\Field;
add_action( 'carbon_fields_register_fields', 'crb_attach_post_meta' );
function crb_attach_post_meta() {
Container::make( 'post_meta', 'Details sidebar' )
->where( 'post_type', '=', 'post' )
->add_fields( array(
Field::make('rich_text', 'crb_details', 'Edit details sidebar')
));
Container::make( 'post_meta', 'Sidebar content' )
->where( 'post_type', '=', 'page' )
->where( 'post_id', '=', get_option( 'page_on_front' ) )
->add_fields( array(
Field::make('rich_text', 'crb_sidebar_content', 'Write a sidebar synopsis')
));
Container::make( 'post_meta', 'Experience' )
->where( 'post_type', '=', 'page' )
->where( 'post_id', '=', get_option( 'page_on_front' ) )
->add_fields( array(
Field::make( 'complex', 'crb_occupations', 'Edit experience' )
->set_layout( 'grid' )
->add_fields( array(
Field::make( 'text', 'occupation_title', 'Title' ),
Field::make( 'text', 'occupation_company', 'Company name' ),
Field::make( 'text', 'occupation_date', 'Date' ),
) ),
) );
Container::make( 'post_meta', 'Education' )
->where( 'post_type', '=', 'page' )
->where( 'post_id', '=', get_option( 'page_on_front' ) )
->add_fields( array(
Field::make( 'complex', 'crb_educations', 'Edit education' )
->set_layout( 'grid' )
->add_fields( array(
Field::make( 'text', 'education_field_of_study', 'Field of study' ),
Field::make( 'text', 'education_degree', 'Degree' ),
Field::make( 'text', 'education_school', 'School' ),
Field::make( 'text', 'education_date', 'Date' ),
) ),
) );
Container::make( 'post_meta', 'Skills' )
->where( 'post_type', '=', 'page' )
->where( 'post_id', '=', get_option( 'page_on_front' ) )
->add_fields( array(
Field::make( 'complex', 'crb_skills', 'Edit skills' )
->set_layout( 'tabbed-vertical' )
->add_fields( array(
Field::make( 'text', 'skill_tag', 'Write new skill' ),
) ),
) );
}
// Custom category color
add_action('category_add_form_fields', 'my_category_fields', 10, 2);
add_action('category_edit_form_fields', 'my_category_fields', 10, 2);
function my_category_fields($term) {
$cat_color = get_term_meta($term->term_id, 'cat_color', true);
if($cat_color == '') $cat_color = '#000000'; // Default black color
?>
<div class="form-field">
<label for="cat_color"><?php _e('Category color'); ?></label>
<input type="color" size="40" value="<?php echo esc_attr($cat_color); ?>" id="cat_color" name="cat_color"><br/>
<p class="description"><?php _e('Please select a color for the category.'); ?></p>
</div>
<?php
}
add_action('edited_category', 'save_my_category_fields', 10, 2);
add_action('create_category', 'save_my_category_fields', 10, 2);
function save_my_category_fields($term_id) {
if (!isset($_POST['cat_color'])) {
return;
}
update_term_meta($term_id, 'cat_color', sanitize_text_field($_POST['cat_color']));
}
// Get current URL
function wp_get_current_url() {
return home_url( $_SERVER['REQUEST_URI'] );
}
// Custom logo
add_theme_support( 'custom-logo' );
// Customization options
function rapsoo_customize_register( $wp_customize ) {
// Header customization
$wp_customize->add_section('rapsoo_header_section', array(
'title' => 'Header',
'priority' => 30,
));
$wp_customize->add_setting('rapsoo_headline', array(
'default' => 'I am John Doe, a Photo Model specializing in WordPress mockup sites',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_headline_control', array(
'label' => 'Headline',
'section' => 'rapsoo_header_section',
'settings' => 'rapsoo_headline',
'type' => 'text',
)));
// Sidebar customization
$wp_customize->add_section('rapsoo_sidebar_section', array(
'title' => 'Sidebar',
'priority' => 31,
));
$wp_customize->add_setting('rapsoo_sidebar_heading', array(
'default' => 'My experience',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_headline_control', array(
'label' => 'Sidebar heading',
'section' => 'rapsoo_sidebar_section',
'settings' => 'rapsoo_sidebar_heading',
'type' => 'text',
)));
// Posts customization
$wp_customize->add_section('rapsoo_posts_section', array(
'title' => 'Posts',
'priority' => 32,
));
$wp_customize->add_setting('rapsoo_posts_heading', array(
'default' => 'My works',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_posts_heading_control', array(
'label' => 'Posts heading',
'section' => 'rapsoo_posts_section',
'settings' => 'rapsoo_posts_heading',
'type' => 'text',
)));
// Footer customization
$wp_customize->add_section('rapsoo_footer_section', array(
'title' => 'Footer',
'priority' => 33,
));
$wp_customize->add_setting('rapsoo_footer_heading', array(
'default' => 'Contact me',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_footer_heading_control', array(
'label' => 'Footer heading',
'section' => 'rapsoo_footer_section',
'settings' => 'rapsoo_footer_heading',
'type' => 'text',
)));
// Email address
$wp_customize->add_setting('rapsoo_email_address', array(
'default' => '',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_email_address_control', array(
'label' => 'Your Email address',
'description' => 'Provide your email address (format: name@domain.com)',
'section' => 'rapsoo_footer_section',
'settings' => 'rapsoo_email_address',
'type' => 'text',
)));
// Social media links
$wp_customize->add_setting('rapsoo_instagram_link', array(
'default' => '',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_instagram_link_control', array(
'label' => 'Your Instagram',
'description' => 'Provide URL for your Instgram account',
'section' => 'rapsoo_footer_section',
'settings' => 'rapsoo_instagram_link',
'type' => 'text',
)));
$wp_customize->add_setting('rapsoo_linkedin_link', array(
'default' => '',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_linkedin_link_control', array(
'label' => 'Your LinkedIn',
'description' => 'Provide URL for your LinkedIn account',
'section' => 'rapsoo_footer_section',
'settings' => 'rapsoo_linkedin_link',
'type' => 'text',
)));
$wp_customize->add_setting('rapsoo_github_link', array(
'default' => '',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_github_link_control', array(
'label' => 'Your Github',
'description' => 'Provide URL for your Github account',
'section' => 'rapsoo_footer_section',
'settings' => 'rapsoo_github_link',
'type' => 'text',
)));
$wp_customize->add_setting('rapsoo_instagram_link', array(
'default' => '',
));
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'rapsoo_instagram_link_control', array(
'label' => 'Your Instagram',
'description' => 'Provide URL for your Instgram account',
'section' => 'rapsoo_footer_section',
'settings' => 'rapsoo_instagram_link',
'type' => 'text',
)));
}
add_action('customize_register', 'rapsoo_customize_register');
?>