Instantly share code, notes, and snippets.

Roberto Vaccaro robertito13

View GitHub Profile
View FaviconTest.php
<?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 );
View rss.js
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 ) => {
View WP_Customize_Editor.php
<?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
View WP_Facebook_Video.php
<?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);
View WP_Clipboard.php
<?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];
View WP_KeepAlive.php
<?php
if ( !defined( 'ABSPATH' ) ) exit;
function wp_keep_alive($headers, $wp) {
foreach ($headers as $key => $value) {
if ('connection' === strtolower($key)) {
unset($headers[$key]);
}
}
View WP_Deduplicator.php
<?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 );
}