Plugin de funcionalidades para quitar funciones de functions.php (http://unaiyecora.com/diseno-web/wordpress/plugin-de-funcionalidades-en-lugar-de-functions-php)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Functionality plugin for [Name of your site] | |
Plugin URI: http://unaiyecora.com/writings/how-to-make-a-functionality-plugin-instead-of-using-functions-php/ | |
Description: Move most of your functions outside of functions.php | |
Author: Unai Yécora | |
Version: 1.0 | |
Author URI: http://www.unaiyecora.com/ | |
License: GPL2 | |
*/ | |
////////////////////////////////////////////////////////// | |
// Add a secret menu with every WordPress configuration | |
// to your admin dashboard | |
////////////////////////////////////////////////////////// | |
function all_settings_link() { | |
add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php'); | |
} | |
add_action('admin_menu', 'all_settings_link'); | |
////////////////////////////////////////////////////////// | |
// Include Google Analytics | |
////////////////////////////////////////////////////////// | |
add_action('wp_head', 'add_googleanalytics'); | |
function add_googleanalytics() { ?> | |
<!-- Put your Google Analytics code here --> | |
<?php } | |
////////////////////////////////////////////////////////// | |
// Custom logo in login page | |
////////////////////////////////////////////////////////// | |
add_filter( 'login_headerurl', 'namespace_login_headerurl' ); | |
/** | |
* Replaces the login header logo URL | |
* @param $url | |
*/ | |
function namespace_login_headerurl( $url ) { | |
$url = home_url( '/' ); | |
return $url; | |
} | |
add_filter( 'login_headertitle', 'namespace_login_headertitle' ); | |
/** | |
* Replaces the login header logo title | |
* @param $title | |
*/ | |
function namespace_login_headertitle( $title ) { | |
$title = get_bloginfo( 'name' ); | |
return $title; | |
} | |
add_action( 'login_head', 'namespace_login_style' ); | |
/** Replaces the login header logo */ | |
function namespace_login_style() { | |
echo '<style>.login h1 a { background-image: url( ' . get_stylesheet_directory_uri() . '/images/logo.png ) !important; }</style>'; | |
} | |
////////////////////////////////////////////////////////// | |
// Remove WP version info from headers and feed to | |
// improve security | |
////////////////////////////////////////////////////////// | |
function complete_version_removal() { | |
return ''; | |
} | |
add_filter('the_generator', 'complete_version_removal'); | |
////////////////////////////////////////////////////////// | |
// Delay sending new posts to the feed (for 15 minutes) | |
////////////////////////////////////////////////////////// | |
function publish_later_on_feed($where) { | |
global $wpdb; | |
if (is_feed()) { | |
// timestamp in WP-format | |
$now = gmdate('Y-m-d H:i:s'); | |
// value for wait; + device | |
$wait = '15'; // integer | |
// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff | |
$device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | |
// add SQL-sytax to default $where | |
$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait "; | |
} | |
return $where; | |
} | |
add_filter('posts_where', 'publish_later_on_feed'); | |
////////////////////////////////////////////////////////// | |
// Define a maximum number of post revisions to be | |
// stored (default = infinite) — This function will be | |
// override if parameter is defined in wp-condig.php | |
////////////////////////////////////////////////////////// | |
if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 12); | |
////////////////////////////////////////////////////////// | |
// Disable WordPress emoji extra code bloat for better | |
// page speed (emojis will keep working on modern browsers) | |
////////////////////////////////////////////////////////// | |
function disable_wp_emojicons() { | |
remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); | |
remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); | |
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); | |
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' ); | |
add_filter( 'emoji_svg_url', '__return_false' ); | |
} | |
add_action( 'init', 'disable_wp_emojicons' ); | |
function disable_emojicons_tinymce( $plugins ) { | |
if ( is_array( $plugins ) ) { | |
return array_diff( $plugins, array( 'wpemoji' ) ); | |
} else { | |
return array(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Functionality plugin for [Name of your site] | |
Plugin URI: http://unaiyecora.com/writings/how-to-make-a-functionality-plugin-instead-of-using-functions-php/ | |
Description: Move most of your functions outside of functions.php | |
Author: Unai Yécora | |
Version: 1.0 | |
Author URI: http://www.unaiyecora.com/ | |
License: GPL2 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Plugin de funcionalidades para [Nombre de tu web] | |
Plugin URI: http://unaiyecora.com/writings/crear-plugin-de-funcionalidades-en-lugar-de-usar-functions-php/ | |
Description: Mueve la mayoría de tus funciones fuera de functions.php | |
Author: Unai Yécora | |
Version: 1.0 | |
Author URI: http://www.unaiyecora.com/ | |
License: GPL2 | |
*/ | |
////////////////////////////////////////////////////////// | |
// Añade un menú secreto con todas las opciones de | |
// configuración de WordPress a tu panel de administración | |
////////////////////////////////////////////////////////// | |
function all_settings_link() { | |
add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php'); | |
} | |
add_action('admin_menu', 'all_settings_link'); | |
////////////////////////////////////////////////////////// | |
// Google Analytics | |
////////////////////////////////////////////////////////// | |
add_action('wp_head', 'add_googleanalytics'); | |
function add_googleanalytics() { ?> | |
<!-- Añade el código de Google Analytics --> | |
<?php } | |
////////////////////////////////////////////////////////// | |
// Logo personalizado en la pagina de login | |
////////////////////////////////////////////////////////// | |
add_filter( 'login_headerurl', 'namespace_login_headerurl' ); | |
/** | |
* Reemplaza la URL del logo del formulario de login | |
* @param $url | |
*/ | |
function namespace_login_headerurl( $url ) { | |
$url = home_url( '/' ); | |
return $url; | |
} | |
add_filter( 'login_headertitle', 'namespace_login_headertitle' ); | |
/** | |
* Reemplaza el título del logo del formulario de login | |
* @param $title | |
*/ | |
function namespace_login_headertitle( $title ) { | |
$title = get_bloginfo( 'name' ); | |
return $title; | |
} | |
add_action( 'login_head', 'namespace_login_style' ); | |
/* Reemplaza el logo del formulario de login */ | |
function namespace_login_style() { | |
echo '<style>.login h1 a { background-image: url( ' . get_stylesheet_directory_uri() . '/images/logo.png ) !important; }</style>'; | |
} | |
////////////////////////////////////////////////////////// | |
// Eliminar información sobre la versión de WP de | |
// headers y feeds para mejorar la seguridad | |
////////////////////////////////////////////////////////// | |
function complete_version_removal() { | |
return ''; | |
} | |
add_filter('the_generator', 'complete_version_removal'); | |
////////////////////////////////////////////////////////// | |
// Retrasar el envío de nuevas entradas al feed (15 min) | |
////////////////////////////////////////////////////////// | |
function publish_later_on_feed($where) { | |
global $wpdb; | |
if (is_feed()) { | |
// fecha y hora en el formato de WP | |
$now = gmdate('Y-m-d H:i:s'); | |
// valor a esperar; | |
$wait = '15'; // numero entero | |
// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff | |
$device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | |
// añadir syntax SQL al $where por defecto | |
$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait "; | |
} | |
return $where; | |
} | |
add_filter('posts_where', 'publish_later_on_feed'); | |
////////////////////////////////////////////////////////// | |
// Define un máximo de revisiones de posts para ser | |
// almacenadas (default = infinito) — Esta función será | |
// ignorada si el parámetro está definido en wp-config.php | |
////////////////////////////////////////////////////////// | |
if (!defined('WP_POST_REVISIONS')) define('WP_POST_REVISIONS', 12); | |
////////////////////////////////////////////////////////// | |
// Desactivar el código extra de WordPress para emojis | |
// para mejorar la velocidad de carga (los emojis seguirán | |
// funcionando en navegadores modernos) | |
////////////////////////////////////////////////////////// | |
function disable_wp_emojicons() { | |
remove_action( 'admin_print_styles', 'print_emoji_styles' ); | |
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); | |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); | |
remove_action( 'wp_print_styles', 'print_emoji_styles' ); | |
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); | |
remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); | |
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); | |
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' ); | |
add_filter( 'emoji_svg_url', '__return_false' ); | |
} | |
add_action( 'init', 'disable_wp_emojicons' ); | |
function disable_emojicons_tinymce( $plugins ) { | |
if ( is_array( $plugins ) ) { | |
return array_diff( $plugins, array( 'wpemoji' ) ); | |
} else { | |
return array(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Plugin de funcionalidades para [Nombre de tu web] | |
Plugin URI: http://unaiyecora.com/writings/crear-plugin-de-funcionalidades-en-lugar-de-usar-functions-php/ | |
Description: Mueve la mayoría de tus funciones fuera de functions.php | |
Author: Unai Yécora | |
Version: 1.0 | |
Author URI: http://www.unaiyecora.com/ | |
License: GPL2 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment