Skip to content

Instantly share code, notes, and snippets.

@trepmal
Last active May 17, 2019 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trepmal/97a9e9775053f109a50057d2c7e56696 to your computer and use it in GitHub Desktop.
Save trepmal/97a9e9775053f109a50057d2c7e56696 to your computer and use it in GitHub Desktop.
Use https://github.com/voceconnect/wp-large-options/ as storage for specific widget types
<?php
// Plugin Name: WLO Widget
// register core 'text' widget
register_wlo_widget( 'text' ); // id base
/**
* hook in
*/
function register_wlo_widget( $widget_id ) {
add_filter( 'pre_option_widget_' . $widget_id, 'wlow_defer_to_wlo_get', 10, 3 );
add_filter( 'pre_update_option_widget_' . $widget_id, 'wlow_defer_to_wlo_update', 10, 3 );
add_action( 'update_option_widget_' . $widget_id, 'wlow_clean_up_option', 10, 3 );
}
/**
* get the option from wlo if possible
*/
function wlow_defer_to_wlo_get( $false, $option, $default ) {
$wlo = wlo_get_option( $option, $default );
if ( $wlo ) {
return $wlo;
}
return $false;
}
/**
* update wlo
*/
function wlow_defer_to_wlo_update( $value, $old_value, $option ) {
wlo_update_option( $option, $value );
return $value;
}
/**
* clean up original option.
* we cannot short-circuit the update call directly
*/
function wlow_clean_up_option( $old_value, $value, $option ) {
delete_option( $option );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment