Created
November 19, 2021 07:13
-
-
Save ThemeSama/f1a37ca4f7ff214768782a8a27487f08 to your computer and use it in GitHub Desktop.
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 | |
// 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