Skip to content

Instantly share code, notes, and snippets.

View mafsdisseny's full-sized avatar

Miguel A. Fdez. mafsdisseny

View GitHub Profile
@mafsdisseny
mafsdisseny / style.css
Created March 1, 2023 16:03
styles for Contact Forms 7
/*
** Contact Form 7 Styles
*/
.wpcf7-form input[type="text"],
.wpcf7-form input[type="email"],
.wpcf7-form input[type="url"],
.wpcf7-form input[type="password"],
.wpcf7-form input[type="search"],
.wpcf7-form input[type="number"],
.wpcf7-form input[type="tel"],
@mafsdisseny
mafsdisseny / style.css
Created February 20, 2023 14:58
GeneratePress > Grids ||| Align last block (inside a container) to the bottom of the grid items
// SOURCE: https://community.generateblocks.com/t/grid-items-with-different-content-heights-aligned-bottom-block/36
//
// If you have grid items in a row with different height contents,
// you may want to pin the last block (a button, for example) to the bottom of the grid items
// so they all align in the row. This is a popular look with pricing tables, for example.
// As of right now, there is no option for this, but it can be done with some simple CSS.
// First, give your Container block a custom class: my-custom-class.
// Then, add the following CSS:
.my-custom-class .gb-inside-container {
@mafsdisseny
mafsdisseny / functions.php
Created February 20, 2023 14:40
GeneratePress & GenerateBlocks > Query loop block ||| Función para filtrar la salida del query loop cuando no se pueden editar las opciones desde su propia UI
// SOURCE: https://generatepress.com/forums/topic/use-query-loop-to-display-the-events-calendar-events-on-home-page/
//
// Mostrar solo eventos futuros
// GeneratePress, GenerateBlocks, ACF
// Hay que añadir clase personalizada al grid del query loop para discriminar sobre el resto de query loops
// En este caso usamos fecha en formato Ymd porque es como guarda ACF las fechas de date picker en la DB
function mafs_agenda_show_future_events( $query_args, $attributes ) {
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'mostrar-agenda-futura' ) !== false ) {
$custom_args = array(
@mafsdisseny
mafsdisseny / functions.php
Created March 15, 2019 08:57
Función que redimensiona las imágenes grandes al subirlas al sistema. Source: https://ayudawp.com/redimensionar-imagenes-grandes/
<?php
/** Redimensionar al subir la imagen completa al tamaño grande de los ajustes de medios */
/** SOURCE: https://ayudawp.com/redimensionar-imagenes-grandes/ */
function ayudawp_reemplazar_imagen_subida($image_data) {
// si no hay imagen grande : return
if (!isset($image_data['sizes']['large']))
return $image_data;
// ruta a la imagen subida y a la imagen grande
$upload_dir = wp_upload_dir();
@mafsdisseny
mafsdisseny / functions.php
Created August 29, 2016 10:31
Send a mail when a post has been updated
<?php
function mafs_updated_send_email( $post_id ) {
// If this is just a revision, don't send the email.
if ( wp_is_post_revision( $post_id ) )
return;
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';
@mafsdisseny
mafsdisseny / functions.php
Last active May 31, 2016 09:20
Limit WordPress media uploader maximum upload file size
<?php
/**
* Limit WordPress media uploader maximum upload file size
* Uploading very large images is pointless as they will hardly ever be used at full size.
* Crunching larger files takes more memory; larger files take more space too.
* @author https://gist.github.com/unfulvio/1ee103a6f86893771b5a
* @param mixed $file the uploaded file item to filter
* @return array $file the filtered file item with response
*/
@mafsdisseny
mafsdisseny / functions.php
Created May 30, 2016 16:40
ACF custom fields: Auto populate end date with the start date value, when it is empty.
<?php
// Auto-populate end date if it is empty.
function mafs_update_data_final( $value, $post_id, $field ) {
//NOTE: don't use get_field() because it retrieves the value
//in a preformatted way different as it is saved in database
$data_final = get_post_meta( $post_id, 'doc_data_final', true );
$data_inicial = get_post_meta( $post_id, 'doc_data_inici', true );
//Check if data_final is empty (when saving) and data_inicial
@mafsdisseny
mafsdisseny / functions.php
Created May 20, 2016 12:17
Función para imprimir el formulario adecuado dependiendo del idioma. Usa CF7 y Polylang. Requiere crear los formularios siguiendo unas normas de sintaxis.
<?php
// Esta función permite imprimir el formulario adecuado dependiendo del idioma.
// Lo único que hay que tener en cuenta es que cuando creamos el título del formulario
// Hay que hacerlo siguiendo esta norma: "nombre del formulario" + " __" + slug del idioma.
// Ejemplo: ESP: "formulario __es", CAT: "formulario __ca", ENG: "formulario __en"
// En este ejemplo concreto, habría que llamar la función así:
// mafs_print_currentlang_form( 'formulario' );
function mafs_print_currentlang_form( $form_name ) {
@mafsdisseny
mafsdisseny / functions.php
Last active February 12, 2016 08:53
Display the advanced tools bar of tiny_mce by default in the WordPress visual editor.
<?php
function show_advanced_tools_bar_tiny_mce( $args ) {
$args['wordpress_adv_hidden'] = false;
return $args;
}
add_filter( 'tiny_mce_before_init', 'show_advanced_tools_bar_tiny_mce' );
@mafsdisseny
mafsdisseny / functions.php
Created November 9, 2015 14:36
Creation of a custom post status for WordPress
<?php
// ----------------------------------------------------------------------
// ----------------------- Custom post status ---------------------------
// ----------------------------------------------------------------------
// "premsa" es el post status
// "publicacio" el cpt asociado.
// Create a custom post status
function mafs_new_archive_post_status() {
register_post_status( 'premsa', array(