Skip to content

Instantly share code, notes, and snippets.

View onur-km's full-sized avatar
🏝️
I may be slow to respond.

kmo onur-km

🏝️
I may be slow to respond.
View GitHub Profile
@onur-km
onur-km / XHR-request.js
Created April 6, 2021 11:48 — forked from deanhume/XHR-request.js
A simple XHR request
function successListener() {
var data = JSON.parse(this.responseText);
console.log(data);
}
function failureListener(err) {
console.log('Request failed', err);
}
var request = new XMLHttpRequest();
@onur-km
onur-km / vergi_daireleri.sql
Created October 9, 2020 08:07 — forked from ridvanucok/vergi_daireleri.sql
Türkiye Vergi Daireleri Veri Tabanı // Turkey Tax Departments Database
CREATE TABLE `vergi_daireleri` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`plaka` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL,
`il` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`ilce` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`daire` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
INSERT INTO vergi_daireleri (id, plaka, il, ilce, daire) VALUES (1, '01', 'ADANA', 'Merkez', '5 Ocak Vergi Dairesi Müdürlüğü');
@onur-km
onur-km / Turbolinks reloading page when clicking hash links.md
Created September 24, 2020 06:57
Turbolinks reloading page when clicking hash links
@onur-km
onur-km / How to detect internet speed in JavaScript?.md
Created September 2, 2020 07:05
How to detect internet speed in JavaScript?

It's possible to some extent but won't be really accurate, the idea is load image with a known file size then in its onload event measure how much time passed until that event was triggered, and divide this time in the image file size.

Example can be found here: https://stackoverflow.com/questions/4583395/calculate-speed-using-javascript

Test case applying the fix suggested there:

@onur-km
onur-km / expose_ACF_fields_to_REST.php
Created August 27, 2020 09:14 — forked from MelMacaluso/expose_ACF_fields_to_REST.php
Automatically expose all the ACF fields to the Wordpress REST API in Pages and in your custom post types.
<?php
function create_ACF_meta_in_REST() {
$postypes_to_exclude = ['acf-field-group','acf-field'];
$extra_postypes_to_include = ["page"];
$post_types = array_diff(get_post_types(["_builtin" => false], 'names'),$postypes_to_exclude);
array_push($post_types, $extra_postypes_to_include);
foreach ($post_types as $post_type) {
register_rest_field( $post_type, 'ACF', [
@onur-km
onur-km / Adding custom fields in the WordPress REST API.md
Last active August 24, 2020 06:49
Adding custom fields in the WordPress REST API

Adding custom fields in the WordPress REST API

When we look at the standard REST API responses it’s clear to see that many download data operations will need additional queries to be effective. One possible solution for this issue is the addition of custom fields to the responses the REST API returns.

What’s the best way to add custom fields in the WordPress?

There’s two possible methods for adding custom fields to to REST API responses:

@onur-km
onur-km / How do you add custom fields defined in posts to the rest API responses in wordpress.md
Created August 24, 2020 06:37
How do you add custom fields defined in posts to the rest API responses in wordpress

First you need to [register_rest_fields][1] to adding custom endpoints in WP REST API JSON Response

add_action( 'rest_api_init', 'add_custom_fields' );
function add_custom_fields() {
register_rest_field(
'post', 
'custom_fields', //New Field Name in JSON RESPONSEs
array(
    'get_callback'    => 'get_custom_fields', // custom function name 

'update_callback' => null,

@onur-km
onur-km / wp-extended-search-in-all-meta-data.php
Created August 18, 2020 08:05 — forked from ionurboz/wp-extended-search-in-all-meta-data.php
wp-extended-search-in-all-meta-data.php
<?php
/**
* Extend WordPress search to include custom fields
*
* https://adambalee.com
*/
/**
* Join posts and postmeta tables
*