AI Verified

Name

WP Cache addition for SportsPress endpoints

About

Adding Cache for SportsPress selected endpoints

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

ClubLand

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

01/03/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

WP Cache addition for SportsPress endpoints

 
                    
1/**
2 * Register the /wp-json/sportspress/v2/players endpoint so it will be cached
3 */
4function wprc_add_sportspress_players_endpoint( $allowed_endpoints ) {
5 if ( ! isset( $allowed_endpoints[ 'sportspress/v2' ] ) || ! in_array( 'posts', $allowed_endpoints[ 'sportspress/v2' ] ) ) {
6 $allowed_endpoints[ 'sportspress/v2' ][] = 'players';
7 }
8 return $allowed_endpoints;
9}
10add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_sportspress_players_endpoint', 10, 1);
11 
12/**
13 * Register the /wp-json/sportspress/v2/teams endpoint so it will be cached
14 */
15function wprc_add_sportspress_teams_endpoint( $allowed_endpoints ) {
16 if ( ! isset( $allowed_endpoints[ 'sportspress/v2' ] ) || ! in_array( 'posts', $allowed_endpoints[ 'sportspress/v2' ] ) ) {
17 $allowed_endpoints[ 'sportspress/v2' ][] = 'teams';
18 }
19 return $allowed_endpoints;
20}
21add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_sportspress_teams_endpoint', 10, 1);
22 
23/**
24 * Register the /wp-json/sportspress/v2/seasons endpoint so it will be cached
25 */
26function wprc_add_sportspress_seasons_endpoint( $allowed_endpoints ) {
27 if ( ! isset( $allowed_endpoints[ 'sportspress/v2' ] ) || ! in_array( 'posts', $allowed_endpoints[ 'sportspress/v2' ] ) ) {
28 $allowed_endpoints[ 'sportspress/v2' ][] = 'seasons';
29 }
30 return $allowed_endpoints;
31}
32add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_sportspress_seasons_endpoint', 10, 1);
33 
34/**
35 * Register the /wp-json/sportspress/v2/leagues endpoint so it will be cached
36 */
37function wprc_add_sportspress_leagues_endpoint( $allowed_endpoints ) {
38 if ( ! isset( $allowed_endpoints[ 'sportspress/v2' ] ) || ! in_array( 'posts', $allowed_endpoints[ 'sportspress/v2' ] ) ) {
39 $allowed_endpoints[ 'sportspress/v2' ][] = 'leagues';
40 }
41 return $allowed_endpoints;
42}
43add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_sportspress_leagues_endpoint', 10, 1);
44 
45/**
46 * Register the /wp-json/sportspress/v2/events endpoint so it will be cached
47 */
48function wprc_add_sportspress_events_endpoint( $allowed_endpoints ) {
49 if ( ! isset( $allowed_endpoints[ 'sportspress/v2' ] ) || ! in_array( 'posts', $allowed_endpoints[ 'sportspress/v2' ] ) ) {
50 $allowed_endpoints[ 'sportspress/v2' ][] = 'events';
51 }
52 return $allowed_endpoints;
53}
54add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_sportspress_events_endpoint', 10, 1);

0

Related Snippets

Please see some snippets below related to this snippet..

General

Unverified

0

floating

Added: 8 months ago

Last Updated: 8 months ago

General

AI Verified

0

Change post name in dashboard

Added: 8 months ago

Last Updated: 7 months ago

General

AI Verified

0

Display and Search Post ID

Added: 8 months ago

Last Updated: 8 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

0

Replace Admin text

Added: 6 months ago

Last Updated: 6 months ago

Used to translate text on the Admin console

General

AI Verified

0

WP Cache addition for SportsPress endpoints

Added: 6 months ago

Last Updated: 6 months ago

Adding Cache for SportsPress selected endpoints