The following plugin is a gambiarra to exchange ids="
for include="
each time a post is saved.
Take into account the following:
You have to enable the search and switch option in all posts when the plugin is enabled. I suggest a database backup if you use this option.
You have to adjust the function get_cpt_sopt_27852()
if you want to add other post types (pages, custom posts, like gallery or portfolio).
The search/replace is very basic. The ideal would be a Regex... The initial search is by [gallery
, if yes and if the post has ids="
, this will be replaced by include="
.
<?php
/**
* Plugin Name: (SOPT) Ajustar Gallery shortcode para PostgreSQL
* Plugin URI: /a/28228/201
* Description: Gambiarra para evitar erro no plugin de PostgreSQL.
* Author: brasofilo
* License: GPLv3
*/
# HABILITAR O SEGUINTE PARA ATUALIZAR TODOS OS POSTS NA ATIVAÇÃO DO PLUGIN
// register_activation_hook( __FILE__, 'ativar_sopt_27852' );
add_action( 'save_post', 'salvar_sopt_27852', 10, 2 );
/**
* Função auxiliar para definir os Post Types do plugin
*
# AJUSTAR array conforme necessário
*/
function get_cpt_sopt_27852()
{
return array( 'post', 'page', 'portfolio' );
}
/**
* Disparada na ativação do plugin
*
* Atualiza todos os posts/post-types já publicados
*/
function ativar_sopt_27852()
{
$args = array(
'post_type' => get_cpt_sopt_27852(),
'numberposts' => -1,
'post_status' => 'published'
);
$posts = get_posts( $args );
foreach ( $posts as $post )
{
if( FALSE !== strpos( $post->post_content, '[gallery' ) )
{
if( FALSE !== strpos( $post->post_content, 'ids="' ) )
{
$post->post_content = str_replace( 'ids="', 'include="', $post->post_content );
wp_update_post( $post );
}
}
}
}
/**
* Disparada a cada "Guardar" ou "Atualizar"
*/
function salvar_sopt_27852( $post_id, $post )
{
// Auto save?
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// Correct post_type
if ( !in_array( $post->post_type, get_cpt_sopt_27852() ) )
return;
if( FALSE !== strpos( $post->post_content, '[gallery' ) )
{
if( FALSE !== strpos( $post->post_content, 'ids="' ) )
{
$post->post_content = str_replace( 'ids="', 'include="', $post->post_content );
# Evita loop do plugin
remove_action( 'save_post', 'salvar_sopt_27852' );
wp_update_post( $post );
add_action( 'save_post', 'salvar_sopt_27852', 10, 2 );
}
}
}
What version of WP?
– Blau
Wordpress Version 3.9.1
– Flávia Amaral
I don’t think that’s the problem, because at the end of the day,
ids
is converted intoinclude
in shortcode processing. Or if you use[gallery include="1,2,3,4,5"]
works? What solution are you using to run Posgresql? Have you read this?– brasofilo
PG4WP plugin to run Postgre
– Flávia Amaral
There are some tips to fix the plugin on Not Working with 3.9... I asked two other questions in my previous comment...
– brasofilo
When I use [gallery include="1,2,3,4,5"] it works. This plugin repair tip I had already made.
– Flávia Amaral