· 4 years ago · Nov 04, 2020, 09:44 AM
1<?php
2/*
3 * Author: Todd Motto | @toddmotto
4 * URL: html5blank.com | @html5blank
5 * Custom functions, support, custom post types and more.
6 */
7
8/*------------------------------------*\
9 External Modules/Files
10\*------------------------------------*/
11
12// Load any external files you have here
13
14/*------------------------------------*\
15 Theme Support
16\*------------------------------------*/
17
18if ( ! isset( $content_width ) ) {
19 $content_width = 900;
20}
21
22if ( function_exists( 'add_theme_support' ) ) {
23 // Add Menu Support
24 add_theme_support( 'menus' );
25
26 // Add Thumbnail Theme Support
27 add_theme_support( 'post-thumbnails' );
28 add_image_size( 'large', 700, '', true ); // Large Thumbnail
29 add_image_size( 'medium', 250, '', true ); // Medium Thumbnail
30 add_image_size( 'small', 120, '', true ); // Small Thumbnail
31 add_image_size( 'custom-size', 700, 200, true ); // Custom Thumbnail Size call using the_post_thumbnail('custom-size');
32
33 // Add Support for Custom Backgrounds - Uncomment below if you're going to use
34 /*add_theme_support('custom-background', array(
35 'default-color' => 'FFF',
36 'default-image' => get_template_directory_uri() . '/img/bg.jpg'
37 ));*/
38
39 // Add Support for Custom Header - Uncomment below if you're going to use
40 /*add_theme_support('custom-header', array(
41 'default-image' => get_template_directory_uri() . '/img/headers/default.jpg',
42 'header-text' => false,
43 'default-text-color' => '000',
44 'width' => 1000,
45 'height' => 198,
46 'random-default' => false,
47 'wp-head-callback' => $wphead_cb,
48 'admin-head-callback' => $adminhead_cb,
49 'admin-preview-callback' => $adminpreview_cb
50 ));*/
51
52 // Enables post and comment RSS feed links to head
53 add_theme_support( 'automatic-feed-links' );
54
55 // Localisation Support
56 load_theme_textdomain( 'html5blank', get_template_directory() . '/languages' );
57}
58
59/*------------------------------------*\
60 Functions
61\*------------------------------------*/
62
63// HTML5 Blank navigation
64function html5blank_nav() {
65 wp_nav_menu(
66 array(
67 'theme_location' => 'header-menu',
68 'menu' => '',
69 'container' => 'div',
70 'container_class' => 'menu-{menu slug}-container',
71 'container_id' => '',
72 'menu_class' => 'menu',
73 'menu_id' => '',
74 'echo' => true,
75 'fallback_cb' => 'wp_page_menu',
76 'before' => '',
77 'after' => '',
78 'link_before' => '',
79 'link_after' => '',
80 'items_wrap' => '<ul>%3$s</ul>',
81 'depth' => 0,
82 'walker' => ''
83 )
84 );
85}
86
87// Load HTML5 Blank scripts (header.php)
88function html5blank_header_scripts() {
89 if ( $GLOBALS[ 'pagenow' ] != 'wp-login.php' && ! is_admin() ) {
90
91 wp_register_script( 'modernizr', get_template_directory_uri() . '/js/lib/modernizr-2.7.1.min.js', array(), '2.7.1' ); // Modernizr
92 wp_enqueue_script( 'modernizr' ); // Enqueue it!
93 }
94}
95
96// Load HTML5 Blank styles
97function html5blank_styles() {
98
99 wp_register_style( 'html5blank', get_template_directory_uri() . '/style.css?ver=1.3', array(), '1.0', 'all' );
100 wp_enqueue_style( 'html5blank' ); // Enqueue it!
101}
102
103// Register HTML5 Blank Navigation
104function register_html5_menu() {
105 register_nav_menus( array( // Using array to specify more menus if needed
106 'header-menu' => __( 'Header Menu', 'html5blank' ),
107 // Main Navigation
108 'footer-mobile-menu' => __( 'Footer Mobile Menu', 'html5blank' ),
109 // Main Navigation
110 'sidebar-menu' => __( 'Sidebar Menu', 'html5blank' ),
111 // Sidebar Navigation
112 'extra-menu' => __( 'Extra Menu', 'html5blank' )
113 // Extra Navigation if needed (duplicate as many as you need!)
114 ) );
115}
116
117// Remove the <div> surrounding the dynamic navigation to cleanup markup
118function my_wp_nav_menu_args( $args = '' ) {
119 $args[ 'container' ] = false;
120
121 return $args;
122}
123
124// Remove Injected classes, ID's and Page ID's from Navigation <li> items
125function my_css_attributes_filter( $var ) {
126 return is_array( $var ) ? array() : '';
127}
128
129// Remove invalid rel attribute values in the categorylist
130function remove_category_rel_from_category_list( $thelist ) {
131 return str_replace( 'rel="category tag"', 'rel="tag"', $thelist );
132}
133
134// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
135function add_slug_to_body_class( $classes ) {
136 global $post;
137 if ( is_home() ) {
138 $key = array_search( 'blog', $classes );
139 if ( $key > - 1 ) {
140 unset( $classes[ $key ] );
141 }
142 } else if ( is_page() ) {
143 $classes[] = sanitize_html_class( $post->post_name );
144 } else if ( is_singular() ) {
145 $classes[] = sanitize_html_class( $post->post_name );
146 }
147
148 return $classes;
149}
150
151// If Dynamic Sidebar Exists
152if ( function_exists( 'register_sidebar' ) ) {
153 // Define Sidebar Widget Area 1
154 register_sidebar( array(
155 'name' => __( 'Phone Number', 'html5blank' ),
156 'description' => __( '', 'html5blank' ),
157 'id' => 'widget-area-1',
158 'before_widget' => '',
159 'after_widget' => '',
160 'before_title' => '',
161 'after_title' => ''
162 ) );
163
164 // Define Sidebar Widget Area 2
165 register_sidebar( array(
166 'name' => __( 'Footer Column 2', 'html5blank' ),
167 'description' => __( 'Business addresses', 'html5blank' ),
168 'id' => 'widget-area-2',
169 'before_widget' => '',
170 'after_widget' => '',
171 'before_title' => '',
172 'after_title' => ''
173 ) );
174
175 // Define Sidebar Widget Area 3
176 register_sidebar( array(
177 'name' => __( 'Business Registration Details', 'html5blank' ),
178 'description' => __( '', 'html5blank' ),
179 'id' => 'widget-area-3',
180 'before_widget' => '',
181 'after_widget' => '',
182 'before_title' => '',
183 'after_title' => ''
184 ) );
185
186 // Define Sidebar Widget Area 4
187 register_sidebar( array(
188 'name' => __( 'Footer Bottom', 'html5blank' ),
189 'description' => __( 'Copyright information', 'html5blank' ),
190 'id' => 'widget-area-4',
191 'before_widget' => '',
192 'after_widget' => '',
193 'before_title' => '',
194 'after_title' => ''
195 ) );
196
197 // Define Sidebar Widget Area 5
198 register_sidebar( array(
199 'name' => __( 'Book a session', 'html5blank' ),
200 'description' => __( 'Book a session text and link', 'html5blank' ),
201 'id' => 'widget-area-5',
202 'before_widget' => '',
203 'after_widget' => '',
204 'before_title' => '',
205 'after_title' => ''
206 ) );
207
208 // Define Sidebar Widget Area 6
209 register_sidebar( array(
210 'name' => __( 'CV', 'html5blank' ),
211 'description' => __( 'CV text and link', 'html5blank' ),
212 'id' => 'widget-area-6',
213 'before_widget' => '',
214 'after_widget' => '',
215 'before_title' => '',
216 'after_title' => ''
217 ) );
218
219 // Define Sidebar Widget Area 7
220 register_sidebar( array(
221 'name' => __( 'Newsletter', 'html5blank' ),
222 'description' => __( 'Newsletter signup', 'html5blank' ),
223 'id' => 'widget-area-7',
224 'before_widget' => '',
225 'after_widget' => '',
226 'before_title' => '',
227 'after_title' => ''
228 ) );
229
230 // Define Sidebar Widget Area 8
231 register_sidebar( array(
232 'name' => __( 'Send a message', 'html5blank' ),
233 'description' => __( 'Email address', 'html5blank' ),
234 'id' => 'widget-area-8',
235 'before_widget' => '',
236 'after_widget' => '',
237 'before_title' => '',
238 'after_title' => ''
239 ) );
240
241 // Define Sidebar Widget Area 9
242 register_sidebar( array(
243 'name' => __( 'Swiss address', 'html5blank' ),
244 'description' => __( '', 'html5blank' ),
245 'id' => 'widget-area-9',
246 'before_widget' => '',
247 'after_widget' => '',
248 'before_title' => '',
249 'after_title' => ''
250 ) );
251
252 // Define Sidebar Widget Area 10
253 register_sidebar( array(
254 'name' => __( 'Greek address', 'html5blank' ),
255 'description' => __( '', 'html5blank' ),
256 'id' => 'widget-area-10',
257 'before_widget' => '',
258 'after_widget' => '',
259 'before_title' => '',
260 'after_title' => ''
261 ) );
262
263}
264
265// Remove wp_head() injected Recent Comment styles
266function my_remove_recent_comments_style() {
267 global $wp_widget_factory;
268 remove_action( 'wp_head', array(
269 $wp_widget_factory->widgets[ 'WP_Widget_Recent_Comments' ],
270 'recent_comments_style'
271 ) );
272}
273
274// Custom Excerpts
275function html5wp_index( $length ) // Create 20 Word Callback for Index page Excerpts, call using html5wp_excerpt('html5wp_index');
276{
277 return 40;
278}
279
280// Create 40 Word Callback for Custom Post Excerpts, call using html5wp_excerpt('html5wp_custom_post');
281function html5wp_custom_post( $length ) {
282 return 40;
283}
284
285// Create the Custom Excerpts callback
286function html5wp_excerpt( $length_callback = '', $more_callback = '' ) {
287 global $post;
288 if ( function_exists( $length_callback ) ) {
289 add_filter( 'excerpt_length', $length_callback );
290 }
291 if ( function_exists( $more_callback ) ) {
292 add_filter( 'excerpt_more', $more_callback );
293 }
294 $output = get_the_excerpt();
295 $output = apply_filters( 'wptexturize', $output );
296 $output = apply_filters( 'convert_chars', $output );
297 $output = '<p class="excerpt">' . $output . '</p>';
298 echo $output;
299}
300
301// Custom View Article link to Post
302function html5_blank_view_article( $more ) {
303 global $post;
304 $viewarticle = get_field( 'view_article_button_text', pll_get_post( 883 ) );
305
306 return '... <p class="button-holder"><a class="button" href="' . get_permalink( $post->ID ) . '">' . __( $viewarticle, 'html5blank' ) . '</a></p>';
307}
308
309// Remove Admin bar
310function remove_admin_bar() {
311 return false;
312}
313
314// Remove 'text/css' from our enqueued stylesheet
315function html5_style_remove( $tag ) {
316 return preg_replace( '~\s+type=["\'][^"\']++["\']~', '', $tag );
317}
318
319// Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail
320function remove_thumbnail_dimensions( $html ) {
321 $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
322
323 return $html;
324}
325
326// Custom Gravatar in Settings > Discussion
327function html5blankgravatar( $avatar_defaults ) {
328 $myavatar = get_template_directory_uri() . '/img/gravatar.jpg';
329 $avatar_defaults[ $myavatar ] = "Custom Gravatar";
330
331 return $avatar_defaults;
332}
333
334// Threaded Comments
335function enable_threaded_comments() {
336 if ( ! is_admin() ) {
337 if ( is_singular() and comments_open() and ( get_option( 'thread_comments' ) == 1 ) ) {
338 wp_enqueue_script( 'comment-reply' );
339 }
340 }
341}
342
343// Custom Comments Callback
344function html5blankcomments( $comment, $args, $depth ) {
345 $GLOBALS[ 'comment' ] = $comment;
346 extract( $args, EXTR_SKIP );
347
348 if ( 'div' == $args[ 'style' ] ) {
349 $tag = 'div';
350 $add_below = 'comment';
351 } else {
352 $tag = 'li';
353 $add_below = 'div-comment';
354 }
355 ?>
356 <!-- heads up: starting < for the html tag (li or div) in the next line: -->
357 <<?php echo $tag ?><?php comment_class( empty( $args[ 'has_children' ] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
358 <?php if ( 'div' != $args[ 'style' ] ) : ?>
359 <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
360 <?php endif; ?>
361 <div class="comment-author vcard">
362 <?php if ( $args[ 'avatar_size' ] != 0 ) {
363 echo get_avatar( $comment, $args[ '180' ] );
364 } ?>
365 <span class="author"><?php printf( __( '%s' ), get_comment_author_link() ) ?></span><span
366 class="date-time"><?php printf( __( '%1$s | %2$s' ), get_comment_date(), get_comment_time() ) ?></span>
367 </div>
368 <?php if ( $comment->comment_approved == '0' ) : ?>
369 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
370 <br />
371 <?php endif; ?>
372 <?php comment_text() ?>
373 <?php if ( 'div' != $args[ 'style' ] ) : ?>
374 </div>
375 <?php endif; ?>
376<?php }
377
378/*------------------------------------*\
379 Actions + Filters + ShortCodes
380\*------------------------------------*/
381
382// Add Actions
383add_action( 'init', 'html5blank_header_scripts' ); // Add Custom Scripts to wp_head
384add_action( 'wp_print_scripts', 'html5blank_conditional_scripts' ); // Add Conditional Page Scripts
385add_action( 'get_header', 'enable_threaded_comments' ); // Enable Threaded Comments
386add_action( 'wp_enqueue_scripts', 'html5blank_styles' ); // Add Theme Stylesheet
387add_action( 'init', 'register_html5_menu' ); // Add HTML5 Blank Menu
388add_action( 'init', 'create_post_type_html5' ); // Add our HTML5 Blank Custom Post Type
389add_action( 'widgets_init', 'my_remove_recent_comments_style' ); // Remove inline Recent Comment Styles from wp_head()
390add_action( 'init', 'html5wp_pagination' ); // Add our HTML5 Pagination
391
392// Remove Actions
393remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
394remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
395remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
396remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
397remove_action( 'wp_head', 'index_rel_link' ); // Index link
398remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // Prev link
399remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // Start link
400remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
401remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version
402remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
403remove_action( 'wp_head', 'rel_canonical' );
404remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
405
406// Add Filters
407add_filter( 'avatar_defaults', 'html5blankgravatar' ); // Custom Gravatar in Settings > Discussion
408add_filter( 'body_class', 'add_slug_to_body_class' ); // Add slug to body class (Starkers build)
409add_filter( 'widget_text', 'do_shortcode' ); // Allow shortcodes in Dynamic Sidebar
410add_filter( 'widget_text', 'shortcode_unautop' ); // Remove <p> tags in Dynamic Sidebars (better!)
411add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' ); // Remove surrounding <div> from WP Navigation
412// add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected classes (Commented out by default)
413// add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected ID (Commented out by default)
414// add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> Page ID's (Commented out by default)
415add_filter( 'the_category', 'remove_category_rel_from_category_list' ); // Remove invalid rel attribute
416add_filter( 'the_excerpt', 'shortcode_unautop' ); // Remove auto <p> tags in Excerpt (Manual Excerpts only)
417add_filter( 'the_excerpt', 'do_shortcode' ); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only)
418add_filter( 'excerpt_more', 'html5_blank_view_article' ); // Add 'View Article' button instead of [...] for Excerpts
419add_filter( 'show_admin_bar', 'remove_admin_bar' ); // Remove Admin bar
420add_filter( 'style_loader_tag', 'html5_style_remove' ); // Remove 'text/css' from enqueued stylesheet
421add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 ); // Remove width and height dynamic attributes to thumbnails
422add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 ); // Remove width and height dynamic attributes to post images
423
424// Remove Filters
425remove_filter( 'the_excerpt', 'wpautop' ); // Remove <p> tags from Excerpt altogether
426
427// Shortcodes
428add_shortcode( 'html5_shortcode_demo', 'html5_shortcode_demo' ); // You can place [html5_shortcode_demo] in Pages, Posts now.
429add_shortcode( 'html5_shortcode_demo_2', 'html5_shortcode_demo_2' ); // Place [html5_shortcode_demo_2] in Pages, Posts now.
430
431// Shortcodes above would be nested like this -
432// [html5_shortcode_demo] [html5_shortcode_demo_2] Here's the page title! [/html5_shortcode_demo_2] [/html5_shortcode_demo]
433
434/*------------------------------------*\
435 Custom Post Types
436\*------------------------------------*/
437
438// Create 1 Custom Post type for a Demo, called HTML5-Blank
439function create_post_type_html5() {
440 register_taxonomy_for_object_type( 'category', 'testimonials_2' ); // Register Taxonomies for Category
441 register_taxonomy_for_object_type( 'post_tag', 'testimonials_2' );
442 register_post_type( 'testimonials_2', // Register Custom Post Type
443 array(
444 'labels' => array(
445 'name' => __( 'Testimonials', 'testimonials_2' ), // Rename these to suit
446 'singular_name' => __( 'Testimonial', 'testimonials_2' ),
447 'add_new' => __( 'Add New', 'testimonials_2' ),
448 'add_new_item' => __( 'Add New Announcement', 'testimonials_2' ),
449 'edit' => __( 'Edit', 'announcement' ),
450 'edit_item' => __( 'Edit Testimonial', 'testimonials_2' ),
451 'new_item' => __( 'New Testimonial', 'testimonials_2' ),
452 'view' => __( 'View', 'testimonials_2' ),
453 'view_item' => __( 'View Testimonial', 'testimonials_2' ),
454 'search_items' => __( 'Search Testimonials', 'testimonials_2' ),
455 'not_found' => __( 'No Testimonials found', 'testimonials_2' ),
456 'not_found_in_trash' => __( 'No Testimonials found in Trash', 'testimonials_2' )
457 ),
458 'public' => true,
459 'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
460 'has_archive' => true,
461 'supports' => array(
462 'title',
463 'editor',
464 'excerpt',
465 'thumbnail'
466 ), // Go to Dashboard Custom HTML5 Blank post for supports
467 'can_export' => true, // Allows export in Tools > Export
468 'taxonomies' => array(
469 'post_tag',
470 'category'
471 ) // Add Category and Post Tags support
472 ) );
473 register_taxonomy_for_object_type( 'category', 'announcements' ); // Register Taxonomies for Category
474 register_taxonomy_for_object_type( 'post_tag', 'announcements' );
475 register_post_type( 'announcement', // Register Custom Post Type
476 array(
477 'labels' => array(
478 'name' => __( 'Announcements', 'announcement' ), // Rename these to suit
479 'singular_name' => __( 'Announcement', 'announcement' ),
480 'add_new' => __( 'Add New', 'announcement' ),
481 'add_new_item' => __( 'Add New Announcement', 'announcement' ),
482 'edit' => __( 'Edit', 'announcement' ),
483 'edit_item' => __( 'Edit Announcement', 'announcement' ),
484 'new_item' => __( 'New Announcement', 'announcement' ),
485 'view' => __( 'View Announcements', 'announcement' ),
486 'view_item' => __( 'View Announcement', 'announcement' ),
487 'search_items' => __( 'Search Announcements', 'announcement' ),
488 'not_found' => __( 'No Announcements found', 'announcement' ),
489 'not_found_in_trash' => __( 'No Announcements found in Trash', 'announcement' )
490 ),
491 'public' => true,
492 'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
493 'has_archive' => true,
494 'supports' => array(
495 'title',
496 'editor',
497 'excerpt',
498 'thumbnail'
499 ), // Go to Dashboard Custom HTML5 Blank post for supports
500 'can_export' => true, // Allows export in Tools > Export
501 'taxonomies' => array(
502 'post_tag',
503 'category'
504 ) // Add Category and Post Tags support
505 ) );
506 register_taxonomy_for_object_type( 'category', 'dreams' ); // Register Taxonomies for Category
507 register_taxonomy_for_object_type( 'post_tag', 'dreams' );
508 register_post_type( 'dream', // Register Custom Post Type
509 array(
510 'labels' => array(
511 'name' => __( 'Dream Diary', 'dream' ), // Rename these to suit
512 'singular_name' => __( 'Dream Diary Entry', 'dream' ),
513 'add_new' => __( 'Add New', 'dream' ),
514 'add_new_item' => __( 'Add New Dream Diary Entry', 'dream' ),
515 'edit' => __( 'Edit', 'dream' ),
516 'edit_item' => __( 'Edit Dream Diary Entry', 'dream' ),
517 'new_item' => __( 'New Dream Diary Entry', 'dream' ),
518 'view' => __( 'View Dream Diary Entries', 'dream' ),
519 'view_item' => __( 'View Dream Diary Entry', 'dream' ),
520 'search_items' => __( 'Search Dream Diary Entries', 'dream' ),
521 'not_found' => __( 'No Dream Diary Entries found', 'dream' ),
522 'not_found_in_trash' => __( 'No Dream Diary Entries found in Trash', 'dream' )
523 ),
524 'public' => true,
525 'hierarchical' => true,
526 // Allows your posts to behave like Hierarchy Pages
527 'has_archive' => true,
528 'supports' => array(
529 'title',
530 'editor',
531 'author',
532 'thumbnail',
533 'excerpt',
534 'comments',
535 'custom-fields'
536 ),
537 // Go to Dashboard Custom HTML5 Blank post for supports
538 'can_export' => true,
539 // Allows export in Tools > Export
540 //'rewrite' => array('slug' => 'dream'),
541 'rewrite' => array( "with_front" => true ),
542 'cptp_permalink_structure' => '%year%/%monthnum%/%day%/%post_id%',
543 'taxonomies' => array(
544 'post_tag',
545 'category'
546 )
547 // Add Category and Post Tags support
548 ) );
549 register_taxonomy_for_object_type( 'post_tag', 'blog' );
550 register_post_type( 'blog', // Register Custom Post Type
551 array(
552 'labels' => array(
553 'name' => __( 'Blog', 'blog' ), // Rename these to suit
554 'singular_name' => __( 'Blog article', 'blog' ),
555 'add_new' => __( 'Add new', 'blog' ),
556 'add_new_item' => __( 'Add new blog article', 'blog' ),
557 'edit' => __( 'Edit', 'blog' ),
558 'edit_item' => __( 'Edit blog article', 'blog' ),
559 'new_item' => __( 'New blog article', 'blog' ),
560 'view' => __( 'View blog articles', 'blog' ),
561 'view_item' => __( 'View blog article', 'blog' ),
562 'search_items' => __( 'Search blog articles', 'blog' ),
563 'not_found' => __( 'No blog articles found', 'blog' ),
564 'not_found_in_trash' => __( 'No blog articles found in Trash', 'blog' )
565 ),
566 'public' => true,
567 'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
568 'has_archive' => true,
569 'supports' => array(
570 'title',
571 'editor',
572 'thumbnail',
573 'comments'
574 ), // Go to Dashboard Custom HTML5 Blank post for supports
575 'can_export' => true, // Allows export in Tools > Export
576 'taxonomies' => array(
577 'post_tag'
578 ) // Add Post Tags support
579 ) );
580}
581
582/* Adding a language class to the body to apply styles individually per language */
583add_filter( 'body_class', 'append_language_class' );
584function append_language_class( $classes ) {
585 $classes[] = 'language-' . ICL_LANGUAGE_CODE;
586
587 return $classes;
588}
589
590// REMOVE WP EMOJI
591remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
592remove_action( 'wp_print_styles', 'print_emoji_styles' );
593
594remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
595remove_action( 'admin_print_styles', 'print_emoji_styles' );
596/*------------------------------------*\
597 Override Amelia styles on booking page
598\*------------------------------------*/
599function amelia_style_overrides() {
600 if ( is_page_template( 'template-book-sub.php' ) ) {
601 wp_enqueue_style( 'template-book-sub', get_template_directory_uri() . '/css/ameliaOverrides.css' );
602 }
603}
604
605add_action( 'wp_enqueue_scripts', 'amelia_style_overrides', 101 );
606/*------------------------------------*\
607 Add classes to next and previous links
608\*------------------------------------*/
609function add_class_next_post_link( $html ) {
610 $html = str_replace( '<a', '<a class="next"', $html );
611
612 return $html;
613}
614
615add_filter( 'next_post_link', 'add_class_next_post_link', 10, 1 );
616
617function add_class_previous_post_link( $html ) {
618 $html = str_replace( '<a', '<a class="prev"', $html );
619
620 return $html;
621}
622
623add_filter( 'previous_post_link', 'add_class_previous_post_link', 10, 1 );
624/*------------------------------------*\
625 Remove website from comment form
626\*------------------------------------*/
627add_filter( 'comment_form_default_fields', 'unset_url_field' );
628function unset_url_field( $fields ) {
629 if ( isset( $fields[ 'url' ] ) ) {
630 unset( $fields[ 'url' ] );
631 }
632
633 return $fields;
634}
635
636/*------------------------------------*\
637 ShortCode Functions
638\*------------------------------------*/
639
640// Shortcode Demo with Nested Capability
641function html5_shortcode_demo( $atts, $content = null ) {
642 return '<div class="shortcode-demo">' . do_shortcode( $content ) . '</div>'; // do_shortcode allows for nested Shortcodes
643}
644
645// Shortcode Demo with simple <h2> tag
646function html5_shortcode_demo_2( $atts, $content = null ) // Demo Heading H2 shortcode, allows for nesting within above element. Fully expandable.
647{
648 return '<h2>' . $content . '</h2>';
649}
650
651pll_register_string( 'Logo Text', 'Logo and sidebar title' );
652pll_register_string( 'Logo Caption', 'Logo caption' );
653pll_register_string( 'Meta Description', 'Description for search engines' );
654pll_register_string( 'Booking Instructions', 'Instructions for calendar booking page' );
655pll_register_string( 'Book Mobile', 'Mobile book button' );
656pll_register_string( 'Book Desktop', 'Desktop book button' );
657pll_register_string( 'Testimonials', 'Testimonials heading' );
658// Get translated url
659function pll_get_page_url( $page_slug ) {
660
661 // Check parameter
662 if ( empty( $page_slug ) ) {
663 return false;
664 }
665
666 // Get the page
667 $page = get_page_by_path( $page_slug );
668
669 // Check if the page exists
670 if ( empty( $page ) || is_null( $page ) ) {
671 return false;
672 }
673
674 // Get the URL
675 $page_ID_current_lang = pll_get_post( $page->ID );
676
677 // Return the current language permalink
678 return empty( $page_ID_current_lang ) ? get_permalink( $page->ID ) : get_permalink( $page_ID_current_lang );
679}
680
681/* Add Placehoder in comment Form Field (Comment) */
682add_filter( 'comment_form_defaults', 'sabretooth_textarea_placeholder' );
683
684function sabretooth_textarea_placeholder( $fields ) {
685 $comment_placeholder = get_field( 'comment_field_placeholder', pll_get_post( 881 ) );
686 $fields[ 'comment_field' ] = str_replace(
687 '<textarea',
688 '<textarea placeholder="' . $comment_placeholder . '"',
689 $fields[ 'comment_field' ]
690 );
691
692 return $fields;
693}
694
695/*Use other shortcodes in contact form 7*/
696add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );
697
698function mycustom_wpcf7_form_elements( $form ) {
699 $form = do_shortcode( $form );
700
701 return $form;
702}
703
704/*Shortcode for current user's email address*/
705function wpb_demo_shortcode() {
706
707// Things that you want to do.
708 $current_user = wp_get_current_user();
709
710// Output needs to be return
711 return $current_user->user_email;
712}
713
714// register shortcode
715add_shortcode( 'user_email', 'wpb_demo_shortcode' );
716
717// Delete post
718function delete_post() {
719 global $post;
720 $deletepostlink = add_query_arg( 'frontend', 'true', get_delete_post_link( get_the_ID() ) );
721 if ( current_user_can( 'edit_post', $post->ID ) ) {
722 echo '<a class="button" href="' . $deletepostlink . '">';
723
724 }
725}
726
727//Redirect after delete post in frontend
728add_action( 'trashed_post', 'trash_redirection_frontend' );
729function trash_redirection_frontend( $post_id ) {
730 if ( filter_input( INPUT_GET, 'frontend', FILTER_VALIDATE_BOOLEAN ) ) {
731 wp_redirect( get_permalink( pll_get_post( 1102 ) ) );
732 exit;
733 }
734}
735
736/**
737 * Redirect user after successful login.
738 *
739 * @param string $redirect_to URL to redirect to.
740 * @param string $request URL the user is coming from.
741 * @param object $user Logged user's data.
742 *
743 * @return string
744 */
745function my_login_redirect( $redirect_to, $request, $user ) {
746 //is there a user to check?
747 if ( isset( $user->roles ) && is_array( $user->roles ) ) {
748 //check for admins
749 if ( in_array( 'administrator', $user->roles ) ) {
750 // redirect them to the default place
751 return $redirect_to;
752 } else {
753 return dream_diary_url();
754 }
755 } else {
756 return $redirect_to;
757 }
758}
759
760function dream_diary_url() {
761 $language = pll_current_language( 'OBJECT' );
762
763 if ( $language->slug === 'en' ) {
764 return home_url( 'en/dream-diary' );
765 }
766
767 return home_url( sprintf( '%s/dream-diary-%s', strtolower( $language->slug ), strtolower( $language->name ) ) );
768}
769
770add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
771// Hide widgets from non admin
772add_action( 'wp_dashboard_setup', 'bt_remove_dashboard_widgets' );
773/**
774 *
775 * Remove WordPress Dashboard Widgets
776 *
777 */
778function bt_remove_dashboard_widgets() {
779 // http://codex.wordpress.org/Function_Reference/is_admin
780 if ( ! is_admin() ) {
781 return;
782 }
783
784 // Grab current user info
785 global $current_user;
786
787 // Check for specific user
788 /*
789 $username = $current_user->user_login;
790 if( 'the_user_login' != $username)
791 return;
792 */
793
794 // Check for capability
795 if ( current_user_can( 'add_users' ) ) {
796 return;
797 }
798
799 remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); // WordPress.com Blog
800 remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); // Plugins
801 remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); // Right Now
802 remove_action( 'welcome_panel', 'wp_welcome_panel' ); // Welcome Panel
803 remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' ); // Try Gutenberg
804 remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); // Quick Press widget
805 remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); // Recent Drafts
806 remove_meta_box( 'dashboard_secondary', 'dashboard', 'side' ); // Other WordPress News
807 remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); //Incoming Links
808 remove_meta_box( 'rg_forms_dashboard', 'dashboard', 'normal' ); // Gravity Forms
809 remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); // Recent Comments
810 remove_meta_box( 'icl_dashboard_widget', 'dashboard', 'normal' ); // Multi Language Plugin
811 remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); // Activity
812}
813
814/*USP PRO SET LANGUAGE*/
815function usp_pll_set_post_language( $default_or_current ) {
816
817 return 'current'; // accepts default or current
818
819}
820
821add_filter( 'usp_pll_set_post_language', 'usp_pll_set_post_language' );
822
823/*ADD EXTRA FIELDS TO WORDPRESS USER PROFILES*/
824add_action( 'show_user_profile', 'extra_user_profile_fields' );
825add_action( 'edit_user_profile', 'extra_user_profile_fields' );
826
827function extra_user_profile_fields( $user ) { ?>
828 <h3><?php _e( "Dream diary user information", "blank" ); ?></h3>
829
830 <table class="form-table">
831 <tr>
832 <th><label for="location"><?php _e( "Location" ); ?></label></th>
833 <td>
834 <input
835 type="text" name="location" id="location"
836 value="<?php echo esc_attr( get_the_author_meta( 'location', $user->ID ) ); ?>"
837 class="regular-text" />
838 </td>
839 </tr>
840 <tr>
841 <th><label for="phone"><?php _e( "Phone number" ); ?></label></th>
842 <td>
843 <input
844 type="text" name="phone" id="phone"
845 value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" />
846 </td>
847 </tr>
848 <tr>
849 <th><label for="access"><?php _e( "Grant Evangelos access to my dream diary posts" ); ?></label></th>
850 <td>
851 <input
852 type="checkbox" name="access" id="access"
853 value="1" <?php echo esc_attr( get_the_author_meta( 'access', $user->ID ) ) === 'true' ? 'checked' : ''; ?>
854 class="regular-text" />
855 </td>
856 </tr>
857 </table>
858<?php }
859
860add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
861add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
862
863/**
864 * Send an email notification to the administrator when a post is published.
865 *
866 * @param object $post
867 */
868function se_notify_admin_on_new_dream_post( $post_id, $post ) {
869 if ( ! $post_type = get_post_type_object( $post->post_type ) ) {
870 return;
871 }
872
873 if ( $post->post_type !== 'dream' ) {
874 return;
875 }
876
877 // Recipient, in this case the administrator email
878 $emailto = get_option( 'admin_email' );
879
880 $translated_post = pll_get_post( $post->ID );
881
882 // Email subject, "New {post_type_label}"
883 $subject = 'New ' . $post_type->labels->singular_name;
884 $author = get_user_by( 'ID', $post->post_author );
885
886 $firstname = ucwords( $author->first_name );
887 $lastname = ucwords( $author->last_name );
888
889 // Email body
890 $message = "Hello,\n\n{$firstname} {$lastname} has submitted a new diary entry.\n\n";
891 $message .= 'View it: ' . get_permalink( $translated_post->ID ) . "\nEdit it: " . get_edit_post_link( $translated_post->ID );
892
893 wp_mail( $emailto, $subject, $message );
894}
895
896add_action( 'save_post', 'se_notify_admin_on_new_dream_post', 10, 3 );
897
898function save_extra_user_profile_fields( $user_id ) {
899 if ( ! current_user_can( 'edit_user', $user_id ) ) {
900 return false;
901 }
902
903 update_user_meta( $user_id, 'location', esc_attr( $_POST[ 'location' ] ) );
904 update_user_meta( $user_id, 'phone', esc_attr( $_POST[ 'phone' ] ) );
905 update_user_meta( $user_id, 'access', (int) $_POST[ 'access' ] ? 'true' : 'false' );
906}
907
908//2. Add validation. In this case, we make sure first_name is required.
909add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
910function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
911
912 if ( empty( $_POST[ 'first_name' ] ) || ! empty( $_POST[ 'first_name' ] ) && trim( $_POST[ 'first_name' ] ) == '' ) {
913 $errors->add( 'first_name_error', __( '<strong>Error</strong>: You must include a first name.', 'mydomain' ) );
914 }
915 if ( empty( $_POST[ 'last_name' ] ) || ! empty( $_POST[ 'last_name' ] ) && trim( $_POST[ 'last_name' ] ) == '' ) {
916 $errors->add( 'last_name_error', __( '<strong>Error</strong>: You must include a last name.', 'mydomain' ) );
917 }
918 if ( empty( $_POST[ 'location' ] ) || ! empty( $_POST[ 'location' ] ) && trim( $_POST[ 'location' ] ) == '' ) {
919 $errors->add( 'location_error', __( '<strong>Error</strong>: You must include a location.', 'mydomain' ) );
920 }
921
922 return $errors;
923}
924
925add_action( 'user_register', 'usp_user_register' );
926
927function usp_user_register( $user_id ) {
928 if ( ! empty( $_POST[ 'first_name' ] ) ) {
929 update_user_meta( $user_id, 'first_name', esc_attr( $_POST[ 'first_name' ] ) );
930 }
931 if ( ! empty( $_POST[ 'last_name' ] ) ) {
932 update_user_meta( $user_id, 'last_name', esc_attr( $_POST[ 'last_name' ] ) );
933 }
934 if ( ! empty( $_POST[ 'location' ] ) ) {
935 update_user_meta( $user_id, 'location', esc_attr( $_POST[ 'location' ] ) );
936 }
937 if ( ! empty( $_POST[ 'phone' ] ) ) {
938 update_user_meta( $user_id, 'phone', esc_attr( $_POST[ 'phone' ] ) );
939 }
940 if ( ! empty( $_POST[ 'access' ] ) ) {
941 update_user_meta( $user_id, 'access', (int) $_POST[ 'access' ] ? 'true' : 'false' );
942 }
943}
944
945/**
946 * Journal Entries Form
947 */
948if ( ! function_exists( 'se_handle_journal_image_upload' ) ) {
949 function se_handle_journal_image_upload( $post_id, $current_images = [] ) {
950 if ( isset( $_FILES[ 'images' ] ) ) {
951 /**
952 * Upload Images
953 */
954 require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
955 require_once( ABSPATH . "wp-admin" . '/includes/file.php' );
956 require_once( ABSPATH . "wp-admin" . '/includes/media.php' );
957
958 $images = [];
959 $files = $_FILES[ 'images' ];
960
961 foreach ( $files[ 'name' ] as $key => $image ) {
962 if ( $files[ 'name' ][ $key ] ) {
963 $file = array(
964 'name' => $files[ 'name' ][ $key ],
965 'type' => $files[ 'type' ][ $key ],
966 'tmp_name' => $files[ 'tmp_name' ][ $key ],
967 'error' => $files[ 'error' ][ $key ],
968 'size' => $files[ 'size' ][ $key ]
969 );
970
971 $_FILES = array( 'image' => $file );
972
973 foreach ( $_FILES as $file => $array ) {
974 $attachment_id = media_handle_upload( $file, $post_id );
975
976 $images[] = $attachment_id;
977 }
978 }
979 }
980
981 $_images = $images;
982 $_images_with_keys = [];
983
984 if ( $current_images ) {
985 $_images = array_merge( $current_images, $images );
986 }
987
988 foreach ( $_images as $key => $attachment_id ) {
989 if ( strpos( $key, 'usp-file-' ) === false ) {
990 $meta_key = 'usp-file-' . $key;
991 } else {
992 $meta_key = $key;
993 }
994
995 $attachment_url = wp_get_attachment_image_url( $attachment_id, 'full' );
996
997 $_images_with_keys[ $meta_key ] = $attachment_id;
998 update_post_meta( $post_id, $meta_key, $attachment_url );
999 update_post_meta( $attachment_id, '_journal_entry_image', true );
1000 }
1001
1002 update_post_meta( $post_id, 'usp-images', $_images_with_keys );
1003 }
1004 }
1005}
1006
1007if ( ! function_exists( 'se_show_journal_entry_edit_form' ) ) {
1008 function se_show_journal_entry_edit_form( $post ) {
1009 if ( ! $post ) {
1010 return;
1011 }
1012
1013 if ( $post_id = (int) $post ) {
1014 $post = get_post( $post_id );
1015 }
1016
1017 /**
1018 * @var \WP_Post $post
1019 */
1020 ?>
1021 <div class="edit-post-form" id="EditPostForm" style="display:none;">
1022 <a href="#" class="close">Close</a>
1023 <h3><?php echo get_field( 'edit_journal_entry_heading', pll_get_post( 1102 ) ); ?></h3>
1024 <?php
1025
1026 if ( function_exists( 'usp_is_session_started' ) ) {
1027 if ( ! usp_is_session_started() ) {
1028 usp_session_start();
1029 }
1030 }
1031
1032 $current_images = get_post_meta( $post->ID, 'usp-images', true );
1033
1034 if ( ! $current_images ) {
1035 $current_images = [];
1036
1037 foreach ( get_post_custom( $post->ID ) as $key => $value ) {
1038 if ( preg_match( "/^usp-file-([0-9]+)$/i", $key, $matches ) ) {
1039 foreach ( $value as $k => $v ) {
1040 $attachment_id = attachment_url_to_postid( $v );
1041
1042 if ( $attachment_id ) {
1043 $current_images[ $key ] = $attachment_id;
1044 }
1045 }
1046 }
1047 }
1048
1049 update_post_meta( $post->ID, 'usp-images', $current_images );
1050 }
1051
1052 if ( 'POST' == $_SERVER[ 'REQUEST_METHOD' ] && ! empty( $_POST[ 'post_title' ] ) && isset( $_POST[ 'update_post_nonce' ] ) && isset( $_POST[ 'postcontent' ] ) ) {
1053 $post_id = $post->ID;
1054 $post_type = $post->post_type;
1055 $capability = ( 'page' == $post_type ) ? 'edit_page' : 'edit_post';
1056
1057 if ( wp_verify_nonce( $_POST[ 'update_post_nonce' ], 'update_post_' . $post_id ) ) {
1058 $post = array(
1059 'ID' => esc_sql( $post_id ),
1060 'post_content' => wp_kses_post( $_POST[ 'postcontent' ] ),
1061 'post_title' => wp_strip_all_tags( $_POST[ 'post_title' ] )
1062 );
1063
1064 wp_update_post( $post );
1065
1066 // Make sure it's a USP submission
1067 update_post_meta( $post_id, 'is_submission', '1' );
1068
1069 if ( isset( $_POST[ 'images_pending_removal' ] ) ) {
1070 $pending_removal_array = explode( ',', $_POST[ 'images_pending_removal' ] );
1071
1072 if ( $pending_removal_array && $current_images ) {
1073 foreach ( $pending_removal_array as $meta_key ) {
1074 if ( isset( $current_images[ $meta_key ] ) ) {
1075 wp_update_post( [
1076 'ID' => $current_images[ $meta_key ],
1077 'post_parent' => 0,
1078 ] );
1079
1080 unset( $current_images[ $meta_key ] );
1081
1082
1083 delete_post_meta( $post_id, $meta_key );
1084 }
1085 }
1086
1087 update_post_meta( 'usp-images', $current_images, true );
1088 }
1089 }
1090
1091 se_handle_journal_image_upload( $post_id, $current_images );
1092
1093 echo "<meta http-equiv='refresh' content='0'>";
1094 } else {
1095 wp_die( "You can't do that" );
1096 }
1097 } else {
1098 if ( 'POST' == $_SERVER[ 'REQUEST_METHOD' ] && isset( $_POST[ 'update_post_nonce' ] ) ) {
1099 $_SESSION[ 'show_edit_form' ] = 'Please make sure that all fields are filled in.';
1100 }
1101 }
1102 ?>
1103
1104 <form id="post" class="post-edit front-end-form" method="post" enctype="multipart/form-data">
1105 <?php if ( isset( $_SESSION[ 'show_edit_form' ] ) ): ?>
1106 <p><?php echo esc_attr( $_SESSION[ 'show_edit_form' ] ); ?></p>
1107 <?php endif; ?>
1108 <input type="hidden" name="post_id" value="<?php $post->ID; ?>" />
1109 <input type="hidden" name="images_pending_removal" value="" />
1110 <?php wp_nonce_field( 'update_post_' . $post->ID, 'update_post_nonce' ); ?>
1111 <fieldset>
1112 <label for="post_title"><?php echo get_field( 'title_fieldname', pll_get_post( 1102 ) ); ?></label>
1113 <input
1114 type="text" id="post_title" name="post_title" class="text-input"
1115 value="<?php echo $post->post_title; ?>" />
1116 </fieldset>
1117 <fieldset>
1118 <label for="post_content"><?php echo get_field( 'content_fieldname', pll_get_post( 1102 ) ); ?></label>
1119 <?php wp_editor( $post->post_content, 'postcontent-edit', [
1120 'media_buttons' => false,
1121 'drag_drop_upload' => false,
1122 'textarea_name' => 'postcontent',
1123 'textarea_rows' => 10,
1124 'teeny' => true,
1125 'quicktags' => false,
1126 'editor_height' => 220,
1127 'tinymce' => apply_filters( 'se_configure_tinymce_plugins', [
1128 'content_css' => get_stylesheet_directory_uri() . '/editor-styles.css'
1129 ] ),
1130 ] ); ?>
1131 </fieldset>
1132 <?php if ( $images = get_post_meta( $post->ID, 'usp-images', true ) ): ?>
1133 <label for="post_images"><?php echo get_field( 'images_fieldname', pll_get_post( 1102 ) ); ?></label>
1134 <div class="uploaded-images">
1135 <?php foreach ( $images as $key => $image ): ?>
1136 <div class="uploaded-image">
1137 <img src="<?php echo wp_get_attachment_image_url( $image, 'thumbnail' ); ?>" />
1138 <a
1139 href="#" data-remove="<?php echo $key; ?>"
1140 style=""><?php echo get_field( 'delete_link_text', pll_get_post( 1102 ) ); ?></a>
1141 </div>
1142 <?php endforeach; ?>
1143 </div>
1144 <?php endif; ?>
1145 <fieldset>
1146
1147 <div id="image-groups">
1148 <input
1149 type="file" name="base" id="base-image-upload" data-image-upload="true"
1150 style="display:none;">
1151 <input type="file" name="images[]" data-image-upload="true" class="upload-input">
1152 </div>
1153
1154 <a
1155 href="#" id="addNewImage"
1156 class="add-file-link"><?php echo get_field( 'add_another_file_text', pll_get_post( 1102 ) ); ?></a>
1157 </fieldset>
1158 <input
1159 type="submit" id="submit"
1160 value="<?php echo get_field( 'update_button_text', pll_get_post( 1102 ) ); ?>" name="submitform"
1161 class="button" />
1162 </form>
1163 </div>
1164 <script type="text/javascript">
1165 jQuery( function ( $ ) {
1166 $( function () {
1167 $( '#addNewImage' ).click( function () {
1168 $( '#base-image-upload' ).clone( false ).removeAttr( 'id' ).attr( 'name', 'images[]' ).css( {
1169 display: 'block',
1170 width: '100%',
1171 marginTop: '20px'
1172 } ).appendTo( $( '#image-groups' ) );
1173
1174 return false;
1175 } );
1176
1177 /**
1178 * Remove images and add them to an array
1179 */
1180 $( '.uploaded-image a[data-remove]' ).click( function ( e ) {
1181 e.preventDefault();
1182
1183 const hidden = $( 'input[type=hidden][name="images_pending_removal"]' );
1184 const pendingRemoval = hidden.val().split( ',' );
1185
1186 pendingRemoval.push( $( this ).attr( 'data-remove' ) );
1187
1188 hidden.val( pendingRemoval.join( ',' ) );
1189
1190 $( this ).closest( '.uploaded-image' ).remove();
1191 return false;
1192 } );
1193 } );
1194 } );
1195
1196 </script>
1197 <?php
1198 }
1199}
1200
1201if ( ! function_exists( 'se_show_journal_entry_new_post_form' ) ) {
1202 function se_show_journal_entry_new_post_form() {
1203 /**
1204 * @var \WP_Post $post
1205 */
1206 ?>
1207 <div class="new-post-form" id="NewPostForm" style="display:none;">
1208 <a href="#" class="close">Close</a>
1209 <h3><?php the_field( 'new_journal_entry_heading', pll_get_post( 1102 ) ); ?></h3>
1210 <?php
1211
1212 if ( function_exists( 'usp_is_session_started' ) ) {
1213 if ( ! usp_is_session_started() ) {
1214 usp_session_start();
1215 }
1216 }
1217
1218 if ( 'POST' == $_SERVER[ 'REQUEST_METHOD' ] && ! empty( $_POST[ 'post_title' ] ) && isset( $_POST[ 'insert_post_nonce' ] ) && isset( $_POST[ 'postcontent' ] ) ) {
1219
1220 if ( wp_verify_nonce( $_POST[ 'insert_post_nonce' ], 'insert_dream_journal' ) ) {
1221 $post = array(
1222 'post_type' => 'dream',
1223 'post_content' => wp_kses_post( $_POST[ 'postcontent' ] ),
1224 'post_title' => wp_strip_all_tags( $_POST[ 'post_title' ] ),
1225 'post_author' => get_current_user_id(),
1226 'post_status' => 'publish',
1227 );
1228
1229 $post_id = wp_insert_post( $post );
1230
1231 // Make sure it's a USP submission
1232 update_post_meta( $post_id, 'is_submission', '1' );
1233
1234 se_handle_journal_image_upload( $post_id );
1235
1236 $permalink = get_the_permalink( $post_id );
1237
1238 // Add in language
1239 $permalink = str_replace( home_url( '/dream' ), home_url( '/' . pll_current_language() . '/dream' ), $permalink );
1240
1241 echo sprintf( "<meta http-equiv=\"refresh\" content=\"0;URL='%s'\" />", $permalink );
1242 } else {
1243 wp_die( "You can't do that" );
1244 }
1245 } else {
1246 if ( 'POST' == $_SERVER[ 'REQUEST_METHOD' ] && isset( $_POST[ 'insert_post_nonce' ] ) ) {
1247 $_SESSION[ 'show_new_post_form' ] = 'Please make sure that all fields are filled in.';
1248 }
1249 }
1250 ?>
1251
1252 <form id="create-post" class="post-new front-end-form" method="post" enctype="multipart/form-data">
1253 <?php if ( isset( $_SESSION[ 'show_new_post_form' ] ) ): ?>
1254 <p><?php echo esc_attr( $_SESSION[ 'show_new_post_form' ] ); ?></p>
1255 <?php endif; ?>
1256
1257 <input type="hidden" name="images_pending_removal" value="" />
1258 <?php wp_nonce_field( 'insert_dream_journal', 'insert_post_nonce' ); ?>
1259 <fieldset>
1260 <label for="post_title"><?php echo get_field( 'title_fieldname', pll_get_post( 1102 ) ); ?></label>
1261 <input type="text" id="post_title" name="post_title" class="text-input" value="" />
1262 </fieldset>
1263 <fieldset>
1264 <label for="post_content"><?php echo get_field( 'content_fieldname', pll_get_post( 1102 ) ); ?></label>
1265 <?php wp_editor( $post->post_content, 'postcontent-add', [
1266 'media_buttons' => false,
1267 'drag_drop_upload' => false,
1268 'textarea_name' => 'postcontent',
1269 'textarea_rows' => 10,
1270 'teeny' => true,
1271 'quicktags' => false,
1272 'editor_height' => 220,
1273 'tinymce' => apply_filters( 'se_configure_tinymce_plugins', [
1274 'content_css' => get_stylesheet_directory_uri() . '/editor-styles.css'
1275 ] ),
1276 ] ); ?>
1277 </fieldset>
1278 <fieldset style="display:block;">
1279 <div id="image-groups2">
1280 <input
1281 type="file" name="base" id="base-image-upload2" data-image-upload="true"
1282 style="display:none;">
1283 <input type="file" name="images[]" data-image-upload="true" class="upload-input">
1284 </div>
1285
1286 <a
1287 href="#" id="addNewImage2"
1288 class="add-file-link"><?php echo get_field( 'add_another_file_text', pll_get_post( 1102 ) ); ?></a>
1289 </fieldset>
1290 <input
1291 type="submit" id="submit"
1292 value="<?php echo get_field( 'submit_button_text', pll_get_post( 1102 ) ); ?>" name="submitform"
1293 class="button" />
1294 </form>
1295 </div>
1296 <script type="text/javascript">
1297 jQuery( function ( $ ) {
1298 $( function () {
1299 <?php if ( isset( $_SESSION[ 'show_edit_form' ] ) ): ?>
1300 $( '#EditPostForm' ).show( 'slow' );
1301 $( '#DeletePostForm' ).hide( 'slow' );
1302 <?php unset( $_SESSION[ 'show_edit_form' ] ); ?>
1303 <?php elseif ( isset( $_SESSION[ 'show_new_post_form' ] ) ): ?>
1304 $( '#NewPostForm' ).show( 'slow' );
1305 $( '#EditPostForm' ).hide( 'slow' );
1306 $( '#DeletePostForm' ).hide( 'slow' );
1307 <?php unset( $_SESSION[ 'show_new_post_form' ] ); ?>
1308 <?php endif; ?>
1309
1310 $( '#showEditPostForm' ).click( function () {
1311 $( '#EditPostForm' ).toggle( 'slow' );
1312 $( '#DeletePostForm' ).hide( 'slow' );
1313 return false;
1314 } );
1315 $( '#EditPostForm .close' ).click( function () {
1316 $( '#EditPostForm' ).hide( 'slow' );
1317 return false;
1318 } );
1319 $( '#showDeletePostForm' ).click( function () {
1320 $( '#DeletePostForm' ).toggle( 'slow' );
1321 $( '#EditPostForm' ).hide( 'slow' );
1322 return false;
1323 } );
1324 $( '#DeletePostForm .close' ).click( function () {
1325 $( '#DeletePostForm' ).hide( 'slow' );
1326 return false;
1327 } );
1328 $( '#NewPostForm .close' ).click( function () {
1329 $( '#NewPostForm' ).hide( 'slow' );
1330 return false;
1331 } );
1332 $( '#addNewImage2' ).click( function () {
1333 $( '#base-image-upload2' ).clone( false ).removeAttr( 'id' ).attr( 'name', 'images[]' ).css( {
1334 display: 'block',
1335 width: '100%',
1336 marginTop: '20px'
1337 } ).appendTo( $( '#image-groups2' ) );
1338
1339 return false;
1340 } );
1341 } );
1342 } );
1343
1344 </script>
1345 <?php
1346 }
1347}
1348
1349/**
1350 * Deleting User Task
1351 */
1352add_action( 'admin_menu', function() {
1353 add_submenu_page(
1354 current_user_can( 'manage_options' ) ? 'options-writing.php' : 'profile.php',
1355 'Delete My Account',
1356 'Delete My Account',
1357 'read',
1358 'se-delete-user',
1359 'delete_user_confirmation_page'
1360 );
1361});
1362
1363function delete_user_confirmation_page() {
1364 if ( current_user_can( 'manage_options' ) && ! isset( $_GET[ 'user' ] ) ) : ?>
1365 <h1><?php echo get_field( 'unauthorized_text', pll_get_post( 1102 ) ); ?></h1>
1366 <p><?php echo get_field( 'cannot_find_user_text', pll_get_post( 1102 ) ); ?></p>
1367 <a href="<?php echo admin_url('users.php'); ?>" class="button button-primary"><?php echo get_field( 'go_back_text', pll_get_post( 1102 ) ); ?></a>
1368 <?php exit;
1369 endif;
1370
1371 $user_id = current_user_can( 'manage_options' ) ? (int) $_GET[ 'user' ] : get_current_user_id();
1372 $user = get_user_by( 'ID', $user_id );
1373
1374 if ( isset( $_GET[ 'confirm' ] ) && (int) $_GET['confirm'] === 1 ) {
1375 if ( user_can( $user_id, 'manage_options' ) ) : ?>
1376 <h1><?php echo get_field( 'unauthorized_text', pll_get_post( 1102 ) ); ?></h1>
1377 <p><?php echo get_field( 'cannot_delete_admin_text', pll_get_post( 1102 ) ); ?></p>
1378 <a href="<?php echo admin_url( 'users.php' ); ?>" class="button button-primary"><?php echo get_field( 'go_back_text', pll_get_post( 1102 ) ); ?></a>
1379 <?php exit;
1380 endif;
1381
1382 wp_delete_user( $user_id, false );
1383
1384 ?>
1385
1386 <h1><?php echo $user->display_name; ?><?php echo get_field( 'user_has_been_deleted', pll_get_post( 1102 ) ); ?></h1>
1387 <p><?php echo get_field( 'admin_user_deleted_text', pll_get_post( 1102 ) ); ?></p>
1388 <a href="<?php echo admin_url( 'users.php' ); ?>" class="button button-primary"><?php echo get_field( 'go_back_text', pll_get_post( 1102 ) ); ?></a>
1389 <?php exit;
1390 }
1391
1392 $confirmation_url = admin_url( sprintf( 'admin.php?page=se-delete-user&user=%d&confirm=1', $user_id ) );
1393
1394 if ( current_user_can( 'manage_options' ) ) {
1395 ?>
1396 <h1><?php echo get_field( 'admin_are_you_sure_delete_account_text', pll_get_post( 1102 ) ); ?></h1>
1397 <h1><?php echo get_field( 'admin_are_you_sure_delete_account_description', pll_get_post( 1102 ) ); ?></h1>
1398 <?php
1399 } else {
1400 ?>
1401 <h1><?php echo get_field( 'are_you_sure_delete_account_text', pll_get_post( 1102 ) ); ?></h1>
1402 <h1><?php echo get_field( 'are_you_sure_delete_account_description', pll_get_post( 1102 ) ); ?></h1>
1403 <?php
1404 }
1405
1406 echo '<a style="display: inline-block; margin-top: 1em; margin-right:1em;" href="' . $confirmation_url . '" class="button button-primary">' . get_field( 'confirm_delete_account_text', pll_get_post( 1102 ) ) . '</a>';
1407 echo '<a style="display: inline-block; margin-top: 1em; margin-right:1em;" href="' . admin_url('users.php') . '" class="button button-secondary" role="button" aria-expanded="false">' . get_field( 'go_back_text', pll_get_post( 1102 ) ) . '</a>';
1408 exit;
1409}
1410
1411add_action( 'delete_user', function( $user_id ) {
1412 $args = array(
1413 'numberposts' => - 1,
1414 'post_type' => 'any',
1415 'author' => $user_id
1416 );
1417
1418 // get all posts by this user: posts, pages, attachments, etc..
1419 $user_posts = get_posts( $args );
1420
1421 if ( empty( $user_posts ) || user_can( $user_id, 'manage_options' ) ) {
1422 return;
1423 }
1424
1425 // delete all the user posts
1426 foreach ( $user_posts as $user_post ) {
1427 if ( $user_post->post_type === 'attachment' ) {
1428 wp_delete_attachment( $user_post->ID, true );
1429 } else {
1430 $medias = get_attached_media( '', $user_post->ID );
1431
1432 foreach ( $medias as $media ) {
1433 wp_delete_attachment( $media->ID, true );
1434 }
1435
1436 wp_delete_post( $user_post->ID, true );
1437 }
1438 }
1439} );
1440
1441add_action( 'wp_enqueue_scripts', function() {
1442 wp_register_script( 'se-sweet-alert', get_stylesheet_directory_uri() . '/js/swal.js' );
1443 wp_register_script( 'se-frontend-account', get_stylesheet_directory_uri() . '/js/scripts.js' );
1444});
1445
1446add_shortcode( 'se-delete-account', function( $atts = [] ) {
1447 global $current_user;
1448
1449 if ( ! $current_user->ID ) {
1450 return;
1451 }
1452
1453 wp_enqueue_script( 'se-sweet-alert' );
1454 wp_enqueue_script( 'se-frontend-account' );
1455 wp_localize_script( 'se-frontend-account', 'se_frontend', [
1456 // Handle translations here
1457 // Use conditions to replace the text, or get_post() like you have been doing throughout the site
1458 'translations' => [
1459 'areYouSure' => 'Are you sure you want to delete your account?',
1460 'noUndo' => 'There is no reversing this action.',
1461 'confirmButton' => 'Yes, delete my account'
1462 ],
1463 'ajax_url' => admin_url( 'admin-ajax.php?action=delete_user_account' ),
1464 ]);
1465
1466 return '<style>.swal2-popup { font-size: 18px !important; }</style><a href="" id="delete-account" class="button small-button">Delete my account</a>';
1467});
1468
1469add_action( 'wp_ajax_delete_user_account', function() {
1470 global $current_user;
1471
1472 if ( current_user_can( 'manage_options' ) ) {
1473 wp_send_json([ 'success' => false, 'message' => 'You cannot delete your profile, you are an administrator' ] );
1474 }
1475
1476 wp_delete_user( $current_user->ID, false );
1477
1478 wp_send_json([ 'success' => true, 'message' => 'Your account has been successfully deleted' ]);
1479});
1480
1481/**
1482 * Add "View Journal Feed row actions
1483 */
1484add_filter( 'se_journal_feed_url', function ( WP_User $user ) {
1485 switch( strtolower( get_user_locale( $user ) ) ) {
1486 case 'de_de': // German
1487 $journal_feed_page_id = 0;
1488 break;
1489 case 'el': // Greek
1490 $journal_feed_page_id = 1370;
1491 break;
1492 case 'en_gb': // English/Default
1493 default:
1494 $journal_feed_page_id = 1239;
1495 break;
1496 }
1497
1498 $url = get_permalink( $journal_feed_page_id );
1499
1500 $query = parse_url( $url, PHP_URL_QUERY );
1501
1502 if ( $query ) {
1503 $url .= '&user=' . $user->user_login;
1504 } else {
1505 $url .= '?user=' . $user->user_login;
1506 }
1507
1508 return $url;
1509} );
1510
1511add_filter( 'se_delete_user_url', function ( WP_User $user ) {
1512 return admin_url( 'admin.php?page=se-delete-user&user=' . $user->ID );
1513} );
1514
1515add_filter( 'user_row_actions', function ( $actions, WP_User $user ) {
1516 global $current_user;
1517
1518 if ( isset( $actions[ 'view' ] ) ) {
1519 unset( $actions[ 'view' ] );
1520 }
1521
1522 if ( $current_user && current_user_can( 'edit_posts' ) ) {
1523 $actions[ 'delete' ] = sprintf( '<a class="submitdelete" href="%s">Delete User</a>', apply_filters( 'se_delete_user_url', $user ) );
1524 $actions[ 'view-journal-feed' ] = sprintf( '<a href="%s">Dream Diary</a>', apply_filters( 'se_journal_feed_url', $user ) );
1525 }
1526
1527 return $actions;
1528}, 10, 2 );
1529
1530
1531/**
1532 * Google ReCAPTCHA Configuration here. You can get this
1533 * information by creating keys here:
1534 *
1535 * https://www.google.com/recaptcha/admin
1536 */
1537function configure_google_recaptcha() {
1538 return (object) [
1539 'secretKey' => '6LeevMkZAAAAACFIZfOfWUhI2viQRwDuQ89jANPC',
1540 'siteKey' => '6LeevMkZAAAAAEg1d6CLAhDFEqH74nvr3h6WOPCJ',
1541//Siaeva's key 'secretKey' => '6LfovskZAAAAAKTG2HL3TBAKXATwN3Guoh81-7hT',
1542//Siaeva's key 'siteKey' => '6LfovskZAAAAAHeq-3-ddPOdpWUPiBuT0KqFNaze',
1543// Programmer's Key 'secretKey' => '6LefL8oZAAAAAOPq1sOX-UQyrqnwYKFs_4RowTlN',
1544// Programmers Key 'siteKey' => '6LefL8oZAAAAAKpsCU_uDOCFDh8r0QwOwWtc56pc',
1545 ];
1546}
1547
1548add_filter( 'se_configure_google_recaptcha', 'configure_google_recaptcha' );
1549
1550/**
1551 * Use this filter to configure what elements of TinyMCE get
1552 * shown on both the edit and create new journal forms.
1553 *
1554 * @since 24/09/2020
1555 */
1556add_filter( 'se_configure_tinymce_plugins', function () {
1557 return [
1558 'plugins' => "lists,link,textcolor,hr",
1559 'toolbar1' => "bold,italic,underline,blockquote,strikethrough,alignleft,aligncenter,alignright,alignjustify,undo,redo,bullist,numlist",
1560 'content_css' => get_stylesheet_directory_uri() . '/editor-styles.css',
1561 ];
1562} );
1563
1564/**
1565 * Modifies the directory for journal post entries
1566 * only.
1567 *
1568 * @since 24/09/2020
1569 */
1570add_filter( 'upload_dir', function ( $upload ) {
1571 global $post, $template;
1572
1573 $allowed_templates = [
1574 'template-dream-journal-dashboard.php',
1575 'single-dream.php',
1576 ];
1577
1578 if ( ( ! $post || $post !== 'dream' ) && ( ! $template || ! in_array( basename( $template ), $allowed_templates ) ) ) {
1579 return $upload;
1580 }
1581
1582 // Override the year / month being based on the post publication date, if year/month organization is enabled
1583 if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
1584 // Generate the yearly and monthly dirs
1585 $time = current_time( 'mysql' );
1586 $y = substr( $time, 0, 4 );
1587 $m = substr( $time, 5, 2 );
1588 $upload[ 'subdir' ] = "/$y/$m";
1589 }
1590
1591 $upload[ 'subdir' ] = '/dream-journal-entries' . $upload[ 'subdir' ];
1592 $upload[ 'path' ] = $upload[ 'basedir' ] . $upload[ 'subdir' ];
1593 $upload[ 'url' ] = $upload[ 'baseurl' ] . $upload[ 'subdir' ];
1594
1595 return $upload;
1596} );
1597
1598/**
1599 * Sends a notification to the admin the comment has been
1600 * added.
1601 *
1602 * @param $emails
1603 * @param $comment_id
1604 *
1605 * @return array
1606 * @since 24/09/2020
1607 */
1608function se_comment_moderation_recipients( $emails, $comment_id ) {
1609 $comment = get_comment( $comment_id );
1610 $post = get_post( $comment->comment_post_ID );
1611 $user = get_user_by( 'id', $comment->user_id );
1612
1613 if ( ! $user || ! $post || $post->post_type !== 'dream' ) {
1614 return $emails;
1615 }
1616
1617 /**
1618 * Don't send a notification if the comment is coming from an
1619 * administrator.
1620 */
1621 if ( user_can( $user, 'edit_posts' ) ) {
1622 if ( (int) $comment->comment_parent === 0 ) {
1623 $post_author = get_userdata( $post->post_author );
1624
1625 return [ $post_author->user_email ];
1626 }
1627
1628 return [];
1629 }
1630
1631 $emails = [ get_bloginfo( 'admin_email' ) ];
1632
1633 return $emails;
1634}
1635
1636add_filter( 'comment_moderation_recipients', 'se_comment_moderation_recipients', 11, 2 );
1637add_filter( 'comment_notification_recipients', 'se_comment_moderation_recipients', 11, 2 );
1638
1639/**
1640 * Removes the IP address from the email.
1641 *
1642 * @since 24/09/2020
1643 */
1644add_filter( 'comment_notification_text', function ( $notify_message ) {
1645 $notify_message = explode( "\n", $notify_message );
1646
1647 foreach ( $notify_message as $k => $line ) {
1648 $header = trim( substr( $line, 0, strpos( $line, ':' ) ) );
1649 switch ( $header ) {
1650 case 'E-mail':
1651 case 'Email':
1652 case 'URL' :
1653 case 'Whois':
1654 case 'Spam it':
1655 case 'Bin it':
1656 unset( $notify_message[ $k ] );
1657 break;
1658 case 'Author' :
1659 $pat = '([^(]+)\(.*$';
1660 $notify_message[ $k ] = trim( preg_replace( '|' . $pat . '|', '$1', $line ) );
1661 break;
1662 }
1663 }
1664
1665 $notify_message = implode( "\n", $notify_message );
1666
1667 return $notify_message;
1668} );
1669
1670/**
1671 * Stops users viewing the direct attachment page.
1672 *
1673 * @since 24/09/2020
1674 */
1675add_action( 'template_redirect', function () {
1676 if ( is_attachment() ) {
1677 global $post;
1678
1679 if ( $post && get_post_meta( $post->ID, '_journal_entry_image' ) === true ) {
1680 wp_redirect( esc_url( home_url( '/' ) ), 301 );
1681 exit;
1682 }
1683 }
1684} );
1685
1686/**
1687 * Stops journal images from showing up in the media
1688 * library.
1689 *
1690 * @since 24/09/2020
1691 */
1692add_filter( 'ajax_query_attachments_args', function ( $query ) {
1693 if ( ! isset( $query[ 'meta_query' ] ) ) {
1694 $query[ 'meta_query' ] = [];
1695 }
1696
1697 $query[ 'meta_query' ][] = [
1698 'key' => '_journal_entry_image',
1699 'compare' => 'NOT EXISTS',
1700 ];
1701
1702 return $query;
1703} );
1704
1705add_action( 'register_post', function ( $user_login, $user_email, $errors ) {
1706 if ( function_exists( 'usp_is_session_started' ) ) {
1707 if ( ! usp_is_session_started() ) {
1708 usp_session_start();
1709 }
1710 }
1711
1712 if ( isset( $_SESSION[ 'registration_errors' ] ) ) {
1713 unset( $_SESSION[ 'registration_errors' ] );
1714 }
1715
1716 $recaptcha_credentials = apply_filters( 'se_configure_google_recaptcha', (object) [
1717 'secretKey' => '6LeevMkZAAAAACFIZfOfWUhI2viQRwDuQ89jANPC',
1718 'siteKey' => '6LeevMkZAAAAAEg1d6CLAhDFEqH74nvr3h6WOPCJ'
1719 ] );
1720
1721 if ( $recaptcha_credentials->secretKey && $recaptcha_credentials->siteKey ) {
1722 if ( empty( $_POST[ 'gcaptcha_token' ] ) ) {
1723 $errors->add( 'invalid_captcha_code', '<strong>ERROR</strong>: Invalid captcha code.' );
1724 }
1725
1726 // Verify Google Captcha results
1727 $url = 'https://www.google.com/recaptcha/api/siteverify';
1728 $data = array(
1729 'secret' => $recaptcha_credentials->secretKey,
1730 'response' => esc_attr( $_POST[ 'gcaptcha_token' ] )
1731 );
1732
1733 $options = array(
1734 'http' => array(
1735 'header' => "Content-type: application/x-www-form-urlencoded\n",
1736 'method' => 'POST',
1737 'content' => http_build_query( $data )
1738 )
1739 );
1740 $context = stream_context_create( $options );
1741 $response = file_get_contents( $url, false, $context );
1742 $responseKeys = json_decode( $response, true );
1743
1744 if ( ! $responseKeys[ "success" ] || $responseKeys[ "score" ] < 0.5 ) {
1745 $errors->add( 'failed_captcha', '<strong>ERROR</strong>: Invalid captcha request.' );
1746 }
1747 }
1748
1749 if ( empty( $_POST[ 'first_name' ] ) ) {
1750 $errors->add( 'empty_first_name', '<strong>ERROR</strong>: Please enter your first name.' );
1751 }
1752
1753 if ( empty( $_POST[ 'last_name' ] ) ) {
1754 $errors->add( 'empty_last_name', '<strong>ERROR</strong>: Please enter your last name.' );
1755 }
1756
1757 if ( empty( $_POST[ 'location' ] ) ) {
1758 $errors->add( 'user_location', '<strong>ERROR</strong>: Please enter your location.' );
1759 }
1760
1761 if ( empty( $_POST[ 'user_email' ] ) ) {
1762 $errors->add( 'empty_email', '<strong>ERROR</strong>: Please enter your email address.' );
1763 }
1764 if ( $errors->has_errors() ) {
1765 $location = $_SERVER[ 'HTTP_REFERER' ];
1766
1767 $_SESSION[ 'registration_errors' ] = $errors->get_error_messages();
1768
1769 $query = parse_url( $location, PHP_URL_QUERY );
1770
1771 if ( $query ) {
1772 if ( strpos( $query, 'show_register=1' ) === false ) {
1773 $location .= '&show_register=1';
1774 }
1775 } else {
1776 $location .= '?show_register=1';
1777 }
1778
1779 wp_safe_redirect( $location );
1780 exit;
1781 }
1782}, 10, 3 );
1783
1784/*USP PRO REGISTER / LOGIN / FORGOT*/
1785function display_usp_login() {
1786
1787 $current_user = wp_get_current_user();
1788
1789 if ( isset( $current_user ) ) {
1790 $user = $current_user->user_login;
1791 $id = $current_user->ID;
1792 }
1793
1794 $reset = false;
1795 $register = false;
1796
1797 if ( isset( $_GET[ 'reset' ] ) ) {
1798 $reset = (bool) sanitize_text_field( $_GET[ 'reset' ] );
1799 }
1800 if ( isset( $_GET[ 'register' ] ) ) {
1801 $register = (bool) sanitize_text_field( $_GET[ 'register' ] );
1802 }
1803
1804 $redirect_login = apply_filters( 'usp_login_redirect_login', esc_url( get_permalink() ) );
1805 $redirect_register = apply_filters( 'usp_login_redirect_register', esc_url( add_query_arg( 'register', 'true', get_permalink() ) ) );
1806 $redirect_reset = apply_filters( 'usp_login_redirect_reset', esc_url( add_query_arg( 'reset', 'true', get_permalink() ) ) );
1807
1808 ?>
1809
1810 <style>
1811 .usp-login #tab2_login, .usp-login #tab3_login {
1812 display: none;
1813 }
1814
1815 .usp-login {
1816 width: 370px;
1817 overflow: hidden;
1818 margin: 25px auto;
1819 padding: 10px;
1820 font-size: 12px;
1821 line-height: 16px;
1822 }
1823
1824 .usp-login p {
1825 margin: 10px 0;
1826 }
1827
1828 .usp-login .tabs_login {
1829 float: left;
1830 margin: 0;
1831 padding: 0;
1832 list-style-type: none;
1833 }
1834
1835 .usp-login .tabs_login li {
1836 float: left;
1837 overflow: hidden;
1838 margin: 0 5px 0 0;
1839 padding: 0;
1840 }
1841
1842 .usp-login .tabs_login li a {
1843 height: 30px;
1844 display: block;
1845 padding: 0 15px;
1846 line-height: 30px;
1847 text-decoration: none;
1848 border: none;
1849 }
1850
1851 .usp-login .tab_container {
1852 width: 100%;
1853 float: left;
1854 margin: 0 0 20px 0;
1855 background-color: #fff;
1856 border: none;
1857 }
1858
1859 .usp-login .tab_content {
1860 padding: 20px;
1861 }
1862
1863 .usp-login .username, .usp-login .password, .usp-login .login_fields {
1864 width: 100%;
1865 overflow: hidden;
1866 margin: 7px 0 0 0;
1867 padding: 3px 0;
1868 }
1869
1870 .usp-login .rememberme {
1871 margin: 0 0 15px 0;
1872 font-size: 11px;
1873 }
1874
1875 .usp-login .rememberme input {
1876 float: left;
1877 margin: 2px 7px 0 0;
1878 }
1879
1880 .usp-login .user-submit {
1881 float: left;
1882 margin: 5px 0 0 0;
1883 }
1884
1885 .usp-login .user-logged-in {
1886 width: 330px;
1887 overflow: hidden;
1888 padding: 20px;
1889 }
1890
1891 .usp-login .user-info {
1892 float: left;
1893 width: 240px;
1894 padding: 20px 0 0 0;
1895 }
1896
1897 .usp-login .user-info a, .usp-login .user-info a:hover {
1898 text-decoration: none;
1899 }
1900
1901 .usp-login .usp-sep {
1902 padding: 0 3px;
1903 }
1904 </style>
1905
1906 <?php if ( ! is_user_logged_in() ) : ?>
1907
1908 <?php $recaptcha_credentials = apply_filters( 'se_configure_google_recaptcha', (object) [
1909 'secretKey' => '6LeevMkZAAAAACFIZfOfWUhI2viQRwDuQ89jANPC',
1910 'siteKey' => '6LeevMkZAAAAAEg1d6CLAhDFEqH74nvr3h6WOPCJ'
1911 ] ); ?>
1912 <!-- ADD ME -->
1913 <script src="https://www.google.com/recaptcha/api.js?render=<?php echo $recaptcha_credentials->siteKey; ?>"></script>
1914 <script>
1915 jQuery( document ).ready( function ( $ ) {
1916 $( window ).on( 'load', function () {
1917 $( '.tab_content' ).hide();
1918 $( '.tabs_login li:first' ).addClass( 'active_tab' ).show();
1919 $( '.tab_content:first' ).show();
1920 $( 'ul.tabs_login li' ).click( function () {
1921 $( 'ul.tabs_login li' ).removeClass( 'active_tab' );
1922 $( this ).addClass( 'active_tab' );
1923 $( '.tab_content' ).hide();
1924 var activeTab = $( this ).find( 'a' ).attr( 'href' );
1925 $( activeTab ).show();
1926 return false;
1927 } );
1928
1929 var urlParams = new URLSearchParams( window.location.search );
1930 var foo = urlParams.get( 'show_register' );
1931
1932 if ( foo ) {
1933 $( '#register-link' ).click();
1934 }
1935
1936 $( '#register-form' ).on( 'submit', function () {
1937 $( this ).find( 'div.error span.error-message' ).remove();
1938 $( this ).find( 'div.error' ).removeClass( 'error' );
1939
1940 let allow = true;
1941
1942 if ( $( this ).find( 'input[name="first_name"]' ).val() === '' ) {
1943 const wrapper = $( this ).find( 'input[name="first_name"]' ).closest( 'div' ).addClass( 'error' );
1944
1945 $( '<span class="error-message"><?php echo get_field( 'required_field_text', pll_get_post( 1102 ) ); ?></span>' ).appendTo( wrapper );
1946
1947 allow = false;
1948 }
1949
1950 if ( $( this ).find( 'input[name="last_name"]' ).val() === '' ) {
1951 const wrapper = $( this ).find( 'input[name="last_name"]' ).closest( 'div' ).addClass( 'error' );
1952
1953 $( '<span class="error-message"><?php echo get_field( 'required_field_text', pll_get_post( 1102 ) ); ?></span>' ).appendTo( wrapper );
1954
1955 allow = false;
1956 }
1957
1958 if ( $( this ).find( 'input[name="user_login"]' ).val() === '' ) {
1959 const wrapper = $( this ).find( 'input[name="user_login"]' ).closest( 'div' ).addClass( 'error' );
1960
1961 $( '<span class="error-message"><?php echo get_field( 'required_field_text', pll_get_post( 1102 ) ); ?></span>' ).appendTo( wrapper );
1962
1963 allow = false;
1964 }
1965
1966 if ( $( this ).find( 'input[name="user_email"]' ).val() === '' ) {
1967 const wrapper = $( this ).find( 'input[name="user_email"]' ).closest( 'div' ).addClass( 'error' );
1968
1969 $( '<span class="error-message"><?php echo get_field( 'required_field_text', pll_get_post( 1102 ) ); ?></span>' ).appendTo( wrapper );
1970
1971 allow = false;
1972 }
1973
1974 if ( $( this ).find( 'input[name="location"]' ).val() === '' ) {
1975 const wrapper = $( this ).find( 'input[name="location"]' ).closest( 'div' ).addClass( 'error' );
1976
1977 $( '<span class="error-message"><?php echo get_field( 'required_field_text', pll_get_post( 1102 ) ); ?></span>' ).appendTo( wrapper );
1978
1979 allow = false;
1980 }
1981
1982 return allow;
1983 } );
1984 } );
1985 } );
1986
1987 jQuery( function ( $ ) {
1988 grecaptcha.ready( function () {
1989 grecaptcha.execute( '<?php echo $recaptcha_credentials->siteKey; ?>', { action: 'homepage' } ).then( function ( token ) {
1990 // pass the token to the backend script for verification
1991 $( '#register-form input[name="gcaptcha_token"]' ).val( token );
1992 } );
1993 } );
1994 } );
1995 </script>
1996
1997 <script>
1998 jQuery( document ).ready( function ( $ ) {
1999 $( '.tab_content' ).hide();
2000 $( '.tabs_login li:first' ).addClass( 'active_tab' ).show();
2001 $( '.tab_content:first' ).show();
2002 $( 'ul.tabs_login li' ).click( function () {
2003 $( 'ul.tabs_login li' ).removeClass( 'active_tab' );
2004 $( this ).addClass( 'active_tab' );
2005 $( '.tab_content' ).hide();
2006 var activeTab = $( this ).find( 'a' ).attr( 'href' );
2007 $( activeTab ).show();
2008 return false;
2009 } );
2010 } );
2011 </script>
2012 <div id="usp-login" class="usp-login">
2013 <ul class="tabs_login">
2014 <li class="active_tab">
2015 <a href="#tab1_login"><?php echo get_field( 'login_tab_text', pll_get_post( 1102 ) ); ?></a></li>
2016 <li>
2017 <a
2018 id="register-link"
2019 href="#tab2_login"><?php echo get_field( 'register_tab_text', pll_get_post( 1102 ) ); ?></a>
2020 </li>
2021 <li>
2022 <a href="#tab3_login"><?php echo get_field( 'forgot_password_tab_text', pll_get_post( 1102 ) ); ?></a>
2023 </li>
2024 </ul>
2025 <div class="tab_container">
2026 <div id="tab1_login" class="tab_content">
2027
2028 <?php if ( $register ) : ?>
2029
2030 <h3><?php echo get_field( 'success_message', pll_get_post( 1102 ) ); ?></h3>
2031 <p><?php echo get_field( 'check_email_for_password_message', pll_get_post( 1102 ) ); ?></p>
2032
2033 <?php elseif ( $reset ) : ?>
2034
2035 <h3><?php echo get_field( 'success_message', pll_get_post( 1102 ) ); ?></h3>
2036 <p><?php echo get_field( 'check_email_reset_password_message', pll_get_post( 1102 ) ); ?></p>
2037
2038 <?php else : ?>
2039 <?php endif; ?>
2040
2041 <form method="post" action="<?php echo wp_login_url(); ?>">
2042 <div class="form-row">
2043 <div class="username usp-form-field">
2044 <label for="log"><?php echo get_field( 'username_form_field', pll_get_post( 1102 ) ); ?></label>
2045 <input name="log" id="log" type="text" value="">
2046 </div>
2047 <div class="password usp-form-field field-right">
2048 <label for="pwd"><?php echo get_field( 'password_form_field', pll_get_post( 1102 ) ); ?></label>
2049 <input name="pwd" id="pwd" type="password" value="" autocomplete="off">
2050 </div>
2051 </div>
2052
2053 <div class="login_fields">
2054 <div class="rememberme">
2055 <label for="rememberme">
2056 <input
2057 name="rememberme" id="rememberme" type="checkbox" value="forever"
2058 checked="checked"> <?php echo get_field( 'remember_me_form_field', pll_get_post( 1102 ) ); ?>
2059 </label>
2060 </div>
2061 <input
2062 type="submit" name="user-submit" value="<?php esc_attr_e( 'Login', 'usp-pro' ); ?>"
2063 class="user-submit">
2064 <input type="hidden" name="redirect_to" value="<?php echo $redirect_login; ?>">
2065 <input type="hidden" name="user-cookie" value="1">
2066 <?php do_action( 'login_form' ); ?>
2067 </div>
2068 </form>
2069 </div>
2070 <div id="tab2_login" class="tab_content">
2071 <div class="intro"><?php echo get_field( 'register_intro_text', pll_get_post( 1102 ) ); ?></div>
2072 <form id="register-form" method="post" action="<?php echo wp_registration_url(); ?>">
2073 <input type="hidden" name="gcaptcha_token" />
2074
2075 <?php
2076
2077 if ( function_exists( 'usp_is_session_started' ) ) {
2078 if ( ! usp_is_session_started() ) {
2079 usp_session_start();
2080 }
2081
2082 if ( isset( $_SESSION[ 'registration_errors' ] ) ) {
2083 ?>
2084 <div class="registration-errors">
2085 <p><?php echo get_field( 'general_error_message', pll_get_post( 1102 ) ); ?></p>
2086 <ul>
2087 <?php foreach ( $_SESSION[ 'registration_errors' ] as $error ) : ?>
2088 <li><?php echo strip_tags( $error, 'strong' ); ?></li>
2089 <?php endforeach; ?>
2090 </ul>
2091 </div>
2092 <?php
2093 }
2094 }
2095
2096 ?>
2097 <div class="form-row">
2098 <div class="firstname usp-form-field">
2099 <label for="first_name"><?php echo get_field( 'first_name_form_field', pll_get_post( 1102 ) ); ?></label>
2100 <input type="text" name="first_name" id="first_name" class="input" value="" />
2101 </div>
2102
2103 <div class="lastname usp-form-field field-right">
2104 <label for="last_name"><?php echo get_field( 'last_name_form_field', pll_get_post( 1102 ) ); ?></label>
2105 <input type="text" name="last_name" id="last_name" class="input" value="" />
2106 </div>
2107 </div>
2108
2109 <div class="form-row">
2110 <div class="username usp-form-field">
2111 <label for="user_login_register"><?php echo get_field( 'username_form_field', pll_get_post( 1102 ) ); ?></label>
2112 <input name="user_login" id="user_login_register" type="text" value="">
2113 </div>
2114
2115 <div class="email usp-form-field field-right">
2116 <label for="user_email"><?php echo get_field( 'email_form_field', pll_get_post( 1102 ) ); ?></label>
2117 <input name="user_email" id="user_email" type="text" value="">
2118 </div>
2119 </div>
2120
2121 <div class="form-row">
2122 <div class="location usp-form-field">
2123 <label for="location"><?php echo get_field( 'location_form_field', pll_get_post( 1102 ) ); ?></label>
2124 <input type="text" name="location" id="location" class="input" value="" />
2125 </div>
2126
2127 <div class="phone usp-form-field field-right">
2128 <label for="phone"><?php echo get_field( 'phone_form_field', pll_get_post( 1102 ) ); ?></label>
2129 <input type="text" name="phone" id="phone" class="input" value="" />
2130 </div>
2131 </div>
2132 <div class="access">
2133 <label for="access"><input
2134 type="checkbox" name="access" id="access" class="input"
2135 value="1" /><span><?php echo get_field( 'grant_access_form_field', pll_get_post( 1102 ) ); ?></span></label>
2136 </div>
2137 <div class="login_fields">
2138 <input
2139 type="submit" name="user-submit"
2140 value="<?php echo get_field( 'sign_up_button_text', pll_get_post( 1102 ) ); ?>"
2141 class="user-submit g-recaptcha" data-sitekey="reCAPTCHA_site_key"
2142 data-callback='onSubmit'>
2143 <input type="hidden" name="redirect_to" value="<?php echo $redirect_register; ?>">
2144 <input type="hidden" name="user-cookie" value="1">
2145 <?php do_action( 'register_form' ); ?>
2146 </div>
2147 </form>
2148
2149 </div>
2150 <div id="tab3_login" class="tab_content">
2151 <form method="post" action="<?php echo wp_lostpassword_url(); ?>">
2152 <div class="usp-form-field field-wide">
2153 <label for="user_login_password"><?php echo get_field( 'username_or_email_form_field', pll_get_post( 1102 ) ); ?></label>
2154 <input name="user_login" id="user_login_password" type="text" value="">
2155 </div>
2156 <div class="login_fields">
2157 <input
2158 type="submit" name="user-submit"
2159 value="<?php echo get_field( 'reset_password_button_text', pll_get_post( 1102 ) ); ?>"
2160 class="user-submit">
2161 <input type="hidden" name="redirect_to" value="<?php echo $redirect_reset; ?>">
2162 <input type="hidden" name="user-cookie" value="1">
2163 <?php do_action( 'login_form', 'resetpass' ); ?>
2164 </div>
2165 </form>
2166 </div>
2167 </div>
2168 </div>
2169
2170 <?php else : ?>
2171
2172 <div class="usp-login">
2173 <div class="user-logged-in">
2174 <div class="wrapper">
2175 <?php $user_info = get_userdata( get_current_user_id() );
2176 $first_name = $user_info->first_name; ?>
2177 <h3><?php echo get_field( 'welcome_text', pll_get_post( 1102 ) ); ?>, <?php echo $first_name; ?></h3>
2178 <div class="user-info">
2179 <p><?php esc_html_e( 'Congratulations, you’re logged in.', 'usp-pro' ); ?></p>
2180 <p>
2181 <a href="<?php echo wp_logout_url( get_permalink() ); ?>"><?php echo get_field( 'log_out_text', pll_get_post( 1102 ) ); ?></a><span
2182 class="usp-sep"> | </span>
2183 <?php if ( current_user_can( 'manage_options' ) ) {
2184 echo '<a href="' . admin_url() . '">' . esc_html__( 'Admin', 'usp-pro' ) . '</a>';
2185 } else {
2186 echo '<a href="' . admin_url() . 'profile.php">' . esc_html__( 'Profile', 'usp-pro' ) . '</a>';
2187 } ?>
2188 </p>
2189 </div>
2190 </div>
2191 </div>
2192 </div>
2193
2194 <?php endif; ?>
2195
2196<?php }
2197
2198/*
2199 Shortcode: shortcode displays a form that lets users login, register, and reset their password
2200 Usage: [usp_login_form]
2201 Based on: https://digwp.com/2010/12/login-register-password-code/
2202*/
2203if ( ! function_exists( 'usp_login_form_shortcode' ) ) :
2204 function usp_login_form_shortcode( $attr, $content = null ) {
2205 ob_start();
2206 display_usp_login();
2207 $form = ob_get_contents();
2208 ob_end_clean();
2209
2210 return $form;
2211 }
2212
2213 add_shortcode( 'usp_login_new', 'usp_login_form_shortcode' );
2214endif;
2215
2216/*
2217 FILTER POSTS BY AUTHOR
2218*/
2219function rudr_filter_by_the_author() {
2220 $params = array(
2221 'name' => 'author', // this is the "name" attribute for filter <select>
2222 'show_option_all' => 'All authors' // label for all authors (display posts without filter)
2223 );
2224
2225 if ( isset( $_GET[ 'user' ] ) ) {
2226 $params[ 'selected' ] = $_GET[ 'user' ];
2227 } // choose selected user by $_GET variable
2228
2229 wp_dropdown_users( $params ); // print the ready author list
2230}
2231
2232add_action( 'restrict_manage_posts', 'rudr_filter_by_the_author' );
2233
2234?>
2235