· 6 years ago · Dec 03, 2019, 12:08 PM
1<?php
2/**
3 * Default functions.php for Wordpress Theme
4 * @author Daniel Drabik (daniel.drabik@outlook.com)
5 * @version 1.0
6 *
7 * Changelog:
8 * 0.1
9 * - Added fields/options functions
10 * 0.2
11 * - Auto register main menu with wp_bootstrap_navwalker.php @link https://github.com/wp-bootstrap/wp-bootstrap-navwalker
12 * - Added support for post thumbnails
13 * - Added support for html title tag
14 * 0.3
15 * - Added update-remove functions
16 * 0.4
17 * - Added custom term fields support
18 * - Removed Welcome widget from dashboard
19 * - Added languages support
20 * - Added bittersweet_pagination @link https://github.com/talentedaamer/Bitter-Sweet/blob/master/functions.php#L172 \
21 * 0.5
22 * - Added optional 'the_content' filter
23 * 0.6
24 * - Added is_field, is_option, is_term_field functions in order to check if the value is not empty
25 * - Removed WP Logo from toolbar
26 * - Added Enqueue Styles and Enqueue Script
27 * - Added functions to apply 'the_content' filters
28 * - Added short function to echo tempalte url
29 * - Remove Spans from Contact Form 7
30 * 0.7
31 * - Moved wp_bootstrap_navwalker.php to inc directory
32 * - Added CMB_helper which provides easy field creation.
33 * 0.8 - Added Multilingual support for Option Metaboxes. Required - Polylang plugin
34 * - Removed additional image sizes
35 * - Added support for Metabox setting icon
36 * - Added support for options and default fields atributes
37 * 0.9
38 * - Added new functionallity 'Sections', which allows you to build pages with new post type that has declared certain template (and fields)
39 * 1.0
40 * - Added directory autoloader ('load_lib')
41 * - Added special library to handle ajax requests
42 * - Moved custom fields of post types into post type declaration file
43 * - Reworked structure of files/directories
44 */
45
46 if ( ! function_exists( 'load_lib' ) ) :
47 /**
48 * Load files in particular directory. Miss files with '_' (dash) as first character in filename.
49 */
50 function load_lib($dir = '') {
51
52 if(!empty($dir))
53 $dir .= '/';
54
55 foreach(glob(get_template_directory() . "/" . $dir . "*.php") as $file) {
56
57 if(substr(basename($file, '.php'), 0, 1) == '_')
58 continue;
59
60 require $file;
61 }
62
63 }
64 endif;
65
66
67 //add_action( 'init', 'gloo_ajax_posts' );
68
69 function gloo_ajax_posts() {
70 wp_register_script( "ajax_posts_script", get_template_directory_uri() . '/js_lib/ajax.js', array('jquery') );
71 wp_localize_script( 'ajax_posts_script', 'ajax_posts', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
72
73 wp_enqueue_script( 'jquery' );
74 wp_enqueue_script( 'ajax_posts_script' );
75
76 wp_enqueue_script( 'script', get_template_directory_uri() . '/js/ajax/login.js');
77
78 }
79
80
81 // Add CMB Helper
82 load_lib('inc');
83
84 // Include Ajax libraries
85 load_lib('ajax');
86 // Include custom fields templates
87 load_lib('cmb');
88 // Include custom fields for sections
89 load_lib('cmb/sections');
90 load_lib('cmb/users');
91 // Custom Post Types
92 load_lib('post_types');
93 // Dynamc sidebars
94 load_lib('sidebars');
95 // Widgets
96 load_lib('widgets');
97 //taxonomy
98 load_lib('taxonomy');
99 //taxonomy
100 load_lib('forms');
101
102 /**
103 * gloo functions and definitions
104 *
105 * @link https://developer.wordpress.org/themes/basics/theme-functions/
106 *
107 * @package gloo
108 */
109 if ( ! function_exists( 'ok_setup' ) ) :
110 /**
111 * Sets up theme defaults and registers support for various WordPress features.
112 *
113 * Note that this function is hooked into the after_setup_theme hook, which
114 * runs before the init hook. The init hook is too late for some features, such
115 * as indicating support for post thumbnails.
116 */
117 function ok_setup() {
118 /*
119 * Make theme available for translation.
120 * Translations can be filed in the /languages/ directory.
121 * If you're building a theme based on gloo, use a find and replace
122 * to change 'gloo' to the name of your theme in all the template files.
123 */
124 load_theme_textdomain( 'ogloszeniakorepetycje', get_template_directory() . '/languages' );
125
126 // Add default posts and comments RSS feed links to head.
127 add_theme_support( 'automatic-feed-links' );
128
129 /*
130 * Let WordPress manage the document title.
131 * By adding theme support, we declare that this theme does not use a
132 * hard-coded <title> tag in the document head, and expect WordPress to
133 * provide it for us.
134 */
135 add_theme_support( 'title-tag' );
136
137 /*
138 * Enable support for Post Thumbnails on posts and pages.
139 *
140 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
141 */
142 add_theme_support( 'post-thumbnails' );
143
144 /**
145 * Initialize menu
146 */
147 require_once('inc/wp_bootstrap_navwalker.php');
148
149 register_nav_menus( array(
150 'primary' => __('Menu w stopce', 'ogloszeniakorepetycje'),
151 //'footer' => __('Menu stopka', 'ogloszeniakorepetycje'),
152 ) );
153
154 /*
155 * Switch default core markup for search form, comment form, and comments
156 * to output valid HTML5.
157 */
158 add_theme_support( 'html5', array(
159 'search-form',
160 'comment-form',
161 'comment-list',
162 'gallery',
163 'caption',
164 ) );
165
166 // Add theme support for selective refresh for widgets.
167 add_theme_support( 'customize-selective-refresh-widgets' );
168
169 /**
170 * Remove Welcome widget
171 */
172 remove_action('welcome_panel', 'wp_welcome_panel');
173
174 /**
175 * Remove the Wordpress Logo from the Toolbar
176 */
177 add_action( 'admin_bar_menu', 'remove_wp_logo', 999 );
178
179 function remove_wp_logo( $wp_admin_bar ) {
180 $wp_admin_bar->remove_node( 'wp-logo' );
181 }
182
183
184 }
185 endif;
186 add_action( 'after_setup_theme', 'ok_setup' );
187
188 /**
189 * Enqueue Script & Styles
190 */
191 function add_theme_scripts() {
192
193 // wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.css', false, 1);
194 // wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/css/font-awesome.css', false, 1);
195 // //wp_enqueue_style( 'owl-carousel', get_template_directory_uri() . '/css/owl.carousel.css', false, 1);
196 // wp_enqueue_style( 'main', get_template_directory_uri() . '/css/main.css', false, 1);
197 // wp_enqueue_style( 'style', get_template_directory_uri() . '/style.css', false, 1);
198
199 wp_enqueue_script( 'chartjs-functions', get_template_directory_uri() . '/js/chart-functions.js', array (), false, false);
200 // //wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/js/owl.carousel.js', array (), false, true);
201 }
202
203 add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
204
205 /**
206 * Echo url of the template directory
207 */
208 function template_url() {
209 echo get_template_directory_uri();
210 }
211
212 /**
213 * Easy pagination implementation
214 */
215 function bittersweet_pagination() {
216
217 global $wp_query;
218
219 $big = 999999999; // need an unlikely integer
220
221 $pages = paginate_links( array(
222 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
223 'format' => '?paged=%#%',
224 'current' => max( 1, get_query_var('paged') ),
225 'total' => $wp_query->max_num_pages,
226 'prev_text' => '<i class="fa fa-angle-left" aria-hidden="true"></i>',
227 'next_text' => '<i class="fa fa-angle-right" aria-hidden="true"></i>',
228 'type' => 'array',
229 ) );
230 if( is_array( $pages ) ) {
231 $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
232 echo '<ul class="pagination">';
233 $iteration = 0;
234 foreach ( $pages as $page ) {
235 if(get_query_var('paged') == $iteration)
236 echo "<li class='active'>$page</li>";
237 else
238 echo "<li>$page</li>";
239 $iteration++;
240 }
241 echo '</ul>';
242 }
243 }
244
245 function facebook_share_url($link) {
246 if (strpos($link, 'https') !== false)
247 $link = substr($link, 8);
248 else
249 $link = substr($link, 7);
250
251 return "https://www.facebook.com/sharer/sharer.php?u=" . $link;
252 }
253
254 function twitter_share_url($link) {
255 if (strpos($link, 'https') !== false)
256 $link = substr($link, 8);
257 else
258 $link = substr($link, 7);
259
260 return "https://twitter.com/home?status=" . $link;
261 }
262
263 /**
264 * Remove spans from Contact Form 7
265 */
266 add_filter('wpcf7_form_elements', function($content) {
267 $content = preg_replace('/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $content);
268
269 return $content;
270 });
271
272 function get_sections($section_ids = array()) {
273
274 $args = array(
275 'post_type' => array( 'templates' ),
276 'posts_per_page' => -1,
277 'post__in' => $section_ids,
278 'orderby' => 'post__in',
279 );
280 $loop = new WP_Query( $args );
281
282 if($loop->have_posts()) {
283 while($loop->have_posts()) {
284 $loop->the_post();
285 include get_page_template_slug();
286 }
287 wp_reset_postdata();
288 }
289 }
290
291 add_action('admin_head', 'my_custom_fonts');
292
293 function my_custom_fonts() {
294 echo '<style>
295 .pw-map {
296 width: 250% !important;
297 }
298 </style>';
299 }
300
301 function _log($item) {
302 if(is_object($item) || is_array($item))
303 error_log(__FILE__ . ': (' . __LINE__ .') ' . print_r($item, 1));
304 else
305 error_log(__FILE__ . ': (' . __LINE__ .') ' .$item);
306 }
307
308
309 // Activity
310 add_action( 'wp_loaded', function () {
311 if ( !is_admin() ) {
312 update_user_meta( get_current_user_id(), 'user_1_activity', time());
313 }
314 });
315
316 // add_action( 'wp_loaded', function () {
317 // if ( !is_admin() ) {
318 // print_r(get_user_meta( get_current_user_id(), 'user_1_feedbacks', 1 ));
319 //
320 // //update_user_meta( get_current_user_id(), 'user_1_activity', time());
321 // }
322 // });
323
324 // Premium
325 function has_premium($user_id) {
326
327 $user = get_userdata( $user_id );
328 if ( $user === false )
329 return false;
330
331 $user_meta = get_user_meta( $user->ID, 'user_1_premium', 1 );
332 if($user_meta < 1)
333 return false;
334
335 return $user_meta;
336 }
337
338 function has_statistics($user_id) {
339
340 $user = get_userdata( $user_id );
341 if ( $user === false )
342 return false;
343
344 $user_meta = get_user_meta( $user->ID, 'user_1_statistics', 1 );
345 if($user_meta < 1)
346 return false;
347
348 return $user_meta;
349 }
350
351 function has_emails($user_id) {
352
353 $user = get_userdata( $user_id );
354 if ( $user === false )
355 return false;
356
357 $user_meta = get_user_meta( $user->ID, 'user_1_mails', 1 );
358 if($user_meta < 1)
359 return false;
360
361 return $user_meta;
362 }
363
364 function remove_feedback($user_id, $post_id) {
365
366 if(!has_premium($user_id))
367 return false;
368
369 $user = get_userdata( $user_id );
370 $user_meta = get_user_meta( $user->ID, 'user_1_feedbacks', 1 );
371
372 if (($key = array_search($post_id, $user_meta)) !== false) {
373 unset($user_meta[$key]);
374 }
375
376 return update_user_meta( $user->ID, 'user_1_feedbacks', $user_meta);
377 }
378
379 function ok_woocommerce_order_status_completed( $order_id ) {
380
381 $order = getOrderDetailById($order_id);
382
383 $customer_id = $order['order']['customer_id'];
384
385 foreach($order['order']['line_items'] as $single_order) {
386
387 switch($single_order['type']) {
388 case 'premium':
389 add_premium_privileges($customer_id, $single_order['quantity']);
390 break;
391 case 'stats':
392 add_statistics_privileges($customer_id, $single_order['quantity']);
393 break;
394 case 'mails':
395 add_mails_privileges($customer_id, $single_order['quantity']);
396 break;
397 case 'points':
398 add_points_privileges($customer_id, $single_order['quantity'], $single_order['variation_id'], $single_order['variation_attributes']);
399 break;
400 }
401 }
402
403 }
404 add_action( 'woocommerce_order_status_completed', 'ok_woocommerce_order_status_completed', 10, 1 );
405
406 function add_premium_privileges($user_id, $quantity = 1) {
407 $user = get_userdata( $user_id );
408 if ( $user === false )
409 return false;
410
411 $days = $quantity * 365;
412
413 $user_meta = get_user_meta( $user->ID, 'user_1_premium', 1 );
414 if(!empty($user_meta))
415 $user_meta += $days;
416 else
417 $user_meta = $days;
418
419 return update_user_meta( $user->ID, 'user_1_premium', $user_meta);
420 }
421
422 function add_statistics_privileges($user_id, $quantity = 1) {
423 $user = get_userdata( $user_id );
424 if ( $user === false )
425 return false;
426
427 $days = $quantity * 365;
428
429 $user_meta = get_user_meta( $user->ID, 'user_1_statistics', 1 );
430 if(!empty($user_meta))
431 $user_meta += $days;
432 else
433 $user_meta = $days;
434
435 return update_user_meta( $user->ID, 'user_1_statistics', $user_meta);
436 }
437
438 function add_mails_privileges($user_id, $quantity = 1) {
439 $user = get_userdata( $user_id );
440 if ( $user === false )
441 return false;
442
443 $days = $quantity * 365;
444
445 $user_meta = get_user_meta( $user->ID, 'user_1_mails', 1 );
446 if(!empty($user_meta))
447 $user_meta += $days;
448 else
449 $user_meta = $days;
450
451 return update_user_meta( $user->ID, 'user_1_mails', $user_meta);
452 }
453
454 function add_points_privileges($user_id, $quantity = 1, $variation_id = false, $advert_id = false) {
455
456 if(empty($variation_id))
457 return false;
458
459 if(empty($user_id))
460 return false;
461
462 if(!$advert_id)
463 return false;
464
465 $points = 0;
466 $points = get_post_meta( $variation_id, 'woocommerce_premium_product_points', true );
467
468 $user = get_userdata( $user_id );
469 if ( $user === false )
470 return false;
471
472 $current_points = 0;
473 $current_points = get_post_meta($advert_id, 'adverts_1_popularity', true);
474
475 $points += $current_points;
476
477 return update_post_meta($advert_id, 'adverts_1_popularity', $points);
478 }
479
480 if (!function_exists('getOrderDetailById')) {
481 //to get full order details
482 function getOrderDetailById($id, $fields = null, $filter = array()) {
483 if (is_wp_error($id))
484 return $id;
485 // Get the decimal precession
486 $dp = (isset($filter['dp'])) ? intval($filter['dp']) : 2;
487 $order = wc_get_order($id); //getting order Object
488 $order_data = array(
489 'id' => $order->get_id(),
490 'order_number' => $order->get_order_number(),
491 'created_at' => $order->get_date_created()->date('Y-m-d H:i:s'),
492 'updated_at' => $order->get_date_modified()->date('Y-m-d H:i:s'),
493 'completed_at' => !empty($order->get_date_completed()) ? $order->get_date_completed()->date('Y-m-d H:i:s') : '',
494 'status' => $order->get_status(),
495 'currency' => $order->get_currency(),
496 'total' => wc_format_decimal($order->get_total(), $dp),
497 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp),
498 'total_line_items_quantity' => $order->get_item_count(),
499 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp),
500 'total_shipping' => wc_format_decimal($order->get_total_shipping(), $dp),
501 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp),
502 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp),
503 'total_discount' => wc_format_decimal($order->get_total_discount(), $dp),
504 'shipping_methods' => $order->get_shipping_method(),
505 'order_key' => $order->get_order_key(),
506 'payment_details' => array(
507 'method_id' => $order->get_payment_method(),
508 'method_title' => $order->get_payment_method_title(),
509 'paid_at' => !empty($order->get_date_paid()) ? $order->get_date_paid()->date('Y-m-d H:i:s') : '',
510 ),
511 'billing_address' => array(
512 'first_name' => $order->get_billing_first_name(),
513 'last_name' => $order->get_billing_last_name(),
514 'company' => $order->get_billing_company(),
515 'address_1' => $order->get_billing_address_1(),
516 'address_2' => $order->get_billing_address_2(),
517 'city' => $order->get_billing_city(),
518 'state' => $order->get_billing_state(),
519 //'formated_state' => WC()->countries->states[$order->get_billing_country()][$order->get_billing_state()], //human readable formated state name
520 'postcode' => $order->get_billing_postcode(),
521 'country' => $order->get_billing_country(),
522 'formated_country' => WC()->countries->countries[$order->get_billing_country()], //human readable formated country name
523 'email' => $order->get_billing_email(),
524 'phone' => $order->get_billing_phone()
525 ),
526 'shipping_address' => array(
527 'first_name' => $order->get_shipping_first_name(),
528 'last_name' => $order->get_shipping_last_name(),
529 'company' => $order->get_shipping_company(),
530 'address_1' => $order->get_shipping_address_1(),
531 'address_2' => $order->get_shipping_address_2(),
532 'city' => $order->get_shipping_city(),
533 'state' => $order->get_shipping_state(),
534 //'formated_state' => WC()->countries->states[$order->get_shipping_country()][$order->get_shipping_state()], //human readable formated state name
535 'postcode' => $order->get_shipping_postcode(),
536 'country' => $order->get_shipping_country(),
537 //'formated_country' => WC()->countries->countries[$order->get_shipping_country()] //human readable formated country name
538 ),
539 'note' => $order->get_customer_note(),
540 'customer_ip' => $order->get_customer_ip_address(),
541 'customer_user_agent' => $order->get_customer_user_agent(),
542 'customer_id' => $order->get_user_id(),
543 'view_order_url' => $order->get_view_order_url(),
544 'line_items' => array(),
545 'shipping_lines' => array(),
546 'tax_lines' => array(),
547 'fee_lines' => array(),
548 'coupon_lines' => array(),
549 );
550 //getting all line items
551 foreach ($order->get_items() as $item_id => $item) {
552 $product = $item->get_product();
553 $product_id = null;
554 $product_sku = null;
555 // Check if the product exists.
556 if (is_object($product)) {
557 $product_id = $product->get_id();
558 $product_sku = $product->get_sku();
559 }
560 $order_data['line_items'][] = array(
561 'id' => $item_id,
562 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp),
563 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp),
564 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp),
565 'total_tax' => wc_format_decimal($item['line_tax'], $dp),
566 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp),
567 'quantity' => wc_stock_amount($item['qty']),
568 'tax_class' => (!empty($item['tax_class']) ) ? $item['tax_class'] : null,
569 'name' => $item['name'],
570 'product_id' => (!empty($item->get_variation_id()) && ('product_variation' === $product->post_type )) ? $product->get_parent_id() : $product_id,
571 'type' => get_post_meta( (!empty($item->get_variation_id()) && ('product_variation' === $product->post_type )) ? $product->get_parent_id() : $product_id, 'woocommerce_premium_product', true ),
572 'variation_id' => (!empty($item->get_variation_id()) && ('product_variation' === $product->post_type )) ? $product_id : 0,
573 'product_url' => get_permalink($product_id),
574 'product_thumbnail_url' => wp_get_attachment_image_src(get_post_thumbnail_id($product_id), 'thumbnail', TRUE)[0],
575 'sku' => $product_sku,
576 'meta' => wc_display_item_meta($item),
577 'variation_attributes' => wc_get_order_item_meta($item_id, 'ID_Ogloszenia', 1),
578 );
579 }
580 //getting shipping
581 foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
582 $order_data['shipping_lines'][] = array(
583 'id' => $shipping_item_id,
584 'method_id' => $shipping_item['method_id'],
585 'method_title' => $shipping_item['name'],
586 'total' => wc_format_decimal($shipping_item['cost'], $dp),
587 );
588 }
589 //getting taxes
590 foreach ($order->get_tax_totals() as $tax_code => $tax) {
591 $order_data['tax_lines'][] = array(
592 'id' => $tax->id,
593 'rate_id' => $tax->rate_id,
594 'code' => $tax_code,
595 'title' => $tax->label,
596 'total' => wc_format_decimal($tax->amount, $dp),
597 'compound' => (bool) $tax->is_compound,
598 );
599 }
600 //getting fees
601 foreach ($order->get_fees() as $fee_item_id => $fee_item) {
602 $order_data['fee_lines'][] = array(
603 'id' => $fee_item_id,
604 'title' => $fee_item['name'],
605 'tax_class' => (!empty($fee_item['tax_class']) ) ? $fee_item['tax_class'] : null,
606 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp),
607 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp),
608 );
609 }
610 //getting coupons
611 foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
612 $order_data['coupon_lines'][] = array(
613 'id' => $coupon_item_id,
614 'code' => $coupon_item['name'],
615 'amount' => wc_format_decimal($coupon_item['discount_amount'], $dp),
616 );
617 }
618 return array('order' => apply_filters('woocommerce_api_order_response', $order_data, $order, $fields));
619 }
620 }
621
622 //Stats
623 function add_search_count($city = false, $subject = false) {
624
625 if(!$city || !$subject)
626 return false;
627
628 global $wpdb;
629
630 $table_name = $wpdb->prefix . 'stats_search';
631 $date = date('Y-m-d', time());
632
633 $stat = $wpdb->get_row( "SELECT * FROM $table_name WHERE city = '$city' AND date = '$date' AND subject = '$subject'", ARRAY_A);
634
635 if(empty($stat)) {
636 $wpdb->insert(
637 $table_name,
638 array(
639 'date' => $date,
640 'city' => $city,
641 'subject' => $subject,
642 'count' => 1,
643 )
644 );
645 }
646 else {
647 $count = $stat['count'] + 1;
648
649 $wpdb->update(
650 $table_name,
651 array(
652 'count' => $count // integer (number)
653 ),
654 array( 'ID' => $stat['ID'] ),
655 array(
656 '%d' // value2
657 ),
658 array( '%d' )
659 );
660 }
661 }
662
663 function get_search_count($city = false, $subject = false) {
664 if(!$city || !$subject)
665 return false;
666
667 global $wpdb;
668
669 $table_name = $wpdb->prefix . 'stats_search';
670 $date = date('Y-m-d', time());
671
672 $stat = $wpdb->get_results( "SELECT * FROM $table_name WHERE city = '$city' AND subject = '$subject' ORDER BY ID DESC LIMIT 0,30", ARRAY_A);
673
674 if(empty($stat))
675 return 0;
676
677 if(key($stat) === 'ID')
678 return array('labels' => array($stat['date']), 'data' => array($stat['count']));
679
680 $stats = array(
681 'labels' => array(),
682 'data' => array(),
683 );
684
685 foreach($stat as $single_stat) {
686 $stats['labels'][] = $single_stat['date'];
687 $stats['data'][] = $single_stat['count'];
688 }
689
690 $stats['labels'] = array_reverse($stats['labels']);
691 $stats['data'] = array_reverse($stats['data']);
692
693 return $stats;
694 }
695
696 function add_entry_count($city = false, $subject = false) {
697
698 if(!$city || !$subject)
699 return false;
700
701 global $wpdb;
702
703 $table_name = $wpdb->prefix . 'stats_entry';
704 $date = date('Y-m-d', time());
705
706 $stat = $wpdb->get_row( "SELECT * FROM $table_name WHERE city = '$city' AND date = '$date' AND subject = '$subject'", ARRAY_A);
707
708 if(empty($stat)) {
709 $wpdb->insert(
710 $table_name,
711 array(
712 'date' => $date,
713 'city' => $city,
714 'subject' => $subject,
715 'count' => 1,
716 )
717 );
718 }
719 else {
720 $count = $stat['count'] + 1;
721
722 $wpdb->update(
723 $table_name,
724 array(
725 'count' => $count // integer (number)
726 ),
727 array( 'ID' => $stat['ID'] ),
728 array(
729 '%d' // value2
730 ),
731 array( '%d' )
732 );
733 }
734 }
735
736 function get_entry_count($city = false, $subject = false) {
737
738 if(!$city || !$subject)
739 return false;
740
741 global $wpdb;
742
743 $table_name = $wpdb->prefix . 'stats_entry';
744 $date = date('Y-m-d', time());
745
746 $stat = $wpdb->get_results( "SELECT * FROM $table_name WHERE city = '$city' AND date = '$date' AND subject = '$subject' ORDER BY ID DESC LIMIT 0,30", ARRAY_A);
747
748 if(empty($stat))
749 return 0;
750
751 if(key($stat) === 'ID')
752 return array('labels' => array($stat['date']), 'data' => array($stat['count']));
753
754 $stats = array(
755 'labels' => array(),
756 'data' => array(),
757 );
758
759 foreach($stat as $single_stat) {
760 $stats['labels'][] = $single_stat['date'];
761 $stats['data'][] = $single_stat['count'];
762 }
763
764 $stats['labels'] = array_reverse($stats['labels']);
765 $stats['data'] = array_reverse($stats['data']);
766
767 return $stats;
768 }
769
770 function add_advert_entry_count($advert_id) {
771
772 if(!$advert_id)
773 return false;
774
775 global $wpdb;
776
777 $table_name = $wpdb->prefix . 'stats_advert_entry';
778 $date = date('Y-m-d', time());
779
780 $stat = $wpdb->get_row( "SELECT * FROM $table_name WHERE post = $advert_id AND date = '$date'", ARRAY_A);
781
782 if(empty($stat)) {
783 $wpdb->insert(
784 $table_name,
785 array(
786 'date' => $date,
787 'post' => $advert_id,
788 'count' => 1,
789 )
790 );
791 }
792 else {
793 $count = $stat['count'] + 1;
794
795 $wpdb->update(
796 $table_name,
797 array(
798 'count' => $count // integer (number)
799 ),
800 array( 'ID' => $stat['ID'] ),
801 array(
802 '%d' // value2
803 ),
804 array( '%d' )
805 );
806 }
807 }
808
809 function get_advert_entry_count($advert_id) {
810
811 if(!$advert_id)
812 return false;
813
814 global $wpdb;
815
816 $table_name = $wpdb->prefix . 'stats_advert_entry';
817
818 $stat = $wpdb->get_results( "SELECT * FROM $table_name WHERE post = $advert_id ORDER BY ID DESC LIMIT 0,30", ARRAY_A);
819
820 if(empty($stat))
821 return 0;
822
823 if(key($stat) === 'ID')
824 return array('labels' => array($stat['date']), 'data' => array($stat['count']));
825
826 $stats = array(
827 'labels' => array(),
828 'data' => array(),
829 );
830
831 foreach($stat as $single_stat) {
832 $stats['labels'][] = $single_stat['date'];
833 $stats['data'][] = $single_stat['count'];
834 }
835
836 $stats['labels'] = array_reverse($stats['labels']);
837 $stats['data'] = array_reverse($stats['data']);
838
839 return $stats;
840 }
841
842 // Pomijanie koszyka
843 add_filter('woocommerce_add_to_cart_redirect', 'themeprefix_add_to_cart_redirect');
844 function themeprefix_add_to_cart_redirect() {
845 global $woocommerce;
846 $checkout_url = wc_get_checkout_url();
847 return $checkout_url;
848 }
849
850 // Fakturka - Nip
851
852 add_action( 'woocommerce_after_order_notes', 'ok_vat_field' );
853 /**
854 * Pole NIP w zamówieniu
855 */
856 function ok_vat_field( $checkout ) {
857 $user_id = get_current_user_id();
858 echo '<div id="ok_vat_field"><h2>' . __('Dane do Faktury', 'ogloszeniakorepetycje') . '</h2>';
859
860 woocommerce_form_field( 'vat_number', array(
861 'type' => 'text',
862 'class' => array( 'vat-number-field form-row-wide') ,
863 'label' => __( 'NIP', 'ogloszeniakorepetycje' ),
864 'placeholder' => __( 'Wpisz NIP, aby otrzymać fakturę', 'ogloszeniakorepetycje' ),
865 ), get_user_meta($user_id, 'user_1_nip', 1));
866
867 echo '</div>';
868 }
869
870 add_action( 'woocommerce_checkout_update_order_meta', 'ok_checkout_vat_number_update_order_meta' );
871 /**
872 * Save VAT Number in the order meta
873 */
874 function ok_checkout_vat_number_update_order_meta( $order_id ) {
875 if ( ! empty( $_POST['vat_number'] ) ) {
876 update_post_meta( $order_id, '_vat_number', sanitize_text_field( $_POST['vat_number'] ) );
877 }
878 }
879
880 add_action( 'woocommerce_admin_order_data_after_billing_address', 'ok_vat_number_display_admin_order_meta', 10, 1 );
881 /**
882 * Wyświetlenie pola NIP
883 */
884 function ok_vat_number_display_admin_order_meta( $order ) {
885 echo '<p><strong>' . __( 'NIP', 'woocommerce' ) . ':</strong> ' . get_post_meta( $order->get_id(), '_vat_number', true ) . '</p>';
886 }
887
888 add_filter( 'woocommerce_email_order_meta_keys', 'ok_vat_number_display_email' );
889 /**
890 * Pole NIP w mailu
891 */
892 function ok_vat_number_display_email( $keys ) {
893 $keys['NIP'] = '_vat_number';
894 return $keys;
895 }
896
897 // Remove woocommerce fields that are not used
898 add_action('admin_head', 'custom_woocommerce_style');
899 function custom_woocommerce_style() {
900 echo '<style>
901 li.shipping_tab,
902 li.inventory_tab,
903 li.linked_product_tab,
904 .hide_if_variation_manage_stock,
905 .variable_description0_field,
906 .form-row.form-row-first.upload_image,
907 .form-field.variable_sku0_field.form-row.form-row-last,
908 .form-field._purchase_note_field {
909 display: none!important;
910 }
911
912 </style>';
913 }
914
915
916 function js_init(){
917
918 wp_register_script('wp-loader', get_template_directory_uri() . '/js/loader.js', array('jquery'), false, false );
919 wp_enqueue_script('wp-loader');
920 wp_register_script('wp-recaptcha', get_template_directory_uri() . '/js/recaptcha.js', array('jquery'), false, false );
921 wp_enqueue_script('wp-recaptcha');
922 }
923 add_action('init', 'js_init');
924
925 require_once __DIR__ . '/inc/recaptcha/autoload.php';
926
927 add_filter('wp_authenticate_user', function($user) {
928
929 if (get_user_meta($user->ID, 'user_status', true) == '1') {
930 return $user;
931 }
932 return new WP_Error('non-active' . get_user_meta($user->ID, 'user_status', true));
933 }, 10, 2);
934
935
936 add_filter( 'get_comment_date', 'wpsites_change_comment_date_format' );
937 function wpsites_change_comment_date_format( $d ) {
938 $d = date('d M Y');
939 return $d;
940 }
941
942 function summary($str, $limit=100, $strip = false) {
943 $str = ($strip == true)?strip_tags($str):$str;
944 if (strlen ($str) > $limit) {
945 $str = substr ($str, 0, $limit - 3);
946 return (substr ($str, 0, strrpos ($str, ' ')).'...');
947 }
948 return trim($str);
949 }
950
951 function gloo_pagination($query) {
952
953 //global $wp_query;
954
955 $big = 999999999; // need an unlikely integer
956
957 $pages = paginate_links( array(
958 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
959 'format' => '?paged=%#%',
960 'current' => max( 1, get_query_var('paged') ),
961 'total' => $query->max_num_pages,
962 'prev_text' => __('POPRZEDNIA', 'ogloszeniakorepetycje'),
963 'next_text' => __('NASTĘPNA', 'ogloszeniakorepetycje'),
964 'type' => 'array',
965 ) );
966
967
968
969 if( is_array( $pages ) ) {
970 $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
971 $iteration = 0;
972 echo '<ul class="cat-pagination">';
973 foreach ( $pages as $page ) {
974 if(get_query_var('paged') == $iteration)
975 echo "<li class='active'>$page</li>";
976 else
977 echo "<li>$page</li>";
978 $iteration++;
979 }
980 echo '</ul>';
981 }
982 }
983
984 function gloo_get_sort($sort = 'default') {
985 switch ($sort) {
986 case 'most_comment':
987 return __('OCENA OD NAJWYŻSZEJ', 'ogloszeniakorepetycje');
988 break;
989
990 case 'expensive':
991 return __('CENA OD NAJWYŻSZEJ', 'ogloszeniakorepetycje');
992 break;
993
994 case 'cheap':
995 return __('CENA OD NAJNIŻSZEJ', 'ogloszeniakorepetycje');
996 break;
997
998 case 'active':
999 return __('NAJNOWSZA AKTYWNOŚĆ', 'ogloszeniakorepetycje');
1000 break;
1001
1002 default:
1003 return __('POPULARNOŚĆ', 'ogloszeniakorepetycje');
1004 break;
1005 }
1006 }
1007
1008 function user_adverts_rewrite() {
1009 add_rewrite_rule('^korepetytor/([^/]+)/?$', 'index.php?pagename=korepetytor&user_id=$matches[1]', 'top');
1010 add_rewrite_rule('^pozostale-ogloszenia/([^/]+)/?$', 'index.php?pagename=pozostale-ogloszenia&user_id=$matches[1]', 'top');
1011 add_rewrite_rule('^wiadomosc/([^/]+)/?$', 'index.php?pagename=wiadomosc&user_id=$matches[1]', 'top');
1012 add_rewrite_rule('^edytuj-ogloszenie/([^/]+)/?$', 'index.php?pagename=edytuj-ogloszenie&advert_id=$matches[1]', 'top');
1013 add_rewrite_rule('^usun-ogloszenie/([^/]+)/?$', 'index.php?pagename=usun-ogloszenie&advert_id=$matches[1]', 'top');
1014 add_rewrite_rule('^popularne-przedmioty/([^/]+)/?$', 'index.php?pagename=popularne-przedmioty&letter=$matches[1]', 'top');
1015 }
1016 add_action('init', 'user_adverts_rewrite');
1017
1018 add_filter( 'query_vars', 'adverts_user_rewrite_add_var' );
1019 function adverts_user_rewrite_add_var( $vars )
1020 {
1021 $vars[] = 'advert_id';
1022 $vars[] = 'user_id';
1023 $vars[] = 'letter';
1024 $vars[] = 'ref_link';
1025 return $vars;
1026 }
1027
1028 /**
1029 * Does this user exist?
1030 *
1031 * @param int|string|WP_User $user_id User ID or object.
1032 * @return bool Whether the user exists.
1033 */
1034 function km_does_user_exist( $user_id = '' ) {
1035 if ( $user_id instanceof WP_User ) {
1036 $user_id = $user_id->ID;
1037 }
1038 return (bool) get_user_by( 'id', $user_id );
1039 }
1040
1041 function first_letter_term_filter( $clauses, $taxonomies, $args ) {
1042 if ( ! empty( $args['first_letter'] ) ) {
1043 global $wpdb;
1044
1045 $first_letter_like = $wpdb->esc_like( $args['first_letter'] );
1046
1047 if ( ! isset( $clauses['where'] ) )
1048 $clauses['where'] = '1=1';
1049
1050 //$clauses['where'] .= $wpdb->prepare( " AND t.name LIKE %s OR t.name LIKE %s", "$first_letter_like%", "% $first_letter_like%" );
1051 $clauses['where'] .= $wpdb->prepare( " AND t.name LIKE %s", "$first_letter_like%" );
1052 }
1053
1054 return $clauses;
1055 }
1056
1057 add_filter( 'terms_clauses', 'first_letter_term_filter', 10, 3 );
1058
1059 function mail_header() {
1060 return '<meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
1061 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1062 <html xmlns="http://www.w3.org/1999/xhtml">
1063
1064 <head>
1065 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1066 <title>Ogłoszenia Korepetycje</title>
1067 </head>
1068
1069 <body bgcolor="#ffffff">
1070 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">
1071 <!-- WRAPPER-->
1072 <table width="600" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">
1073 <tr>
1074 <td>
1075 <!-- HEADER -->
1076 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">
1077 <tr>
1078 <td>
1079 <font style="display: block; font-family: \'Verdana\'; color: #000000; font-size: 24px; font-weight: 700; text-align: center; line-height: 64px;"><img src="'.get_template_directory_uri().'/img/header_bg.png" width="600" height="auto" border="0" alt="Ogłoszenia Korepetycje" style="display: block; border: 0;"></font>
1080 </td>
1081 </tr>
1082 </table>
1083 <!-- HEADER END -->
1084 </td>
1085 </tr>';
1086 }
1087
1088 function mail_footer($leave = false) {
1089 if($leave)
1090 return '<tr>
1091 <td>
1092 <!-- FOOTER -->
1093 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">
1094 <tr>
1095 <td>
1096 <font style="display: block; font-family: \'Verdana\'; color: #000000; font-size: 24px; font-weight: 700; text-align: center; line-height: 64px;"><a href="#" target="_blank" style="color: #000; text-decoration: none;"><img src="'.get_template_directory_uri().'/img/footer_bg.png" width="600" height="auto" border="0" alt="Ogłoszenia Korepetycje" style="display: block; border: 0;"></a></font>
1097 </td>
1098 </tr>
1099 <tr>
1100 <td>
1101 <font style="display: block; font-family: \'Verdana\'; color: #000000; font-size: 14px; font-weight: 400; text-align: center; line-height: 20px;"><a href="#" target="_blank" style="color: #000; text-decoration: none;"><span style="color: #00cfba;">Wypisz</span> się z newslettera</a>
1102 </td>
1103 </tr>
1104 </table>
1105 <!-- FOOTER END -->
1106 </td>
1107 </tr>
1108 </table>
1109 <!-- WRAPPER END -->
1110 </table>
1111 </body>
1112
1113 </html>';
1114
1115 return '<tr>
1116 <td>
1117 <!-- FOOTER -->
1118 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">
1119 <tr>
1120 <td>
1121 <font style="display: block; font-family: \'Verdana\'; color: #000000; font-size: 24px; font-weight: 700; text-align: center; line-height: 64px;"><a href="#" target="_blank" style="color: #000; text-decoration: none;"><img src="'.get_template_directory_uri().'/img/footer_bg.png" width="600" height="auto" border="0" alt="Ogłoszenia Korepetycje" style="display: block; border: 0;"></a></font>
1122 </td>
1123 </tr>
1124 </table>
1125 <!-- FOOTER END -->
1126 </td>
1127 </tr>
1128 </table>
1129 <!-- WRAPPER END -->
1130 </table>
1131 </body>
1132
1133 </html>';
1134 }
1135
1136 function mail_text_start() {
1137 return '<tr>
1138 <td>
1139 <!-- MAIN-TEXT -->
1140 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">
1141 <tr>
1142 <td width="40" valign="top" style="vertical-align: top;"></td>
1143 <td>
1144 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">
1145 <tr>
1146 <td height="33"></td>
1147 </tr>
1148 <tr>
1149 <td>
1150 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">';
1151 }
1152 function mail_text_end() {
1153 return '</table>
1154 </td>
1155 </tr>
1156 <tr>
1157 <td height="37"></td>
1158 </tr>
1159 </table>
1160 </td>
1161 <td width="40" valign="top" style="vertical-align: top;"></td>
1162 </tr>
1163 </table>
1164 <!-- MAIN-TEXT END -->
1165 </td>
1166 </tr>';
1167 }
1168
1169 function mail_text_start_gray() {
1170 return '<tr>
1171 <td>
1172 <!-- PROMO-TEXT -->
1173 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#f0f0f0" align="center">
1174 <tr>
1175 <td width="40" valign="top" style="vertical-align: top;"></td>
1176 <td>
1177 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#f0f0f0" align="center">
1178 <tr>
1179 <td height="36"></td>
1180 </tr>
1181 <tr>
1182 <td>
1183 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#f0f0f0" align="center">';
1184 }
1185
1186 function mail_text_end_gray() {
1187 return '</table>
1188 </td>
1189 </tr>
1190 <tr>
1191 <td height="40"></td>
1192 </tr>
1193 </table>
1194 </td>
1195 <td width="40" valign="top" style="vertical-align: top;"></td>
1196 </tr>
1197 </table>
1198 <!-- PROMO-TEXT END -->
1199 </td>
1200 </tr>';
1201 }
1202
1203 function mail_heading($text) {
1204 return '<tr>
1205 <td>
1206 <font style="display: block; font-family: \'Verdana\'; color: #00cfba; font-size: 24px; font-weight: 400; text-align: center; line-height: 30px;">'.$text.'</font>
1207 </td>
1208 </tr>
1209 <tr>
1210 <td height="30"></td>
1211 </tr>';
1212 }
1213
1214 function mail_heading_centered($text) {
1215 return '<tr>
1216 <td>
1217 <font style="display: block; font-family: \'Verdana\'; color: #00cfba; font-size: 24px; font-weight: 400; text-align: center; line-height: 24px;">'.$text.'</font>
1218 </td>
1219 </tr>
1220 <tr>
1221 <td height="19"></td>
1222 </tr>';
1223 }
1224
1225 function mail_heading_centered_bold($text) {
1226 return '<tr>
1227 <td>
1228 <font style="display: block; font-family: \'Verdana\'; color: #00cfba; font-size: 24px; font-weight: 700; text-align: center; line-height: 24px;">'.$text.'</font>
1229 </td>
1230 </tr>
1231 <tr>
1232 <td height="20"></td>
1233 </tr>';
1234 }
1235
1236 function mail_button_1($text, $url) {
1237 return '<tr>
1238 <td>
1239 <table width="150" height="42" border="0" cellspacing="0" cellpadding="0" bgcolor="#e61468" align="center" style="-moz-border-radius: 24px; border-radius: 24px;">
1240 <tr>
1241 <td>
1242 <a href="'.$url.'" target="_blank" style="display: block; font-family: \'Verdana\'; color: #ffffff; font-size: 14px; font-weight: 400; text-align: center; text-decoration: none; line-height: 42px;">'.$text.'</a>
1243 </td>
1244 </tr>
1245 </table>
1246 </td>
1247 </tr>
1248 <tr>
1249 <td height="30"></td>
1250 </tr>';
1251 }
1252
1253 function mail_button_2($text, $url) {
1254 return '<tr>
1255 <td>
1256 <table width="150" height="42" border="0" cellspacing="0" cellpadding="0" bgcolor="#e61468" align="center" style="-moz-border-radius: 24px; border-radius: 24px;">
1257 <tr>
1258 <td>
1259 <a href="'.$url.'" target="_blank" style="display: block; font-family: \'Verdana\'; color: #ffffff; font-size: 14px; font-weight: 400; text-align: center; text-decoration: none; line-height: 42px;">'.$text.'</a>
1260 </td>
1261 </tr>
1262 </table>
1263 </td>
1264 </tr>';
1265 }
1266
1267 function mail_texts($texts) {
1268 $prepare = '<tr>
1269 <td>
1270 <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff" align="center">';
1271 if(is_array($texts) && !empty($texts)) {
1272 $last_key = end(array_keys($texts));
1273 foreach($texts as $key => $text) {
1274 $prepare .= '<tr>
1275 <td>
1276 <font style="display: block; font-family: \'Verdana\'; color: #000000; font-size: 16px; font-weight: 400; text-align: center; line-height: 20px;">'.$text.'</font>
1277 </td>
1278 </tr>';
1279 if($last_key != $key) {
1280 $prepare .= '<tr>
1281 <td height="20"></td>
1282 </tr>';
1283 }
1284 }
1285 }
1286
1287 $prepare .= '</table>
1288 </td>
1289 </tr>';
1290 return $prepare;
1291 }
1292
1293 function mail_paragraph($text) {
1294 return '<tr>
1295 <td>
1296 <font style="display: block; font-family: \'Verdana\'; color: #000000; font-size: 14px; font-weight: 400; text-align: center; line-height: 18px;">'.$text.'</font>
1297 </td>
1298 </tr>
1299 <tr>
1300 <td height="32"></td>
1301 </tr>';
1302 }
1303
1304 function mail_paragraph_centered($text) {
1305 return '<p style="padding:10px 13px;margin: 0;font-size:17px;font-family:\'Open sans\';text-align: center;">'.$text.'</p>';
1306 }
1307
1308 function mail_paragraph_2($text) {
1309 return '<p style="padding:10px 13px;margin: 0 0 22px;font-family:\'Open sans\';text-align: center;">'.$text.'</p>';
1310 }
1311
1312 add_filter('password_change_email', 'wpse207879_change_password_mail_message', 10, 3);
1313 function wpse207879_change_password_mail_message($pass_change_mail, $user, $userdata) {
1314
1315 _log($user);
1316 $message = mail_header();
1317
1318 $message .= mail_text_start();
1319 $message .= mail_heading(__('Email potwierdza zmianę hasła na witrynie OgłoszeniaKorepetycje.pl', 'ogloszeniakorepetycje'));
1320 $message .= mail_paragraph(__('Jeśli nie próbowano zmieniać hasła, prosimy o kontakt z Administratorem: wordpress@ogloszeniakorepetycje.pl', 'ogloszeniakorepetycje'));
1321 $message .= mail_paragraph(__('Ten email został wysłany do ', 'ogloszeniakorepetycje') . $user['user_email']);
1322 $message .= mail_paragraph(__('Pozdrawiamy,', 'ogloszeniakorepetycje'));
1323 $message .= mail_paragraph(__('Zespół witryny OgłoszeniaKorepetycje.pl http://ogloszeniakorepetycje.pl', 'ogloszeniakorepetycje'));
1324 $message .= mail_text_end();
1325
1326 $message .= mail_footer();
1327
1328
1329 $pass_change_mail[ 'message' ] = $message;
1330 return $pass_change_mail;
1331 }
1332
1333 // Function to change sender name
1334 function wpb_sender_name( $original_email_from ) {
1335 return __('OgłoszeniaKorepetycje.pl', 'ogloszeniakorepetycje');
1336 }
1337
1338 add_filter( 'wp_mail_from_name', 'wpb_sender_name' );
1339
1340 add_action('init', 'myStartSession', 1);
1341 add_action('wp_logout', 'myEndSession');
1342 add_action('wp_login', 'myEndSession');
1343
1344 function myStartSession() {
1345 if(!session_id()) {
1346 session_start();
1347 }
1348 }
1349
1350 function myEndSession() {
1351 session_destroy ();
1352 }
1353
1354 function mb_ucfirst($string, $encoding)
1355 {
1356 $strlen = mb_strlen($string, $encoding);
1357 $firstChar = mb_substr($string, 0, 1, $encoding);
1358 $then = mb_substr($string, 1, $strlen - 1, $encoding);
1359 return mb_strtoupper($firstChar, $encoding) . $then;
1360 }
1361
1362 function woocommerce_clear_cart_url() {
1363 global $woocommerce;
1364 $woocommerce->cart->empty_cart();
1365 }
1366
1367 add_filter( 'wp_new_user_notification_email', 'test_filter' );
1368 function test_filter($wp_new_user_notification_email) {
1369 $wp_new_user_notification_email['message'] = mail_header();
1370 $wp_new_user_notification_email['message'] .= mail_text_start();
1371 $wp_new_user_notification_email['message'] .= mail_heading(__('Dziękujemy za rejestrację! ','ogloszeniakorepetycje'));
1372 $wp_new_user_notification_email['message'] .= mail_button_1(__('Zaloguj się', 'ogloszeniakorepetycje'), get_the_permalink(7));
1373 $texts = array(
1374 __('W mgnieniu oka znajdziesz tu najlepszą pomoc w nauce. Korepetytorzy i prywatne szkoły dodają swoje ogłoszenia, aby uczniowie mogli je szybko wyszukać.', 'ogloszeniakorepetycje'),
1375 // __('W przeciwieństwie do rozpowszechnionych opinii, Lorem Ipsum nie jest tylko przypadkowym tekstem. Ma ono korzenie w klasycznej łacińskiej literaturze z 45 roku przed Chrystusem, czyli ponad 2000 lat temu! Richard McClintock.', 'ogloszeniakorepetycje'),
1376// __('W mgnieniu oka znajdziesz tu najlepszą pomoc w nauce. Korepetytorzy i prywatne szkoły dodają swoje ogłoszenia, aby uczniowie mogli je szybko wyszukać.', 'ogloszeniakorepetycje'),
1377 );
1378 $wp_new_user_notification_email['message'] .= mail_texts($texts);
1379 $wp_new_user_notification_email['message'] .= mail_text_end();
1380 $wp_new_user_notification_email['message'] .= mail_footer();
1381
1382
1383 return $wp_new_user_notification_email;
1384 }
1385
1386 add_action( 'wp_footer', 'check_textarea_length' );
1387
1388 function check_textarea_length() {
1389 ?>
1390
1391 <?php
1392 }
1393
1394 add_action( 'init', function() {
1395
1396 // Remove the REST API endpoint.
1397 remove_action('rest_api_init', 'wp_oembed_register_route');
1398
1399 // Turn off oEmbed auto discovery.
1400 // Don't filter oEmbed results.
1401 remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
1402
1403 // Remove oEmbed discovery links.
1404 remove_action('wp_head', 'wp_oembed_add_discovery_links');
1405
1406 // Remove oEmbed-specific JavaScript from the front-end and back-end.
1407 remove_action('wp_head', 'wp_oembed_add_host_js');
1408 }, PHP_INT_MAX - 1 );
1409
1410
1411 function wpse62415_filter_wp_title( $title ) {
1412 // Return a custom document title for
1413 // the boat details custom page template
1414 $post_id = get_the_ID();
1415
1416 if('adverts' == get_post_type($post_id)) {
1417
1418 $cities = wp_get_post_terms( $post_id, 'city' );
1419 if(!empty($cities))
1420 $city = $cities[0];
1421 else
1422 return $title;
1423
1424 $subjects = wp_get_post_terms( $post_id, 'subject' );
1425 if(!empty($subjects))
1426 $subject = $subjects[0];
1427 else
1428 return $title;
1429
1430 return $subject->name . ' ' . $city->name . ' - ' . __('OgłoszeniaKorepetycje.pl', 'ogloszeniakorepetycje');
1431 }
1432
1433 // Otherwise, don't modify the document title
1434 return $title;
1435 }
1436 add_filter( 'pre_get_document_title', 'wpse62415_filter_wp_title', 20 );