Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Taller WPO - Carga condicional de plugins

58,273 views

Published on

Uno de los factores más desconocidos y que más beneficio aporta en las estrategias de WPO es la carga condicional de plugins, dependiendo del entorno, página, tipo de llamada, usuario.... y que es distinto de cada proyecto. Aprende a desarrollar un plugin que controle la carga condicional de los plugins instalados y activos, cómo manejarlo en multitud de escenarios posibles y mejorar el rendimiento de tu sitio reduciendo notablemente la carga en el servidor.
Aquí el video del taller impartido en WC Zaragoza 2019 - https://wordpress.tv/2019/01/27/fernando-puente-taller-wpo-carga-condicional-de-plugins/

Published in: Internet
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://shorturl.at/krvUW } ......................................................................................................................... Download Full EPUB Ebook here { http://shorturl.at/krvUW } ......................................................................................................................... Download Full doc Ebook here { http://shorturl.at/krvUW } ......................................................................................................................... Download PDF EBOOK here { http://shorturl.at/krvUW } ......................................................................................................................... Download EPUB Ebook here { http://shorturl.at/krvUW } ......................................................................................................................... Download doc Ebook here { http://shorturl.at/krvUW } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://shorturl.at/krvUW } ......................................................................................................................... Download Full EPUB Ebook here { http://shorturl.at/krvUW } ......................................................................................................................... Download Full doc Ebook here { http://shorturl.at/krvUW } ......................................................................................................................... Download PDF EBOOK here { http://shorturl.at/krvUW } ......................................................................................................................... Download EPUB Ebook here { http://shorturl.at/krvUW } ......................................................................................................................... Download doc Ebook here { http://shorturl.at/krvUW } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Taller WPO - Carga condicional de plugins

  1. 1. Taller WPO
 Carga condicional de plugins Fernando Puente @fpuenteonline
  2. 2. BIO @fpuenteonline - Informático de vocación y de profesión, formador ocasional y beginner de comer y beber. Desde 1996 trabajando en TI, los últimos 12 en medios de comunicación online y comercio electrónico •  Consultor Enterprise en SiteGround •  Consultor Desarrollo de Negocio en YITH •  CTO de Exprime Viajes y Dormir de Chollo •  Formador en Fundación COPE •  Consultor freelance especializado en performance
  3. 3. WPO y WordPress
  4. 4. La carga condicional
  5. 5. Recordatorio WPO no es velocidad
  6. 6. Estrategia para reducir… •  El tiempo de respuesta al navegador: menor TTFB •  La carga innecesaria de código: mejor rendimiento del servidor •  El número de recursos necesarios por la página: carga total de página más rápida
  7. 7. La magia, crearla antes de la carga de plugins, en un MU-plugin: add_filter( 'option_active_plugins', callable $function_to_add, 1);
  8. 8. Notas finales •  Técnica MUY peligrosa, necesario conocer en detalle el sitio y el funcionamiento de los plugins objetivo y del tema activo •  Crear condiciones programáticas para cada caso concreto que deseemos controlar •  A medida de cada proyecto web, no existe un estándar
  9. 9. ¡Vamos al taller!
  10. 10. Esquema de trabajo Creación de un MU Plugin para la gestión de la carga condicional de los plugins activos en el sitio: •  Sobre la instalación de WordPress, crear si no existe el directorio wp-content/mu-plugins •  Crear un fichero php, fichero de nuestro plugin, sobre ese directorio para ser ejecutado antes de los plugins activos •  Los plugins MU (must-use) se ejecutan alfabéticamente, por lo que se recomienda utilizar un nombre de fichero adecuado El objetivo es “engañar” a WordPress para que cargue menos plugins de los que realmente están activos en el sitio
  11. 11. Ejemplos y usos
  12. 12. <?php //Uso: mostrar la carga de WP hasta el MU-Plugin y listado de plugins activos en BD add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ print_r($plugin_list); debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); exit; }
  13. 13. <?php //Ejemplo: no cargar el plugin AMP (sin condición) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ unset( $plugin_list[array_search( 'amp/amp.php', $plugin_list)]); return $plugin_list; }
  14. 14. <?php //Uso: cómo habilitar el filtro sólo para el front-end if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ print_r($plugin_list); debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); exit; }
  15. 15. <?php //Uso: medir el impacto de una URL sin ningún plugin activo //http://example.com/url-2-test/?sinplugins if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ if(isset($_GET['sinplugins'])) return array(); else return $plugin_list; }
  16. 16. <?php //Uso: medir el impacto de una URL sin un plugin concreto (según el índice del listado de activos) //http://example.com/url-2-test/?sinplugins=1 if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ if(isset($_GET['sinplugins'])) unset( $plugin_list[$_GET['sinplugins']] ); return $plugin_list; }
  17. 17. <?php //ERROR: no podemos utilizar condiciones is_single() o similares if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ if(!is_single()) unset( $plugin_list[array_search( 'amp/amp.php', $plugin_list)]); return $plugin_list; }
  18. 18. <?php //Ejemplo: no cargar en la home los plugins no necesarios //Condiciones por URL solicitada if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ $request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); if ($request_uri === '/') { unset( $plugin_list[array_search( 'mailchimp-for-woocommerce/mailchimp-woocommerce.php', $plugin_list)]); unset( $plugin_list[array_search( 'woo-gutenberg-products-block/woocommerce-gutenberg- products-block.php', $plugin_list)]); unset( $plugin_list[array_search( 'woocommerce-gateway-paypal-express-checkout/woocommerce- gateway-paypal-express-checkout.php', $plugin_list)]); unset( $plugin_list[array_search( 'woocommerce-gateway-stripe/woocommerce-gateway- stripe.php', $plugin_list)]); unset( $plugin_list[array_search( 'woocommerce/woocommerce.php', $plugin_list)]); } return $plugin_list; }
  19. 19. <?php //Ejemplo: no cargar en el front-end los plugins que son sólo de uso en el back-end if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ unset( $plugin_list[array_search( 'broken-link-checker/broken-link-checker.php', $plugin_list)]); unset( $plugin_list[array_search( 'classic-editor/classic-editor.php', $plugin_list)]); unset( $plugin_list[array_search( 'duplicate-post/duplicate-post.php', $plugin_list)]); unset( $plugin_list[array_search( 'updraftplus/updraftplus.php', $plugin_list)]); unset( $plugin_list[array_search( 'wp-smushit/wp-smush.php', $plugin_list)]); return $plugin_list; }
  20. 20. <?php //Ejemplo: carga condicional del plugin CF7 sólo para una URL concreta //ERROR: el plugin usa otra URL para enviar los datos del formulario if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ $request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); if ($request_uri != '/contacto/') { unset( $plugin_list[array_search( 'contact-form-7/wp-contact-form-7.php', $plugin_list)]); } return $plugin_list; }
  21. 21. <?php //Ejemplo: carga condicional del plugin CF7 sólo para una URL concreta //CORREGIDO: incluidas las URL necesarias para el plugin if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ $request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $is_cf7_needed = ($request_uri === '/contacto/' || strpos( $request_uri, '/wp-json/contact- form-7/v1/contact-forms/') !== false); if (!$is_cf7_needed) { unset( $plugin_list[array_search( 'contact-form-7/wp-contact-form-7.php', $plugin_list)]); } return $plugin_list; }
  22. 22. <?php //Ejemplo: carga condicional de plugins por entorno de ejecución if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ if( $_SERVER['HTTP_HOST'] === 'localhost' ) { $plugins_to_disable = array( 'updraftplus/updraftplus.php', 'wordpress-seo/wp-seo.php', 'wp-smushit/wp-smush.php', 'wps-hide-login/wps-hide-login.php'); $plugin_list = array_diff( $plugin_list, $plugins_to_disable ); } return $plugin_list; }
  23. 23. <?php //Ejemplo: carga condicional de plugin para usuarios conectados if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ require (ABSPATH . WPINC . '/pluggable.php'); if ( is_user_logged_in() ) { unset( $plugin_list[array_search( 'cookie-law-info/cookie-law-info.php', $plugin_list)]); } return $plugin_list; }
  24. 24. <?php //Ejemplo: carga condicional de plugins cuando se ejecuta wp-cron if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ $request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); if ($request_uri === '/wp-cron.php' ) { $plugins_to_disable = array( 'advanced-custom-fields/acf.php', 'classic-editor/classic-editor.php', 'duplicate-post/duplicate-post.php', 'wps-hide-login/wps-hide-login.php'); $plugin_list = array_diff( $plugin_list, $plugins_to_disable ); } return $plugin_list; }
  25. 25. <?php //Ejemplo: carga condicional de plugin por horas cuando se ejecuta wp-cron if(!is_admin()) add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ $request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); if ($request_uri === '/wp-cron.php' ) { //Habilitar Broken link checker sólo por la noche if(current_time('H') >= 7 && current_time('H') <=23 ) unset( $plugin_list[array_search( 'broken-link-checker/broken-link-checker.php', $plugin_list)]); } return $plugin_list; }
  26. 26. <?php //Uso: mejorar la carga de las llamadas AJAX en back-end add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ if ( wp_doing_ajax() ) { if($_POST['action'] === 'blc_work' || $_GET['action'] === 'blc_dashboard_status') return array('broken-link-checker/broken-link-checker.php'); if($_POST['action'] === 'gadwp_backend_item_reports') return array('google-analytics-dashboard-for-wp/gadwp.php'); if($_POST['action'] === 'sucuriscan_ajax') return array('sucuri-scanner/sucuri.php'); if($_POST['action'] === 'heartbeat') return array(); } return $plugin_list; }
  27. 27. <?php //Ejemplo: carga condicional del plugin AMP para un sitio concreto dentro de una instalación multisite add_filter( 'option_active_plugins', 'WCZGZ_option_active_plugins', 1); add_filter( 'site_option_active_sitewide_plugins', 'WCZGZ_option_active_plugins', 1); function WCZGZ_option_active_plugins( $plugin_list ){ global $current_blog; if( $current_blog->blog_id == 2 ) { unset( $plugin_list[array_search( 'amp/amp.php', $plugin_list)]); } return $plugin_list; }
  28. 28. Ya conoces la estrategia de carga condicional para WPO, ¡creatividad al poder!
  29. 29. "Let's be careful out there“ Fernando Puente @fpuenteonline Muchas gracias

×