Skip to content

Instantly share code, notes, and snippets.

function is_spam_akismet($args){
global $akismet_api_host, $akismet_api_port;
$query['user_ip'] = preg_replace( '/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR'] );
$query['user_agent'] = (isset( $_SERVER['HTTP_USER_AGENT'] )) ? $_SERVER['HTTP_USER_AGENT'] : '';
$query['referrer'] = (isset( $_SERVER['HTTP_REFERER'] )) ? $_SERVER['HTTP_REFERER'] : '';
$query['blog'] = get_option( 'home' );
$query['blog_lang'] = get_locale(); // default 'en_US'
$query['blog_charset'] = get_option( 'blog_charset' );
$query['comment_type'] = 'forum-post'; //For more info http://bit.ly/2bVOMay
@marcelotorres
marcelotorres / wc_custom_cat_product_links.php
Last active August 22, 2019 18:49
Create Custom URL structure for specific Post category
@marcelotorres
marcelotorres / core-blocks-list-cpt-register.php
Last active March 25, 2022 13:41
Gutenberg Templates: Core Blocks List in CPT register
<?php
[...]
'template' =>
array(
array('core/archives'),
array('core/audio'),
array('core/block'),
array('core/button'),
array('core/categories'),
<?php
function delete_associated_post( $post_id ) {
if( get_post_type( $post_id ) === 'books' ){
$medias = get_children( array(
'post_parent' => $post_id,
'post_type' => 'attachment'
) );
@marcelotorres
marcelotorres / Deletar anexos automaticamente ao deletar um post no WordPress
Created October 22, 2018 02:30
Por padrão o WordPress não exclui os anexos(imagens, PDF...) de um post quando você exclui o post, ao invés ... https://www.marcelotorresweb.com/deletar-anexos-automaticamente-ao-deletar-um-post-no-wordpress/
function delete_associated_post( $post_id ) {
if( get_post_type( $post_id ) === 'books' ){
$medias = get_children( array(
'post_parent' => $post_id,
'post_type' => 'attachment'
) );
if( $medias ){
@marcelotorres
marcelotorres / Adicionando campos customizados na resposta da REST API do WordPress
Created October 14, 2018 00:37
Muitas vezes necessitamos usar mais do que os valores padrão do post que o WordPress disponibiliza, tanto para facilitar o uso dos dados, quanto para diminuir o número de requisições... https://www.marcelotorresweb.com/adicionando-campos-customizados-na-resposta-da-rest-api-do-wordpress
<?php
/**
* Show custom fields in REST API
*/
// Callback function
function get_post_meta_for_api( $object ) {
$more_post_meta['featured_media_url'] = get_the_post_thumbnail_url( $object['id'], 'medium' );
@marcelotorres
marcelotorres / fontawesome-5.3.1.json
Last active October 2, 2018 14:26
Font Awesome - 5.3.1 - All icons ids
{
"500px":{},
"accessible-icon":{},
"accusoft":{},
"ad":{},
"address-book":{},
"address-card":{},
"adjust":{},
"adn":{},
"adversal":{},
@marcelotorres
marcelotorres / custom_admin_product_option.php
Created July 13, 2017 23:02
WooCommerce - Customizar as opções de tipos de produtos
<?php
function custom_admin_product_option($options){
$options = array(
'virtual' => array(
'id' => '_virtual',
'wrapper_class' => 'show_if_simple',
'label' => __( 'Virtual', 'woocommerce' ),
'description' => __( 'Virtual products are intangible and aren\'t shipped.', 'woocommerce' ),
'default' => 'yes', //Alterado
@marcelotorres
marcelotorres / functions.php
Last active March 14, 2017 20:19
Customizando a saída de texto da tag 'title' e a 'meta description' ao usar o plugin Yoast SEO
<?php
add_filter('wpseo_title', 'filter_wpseo_title');
function filter_wpseo_title($title) {
if( is_tax( 'mes-alimento') ) {
$title = 'Frutas, verduras e legumes do mês de '.ucfirst(strftime("%B", mktime(0, 0, 0, get_queried_object()->slug) )); // Mostra o nome do mês e não o numero
}
return $title;
}
add_filter('wpseo_metadesc', 'filter_wpseo_description');
<?php
/**
** convert input array to a csv file and force downlaod the same
**
** should be called before any output is send to the browser
** input array should be an associative array
** the key of the associative array will be first row of the csv file
**
** @link http://perials.com/php-function-convert-array-csv-file-download/ Original post - Php function to convert an array to CSV file for download
** @param array $array