Skip to content

Instantly share code, notes, and snippets.

View felipeelia's full-sized avatar

Felipe Elia felipeelia

View GitHub Profile
@felipeelia
felipeelia / wordpress-locale-stats.php
Created September 18, 2019 22:44
List the percentage of usage of WordPress installs per locale
<?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 / wpinstall.sh
Last active October 31, 2019 23:39
Instalação automatizada do WordPress em pt-BR com WP-CLI e bash. Explicações em http://felipeelia.com.br/wp-cli-e-bash-automatizando-instalacao-do-wordpress-em-pt-br/
#!/bin/bash
set -euo pipefail
# define variáveis padrão para o BD (com possibilidade de receber de outro script)
DB_HOST="${DB_HOST:-127.0.0.1}"
DB_USER="${DB_USER:-root}"
DB_PASS="${DB_PASS:-root}"
if (( DOCKER_INST )); then
DIR_INSTALACAO=
WPCLI=$wp_docker
@felipeelia
felipeelia / wp-author-import-auto-select.js
Last active March 6, 2020 13:41 — 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.
( 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 ) {
<?php
function submit_form_data( $confirmation, $form, $entry ) {
...
/**
* hold the form data that will be submitted to leap API
*/
$leap_form_data = [];
@felipeelia
felipeelia / elasticpress-remove-terms-from-facet-widget.php
Created October 12, 2020 13:30
Exclude some terms form the ElasticPress Facets Widget Filter
<?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 / fb-instagram-oembed-time.sql
Created October 21, 2020 18:47
[WordPress] Bump FB and Instagram oembed time
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 / ep-product-variation-titles.php
Last active March 18, 2021 17:50
ElasticPress - Index product variation titles into the parent product
<?php
// Create a new field with product variation titles.
add_filter(
'ep_prepare_meta_data',
function( $post_meta, $post ) {
if ( 'product' !== get_post_type( $post ) ) {
return $post_meta;
}
@felipeelia
felipeelia / elasticpress-add-meta-fields-to-search.php
Last active June 11, 2021 00:55
ElasticPress: Add specific post meta to search fields
<?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 / log-db-queries-wordpress.php
Created September 25, 2021 13:03
Log DB Queries for WordPress
<?php
namespace TenUp_QueryLog;
function log_queries( $query ) {
if ( ! preg_match( '/^\s*(create|alter|truncate|drop|insert|delete|update|replace)\s/i', $query ) ) {
return $query;
}
// Not interested in any operations with transients
@felipeelia
felipeelia / ep-add-cross-fields.php
Last active December 10, 2021 19:25
ElasticPress: Make Elasticsearch search for the string in different fields
<?php
/**
* Add a cross_field type clause to the ES query, so it searches for terms
* in different fields.
*
* @param array $query Current query
* @param array $args Query variables
* @param string $search_text Search text
* @param array $search_fields Search fields