Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brandonjp/a0a07c1a1528cbe71c00d9fc7ea6f684 to your computer and use it in GitHub Desktop.
Save brandonjp/a0a07c1a1528cbe71c00d9fc7ea6f684 to your computer and use it in GitHub Desktop.
Code Snippets Pro: Add Filetype to Export Buttons - WP
<? // <- remove this line if you copy/paste into Code Snippets Pro
/**
* Code Snippets Pro: Add Filetype to Export Buttons
*
* In the Code Snippets Pro interface, I always forget which button Downloads the PHP snippet and which Exports the JSON, so this snippet simply appends the filetype onto the button text.
*/
namespace bhT0Vm4;
if (\current_user_can('manage_options')) {
\add_action( 'admin_footer', '\bhT0Vm4\add_filetype_to_btns' );
function add_filetype_to_btns() {
global $pagenow;
$editPage = isset($_GET['page']) && ('edit-snippet' === $_GET['page']);
$pages = array('admin.php',);
if (in_array($pagenow,$pages) && $editPage) {
?>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', ()=>{
function appendBtnText(btnID,appendText) {
let btn = document.querySelector('input#'+btnID);
if (btn) btn.value = (btn.value + " " + appendText).trim();
}
appendBtnText('download_snippet',' PHP');
appendBtnText('export_snippet',' JSON');
});
</script>
<?php }
}
}
@brandonjp
Copy link
Author

In the Code Snippets Pro interface, I always forget which button Downloads the PHP snippet and which Exports the JSON, so this snippet simply appends the filetype onto the button text.

CleanShot 2023-01-18 at 15 02 03@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment