Skip to content

Instantly share code, notes, and snippets.

const { registerPlugin } = wp.plugins;
const { PluginDocumentSettingPanel } = wp.editPost;
const PANEL_NAME = 'my-panel';
const Render = () => (
<PluginDocumentSettingPanel
name="custom-setting-panel"
title="Custom Panels"
className="custom-panel"
<?php
register_post_meta( 'page', 'sidebar_plugin_meta_block_field', [
'show_in_rest' => [
'prepare_callback' => __NAMESPACE__ . '\\prevent_meta_exposition'
],
'single' => true,
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
] );
const { registerPlugin } = wp.plugins;
const { PluginSidebar } = wp.editPost;
const { useSelect, useDispatch } = wp.data;
const { PanelBody, PanelRow, TextControl } = wp.components;
const PLUGIN_NAME = 'my-plugin-sidebar';
/**
* Note: sidebar_plugin_meta_block_field needs to be register_post_meta() in PHP
*/
<?php
$tags = wp_get_object_terms( $post_id, 'product_tag' );
// array_filter sólo se queda con los elementos que devuelven true dentro de la función anónima.
// Lista de etiquetas cuyo padre es marcas (podría ser más de uno).
// 10 es el Term ID de Marcas
$tags_that_belong_to_marcas_term = array_filter( $tags, function ( $term ) {
return 10 === absint( $term->parent );
} );
<?php
function convert( $number ) {
if ( $number > 0 ) {
return $number * 2;
}
return $number / 2;
}
<?php
function answer() {
return '42';
}
const postId = 1000;
const frames = {};
/**
* Get a Media Modal instance for a given item ID
*
* @param itemId
* @return {object}
*/
function getMediaFrame( itemId ) {
@igmoweb
igmoweb / review.sh
Created December 19, 2017 13:52
Executes a phpcs review
#!/usr/bin/env bash
# Change this!
PATH_TO_RULESETS="~/source"
echo "Select what type of review you want to make: Security(s)/All(a). Default Security"
read SUFFIX
if [[ -z "$SUFFIX" ]]
then
SUFFIX='s'
@igmoweb
igmoweb / phpcs-all.xml
Created December 19, 2017 13:23
PHPCS with a bunch of rules
<?xml version="1.0"?>
<ruleset name="My-Project">
<description>Sniffs for the coding standards of your project.</description>
<file>.</file>
<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
<!-- Exclude the Node Modules directory. -->
@igmoweb
igmoweb / phpcs-security.xml
Created December 19, 2017 13:07
PHPCS just with security rules
<?xml version="1.0"?>
<ruleset name="Ignacio">
<description>Security reviews with PHPCS.</description>
<file>.</file>
<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
<!-- Exclude the Node Modules directory. -->