Last active
May 17, 2019 20:15
-
-
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
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: 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