I need to set a couple of Theme Mods to boolean and array values using WP CLI but can't find any way to do achieve it.
I have already tried the following for booleans, but they appear to be treated as string:
wp theme mod set my_theme_mod true
wp theme mod set my_theme_mod 1
For arrays, I don't even know where to start, so have not tried anything yet.
Any pointers please?
I need to set a couple of Theme Mods to boolean and array values using WP CLI but can't find any way to do achieve it.
I have already tried the following for booleans, but they appear to be treated as string:
wp theme mod set my_theme_mod true
wp theme mod set my_theme_mod 1
For arrays, I don't even know where to start, so have not tried anything yet.
Any pointers please?
Share Improve this question asked Mar 9, 2022 at 12:29 Dash DesaiDash Desai 313 bronze badges 2 |1 Answer
Reset to default 1Funny how you find the answer just after posting a question. Posting here, in case someone comes looking for it.
As per @Kero's comment above, that's correct. The command-line option will only recognise strings.
There is however an eval-file command that can be used to achieve this (and now that I have discovered it, a lot more).
Here are the steps for achieving the goal I posted in my question, however as the eval-file WP CLI command can be used to execute a PHP file, we can code anything that we deem fit.
Step 1: Create a PHP file with the required code. In my example here, I added the following:
<?php
set_theme_mod('my_boolean_mod', false);
set_theme_mod('my_array_mod', array(1, 2, 3));
The above code will use the WordPress set_theme_mod function to create/update mods named my_boolean_mod and my_array_mod.
Step 2: Execute the above file using the WP CLI eval-file command
wp eval-file my_file.php
That's it. Hope this is useful!
$value
argument. So if it doesn't behave correctly right now, I'm not sure how you can better force it. You can create an issue in their GitHub. – kero Commented Mar 9, 2022 at 12:50