Skip to content

Instantly share code, notes, and snippets.

View pavlo-bondarchuk's full-sized avatar
🏠
remote

Pavlo Bondarchuk pavlo-bondarchuk

🏠
remote
View GitHub Profile
@pavlo-bondarchuk
pavlo-bondarchuk / .php
Created December 17, 2018 08:28
ACF nested group
<?php
// vars
$hero = get_field('hero');
if( $hero ): ?>
<div id="hero">
<img src="<?php echo $hero['image']['url']; ?>" alt="<?php echo $hero['image']['alt']; ?>" />
<div class="content">
<?php echo $hero['caption']; ?>
@pavlo-bondarchuk
pavlo-bondarchuk / tpl.php
Created December 17, 2018 08:29
ACF repeater in group
<?php
// Stop if there's nothing to display.
if ( ! have_rows( 'services', 'option' ) ) {
return false;
}
if ( have_rows( 'services', 'option' ) ) : ?>
<?php while ( have_rows( 'services', 'option' ) ) : the_row();
@pavlo-bondarchuk
pavlo-bondarchuk / WP - get custom post
Created December 20, 2018 23:02 — forked from gianlucacandiotti/WP - get custom post
Get all posts for a custom post type and query them.
<?php
$type = 'custom_post_type';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts'=> true
);
$my_query = null;
$my_query = new WP_Query($args);
@pavlo-bondarchuk
pavlo-bondarchuk / Convert strings to slugs
Created December 22, 2018 20:46 — forked from vrushank-snippets/Convert strings to slugs
PHP : Convert strings to slugs
function slug($str){
$str = strtolower(trim($str));
$str = preg_replace('/[^a-z0-9-]/', '-', $str);
$str = preg_replace('/-+/', "-", $str);
return $str;
}
@pavlo-bondarchuk
pavlo-bondarchuk / .php
Created December 22, 2018 21:08
get first term of taxonomy current post / custom post type
$terms = get_the_terms( $post->ID, 'taxonomy-name' );
if( $terms ){
$term = array_shift( $terms );
// echo name or slug
echo $term->name; //or
echo $term->slug;
}
@pavlo-bondarchuk
pavlo-bondarchuk / .php
Created December 24, 2018 14:07
Поддержка Open Graph в WordPress / insert in head (wp_head)
// Поддержка Open Graph в WordPress
function add_opengraph_doctype( $output ) {
return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter('language_attributes', 'add_opengraph_doctype');
function insert_fb_in_head() {
global $post;
if ( !is_singular())
return;
echo '<meta property="fb:admins" content="Ваш ID в Facebook"/>';
@pavlo-bondarchuk
pavlo-bondarchuk / blockClicks.js
Created December 28, 2018 14:18 — forked from lucas-pelton/blockClicks.js
Prevent multiple clicks and submissions in Contact Form 7
//http://epsiloncool.ru/programmirovanie/preventing-multiple-submits-in-contact-form-7
jQuery(document).on('click', '.wpcf7-submit', function(e){
if( jQuery('.ajax-loader').hasClass('is-active') ) {
e.preventDefault();
return false;
}
});
@pavlo-bondarchuk
pavlo-bondarchuk / javascript
Created January 30, 2019 14:50
lazy-load image
<img src="data:image/png;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" data-src="your-image-here">
<script>
function init() {
var imgDefer = document.getElementsByTagName('img');
for (var i=0; i<imgDefer.length; i++) {
if(imgDefer[i].getAttribute('data-src')) {
imgDefer[i].setAttribute('src',imgDefer[i].getAttribute('data-src'));
} } }
window.onload = init;
@pavlo-bondarchuk
pavlo-bondarchuk / functions.php
Last active February 3, 2019 16:35
Welcome Message for Repeat Customers
function wc_get_customer_orders() {
// Get all customer orders
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
add_action('http_api_curl', 'sar_custom_curl_timeout', 9999, 1);
function sar_custom_curl_timeout( $handle ){
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 60 ); // 30 seconds. Too much for production, only for testing.
curl_setopt( $handle, CURLOPT_TIMEOUT, 60 ); // 30 seconds. Too much for production, only for testing.
}
// Setting custom timeout for the HTTP request
add_filter( 'http_request_timeout', 'sar_custom_http_request_timeout', 9999 );
function sar_custom_http_request_timeout( $timeout_value ) {
return 60; // 30 seconds. Too much for production, only for testing.
}