Skip to content

Instantly share code, notes, and snippets.

View felipeelia's full-sized avatar

Felipe Elia felipeelia

View GitHub Profile
<?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 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 ) {
@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 / fetch-from-wp-rest-api.php
Last active September 15, 2019 19:15
Given a WP REST API content list route, fetches all IDs, URLs, and Titles into a CSV file.
<?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++ ) {
@felipeelia
felipeelia / paginacao-wordpress.php
Created August 4, 2019 13:17
Paginação no WordPress
<?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 March 29, 2019 12:14
Randomize the content list in REST API passing `orderby=rand` as parameter.
<?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
*/
/**
@felipeelia
felipeelia / db-backup.php
Created October 3, 2018 18:38
Generate a dump from a WordPress website
<?php
include 'wp-config.php';
ini_set( 'display_errors', 1 );
ini_set( 'display_startup_errors', 1 );
error_reporting( E_ALL );
$dir = dirname( __FILE__ ) . '/dump.sql';
echo "<h3>Backing up database to `<code>{$dir}</code>`</h3>";
@felipeelia
felipeelia / woocommerce-orderby-featured-products.php
Last active August 3, 2023 13:47
Bring featured products first in a WP_Query
<?php
/**
* The public-facing functionality of the plugin.
*
* @link https://dualcon.ddns.net/
* @since 1.0.0
*
* @package My_Wp_Tools
* @subpackage My_Wp_Tools/public
@felipeelia
felipeelia / forum.html
Last active April 20, 2018 19:16 — forked from claudiosanches/forum.html
Forum
<h2 id="bem-vindos-ao-forum-de-suporte">Bem-vindo(a) ao fórum de suporte <a href="#bem-vindos-ao-forum-de-suporte">#</a></h2>
Esta página é uma mensagem de boas-vindas aos <a href="https://br.wordpress.org/support/">fóruns de suporte</a> do WordPress do Brasil. Esperamos que este documento seja útil para você, uma vez que é destinado a ser um manual de "começo rápido" ao invés de uma documentação completa. Esta introdução feita para que você possa encontrar o seu caminho pelo fórum e comece a usá-lo o mais rápido possível. <!-- Para encontrar informações detalhadas e completas sobre o fórum, acesse o artigo [[pt-br:Usando_o_Fórum_de_Suporte|Utilizando os fóruns de suporte]] do Codex. -->
Antes de publicar, tenha certeza de que está publicando sobre um site que utiliza o WordPress.org e <strong>NÃO</strong> o WordPress.com. Caso você não tenha certeza, leia o artigo <a href="https://br.support.wordpress.com/com-vs-org/">WordPress.com e WordPress.org</a> para entender a diferença.
Estes fóruns são destinados