Skip to content

Instantly share code, notes, and snippets.

@lilumi
lilumi / wp-config.php
Created July 17, 2019 20:28
Local dev config
<?php
if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
include( dirname( __FILE__ ) . '/local-config.php' );
define( 'WP_LOCAL_DEV', true ); // We'll talk about this later
} else {
define( 'DB_NAME', 'production_db' );
define( 'DB_USER', 'production_user' );
define( 'DB_PASSWORD', 'production_password' );
define( 'DB_HOST', 'production_db_host' );
}
@lilumi
lilumi / request.php
Last active July 4, 2019 11:47
wordpress rest api example
<?php
/**
* Regsiter script
*/
add_action( 'wp_enqueue_scripts', function() {
// Set dependency to wp-api, which has nonce and endpoint root.
wp_enqueue_script( 'api-handler', '/path/to/api-handler.js', [ 'jquery', 'wp-api' ], '1.0', true );
} );
// Below is the content of api-handler.js
?>
@lilumi
lilumi / ol_with_colored_numbers.css
Created December 7, 2018 17:00
Ol with Colored Numbers
ol {
list-style: none;
counter-reset: li;
}
ol > li {
counter-increment: li;
margin-bottom: 7px;
}
@lilumi
lilumi / style_version_always_actual.php
Last active February 27, 2017 18:04
Add ver filemtime to styles
<?php
add_filter( 'script_loader_src', 'remove_src_version' );
add_filter( 'style_loader_src', 'remove_src_version' );
function remove_src_version ( $src ) {
global $wp_version;
$version_str = '?ver='.$wp_version;
$version_str_offset = strlen( $src ) - strlen( $version_str );
$version_str_alt = '&ver='.$wp_version;
$version_str_offset_alt = strlen( $src ) - strlen( $version_str_alt );
javascript:void(function()%7Bvar i,a,s%3Ba%3Ddocument.getElementsByTagName(%27link%27)%3Bfor(i%3D0%3Bi<a.length%3Bi%2B%2B)%7Bs%3Da%5Bi%5D%3Bif(s.rel.toLowerCase().indexOf(%27stylesheet%27)>%3D0%26%26s.href) %7Bvar h%3Ds.href.replace(/(%26%7C%5C%3F)forceReload%3D%5Cd%2B/,%27%27)%3Bs.href%3Dh%2B(h.indexOf(%27%3F%27)>%3D0%3F%27%26%27:%27%3F%27)%2B%27forceReload%3D%27%2B(new Date().valueOf())%7D%7D%7D)()%3B
// Just set the pointer-events: none CSS to the <iframe> to disable mouse scroll.
/*
<div id="gmap-holder">
<iframe width="100%" height="400" frameborder="0" style="border:0; pointer-events:none"
src="https://www.google.com/maps/embed/v1/place?q=XXX&key=YYY"></iframe>
</div>
If you want the mouse scroll to be activated when the user clicks into the map, then use the following JS code.
It will also disable the mouse scroll again, when the mouse moves out of the map.
<?php
/*
Plugin Name: Disable plugins when doing local dev
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
<?php
/**
* Get field key for field name.
* Will return first matched acf field key for a give field name.
*
* ACF somehow requires a field key, where a sane developer would prefer a human readable field name.
* http://www.advancedcustomfields.com/resources/update_field/#field_key-vs%20field_name
*
* This function will return the field_key of a certain field.
@lilumi
lilumi / ul-li
Created June 17, 2015 18:04
UL LI with colored bulltes
ul {
list-style: none;
margin-bottom: 1em;
}
ul li {
list-style: none;
position: relative;
padding-left: 16px;
padding-bottom: 0;
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*/
define('WP_DEBUG', false);
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );