Definitely not comprehensive. This is meant to be a basic memory aid with links to get more details. I'll add to it over time.
$ npm install mongoose --save
const mongoose = require('mongoose');
<?php | |
//* Do NOT include the opening php tag shown above. Copy the code shown below into functions.php | |
/** | |
* Manage WooCommerce styles and scripts. | |
*/ | |
function grd_woocommerce_script_cleaner() { | |
// Remove the generator tag | |
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) ); |
<?php | |
/** | |
* [list_searcheable_acf list all the custom fields we want to include in our search query] | |
* @return [array] [list of custom fields] | |
*/ | |
function list_searcheable_acf(){ | |
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF"); | |
return $list_searcheable_acf; | |
} |
document.getElementsByTagName('button')[0].onclick = function () { | |
scrollTo(document.body, 0, 1250); | |
} | |
function scrollTo(element, to, duration) { | |
var start = element.scrollTop, | |
change = to - start, | |
currentTime = 0, | |
increment = 20; | |
# Installation --- | |
# 1. In Bitbucket, add FTP_USERNAME, FTP_PASSWORD and FTP_HOST as environment variables. | |
# 2. Commit this file (bitbucket-pipelines.yml) to your repo (in the repo root dir) | |
# 3. From Bitbucket Cloud > Commits > Commit Number > Run Pipeline > Custom:Init (this will | |
# push everything and initialize GitFTP) | |
# | |
# Usage --- | |
# - On each commit to master branch, it'll push all files to the $FTP_HOST | |
# - You also have the option to 'init' (see 'Installation' above) - pushes everything and initialises | |
# - Finally you can also 'deploy-all' (from Bitbucket Cloud > Commits > Commit Number > Run Pipeline > Custom:deploy-all) |
FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works | |
const axios = require('axios'); // promised based requests - like fetch() | |
function getCoffee() { | |
return new Promise(resolve => { | |
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee | |
}); | |
} |
<?php | |
/** | |
* List of global WP variables. | |
* | |
* @since 0.3.0 | |
* @since 0.11.0 Changed visibility from public to protected. | |
* @since 0.12.0 Renamed from `$globals` to `$wp_globals` to be more descriptive. | |
* @since 0.12.0 Moved from WordPress_Sniffs_Variables_GlobalVariablesSniff to WordPress_Sniff | |
* | |
* @var array |
Thanks to React hooks you have now happily turned all your classes into functional components.
Wait, all your components? Not quite. There is one thing that can still only be implemented using classes: Error boundaries.
There is just no functional equivalent for componentDidCatch
and deriveStateFromError
yet.
<?php | |
add_action( 'wp_ajax_ajaxcomments', 'ugwps_submit_ajax_comment' ); // wp_ajax_{action} for registered user | |
add_action( 'wp_ajax_nopriv_ajaxcomments', 'ugwps_submit_ajax_comment' ); // wp_ajax_nopriv_{action} for not registered users | |
function ugwps_submit_ajax_comment(){ | |
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) ); | |
if ( is_wp_error( $comment ) ) { | |
$error_data = intval( $comment->get_error_data() ); | |
if ( ! empty( $error_data ) ) { | |
wp_die( '<p>' . $comment->get_error_message() . '</p>', __( 'Comment Submission Failure' ), array( 'response' => $error_data, 'back_link' => true ) ); |