Skip to content

Instantly share code, notes, and snippets.

Avatar

Felipe Elia felipeelia

View GitHub Profile
@felipeelia
felipeelia / fb-instagram-oembed-time.sql
Created Oct 21, 2020
[WordPress] Bump FB and Instagram oembed time
View fb-instagram-oembed-time.sql
UPDATE
`wp_postmeta` pm
SET meta_value = 1924905600
WHERE meta_key IN
(
SELECT * FROM
(
SELECT REPLACE(meta_key, '_oembed_', '_oembed_time_')
FROM `wp_postmeta`
WHERE meta_key LIKE '_oembed_%' AND ( meta_value LIKE '%id="fb-root"%' OR meta_value LIKE '%class="instagram-media"%' )
@felipeelia
felipeelia / elasticpress-remove-terms-from-facet-widget.php
Created Oct 12, 2020
Exclude some terms form the ElasticPress Facets Widget Filter
View elasticpress-remove-terms-from-facet-widget.php
<?php
// Exclude some terms form the ElasticPress Facets Widget Filter
add_action(
'pre_get_terms',
function ( $wp_term_query ) {
global $wp_query;
if ( ! $wp_query->get( 'ep_facet', false ) ) {
return false;
}
@felipeelia
felipeelia / elasticpress-add-meta-fields-to-search.php
Last active Sep 18, 2020
ElasticPress: Add specific post meta to search fields
View elasticpress-add-meta-fields-to-search.php
<?php
add_filter(
'ep_weighting_configuration_for_search',
function( $weighting_config ) {
global $wpdb;
$post_meta = get_transient( 'custom_ep_distinct_post_meta' );
if ( ! $post_meta ) {
$post_meta = $wpdb->get_col(
"SELECT DISTINCT meta_key
@felipeelia
felipeelia / elasticpress-remove-some-meta.php
Last active Sep 24, 2020
Remove some meta fields from the ElasticPress/Elasticsearch index
View elasticpress-remove-some-meta.php
<?php
add_filter(
'ep_prepare_meta_data',
function ( $prepared_meta ) {
foreach ( $prepared_meta as $key => $meta_val ) {
// Remove empty meta fields.
if ( empty( $key ) || empty( $meta_val ) || empty( $meta_val[0] ) ) {
unset( $prepared_meta[ $key ] );
continue;
}
View leap_api.php
<?php
function submit_form_data( $confirmation, $form, $entry ) {
...
/**
* hold the form data that will be submitted to leap API
*/
$leap_form_data = [];
@felipeelia
felipeelia / wp-author-import-auto-select.js
Last active Mar 6, 2020 — forked from webercoder/wp-author-import-auto-select.js
Auto-select authors for posts during WordPress import. They must already be assigned to the project. Enable jQuery in a plugin or functions.php, and paste this in the browser console.
View wp-author-import-auto-select.js
( function( $ ) {
$( '#authors li' ).each( function( key, value ) {
const fullInfo = $( this ).children( 'strong' ).first().html(),
name = fullInfo.replace( /\s\([^\)]+\)/gi, '' ),
username = /\(([^)]*)\)/.exec( fullInfo )[ 1 ];
let selectName = '';
$( this ).find( 'select' ).first().children( 'option' ).each( function() {
selectName = $( this ).html();
if ( selectName == fullInfo ) {
@felipeelia
felipeelia / wordpress-locale-stats.php
Created Sep 18, 2019
List the percentage of usage of WordPress installs per locale
View wordpress-locale-stats.php
<?php
$locales = file_get_contents( 'https://api.wordpress.org/stats/locale/1.0/' );
$locales = json_decode( $locales, true );
arsort( $locales );
$others = '';
$index = 1;
foreach ( $locales as $locale => $value ) {
if ( 'Others' === $locale ) {
$others = $value;
@felipeelia
felipeelia / fetch-from-wp-rest-api.php
Last active Sep 15, 2019
Given a WP REST API content list route, fetches all IDs, URLs, and Titles into a CSV file.
View fetch-from-wp-rest-api.php
<?php
/**
* Usage example: `php -f fetch-from-wp-rest-api.php https://wordpress.org/support/wp-json/wp/v2/articles helphub-list`
*/
$first_page = file_get_contents( $argv[1] . '?per_page=100' );
$first_page_headers = parse_headers( $http_response_header );
$content = json_decode( $first_page, true );
for ( $i = 2; $i < $first_page_headers['X-WP-TotalPages']; $i++ ) {
View paginacao-wordpress.php
<?php
/**
* Função para exibir paginação
*
* @param WP_Query $query Query que deverá ser paginada.
* @param integer $range Quantidade de páginas ao redor da página atual.
* @param string $get_param Nome do parâmetro em `$_GET` com o número da página atual.
* @return string HTML com a paginação
*/
function starter_pagination( $query = null, $range = 2, $get_param = null ) {
@felipeelia
felipeelia / add_rand_orderby_restapi_post.php
Created Mar 29, 2019
Randomize the content list in REST API passing `orderby=rand` as parameter.
View add_rand_orderby_restapi_post.php
<?php
/**
* Plugin Name: REST API - Post list randomize
* Description: Randomize the content list in REST API passing `orderby=rand` as parameter.
* Version: 1.0.0
* Author: Felipe Elia | Codeable
* Author URI: https://codeable.io/developers/felipe-elia?ref=qGTOJ
*/
/**