Useful Tip: Code Snippets to Improve Plugin Text and Links
-
Useful Tip:
The code snippets provided below will update the WP Fastest Cache plugin links and text used in the backend and frontend to ensure homogeneity across the board and agree better with WordPress’ guidelines.
Any questions or issues, please let me know.
Enjoy!
———————
Code Snippet (Affects Backend):
/* BACKEND: Change WP Fastest Cache "Delete Cache" and "Clear Cache" Strings to "Purge Cache" */
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Clear cache files when a post or page is published' :
$translated_text = 'Purge cache files when a post or page is published';
break;
case 'Clear cache files when a post or page is updated' :
$translated_text = 'Purge cache files when a post or page is updated';
break;
case 'Delete Cache' :
$translated_text = 'Purge Cache';
break;
case 'Clear All Cache' :
$translated_text = 'Purge Cache';
break;
case 'Clearing Specific Pages' :
$translated_text = 'Purging Specific Pages';
break;
case 'Delete Cache and Minified CSS/JS' :
$translated_text = 'Purge Cache and Minified CSS/JS';
break;
case 'Minify Css' :
$translated_text = 'Minify CSS';
break;
case 'Minify Css Plus' :
$translated_text = 'Minify CSS Plus';
break;
case 'Combine Css' :
$translated_text = 'Combine CSS';
break;
case 'Minify Js' :
$translated_text = 'Minify JS';
break;
case 'Combine Js' :
$translated_text = 'Combine JS';
break;
case 'Combine Js Plus' :
$translated_text = 'Combine JS Plus';
break;
case 'More powerful minify html' :
$translated_text = 'More powerful minify HTML';
break;
case 'You can decrease the size of css files' :
$translated_text = 'You can decrease the size of CSS files';
break;
case 'More powerful minify css' :
$translated_text = 'More powerful minify CSS';
break;
case 'Reduce HTTP requests through combined css files' :
$translated_text = 'Reduce HTTP requests through combined CSS files';
break;
case 'You can decrease the size of js files' :
$translated_text = 'You can decrease the size of JS files';
break;
case 'Reduce HTTP requests through combined js files' :
$translated_text = 'Reduce HTTP requests through combined JS files';
break;
case 'You can remove the emoji inline css and wp-emoji-release.min.js' :
$translated_text = 'You can remove the emoji inline CSS and wp-emoji-release.min.js';
break;
case 'Render Blocking Js' :
$translated_text = 'Render Blocking JS';
break;
case 'Delay Js' :
$translated_text = 'Delay JS';
break;
case 'Some js sources will not be loaded until scrolling or moving the mouse' :
$translated_text = 'Some JS sources will not be loaded until scrolling or moving the mouse';
break;
}
return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );
/* BACKEND: Change WP Fastest Cache Admin Toolbar Main Link String from "Delete Cache" to "Fastest Cache" */
function change_admin_toolbar_main_link_backend() {
if ( is_admin_bar_showing() ) {
global $wp_admin_bar;
$wp_admin_bar->remove_node('wpfc-toolbar-parent');
$args = array(
'id' => 'wpfc-toolbar-parent',
'title' => 'Fastest Cache',
'href' => '/wp-admin/admin.php?page=wpfastestcacheoptions',
);
$wp_admin_bar->add_node($args);
}}
add_action('wp_before_admin_bar_render', 'change_admin_toolbar_main_link_backend', 20, 3);
/* BACKEND: Change WP Fastest Cache Admin Toolbar Sub-Links Strings from "Clear Cache" and "Delete Cache" to "Purge Cache" */
function change_admin_toolbar_sub_links_backend() {
if ( ! is_admin() ) {
global $wp_admin_bar;
$wp_admin_bar->remove_node('wpfc-toolbar-parent-delete-cache');
$args = array(
'parent' => 'wpfc-toolbar-parent',
'id' => 'wpfc-toolbar-parent-delete-cache',
'title' => 'Purge Cache',
);
$wp_admin_bar->add_node($args);
global $wp_admin_bar;
$wp_admin_bar->remove_node('wpfc-toolbar-parent-clear-cache-of-this-page');
$args = array(
'parent' => 'wpfc-toolbar-parent',
'id' => 'wpfc-toolbar-parent-clear-cache-of-this-page',
'title' => 'Purge Cache of this Page',
);
$wp_admin_bar->add_node($args);
global $wp_admin_bar;
$wp_admin_bar->remove_node('wpfc-toolbar-parent-delete-cache-and-minified');
$args = array(
'parent' => 'wpfc-toolbar-parent',
'id' => 'wpfc-toolbar-parent-delete-cache-and-minified',
'title' => 'Purge Cache and Minified CSS/JS',
);
$wp_admin_bar->add_node($args);
}}
add_action('wp_before_admin_bar_render', 'change_admin_toolbar_sub_links_backend', 20, 3);
/* BACKEND: Change WP Fastest Cache Admin Toolbar Ajax Spinner and Icon from "Cheetah" to Generic ("Gear") Icon */
function override_admin_toolbar_css_backend() {
if ( is_admin_bar_showing() ) { ?>
<style type="text/css">
#revert-loader-toolbar {
background-image: url(/wp-content/uploads/2024/08/ajax-loading-gif-1.gif)!important; // use the File URL of your spinner
}
/* Change plugin icon in Admin Toolbar */
#wp-admin-bar-wpfc-toolbar-parent > .ab-item::before {
// content: url(/wp-content/plugins/wp-fastest-cache/images/icon.svg)!important; /* use original plugin logo */
content: "\f111"!important; /* use custom plugin logo (gear) */
margin-top: .1em!important;
}
</style>
<?php }
}
add_action( 'admin_head', 'override_admin_toolbar_css_backend', 20, 3 );Code Snippet (Affects Frontend):
/* FRONTEND: Change WP Fastest Cache "Delete Cache" and "Clear Cache" Strings to "Purge Cache" */
function change_admin_toolbar_main_link_frontend() {
if ( ! is_admin() ) {
global $wp_admin_bar;
$wp_admin_bar->remove_node('wpfc-toolbar-parent');
$args = array(
'id' => 'wpfc-toolbar-parent',
'title' => 'Fastest Cache',
'href' => '/wp-admin/admin.php?page=wpfastestcacheoptions',
);
$wp_admin_bar->add_node($args);
}}
add_action('wp_before_admin_bar_render', 'change_admin_toolbar_main_link_frontend', 20, 3);
/* FRONTEND: Change WP Fastest Cache Admin Toolbar Sub-Links Strings from "Clear Cache" and "Delete Cache" to "Purge Cache" */
function change_admin_toolbar_sub_links_frontend() {
if ( ! is_admin() ) {
global $wp_admin_bar;
$wp_admin_bar->remove_node('wpfc-toolbar-parent-delete-cache');
$args = array(
'parent' => 'wpfc-toolbar-parent',
'id' => 'wpfc-toolbar-parent-delete-cache',
'title' => 'Purge Cache',
);
$wp_admin_bar->add_node($args);
global $wp_admin_bar;
$wp_admin_bar->remove_node('wpfc-toolbar-parent-clear-cache-of-this-page');
$args = array(
'parent' => 'wpfc-toolbar-parent',
'id' => 'wpfc-toolbar-parent-clear-cache-of-this-page',
'title' => 'Purge Cache of this Page',
);
$wp_admin_bar->add_node($args);
global $wp_admin_bar;
$wp_admin_bar->remove_node('wpfc-toolbar-parent-delete-cache-and-minified');
$args = array(
'parent' => 'wpfc-toolbar-parent',
'id' => 'wpfc-toolbar-parent-delete-cache-and-minified',
'title' => 'Purge Cache and Minified CSS/JS',
);
$wp_admin_bar->add_node($args);
}}
add_action('wp_before_admin_bar_render', 'change_admin_toolbar_sub_links_frontend', 20, 3);
/* FRONTEND: Change WP Fastest Cache Admin Toolbar Ajax Spinner and Icon from "Cheetah" to Generic ("Gear") Icon */
function override_admin_toolbar_css_frontend() {
if ( is_admin_bar_showing() ) { ?>
<style type="text/css">
#revert-loader-toolbar {
background-image: url(/wp-content/uploads/2024/08/ajax-loading-gif-1.gif)!important; // use the File URL of your spinner
}
/* Change plugin icon in Admin Toolbar */
#wp-admin-bar-wpfc-toolbar-parent > .ab-item::before {
// content: url(/wp-content/plugins/wp-fastest-cache/images/icon.svg)!important; /* use original plugin logo */
content: "\f111"!important; /* use custom plugin logo (gear) */
margin-top: .1em!important;
}
</style>
<?php }
}
add_action( 'wp_head', 'override_admin_toolbar_css_frontend', 20, 3 );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.