Skip to content

Instantly share code, notes, and snippets.

@them-es
them-es / functions.php
Last active November 22, 2020 05:17
Ninja Forms: Server side spam protection using WordPress comment blacklist keys
<?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 December 9, 2019 15:19
Include Gutenberg blocks in WP-API response
<?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 November 11, 2021 07:14
Include ACF fields in WP-API response
<?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 November 21, 2019 14:44
Multisite: Duplicate Theme Customizer values across network
<?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 November 30, 2019 05:53
WordPress Multiblog: Combine WP-API feeds from different websites and cache the output
<?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 September 26, 2023 09:52
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.
<?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');