Skip to content

Instantly share code, notes, and snippets.

View yuriitaran's full-sized avatar

Yurii Taran yuriitaran

View GitHub Profile
@yuriitaran
yuriitaran / responsive-video.css
Created November 27, 2018 13:21 — forked from jaicab/responsive-video.css
Pure CSS solution for embed videos with an aspect ratio of 16:9
.video-container {
position: relative;
padding-bottom: 56.25%; /*16:9*/
padding-top: 30px;
height: 0;
overflow: hidden;
}
.video-container iframe,
.video-container object,
@yuriitaran
yuriitaran / WP: Remove 100 post limit for RESR API
Created November 26, 2018 16:04
WP: Remove 100 post limit for RESR API
add_filter( 'rest_endpoints', function( $endpoints ){
if ( ! isset( $endpoints['/wp/v2/posts'] ) ) {
return $endpoints;
}
unset( $endpoints['/wp/v2/posts'][0]['args']['per_page']['maximum'] );
return $endpoints;
});
//
@yuriitaran
yuriitaran / javascript sorting
Last active February 20, 2019 13:23
Javascript sorting
// sort array of objects by items value ('jobId')
data.sort((a, b) => {
if (a.jobId > b.jobId) {
return -1
} else if (a.jobId < b.jobId) {
return 1
} else {
return 0
}
})
@yuriitaran
yuriitaran / helpers-write-log.php
Created November 14, 2018 16:01 — forked from kostiantyn-petlia/helpers-write-log.php
Logging function write_log() for debugging process
// -----------------------------------------------------------------------------
/**
* Logging to debug.log in DEBUG_LOG_DIR dir (default is the root site dir)
*
* Note: You can define in the wp-config.php:
* 1) define( 'DEBUG_LOG_DIR', dirname( __FILE__ ) . '/' );
* 2) define( 'DEBUG_LOG_INVERTED', false);
*
* Author K
@yuriitaran
yuriitaran / functions.php
Last active November 12, 2018 00:16
Retrieving data from Wordpress REST API
wp_enqueue_script( 'wp-rest', get_template_directory_uri() . '/js/wp-rest.js', null, null, true );
// Posts custom fields
function prepare_rest($data, $post, $request){
$_data = $data->data;
$_data['custom_fields'] = get_post_meta($post->ID); // retrieving all post meta fields
return $_data;
}
add_filter('rest_prepare_post', 'prepare_rest', 10, 3);
<?php
function my_customize_rest_cors() {
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
add_filter( 'rest_pre_serve_request', function( $value ) {
header( 'Access-Control-Allow-Origin: *' );
header( 'Access-Control-Allow-Methods: GET' );
header( 'Access-Control-Allow-Credentials: true' );
header( 'Access-Control-Expose-Headers: Link', false );
@yuriitaran
yuriitaran / span wrapper for currency symbol
Created October 29, 2018 11:42
Opencart tweaks and tricks
// in \system\library\currency.php
// change
if (($symbol_right) && ($format)) {
$string .= $symbol_right;
}
// to
if (($symbol_right) && ($format)) {
$string .= '<span class="currency-symbol">' . $symbol_right . '</span>';
@yuriitaran
yuriitaran / Slick click (touch) event inside a slide
Created September 29, 2018 20:24
Slick click (touch) event inside a slide
The solution is to use event delegation (jquery's ".on()" method) from outside of the carousel's top element
(with the "slick-slider" class), targeting the elements inside the carousel.
This way the event handler is unaffected by the bug.
Example:
$('.carousel-container').on('click', 'div.button', function() {
// do stuff
});
@yuriitaran
yuriitaran / Foo.test.js
Created September 15, 2018 06:58 — forked from mweibel/Foo.test.js
Mock react-beautiful-dnd
// mocks react-beautiful-dnd Droppable without the need of a DragDropContext etc.
jest.mock('react-beautiful-dnd', () => ({
Droppable: jest.fn(
// params to children are `provider`, `snapshot`
({children}) => children({}, {})
)
}));
class Checkbox extends React.Component {
constructor() {
super();
this.state = {
checked: false
};
this.handleClick = this.handleClick.bind(this);
}