Skip to content

Instantly share code, notes, and snippets.

View robertito13's full-sized avatar

Roberto Vaccaro robertito13

View GitHub Profile
@robertito13
robertito13 / FaviconTest.php
Created December 2, 2018 15:18
Idea de tests para un Theme de WordPress
<?php
use PHPUnit\Framework\TestCase;
final class FaviconTest extends TestCase {
public function testFaviconIncluded() {
$icons = array();
$qp = html5qp( SITE_URL );
$qp->find('link[rel="icon"]')->each( function( $i, $node ) use ( &$icons ) {
$icons[] = parse_url( $node->getAttribute( 'href' ), PHP_URL_PATH );
document.addEventListener( 'DOMContentLoaded', function() {
const websiteUrl = 'http://www.anred.org/?feed=rss2';
const entityPattern = /\[(&(?:\#(?:(?<dec>[0-9]+)|[Xx](?<hex>[0-9A-Fa-f]+))|(?<named>[A-Za-z0-9]+));)\]/
const feeds = [
'http://www.anred.org/?feed=rss2'
];
feeds.forEach( function( websiteUrl ) {
fetch( websiteUrl ).then( ( res ) => {
@robertito13
robertito13 / WP_Customize_Editor.php
Last active August 9, 2018 17:46
Implementación del editor de texto como control para el Customizer de Wordpress
<?php
class WP_Customize_Editor extends WP_Customize_Control {
public $type = 'editor';
public function render_content() { ?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<input id="<?php echo $this->id; ?>-link" type="hidden" class="wp-editor-area" <?php $this->link(); ?> value="<?php echo esc_textarea( $this->value() ); ?>">
<?php
@robertito13
robertito13 / WP_Facebook_Video.php
Created July 6, 2018 10:22
Videos de Facebook con ancho automático
<?php
function auto_width_facebook_video( $result, $url, $args, $post_id ) {
return preg_replace('/data-width="(\d+)"/', 'data-width="auto"', $result);
}
add_filter('embed_oembed_html', 'auto_width_facebook_video', 11, 4);
@robertito13
robertito13 / WP_Clipboard.php
Created July 5, 2018 15:50
Borrar etiquetas HTML del texto pegado en el editor
<?php
function wp_clean_on_paste( $in ) {
$in['paste_preprocess'] = "function( plugin, args ) {
var whitelist = 'a,p,span,b,strong,i,em,h3,h4,h5,h6,ul,li,ol';
var stripped = jQuery('<div>' + args.content + '</div>');
var els = stripped.find('*').not(whitelist);
for (var i = els.length - 1; i >= 0; i--) {
var e = els[i];
<?php
if ( !defined( 'ABSPATH' ) ) exit;
function wp_keep_alive($headers, $wp) {
foreach ($headers as $key => $value) {
if ('connection' === strtolower($key)) {
unset($headers[$key]);
}
}
@robertito13
robertito13 / WP_Deduplicator.php
Last active April 20, 2018 16:12
Evitar los post duplicados al utilizar múltiples loops en WordPress
<?php
class WP_Deduplicator {
private static $published = array();
public static function add( $post = null ) {
$post = get_post( $post );
if ( !in_array( $post->ID, self::$published ) )
array_push( self::$published, $post->ID );
}