replace Archives | Lee Willis https://www.leewillis.co.uk/tag/replace/ Sun, 22 Mar 2015 20:53:43 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 WP-CLI import and export for Say What? https://www.leewillis.co.uk/wp-cli-import-and-export-for-say-what/ https://www.leewillis.co.uk/wp-cli-import-and-export-for-say-what/#respond Sun, 22 Mar 2015 20:53:43 +0000 http://www.leewillis.co.uk/?p=709 I’ve been at WordCamp London for the last two days (An excellent event, you should definitely consider it if you’re into WordPress and are in – or can get to – the UK). There were a fair few talks about … Continue reading

The post WP-CLI import and export for Say What? appeared first on Lee Willis.

]]>
I’ve been at WordCamp London for the last two days (An excellent event, you should definitely consider it if you’re into WordPress and are in – or can get to – the UK). There were a fair few talks about making the admin area of WordPress better by customising according to the site architecture.

This is something I’ve always been an advocate of – particular on sites that go beyond simple posts and pages. One of my plugins provides some of the tools that can help with this. The “Say What?” string replacement plugin for WordPress allows you to override strings from WordPress core and/or plugins that you’re using so you can personalise the phrases that are used to your particular use case.

I took the opportunity to make some small updates to the plugin over the last few days. Particularly I’ve extended the plugin to have support for WP-CLI. This allows you to import and export string replacements – particularly useful if you have a standard set (or sets) of replacements that you use on sites you build. You can also use it to get a list of all replacements you currently have set up on your site.

Generating a list of replacements

$ wp say-what list
+-----------+-------------+--------+--------------------+---------+
| string_id | orig_string | domain | replacement_string | context |
+-----------+-------------+--------+--------------------+---------+
| 3         | Tools       |        | Lee's tools        |         |
| 9         | Dashboard   |        | The dashboard      |         |
+-----------+-------------+--------+--------------------+---------+

Exporting your replacements

This will ‘export’ all of your replacements in CSV format to the file /tmp/my-replacements.csv. This file is in the same format you need for importing back into the site, or into another site.

$ wp say-what export --format=csv > /tmp/my-replacements.csv

Updating replacements

Sometimes you might want to export a set of replacements, edit them, and then re-import. You can do this with the ‘update’ command – this will update any items with a string_id provided, or insert any items without a string ID. The following command will read in the file /tmp/my-replacements-amended.csv and update the database.

$ wp say-what update /tmp/my-replacements-amended.csv

Importing replacements

If you just want to add the replacements in a file to the database, you can use the ‘import’ command. This will insert each item in the file as a new item in the database.

$ wp say-what import /tmp/my-replacements-new.csv

Trying it out?

You can grab the plugin from WordPress.org – or check it out on GitHub – thanks to WordCamp London for the inspiration!

The post WP-CLI import and export for Say What? appeared first on Lee Willis.

]]>
https://www.leewillis.co.uk/wp-cli-import-and-export-for-say-what/feed/ 0
How to change text in a WordPress plugin https://www.leewillis.co.uk/how-to-change-text-in-a-wordpress-plugin/ https://www.leewillis.co.uk/how-to-change-text-in-a-wordpress-plugin/#comments Sun, 10 Mar 2013 17:30:00 +0000 http://www.leewillis.co.uk/?p=543 One of the great things about using an out-of-the-box solution like WordPress is that you can get something up and running pretty quickly. That’s been one of WordPress’ strengths over the years. However, if you’re building sites for other people … Continue reading

The post How to change text in a WordPress plugin appeared first on Lee Willis.

]]>
One of the great things about using an out-of-the-box solution like WordPress is that you can get something up and running pretty quickly. That’s been one of WordPress’ strengths over the years. However, if you’re building sites for other people then sometimes parts of the generic-ness seep through and detract from the overall feel of the solution. Specifically – terminology that is great in a generic solution isn’t always helpful in a custom, or specific solution.

None of this is a criticism of WordPress, but as you start building larger, or more complex sites you’ll probably want to start smoothing off some of these rough edges, and make sure the language of the site (frontend or admin side) makes sense in the specific context of the site you’re working on.

That’s something I come across frequently in my day job as a Drupal developer. Fortunately Drupal has the excellent String Overrides module. This lets you specify the current string, and a replacement, and will change the text whenever that string is used, with the caveat that the original string has to be passed through Drupal’s translation function t().

When someone recently asked me how to change some text in one of my own WordPress plugins – my first suggestion was this exact same approach. After all, all of my Premium plugins use translatable strings, and suggesting to someone that they should create a translation file just to change one or two strings for their needs has always seemed a bit excessive. So – I had a hunt around the WordPress.org repo for something similar, but couldn’t really find anything that did the job.

Figuring it’d be something fairly simple to achieve I set out to knock up a plugin that did the job. So next time you need to quickly change a string in WordPress, or a plugin you’re using – don’t hack it in the plugin – or in WordPress core, leaving your client unable to upgrade, give “Say What?” a go:

The strings we want to change

The strings we want to change

The say what page - setting up our string replacements

The say what page – setting up our string replacements

The text - automatically replaced for us

The text – automatically replaced for us

 

Say what?
by Lee Willis

An easy-to-use plugin that allows you to change translatable strings from plugins / themes and WordPress core without editing code. Simply enter the current string, and what you want to replace it with and the plugin will automatically do the rest!

The plugin’s available for forking and contribution over on GitHub

Check out Say What Pro for:

  • String Discovery and autocomplete – find the strings you need without diving through code. Works with server-side and Javascript-rendered strings
  • Improved performance using text-domain-specific filters
  • Wildcard string replacements – replace individual words, or fragments across your whole site
  • Multi-lingual support – set different replacements for different languages on multi-lingual sites
  • Import/export features – Easy import/export of replacements through the user interface

Support this free plugin

As a business, we already donate a percentage of our profits from premium plugins to global climate change projects. You’re free to use this plugin free of charge, but if you do, please consider buying the world some trees in return. You’ll be creating employment for local families and restoring wildlife habitats.

Stats:

  • Current version: 2.2.5
  • Rating: 86(91 ratings)
  • Downloaded 637,851 times

The post How to change text in a WordPress plugin appeared first on Lee Willis.

]]>
https://www.leewillis.co.uk/how-to-change-text-in-a-wordpress-plugin/feed/ 21