Skip to content

Instantly share code, notes, and snippets.

@ThemeSama
Created November 19, 2021 07:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThemeSama/f1a37ca4f7ff214768782a8a27487f08 to your computer and use it in GitHub Desktop.
Save ThemeSama/f1a37ca4f7ff214768782a8a27487f08 to your computer and use it in GitHub Desktop.
<?php
// Real Media Library Disable Auto Expands
if ( !function_exists( 'rml_custom_js' ) ) {
function rml_custom_js(){
$list = wp_rml_root_childs();
$idList = [];
foreach ($list as $listItem) {
$idList[$listItem->getId()] = false;
}
$customJs = 'let rmlRootTreeList = '.json_encode($idList).';';
$customJs.= 'let rmlRootTreeLabelId = '.get_current_blog_id().';';
$customJs.= <<<EOD
let rmlTreeLocalStorageLabel = "AIOT-rml" + rmlRootTreeLabelId,
rmlTreeLocalStorageItem = window.localStorage.getItem(rmlTreeLocalStorageLabel);
if( rmlTreeLocalStorageItem && rmlTreeLocalStorageItem.includes("expandNodes") ) {
rmlTreeLocalStorageItem = JSON.parse(rmlTreeLocalStorageItem);
rmlTreeLocalStorageItem.expandNodes = rmlRootTreeList;
} else {
rmlTreeLocalStorageItem = {
"width": 250,
"rwidth": 250,
"expandNodes": rmlRootTreeList
}
}
window.localStorage.setItem(rmlTreeLocalStorageLabel, JSON.stringify(rmlTreeLocalStorageItem));
EOD;
return $customJs;
}
}
if ( !function_exists( 'rml_enqueue_custom' ) && function_exists( 'rml_custom_js' ) ) {
function rml_enqueue_custom() {
wp_add_inline_script( 'react-aiot', rml_custom_js() );
}
add_action( 'admin_enqueue_scripts', 'rml_enqueue_custom', 20 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment