admin管理员组

文章数量:1134589

I need the code to replace a post to be executed when publishing, it asks me for the ''updateSaved'' function.

function actualizacionPost($condicion){
                        
                        if($condicion == 0){
                            $args = [
                                'post_type' => array('page','post'),
                                    'numberposts' => -1,
                                ];
                            $posts = get_posts($args);

                            foreach($posts as $post){
                                $contenido_modificado = preg_replace_callback('/\[et_pb_section[^\]]*\]/i', function($matches) {
                                    $seccion = $matches[0];
                                
                                    if (preg_match('/hover_transition_duration="/i', $seccion)) {
                                        // Si existe 
                                        $seccion = preg_replace('/hover_transition_duration="[^"]*"/i', 'hover_transition_duration="0ms"', $seccion);
                                    } else {
                                        // En caso de que esté por defecto, no existe, entonces se agrega
                                        $seccion = preg_replace('/\]/', ' hover_transition_duration="0ms"]', $seccion);
                                    }
                                
                                    return $seccion;
                                }, $post->post_content);
                                
                                
                                $post = array(
                                    'ID'           => $post-> ID,
                                    'post_content' => $contenido_modificado,
                                );
                            
                                wp_update_post( $post );
                                
                            }
                        }
                        else{
                            $args = [
                                'post_type' => array('page','post'),
                                    'p' => $condicion,
                                ];
                            $posts = get_posts($args);

                            $contenido_modificado = preg_replace_callback('/\[et_pb_section[^\]]*\]/i', function($matches) {
                                $seccion = $matches[0];
                            
                                if (preg_match('/hover_transition_duration="/i', $seccion)) {
                                    // Si existe 
                                    $seccion = preg_replace('/hover_transition_duration="[^"]*"/i', 'hover_transition_duration="0ms"', $seccion);
                                } else {
                                    // En caso de que esté por defecto, no existe, entonces se agrega
                                    $seccion = preg_replace('/\]/', ' hover_transition_duration="0ms"]', $seccion);
                                }
                            
                                return $seccion;
                            }, $posts);

                            $post = array(
                                'ID'           => $condicion,
                                'post_content' => $contenido_modificado,
                            );
                        
                            wp_update_post( $post );
                        }
                        
                        foreach($posts as $post){
                            $contenido_modificado = preg_replace_callback('/\[et_pb_section[^\]]*\]/i', function($matches) {
                                $seccion = $matches[0];
                            
                                if (preg_match('/hover_transition_duration="/i', $seccion)) {
                                    // Si existe 
                                    $seccion = preg_replace('/hover_transition_duration="[^"]*"/i', 'hover_transition_duration="0ms"', $seccion);
                                } else {
                                    // En caso de que esté por defecto, no existe, entonces se agrega
                                    $seccion = preg_replace('/\]/', ' hover_transition_duration="0ms"]', $seccion);
                                }
                            
                                return $seccion;
                            }, $post->post_content);
                            
                            
                            $post = array(
                                'ID'           => $post-> ID,
                                'post_content' => $contenido_modificado,
                            );
                        
                            wp_update_post( $post );
                            
                        }
                    }

                    if (false === get_transient('mi_codigo_ejecutado')) {
                        $condicion = 0;
                        actualizacionPost($condicion);
                    }
                    set_transient('mi_codigo_ejecutado', true, DAY_IN_SECONDS);

                    function actualizarGuardado(){

                        if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
                            $url = "https://"; 
                          }else{
                            $url = "http://"; 
                          }
                        $url_actual = $url . $_SERVER['HTTP_HOST'] .  $_SERVER['REQUEST_URI'];
    
                        $mypost_id = url_to_postid ($url_actual);

                        actualizacionPost($mypost_id);
                    }
                    add_action('save_post','actualizarGuardado');

本文标签: postsIt tells me that I exceeded the maximum number of executions when trying to publish content