%PDF- %PDF-
Direktori : /var/www/cwg/wp-content/themes/cwg/inc/ |
Current File : //var/www/cwg/wp-content/themes/cwg/inc/template-functions.php |
<?php use function PHPSTORM_META\map; function get_full_page_nav() { $menu_slug = 'main-menu'; $location = get_nav_menu_locations(); if (isset($location[$menu_slug])) : $menu_items = wp_get_nav_menu_items(wp_get_nav_menu_object($location[$menu_slug])->term_id); ?> <ul class="flex flex-nowrap space-x-10 my-auto"> <?php foreach ($menu_items as $menu_item) : ?> <li class="flex"> <a href="<?= $menu_item->url ?>" class="duration-200 font-medium text-xs <?= get_menu_item_class($menu_item) ?>"> <?= $menu_item->title ?> </a> </li> <?php endforeach; ?> </ul> <?php endif; } function get_menu_item_class($menu_item) { $current_menu_post_id = get_post_meta($menu_item->ID, '_menu_item_object_id', true); $current_page_id = get_the_ID(); $classList = 'text-menu-initial'; if ( intval($current_menu_post_id) === $current_page_id || intval($current_menu_post_id) === wp_get_post_parent_id($current_page_id) || (($current_page_id) === "post" && $menu_item->classes[0] === "news") ) { $classList = 'text-primary'; } if (intval($current_menu_post_id) === apply_filters('wpml_object_id', 296, 'page')) { $classList .= ' text-primary'; } return $classList; } function get_product_filters($type = null, $filters_data = null, $display_rules = null) { global $post; $item_classes = ''; switch ($type) { case 'artists': $i = 1; foreach ($filters_data as $post) : setup_postdata($post); if ($display_rules) { $item_classes = $i < $display_rules['count'] ? '' : $display_rules['class']; } ?> <div class="<?= $item_classes; ?>"> <input type="checkbox" name="artist[]" id="<?= get_the_id(); ?>" value="<?= get_the_id(); ?>" class="hidden js-quickFiltersInput"> <label for="<?= get_the_id(); ?>" class="btn-selectable w-[95px] xxs:w-[100px] xs:w-[110px] lg:w-[120px] capitalize <?= $item_classes; ?>"><?= strtolower(get_the_title()); ?></label> </div> <?php $i++; endforeach; wp_reset_postdata(); break; case 'category': $i = 1; foreach ($filters_data as $term) : if ($display_rules) { $item_classes = $i < $display_rules['count'] ? '' : $display_rules['class']; } ?> <div class="<?= $item_classes; ?>"> <input <?= $term->term_id === 403 ? 'checked' : '' ?> type="checkbox" name="category[]" id="<?= $term->term_id; ?>" value="<?= $term->term_id; ?>" class="hidden js-quickFiltersInput"> <label for="<?= $term->term_id; ?>" class="btn-selectable w-[95px] xxs:w-[100px] xs:w-[110px] <?= $item_classes; ?>"><?= esc_html($term->name); ?></label> </div> <?php $i++; endforeach; break; } } function get_collectibles($custom_args = null, $is_b2b = false, $after_query = "display", $is_home = false) { global $post; $has_query_args = false; if(isset($_GET['page'])) { $page = intval($_GET['page']); } else { $page = 1; } $args = array( 'post_type' => 'product', 'order' => 'DESC', 'post_status' => 'publish' ); if(isset($_GET['isHome'])) { $is_home = true; } if(!isset($_GET['category'])) { $args['product_cat'] = 'Work'; } else { $has_query_args = true; } if (isset($_GET['artist']) || isset($_GET['period']) || isset($_GET['inout']) || isset($_GET['price']) || isset($_GET['instock']) || isset($_GET['width']) || isset($_GET['length']) || isset($_GET['height'])) { $args['meta_query'] = array( 'relation' => 'AND' ); $has_query_args = true; } if (isset($_GET['category']) || isset($_GET['color']) || isset($_GET['material'])) { $args['tax_query'] = array( 'relation' => 'AND' ); $has_query_args = true; } if(!$is_home) { $has_query_args = true; } $size_unit_suffix = isset($_GET['unit']) && $_GET['unit'] === "cm" ? '' : '_inches'; $posts_per_page = $custom_args['posts_per_page'] ?? (wp_is_mobile() ? 8 : 20); $highlighted_products = []; $post__not_in = []; if ($is_home) { $args['meta_query'] = []; if ($page === 1) { $highlighted_products = isUserB2B() ? get_field( 'highlighted_products') : get_field('collectible_designs'); $highlighted_products = $highlighted_products ? $highlighted_products : []; $posts_per_page = $posts_per_page - count($highlighted_products); if(!empty($highlighted_products)) { foreach($highlighted_products as $highlighted_product) { if(isset($highlighted_product->ID)) { $post__not_in[] = $highlighted_product->ID; } } } if(!empty($post__not_in)) { $args['post__not_in'] = $post__not_in; } } } $args['posts_per_page'] = $posts_per_page; $args['offset'] = ($page - 1) * $posts_per_page; if ( $has_query_args ) { foreach ( $_GET as $get_key => $get_value ) { switch ( $get_key ) { case 'artist': $artists = array( 'relation' => 'OR' ); foreach ( $get_value as $artistId ) { array_push( $artists, array( 'key' => 'artist_override', 'value' => '"' . $artistId . '"', 'compare' => 'LIKE', ) ); } array_push( $args[ 'meta_query' ], $artists ); break; //case tax query case 'category': array_push( $args[ 'tax_query' ], array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => $get_value, 'operator' => 'IN' ) ); break; case 'period': array_push( $args[ 'meta_query' ], array( 'key' => 'period', 'value' => $get_value, 'compare' => 'IN', ) ); break; case 'material': array_push( $args[ 'tax_query' ], array( 'taxonomy' => 'material', 'field' => 'term_id', 'terms' => $get_value, 'operator' => 'IN' ) ); break; case 'color': array_push( $args[ 'tax_query' ], array( 'taxonomy' => 'color', 'field' => 'term_id', 'terms' => $get_value, 'operator' => 'IN' ) ); break; case 'price': array_push( $args[ 'meta_query' ], array( 'key' => '_price', 'value' => $get_value, 'compare' => 'BETWEEN', 'type' => 'NUMERIC', ) ); array_push( $args[ 'meta_query' ], array( 'key' => 'retail_price_note', 'value' => ['1'], 'compare' => 'NOT IN', ) ); array_push( $args[ 'meta_query' ], array( 'key' => '_price', 'value' => ['', '0'], 'compare' => 'NOT IN', ) ); break; case 'width': array_push( $args[ 'meta_query' ], array( 'key' => 'width' . $size_unit_suffix, 'value' => $get_value, 'compare' => 'BETWEEN', 'type' => 'NUMERIC', ) ); break; case 'height': array_push( $args[ 'meta_query' ], array( 'key' => 'height' . $size_unit_suffix, 'value' => $get_value, 'compare' => 'BETWEEN', 'type' => 'NUMERIC', ) ); break; case 'length': array_push( $args[ 'meta_query' ], array( 'key' => 'depth' . $size_unit_suffix, 'value' => $get_value, 'compare' => 'BETWEEN', 'type' => 'NUMERIC', ) ); break; case 'inout': array_push( $args[ 'meta_query' ], array( 'key' => 'indoor__outdoor', 'value' => $get_value, 'compare' => 'LIKE', ) ); break; case 'instock': array_push( $args[ 'meta_query' ], array( 'key' => '_stock_status', 'value' => 'instock', ) ); break; case 'newest': $args[ 'date_query' ] = array( 'after' => array( 'year' => date( "Y", strtotime( "-1 Months" ) ), 'month' => date( "m", strtotime( "-1 Months" ) ), 'day' => date( "d", strtotime( "-1 Months" ) ), ), 'inclusive' => true, ); break; default: break; } } if ( !empty($custom_args) ) { $args = array_merge( $args, $custom_args ); } } $total_count = 0; $highlight_cd = get_field('highlight'); $index = 0; if(!empty($highlight_cd)) { $args_highlight = $args; $args_highlight['post__in'] = $highlight_cd; $args_highlight['orderby'] = 'post__in'; $hl_query = new WP_Query($args_highlight); $args['posts_per_page'] -= $hl_query->found_posts; $total_count += $hl_query->found_posts; } $wc_query = new WP_Query($args); $total_count += $wc_query->found_posts; $after_query = isset($_GET['after_query']) ? $_GET['after_query'] : $after_query; if ($after_query === "display") { if (isset($hl_query) && $hl_query->have_posts()) { while ($hl_query->have_posts()) { $hl_query->the_post(); $product = wc_get_product(get_the_ID()); if (!empty($product)) { $price = $product ? $product->get_price() : null; $index++; $desktop_class = in_array( $index, [ 1, 8, 11, 18 ] ) ? 'lg:col-span-2 lg:row-span-2' : ''; $artist = get_field( 'artist_label' ); include( locate_template( 'template-parts/products/collectible-item.php' ) ); } } } if(!empty($highlighted_products)) { foreach($highlighted_products as $post) { setup_postdata($post); $index++; $product = wc_get_product($post->ID); if (!empty($product)) { $price = $product ? $product->get_price() : null; $desktop_class = in_array( $index, [ 1, 8, 11, 18 ] ) ? 'lg:col-span-2 lg:row-span-2' : 'lg:col-span-1 lg:rown-span-1'; $artist = get_field( 'artist_label' ); include( locate_template( 'template-parts/products/collectible-item.php' ) ); } } wp_reset_postdata(); } if ($wc_query->have_posts()) { while ($wc_query->have_posts()) { $wc_query->the_post(); $product = wc_get_product(get_the_ID()); if (!empty($product)) { $price = $product ? $product->get_price() : null; $index++; $desktop_class = in_array( $index, [ 1, 8, 11, 18 ] ) ? 'lg:col-span-2 lg:row-span-2' : ''; $artist = get_field( 'artist_label' ); include( locate_template( 'template-parts/products/collectible-item.php' ) ); } } if($wc_query->max_num_pages > $page) { echo '<div class="js-lastPageScrolling hidden md:hidden">' . ($page) . '</div>'; } wp_reset_postdata(); } else { echo '<p>' . __('No products matches your search') . '</p>'; } } else if ($after_query === "count") { echo '(' . $total_count . ')'; } if (isset($_GET['action'])) { die(); } } add_action('wp_ajax_get_collectibles', 'get_collectibles'); add_action('wp_ajax_nopriv_get_collectibles', 'get_collectibles'); function first_login_message() { $b2b_options = get_field('b2b', 'options'); $content = $b2b_options['first_login_message']; $button = $b2b_options['b2b_first_login_button_label']; $current_user = wp_get_current_user(); $content = str_replace('{{user}}', $current_user->user_firstname, $content); generate_popup($content, $button, 'font-thin prose gap-[16px] flex flex-col'); } /** * Animations have to be added to tailwind config */ function generate_popup($content = null, $button = null, $content_class = '', $type = 'center', $icon = null, $animationIn = 'slideInUp', $animationOut = 'slideOutDown') { $content = isset($_POST['content']) ? $_POST['content'] : $content; $button = isset($_POST['button']) ? $_POST['button'] : $button; $content_class = isset($_POST['content_class']) ? $_POST['content_class'] : $content_class; $type = isset($_POST['type']) ? $_POST['type'] : $type; $icon = isset($_POST['icon']) ? $_POST['icon'] : $icon; switch ($type) { case 'center': $modal_classes = 'bottom-0 h-auto rounded-xl pt-7 pb-10 px-9 z-10 lg:relative lg:w-[700px] lg:px-16 lg:py-10'; $animationIn = 'animate-slideInUp'; $animationOut = 'animate-slideOutDown'; break; case 'right': $modal_classes = 'absolute bottom-0 h-[50%] p-5 lg:h-full lg:w-[480px] lg:right-0 lg:py-32 lg:px-[60px]'; $animationIn = 'animate-slideInLeft'; $animationOut = 'animate-slideOutRight'; break; default: # code... break; } switch ($icon) { case 'success': $icon = '/assets/img/icon-check-mail.svg'; break; default: # code... break; } include(locate_template('/template-parts/popups/base.php')); if(isset($_GET['action'])) { echo '<script> modalInit(); </script>'; die(); } } add_action('wp_ajax_generate_popup', 'generate_popup'); add_action('wp_ajax_nopriv_generate_popup', 'generate_popup'); function new_items_since_last_login($user = null) { $user = $user ? $user : get_current_user(); $last_login = get_user_meta($user->ID, 'last_login', true); $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'date_query' => array( 'after' => $last_login ) ); $new_products = new WP_Query($args); return $new_products->found_posts; } function get_taxonomy_name($post_type) { $table_response = [ 'exhibitions' => 'exhibitions-location', 'fairs' => 'fair-location', 'viewingroom' => 'viewingroom-location', 'popups' => 'popups-location' ]; return isset($table_response[$post_type]) ? $table_response[$post_type] : false; } function get_city_name($city) { switch($city) { case 'newyork': return 'New York'; case 'sanfrancisco': return 'San Francisco'; case 'losangeles': return 'Los Angeles'; default: return $city; } } function show_exhibitions_and_fairs_row($query_posts, $row_title) { if(!empty($query_posts) && !empty($query_posts->posts)): ?> <div class="w-full flex flex-col"> <h2 class="text-[13px] leading-6 mb-[18px] md:mb-[15px] uppercase"><?= $row_title ?></h2> <div class="w-full grid grid-cols-1 md:grid-cols-4 gap-[40px] md:gap-[23px] mb-[40px] md:mb-[30px]"> <?php $mobile_class = 'w-full'; ?> <?php foreach($query_posts->posts as $event): ?> <?php include(locate_template('template-parts/events/event-item.php')); ?> <?php endforeach; ?> </div> </div> <?php endif; } function get_collectible_filters($display_on) { $filters = array( 'period' => array( 'title' => 'Period', 'layout' => 'flex gap-2.5', 'hidden-mobile' => true ), 'category' => array( 'title' => 'Categories', 'layout' => 'grid grid-cols-2 gap-4', 'hidden-mobile' => false ), 'artist' => array( 'title' => 'Artists', 'layout' => 'grid grid-cols-2 gap-4', 'hidden-mobile' => false ), 'size' => array( 'title' => 'Size', 'layout' => '', 'hidden-mobile' => true ), 'material' => array( 'title' => "Material", 'layout' => 'grid grid-cols-2 gap-4', 'hidden-mobile' => true ), 'color' => array( 'title' => 'Colors', 'layout' => '', 'layout' => 'grid grid-cols-2 gap-4', 'hidden-mobile' => true ), 'price' => array( 'title' => 'Price', 'layout' => '', 'hidden-mobile' => true ) ); $B2B = isUserB2B(); if(!$B2B) { array_shift($filters); } $formPrefix = "collectibles-" . $display_on; if ($display_on === 'mobile') { echo '<div class="flex flex-wrap gap-4">'; } foreach ($filters as $key => $item) { if ($display_on === 'desktop') { include(locate_template('template-parts/header/dropdown/start.php')); } elseif ($display_on === 'mobile') { include(locate_template('template-parts/collapsible/start.php')); } switch ($key) { case 'category': $all_categories = get_terms('product_cat', array( // 'taxonomy' => '', 'child_of' => get_term_by( 'slug', 'work', 'product_cat' )->term_id ) ); break; case 'period': //no need break; case 'artist': //used to generate artists filters $args = array( 'post_type' => 'artists', 'order' => 'ASC', 'orderby' => 'title', 'post__in' => get_all_associated_artists_IDs(array(1272)), 'post_per_page' => '-1', 'post_status' => "publish", ); // var_dump(get_all_associated_artists_IDs()); $artistsCD = new WP_Query($args); break; case 'size': //no need break; case 'material': $materials = get_categories( array('taxonomy' => 'material') ); break; case 'color': $colors = get_categories( array('taxonomy' => 'color') ); break; case 'price': //no need break; default: break; } include(locate_template('template-parts/filters/collectibles/' . $key . '.php')); wp_reset_query(); wp_reset_postdata(); if ($display_on === 'desktop') { include(locate_template('template-parts/header/dropdown/end.php')); } elseif ($display_on === 'mobile') { include(locate_template('template-parts/collapsible/end.php')); } } if ($display_on === 'mobile') { echo '</div>'; // end of opening div } echo $display_on === 'desktop' ? '<div class="hidden xl:flex pl-5">' : '<div class="mt-8">'; include(locate_template('template-parts/filters/collectibles/extra.php')); echo '</div>'; } function include_in_var($file) { ob_start(); include($file); return ob_get_clean(); } // should be in the loop to work (after the_post()) function the_breadcrumbs($showHome = true, $insertBefore = null) { global $post; $separator = include_in_var(locate_template('/assets/img/icon-grey-navigation-next-off.svg')); $parentClasses = "text-grey-textLight overflow-hidden whitespace-nowrap overflow-ellipsis"; // $separator = '<span> > </span>'; echo '<div class="text-xs font-thin flex gap-2">'; if ($showHome) { echo '<a href="' . get_home_url() . '" class="text-grey-textLight">Home</a>'; echo $separator; } switch (get_post_type()) { case 'pressarticles': echo '<a href="' . get_permalink(4886) . '" class="text-grey-textLight overflow-hidden whitespace-nowrap overflow-ellipsis">' . "Press" . '</a>'; break; case 'exhibitions' : case 'popups' : case 'fairs' : $post_type = get_post_type(); $parent_page_id = [ 'exhibitions' => 191727, 'popups' => 282784, 'fairs' => 191729, ]; $parent_page_name = $post_type == 'popups' ? 'Pop-ups' : ucfirst($post_type); echo '<a href="' . get_permalink($parent_page_id[$post_type]) . '" class="text-grey-textLight overflow-hidden whitespace-nowrap overflow-ellipsis">' . $parent_page_name . '</a>'; echo $separator; echo '<span class="text-xs font-light">' . get_the_title() . '</span>'; break; case 'artists': echo '<a href="' . get_permalink(184796) . '" class="'.$parentClasses.'">' . ucfirst(get_post_type()) . '</a>'; echo $separator; echo '<span class="text-xs font-light">' . get_the_title() . '</span>'; break; case 'product': $product_cat = get_product_category_originel(get_the_ID()); $parentCat = isset($product_cat[0]->name) ? $product_cat[0]->name : ''; switch ($parentCat) { case 'Shop': $parentCatLabel = "The Workshop Shop"; $parentCatLink = get_permalink(265654); break; case 'Work': $parentCatLabel = "Collectible Design"; $parentCatLink = get_permalink(257580); break; case 'Jewellery': $parentCatLabel = "Jewellery"; $parentCatLink = get_permalink(198998); break; default: # code... break; } echo '<h1><a href="' . $parentCatLink . '" class="'.$parentClasses.'">' . $parentCatLabel . '</a></h1>'; echo $separator; echo '<span class="font-light overflow-hidden whitespace-nowrap overflow-ellipsis">' . get_the_title() . '</span>'; break; case 'page': $post_parents = get_ancestors(get_the_ID(), 'page'); if($post_parents) { foreach($post_parents as $parent) { $parent_post = get_post($parent); echo '<h1><a href="' . get_permalink($parent_post->ID) . '" class="'.$parentClasses.'">' . $parent_post->post_title . '</a></h1>'; echo $separator; } } if($insertBefore) { echo '<a href="' . $insertBefore['link'] . '" class="'.$parentClasses.'">' . $insertBefore['label'] . '</a>'; echo $separator; } echo '<span class="text-xs font-light">' . get_the_title() . '</span>'; break; case 'career': echo '<h1><a href="' . get_permalink(280888) . '" class="'.$parentClasses.'">Careers</a></h1>'; echo $separator; echo '<span class="font-light overflow-hidden whitespace-nowrap overflow-ellipsis">' . get_the_title() . '</span>'; break; default: # code... break; } echo '</div>'; } function getPriceRange($productPrice){ switch ($productPrice) { case (0 <= $productPrice) && ($productPrice <= 19999): $productPriceText = "$0-$20,000"; break; case (20000 <= $productPrice) && ($productPrice <= 49999): $productPriceText = "$20,000-$50,000"; break; case (50000 <= $productPrice) && ($productPrice <= 99999): $productPriceText = "$50,000-$100,000"; break; case (100000 <= $productPrice) && ($productPrice <= 199999): $productPriceText = "$100,000-$200,000 "; break; case (200000 <= $productPrice): $productPriceText = "$200,000+"; break; } return $productPriceText; } function get_city_from_label($label) { foreach(get_field('cities', 259785) as $city) { if($city['name_of_city'] == ucwords($label)) { return $city; } } return ''; } function artist_tuile($product_cat, $title, $custom_placment = []) { $nb_custom_placement = is_array($custom_placment) ? count($custom_placment) : 0; $args = array( 'posts_per_page' => 4 - $nb_custom_placement, 'post_type' => 'product', 'post__not_in' => $custom_placment, 'product_cat' => $product_cat, 'order' => 'DESC', 'post_status' => 'publish', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'artist_override', 'value' => get_the_id(), 'compare' => 'LIKE', ) ) ); ?> <?php $wc_query = new WP_Query($args); if ($wc_query->have_posts() || $nb_custom_placement > 0) : ?> <section class="w-full mb-12 md:mb-[60px] px-5 md:px-14"> <div class="w-full flex items-center justify-between mb-[13px] md:mb-[30px]"> <h2 class="text-[13px] md:text-[15px] font-normal uppercase"><?= $title ?></h2> <div class="flex flex-row"> <div class="flex text-xs uppercase font-thin items-center"> <?php if ($product_cat == 'Jewellery') : ?> <a href="<?php echo get_permalink(198998) . '?artist[]=' . get_the_id() ?>" class="btn-stroked w-[100px] md:w-[160px] whitespace-nowrap btn-view-all-artist px-8 py-3 font-thin uppercase">View all</a> <?php endif; ?> <?php if ($product_cat == 'Shop') : ?> <a href="<?php echo get_permalink(265654) . '?artist[]=' . get_the_id() ?>" class="btn-stroked w-[100px] md:w-[160px] whitespace-nowrap btn-view-all-artist px-8 py-3 font-thin uppercase">View all</a> <?php endif; ?> </div> </div> </div> <div class="w-full show-mobile-2 grid grid-cols-2 gap-3 grid-rows-1 md:gap-10 md:grid-cols-4"> <?php if ($nb_custom_placement > 0) { foreach ($custom_placment as $prod) { $product_post = new WP_Query(['p' => $prod, 'post_type' => 'product', 'post_status' => 'publish']); if ($product_post->have_posts()) { $product_post->the_post(); $product = wc_get_product($prod); $price = $product->get_price(); $is_jewellery = $product_cat == 'Jewellery'; $artist = get_field('multiple_artist_title') ? get_field('multiple_artist_title') : get_field('artist_override'); include(locate_template('template-parts/products/list-item-reco-little.php')); } } wp_reset_postdata(); } while ($wc_query->have_posts()) { $wc_query->the_post(); $product = wc_get_product(get_the_ID()); $price = $product->get_price(); $is_jewellery = $product_cat === 'Jewellery'; $artist = get_field('multiple_artist_title') ? get_field('multiple_artist_title') : get_field('artist_override'); include(locate_template('template-parts/products/list-item-reco-little.php')); } wp_reset_postdata(); ?> </div> </section> <?php endif; } function get_careers() { $args = array( 'post_type' => 'career', 'post_status' => 'publish', ); if(isset($_GET['action'])) { $args['tax_query'] = array( 'relation', 'AND'); foreach ( $_GET as $get_key => $get_value ) { if($get_key !== "action" && $get_value !== "all") { array_push( $args[ 'tax_query' ], array( 'taxonomy' => $get_key, 'field' => 'term_id', 'terms' => $get_value, 'operator' => 'IN' ) ); } } } // var_dump($args); $careers = new WP_Query($args); if($careers->have_posts()) { while($careers->have_posts()) { $careers->the_post(); ?> <div class="js-careerItem w-full flex py-4 border-t border-[#eeeeee]"> <div class="w-full text-[11px] uppercase"> <a href="<?= get_permalink(); ?>" class="font-medium text-grey-darker"><?= get_the_title(); ?></a> <p class="text-grey-textLight text-light"><?= get_field('city')->name; ?></p> </div> <?php if(get_field('linkedin_link')): ?> <div class="ml-auto"> <a href="<?= get_field('linkedin_link'); ?>" target="_blank" rel="noopener noreferrer"> <?php include(locate_template('/assets/img/logo-linkedin.svg')); ?> </a> </div> <?php endif; ?> </div> <?php } } wp_reset_query(); wp_reset_postdata(); if(isset($_GET['action'])) { die(); } } add_action('wp_ajax_get_careers', 'get_careers'); add_action('wp_ajax_nopriv_get_careers', 'get_careers'); function renameFileBeforeSend($filename) { $newname = $_FILES[$filename]["tmp_name"].".".$_FILES[$filename]["name"]; rename($_FILES[$filename]["tmp_name"], $newname); return $newname; } function renameFileAfterSend($filename) { $newname = $_FILES[$filename]["tmp_name"].".".$_FILES[$filename]["name"]; rename($newname, $_FILES[$filename]["tmp_name"]); return $newname; } function career_apply() { if( (isset($_FILES['cv_file']) && mime_content_type($_FILES['cv_file']) === "application/pdf") || (isset($_FILES['optional_file']) && mime_content_type($_FILES['optional_file']) === "application/pdf") ) { echo 'file_error'; } elseif( !isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['phone_number']) ) { echo 'missing_fields'; } elseif( isset($_POST['compliance']) && $_POST['compliance'] === "false" ) { echo 'compliance_refused'; } else { function wpse27856_set_content_type(){ return "text/html"; } add_filter( 'wp_mail_content_type','wpse27856_set_content_type' ); $cv_path = renameFileBeforeSend('cv_file'); $optional_path = $_FILES['optional_file']['error'] === 0 ? renameFileBeforeSend('optional_file') : null; $attachment = $_FILES["OrderList"]["tmp_name"]; $content = file_get_contents($attachment); $content = chunk_split(base64_encode($content)); $email = get_field('emails', 'options')['hr_mail']; $applicant_info = "<p>Here are the informations about the applicant : </p>" . "<p>" . $_POST['first_name'] . " " . $_POST['last_name'] . "</p>" . "<p>" . $_POST['email'] . "</p>" . "<p>" . $_POST['phone_number'] . "</p>"; if($_POST['spec_application'] == "true") { $subject = $_POST['first_name'] ." ". $_POST['last_name']." sent a spontaneous application at CWG"; $message = $applicant_info; } else { $subject = $_POST['first_name'] ." ". $_POST['last_name']." applied for " . $_POST['job_title']; $message = "<p>You received an application for the following job offer : <a href='". get_permalink($_POST['job_id'])."'>". $_POST['job_title'] . "</a> </p>". $applicant_info; } ajax_send_mail($email, $subject, $message, array($cv_path, $optional_path)); renameFileAfterSend('cv_file'); $_FILES['optional_file']['error'] === 0 ? renameFileAfterSend('optional_file') : null; echo 'success'; } if(isset($_GET['action'])) { die(); } } add_filter('wp_mail_content_type', 'text/html'); add_action('wp_ajax_career_apply', 'career_apply'); add_action('wp_ajax_nopriv_career_apply', 'career_apply'); function sideModal() { } add_action('wp_ajax_career_apply', 'career_apply'); add_action('wp_ajax_nopriv_career_apply', 'career_apply'); function replace_system_type_publisher( $post_link, $id = 0 ){ $post = get_post($id); if ( is_object( $post ) ){ $terms = wp_get_object_terms( $post->ID, 'publisher' ); if( $terms ){ return str_replace( '%publisher%' , $terms[0]->slug , $post_link ); }else{ return str_replace( '%publisher%/' , '' , $post_link ); } } return $post_link; } add_filter( 'post_type_link', 'replace_system_type_publisher', 1, 3 );