wp cli tricks

wp post delete $(wp post list –post_type=’post’ –s=’keyword here’ –format=ids) –force

Tweaking OneSignal WordPress Plugin

/** * Send push based on last active time (Intelligent Delivery). */ add_filter( ‘onesignal_send_notification’, function( $fields ) { $fields[‘delayed_option’] = ‘last-active’; return $fields; }); /** * Always set notification unchecked in post editor. */ add_filter( ‘onesignal_meta_box_send_notification_checkbox_state’, ‘__return_false’ ); /** *

Tweaking WordPress

/** * Logged in for 1 year. */ add_filter( ‘auth_cookie_expiration’, function() { return YEAR_IN_SECONDS; });

Clear cache in WP Rocket when post permalink (slug) changes

To learn more about the issue: https://github.com/wp-media/wp-rocket/issues/1936 Fix: // Fires before an existing post is updated in the database. add_action( ‘pre_post_update’, function( $post_ID, $data ) { // compare slug, if changed clear cache. if ( get_post_field( ‘post_name’, $post_ID ) !=

Use statically.io CDN with WP Offload Media

add_filter( ‘as3cf_get_attachment_url’, function( $url ) { // matches http and https both. $url = ‘https://cdn.statically.io/img/’. preg_replace( ‘#^https?://#’, ”, $url ) .”; return $url; }); More hooks: https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront-tweaks/blob/master/amazon-s3-and-cloudfront-tweaks.php

Use Rocket-Nginx under RunCloud

Login as root then enter following commands. cd /etc/nginx-rc git clone https://github.com/satellitewp/rocket-nginx.git cd rocket-nginx cp rocket-nginx.ini.disabled rocket-nginx.ini php rocket-parser.php As of version 2.1.1 there is a typo in the rocket-nginx.ini ,ย change media_header to medias_header My template: https://gist.github.com/Dibbyo456/2b08a4ff74665ccc40e0985b8f22292a Create file {app-name}.location.main-before.rocket.conf

Tweaking WP Rocket

Edit function get_subscribed_events() on /wp-rocket/inc/classes/subscriber/admin/Settings/class-page-subscriber.php //[ ‘add_imagify_page’, 9 ], Edit function render_page() onย  /wp-rocket/inc/classes/admin/settings/class-page.php /*$this->heartbeat_section(); $this->addons_section(); $this->cloudflare_section(); $this->sucuri_section();*/ Add to functions.php or wp-rocket.php /** * Clean Up WP Rocket. */ add_action( ‘init’, function() { // Hide account info. defined( ‘WP_ROCKET_WHITE_LABEL_ACCOUNT’

Optimal Settings & Tweaking UpdraftPlus

Optimal Settings: Untick โŒ -> UpdraftPlus Automatic Backups Untick โŒ -> Automatic updates Tick โœ… -> Backup more databases Tick โœ… -> Delete local backup Tweaking: Add below codes to: updraftplus.php /* Disable top admin bar */ defined( ‘UPDRAFTPLUS_ADMINBAR_DISABLE’ )

Disable cURL SSL verification in WordPress

/** * Don’t verify SSL certificates */ add_action( ‘http_api_curl’, function( $handle ) { curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, false ); });

Use WP Smush without slowing down WordPress

I use WP Smush to compress images in WordPress. But lately the plugin became extremely slow because of excessive database queries. The media library takes 10 seconds to open while the plugin is active but takes only 2 seconds when

WP Rocket Hooks

after_rocket_clean_post action is fired after clear cache of a post. add_action( ‘after_rocket_clean_post’, function( $post ) { if ( $post->post_name == ‘foo’ ) { rocket_clean_files( ‘https://example.com/foo/’ ); } }); after_rocket_clean_domain action is fired after clear cache of whole domain (clear all

WP Smush using WP-CLI

If you use WP Smush then you should know that you can use it via WP-CLI too. This feature became available since the version 3.1 Here are some commands: /** * Optimize image. * * ## OPTIONS * * [–type=<type>]

Remove any action or filter in WordPress

Sometimes we need to remove actions or filters added via Themes or Plugins. To remove a action or filter check mekshq.com’s guide. But sometimes that is not enough, sometimes some hooks are too stubborn to remove. In that case use

Delete comment replies when deleting comment in WordPress

By default when a comment is deleted, WordPress does not delete the replies of that comment. With this function whenever comment is deleted, its replies will be automatically deleted. /** * Delete comment replies when deleting comment. */ add_action( ‘delete_comment’,