Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View rfmeier's full-sized avatar
💭
Nada.

Ryan Meier rfmeier

💭
Nada.
View GitHub Profile
@rfmeier
rfmeier / response.json
Created April 28, 2022 17:50
Successful formatted response
{
"success": true,
"data": {
"show_in_rest": true,
"show_in_graphql": true,
"singular": "Person",
"plural": "Persons",
"slug": "person",
"api_visibility": "private",
"model_icon": "dashicons-admin-post",
@rfmeier
rfmeier / helper.php
Created April 28, 2022 17:46
Example response helper function
<?php
/**
* Create a WP_REST_Response that uses ACM response data formatting.
*
* @param bool $success Whether the response was successful or not.
* @param array $data The data for the response.
* @param int $status Optional http status code. Default 200.
* @param array $headers Optional http headers. Default empty array.
*
@rfmeier
rfmeier / response-format.json
Created April 27, 2022 21:02
Proposed response format
{
"success": true,
"data": {
"name": "John Doe",
"username": "johndoe123"
}
}
@rfmeier
rfmeier / response.json
Created April 27, 2022 20:56
WP REST json response for a WP_Error
{
"code": "name",
"message": "Name is required",
"data": {
"status": 400
},
"additional_data": [
{
"status": 400
}
@rfmeier
rfmeier / response.json
Created April 27, 2022 20:59
Formatted response for WP_Error
{
"success": false,
"data": {
"name": [
"Name is required",
"A second Name error message",
"A third Name error message"
],
"email": [
"Email is required"
@rfmeier
rfmeier / functions.php
Last active January 7, 2022 15:09
Enable taxonomy wildcard name searching within WordPress search.
<?php
/**
* Callback for WordPress 'pre_get_posts' action.
*
* If doing a search, set the post type to 'post'.
*
* @author Ryan Meier http://www.rfmeier.net/
*
@rfmeier
rfmeier / functions.php
Last active October 24, 2021 21:37
Sanitize callback for WordPress register_meta() function.
<?php //* do not include php tag
/**
* Callback for WordPress register_meta() sanitize parameter.
*
* Sanitize the 'sample_count' meta value before saved to the database.
*
* @see https://codex.wordpress.org/Function_Reference/register_meta
*
* @uses absint()
@rfmeier
rfmeier / example.html
Created October 14, 2014 15:08
html5 microdata GeoCoordinates markup
<!-- The parent 'SportsActivityLocation' element, however you may structure it -->
<div itemscope itemtype="http://schema.org/SportsActivityLocation">
<!--
Some other possible elements.
-->
<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
<!-- Display coordinate data if you wish... -->
<meta itemprop="latitude" content="-33.0000" />
<meta itemprop="longitude" content="18.0000" />
</span>
@rfmeier
rfmeier / functions.php
Created June 17, 2014 01:44
Display a Genesis custom loop within a shortcode.
<?php
add_action('init' , 'jspt_init');
/**
* Callback for WordPress 'init' action.
*
* Reigster the custom shortcode.
*
* @return void
*/
@rfmeier
rfmeier / functions.php
Last active July 24, 2019 18:18
Append a GROUP BY clause to the current WP_Query SQL clause for the search.
<?php
/**
* Do not include php tags
*/
add_filter( 'posts_groupby', 'custom_posts_groupby', 10, 2 );
/**
* Callback for WordPress 'posts_groupby' filter.
*
* Set the GROUP BY clause to post IDs.