Skip to content

Instantly share code, notes, and snippets.

Antonio Villegas avillegasn

Block or report user

Report or block avillegasn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@avillegasn
avillegasn / my-component.js
Last active Jun 28, 2019
Extending @wordpress/scripts to load SVG files inside JSX files.
View my-component.js
import {
Component,
Fragment,
} from '@wordpress/element';
import Icon from './icon.svg';
class MyComponent extends Component {
render() {
return (
@avillegasn
avillegasn / package.json
Created Jun 3, 2019
Content of package.json file to use @wordpress/scripts package
View package.json
{
"name": "my-wp-plugin",
"version": "1.0.0",
"description": "My WP plugin description",
"keywords": [
"my",
"wordpress",
"plugin"
],
"author": "avillegasn",
@avillegasn
avillegasn / settings-link.php
Last active May 7, 2019
Add a settings link under your plugin title in the list of plugins
View settings-link.php
@avillegasn
avillegasn / only-for-admins.php
Last active Feb 27, 2019
Code snippets to hide/manage routes in WordPress REST API
View only-for-admins.php
<?php
add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) );
}
if ( ! current_user_can( 'administrator' ) ) {
@avillegasn
avillegasn / react-ui-without-jsx.js
Last active Feb 4, 2019
React UI with JSX syntax.
View react-ui-without-jsx.js
class Product extends Component {
render() {
return wp.element.createElement(
"div",
{ className: "product" },
wp.element.createElement(
"p",
null,
this.props.name
)
@avillegasn
avillegasn / gutenberg.js
Last active Mar 8, 2019
Fragments of code to add a custom button to Gutenberg rich text blocks
View gutenberg.js
import ElementIcon from '../images/logo.svg';
const { Fragment } = wp.element;
const { __ } = window.wp.i18n;
const { registerFormatType, unregisterFormatType } = window.wp.richText;
const { RichTextToolbarButton } = window.wp.editor;
unregisterFormatType( 'nelio/button' );
registerFormatType( 'nelio/button', {
@avillegasn
avillegasn / acf-export.json
Last active Nov 26, 2018
Plugin file to use different image sizes with Nelio Content and Advanced Custom Fields
View acf-export.json
[
{
"key": "group_5bf27651e03b6",
"title": "Social Images",
"fields": [
{
"key": "field_5bf2766a5c07d",
"label": "Facebook",
"name": "nc-facebook-featured-image",
"type": "image",
@avillegasn
avillegasn / heatmap-hidden.js
Last active Nov 8, 2018
Scripts to play with heatmaps in a web
View heatmap-hidden.js
(function(a,b,c){if(typeof module!=="undefined"&&module.exports){module.exports=c()}else if(typeof define==="function"&&define.amd){define(c)}else{b[a]=c()}})("h337",this,function(){var a={defaultRadius:40,defaultRenderer:"canvas2d",defaultGradient:{.25:"rgb(0,0,255)",.55:"rgb(0,255,0)",.85:"yellow",1:"rgb(255,0,0)"},defaultMaxOpacity:1,defaultMinOpacity:0,defaultBlur:.85,defaultXField:"x",defaultYField:"y",defaultValueField:"value",plugins:{}};var b=function h(){var b=function d(a){this._coordinator={};this._data=[];this._radi=[];this._min=0;this._max=1;this._xField=a["xField"]||a.defaultXField;this._yField=a["yField"]||a.defaultYField;this._valueField=a["valueField"]||a.defaultValueField;if(a["radius"]){this._cfgRadius=a["radius"]}};var c=a.defaultRadius;b.prototype={_organiseData:function(a,b){var d=a[this._xField];var e=a[this._yField];var f=this._radi;var g=this._data;var h=this._max;var i=this._min;var j=a[this._valueField]||1;var k=a.radius||this._cfgRadius||c;if(!g[d]){g[d]=[];f[d]=[]}if(!g[d][e]){g[d
View custom-post-type-recipe-full.php
<?php
// Register Custom Post Type
function custom_post_type() {
$labels = array(
'name' => _x( 'Recipes', 'Post Type General Name', 'nelio' ),
'singular_name' => _x( 'Recipe', 'Post Type Singular Name', 'nelio' ),
'menu_name' => __( 'Recipes', 'nelio' ),
'name_admin_bar' => __( 'Recipe', 'nelio' ),
View custom-post-type-recipe.php
<?php
function create_post_type() {
register_post_type( 'recipe',
array(
'labels' => array(
'name' => __( 'Recipes', 'nelio' ),
'singular_name' => __( 'Recipe', 'nelio' )
),
'public' => true,
You can’t perform that action at this time.