Skip to content

Instantly share code, notes, and snippets.

@them-es
them-es / functions.php
Last active Nov 22, 2020
Ninja Forms: Server side spam protection using WordPress comment blacklist keys
View functions.php
<?php
/**
* [Update] This Gist has been integrated into the WordPress Plugin "I don't like Spam!" which supports more WordPress Contact Forms:
* https://wordpress.org/plugins/i-dont-like-spam
*
* Ninja Forms: Server side spam protection making use of the WordPress Comment Blocklist
* https://developer.ninjaforms.com/codex/custom-server-side-validation
*
* Enter your blocklist here: Settings > Discussion > Comment Blocklist
* https://developer.wordpress.org/reference/functions/wp_blacklist_check
@them-es
them-es / functions.php
Created Dec 9, 2019
Include Gutenberg blocks in WP-API response
View functions.php
<?php
/**
* Include all Gutenberg blocks from content in REST API response
*
*
*/
function my_theme_blocks_to_rest_api( $response, $post, $request ) {
if ( ! function_exists( 'parse_blocks' ) ) {
return $response;
}
@them-es
them-es / functions.php
Last active Jul 8, 2020
Include ACF fields in WP-API response
View functions.php
<?php
/**
* Include ACF fields in REST API response
*
* Post, Page or Custom Posttype
*/
function my_theme_acf_to_rest_api( $response, $post, $request ) {
if ( ! function_exists( 'get_fields' ) ) {
return $response;
}
@them-es
them-es / functions.php
Last active Nov 21, 2019
Multisite: Duplicate Theme Customizer values across network
View functions.php
<?php
/**
* Duplicate specific Theme Customizer values across Multisite network
*
*/
function my_theme_customize_multisite_duplicate() {
if ( is_multisite() ) {
// Get existing values from current blog as array
@them-es
them-es / functions.php
Last active Nov 30, 2019
WordPress Multiblog: Combine WP-API feeds from different websites and cache the output
View functions.php
<?php
/**
* WordPress "Multiblog"
*
* Combine multiple WP-API feeds sorted by date and cache the output via Transients API
*/
// Cache transients in database: https://codex.wordpress.org/Transients_API
$transient = 'wp_api_remote_posts_cache;
$content = get_transient( $transient ); // Try to get cached data
@them-es
them-es / functions.php
Last active Jun 10, 2021
Make Polylang compatible with the WP-API. Query language specific WP-API posts via a parameter and add the post language as a new REST field.
View functions.php
<?php
/**
* https://developer.wordpress.org/reference/hooks/rest_this-post_type_query
*
* Query language specific posts via "lang" parameter: /wp-json/wp/v2/posts?lang=en
*/
function my_theme_filter_rest_post_query( $args, $request ) {
$lang_parameter = $request->get_param('lang');