Skip to content

Instantly share code, notes, and snippets.

@donini
donini / 16-move-post-between-sites.php
Last active June 5, 2020 13:35
Move Posts Between WordPress Sites
<?php
add_filter( 'bulk_actions-edit-post', 'move_posts_bulk_multisite_actions' );
function move_posts_bulk_multisite_actions( $bulk_array ) {
if( $sites = get_sites( array(
'site__not_in' => get_current_blog_id(), // excluding current blog
'number' => 50,
))) {
foreach( $sites as $site ) {
@donini
donini / 15-add-custom-class-to-your-body-element.php
Last active September 18, 2019 14:11
Add Custom Class To Your Body Element
<?php
add_filter('body_class', 'add_slug_to_body_class');
public function add_slug_to_body_class( $classes ) {
global $post;
if ( is_home() ) {
$key = array_search( 'blog', $classes );
if ( $key > -1 ) {
unset( $classes[$key] );
}
@donini
donini / .htaccess
Last active September 18, 2019 00:16
14- Leverage Browser Caching using .htaccess
#Customize expires cache start - adjust the period according to your needs
<IfModule mod_expires.c>
FileETag MTime Size
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
ExpiresActive On
ExpiresByType text/html "access 600 seconds"
ExpiresByType application/xhtml+xml "access 600 seconds"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType text/javascript "access 1 month"
@donini
donini / 13-run-task-before-activate-plugin.php
Created September 14, 2019 01:48
13-run-task-before-activate-plugin.php
<?php
register_activation_hook( __FILE__, 'activation_check' );
/* Test before activate the plugin */
function activation_check() {
if ( ! is_plugin_active( 'pods/init.php' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( 'The plugin <a href="https://www.pods.io/">PODS</a> is prerequisite to run this Plugin.</p>' );
}
}
@donini
donini / 12-hide-admin-bar.php
Created September 14, 2019 01:41
12-hide-admin-bar.php
<?php
add_filter('show_admin_bar', '__return_false');
<?php
add_action( 'admin_notices', 'admin_notice__success' );
function admin_notice__success() {
$class = 'notice notice-success is-dismissible';
$message = __( 'Completelly with success!', 'text_domain' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
add_action( 'admin_notices', 'admin_notice__error' );
<?php
add_filter( 'bulk_actions-edit-post', 'new_bulk_actions' );
function new_bulk_actions( $bulk_actions ) {
$bulk_actions['send_by_email'] = __( 'Send By E-mail', 'text_domain' );
return $bulk_actions;
}
add_filter( 'handle_bulk_actions-edit-post', 'new_bulk_action_handler', 10, 3 );
function new_bulk_action_handler( $redirect_to, $doaction, $post_ids ) {
/* Exit if it's not send by email action */
<?php
add_filter( 'cron_schedules', 'add_cron_interval' );
function add_cron_interval( $intervals ) {
/* Add new cron interval */
$intervals['one_minute'] = array(
'interval' => 60, /* It's not recomended cron schedules with less then 15 minutes */
'display' => esc_html__( 'Every minute' ),
);
@donini
donini / 8-hide-wordpress-updates.php
Created September 7, 2019 21:08
8-hide-wordpress-updates.php
<?php
add_filter( 'pre_site_transient_update_core', 'remove_core_updates' ); /* Hide WordPress Core updates */
add_filter( 'pre_site_transient_update_plugins', 'remove_core_updates' ); /* Hide Plugins updates */
add_filter( 'pre_site_transient_update_themes', 'remove_core_updates' ); /* Hide Theme updates */
/* Hide update notifications */
function remove_core_updates(){
global $wp_version;
return (object) array(
@donini
donini / 7-add-new-taxonomy-filter.php
Last active September 7, 2019 20:57
7-add-new-taxonomy-filter.php
<?php
add_action( 'restrict_manage_posts', 'filter_posts_by_topics', 10, 2 );
function filter_posts_by_topics( $post_type, $which ) {
/* Apply this only on a specific post type */
if ( 'post' !== $post_type ) {
return;
}