Wp option patch (WP-CLI)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

wp option patch: Verwijderen, invoegen & bijwerken van serialised value.

$ wp help option patch


NAME

  wp option patch

DESCRIPTION

  Updates a nested value in an option.

SYNOPSIS

  wp option patch <action> <key> <key-path>... [<value>] [--format=<format>]

OPTIONS

  <action>
    Patch action to perform.
    ---
    options:
      - insert
      - update
      - delete
    ---

  <key>
    The option name.

  <key-path>...
    The name(s) of the keys within the value to locate the value to patch.

  [<value>]
    The new value. If omitted, the value is read from STDIN.

  [--format=<format>]
    The serialization format for the value.
    ---
    default: plaintext
    options:
      - plaintext
      - json
    ---

wp option patch delete

wp option patch insert

wp option patch update

Update een serialised veld:

  • Subvelden geef je aan door alle tussenliggende elementen te benoemen (spatie-gescheiden)
  • LET OP: Het huidige serialised veld/subboom wordt overschreven door dit commando. Als je bv. tussenliggende elementen vergeet te vermelden, wis je het complete datamodel rondom dat veld
  • Mogelijk een veilige manier om dit commando toe te passen: Lees eerst de huidige waarde uit met wp option pluck en update het pas daarna met dit commando.
  • Numerieke waardes mogen zowel met als zonder enkele/dubbele aanhalingstekens

Voorbeeld (1)

$ wp option get aws_settings

array (
  'seamless' => 'true',
  'cache' => 'true',
  'autoupdates' => 'true',
  'search_in' => 
  array (
    'title' => 1,
    'content' => 0,
    'sku' => 1,
    'excerpt' => 0,
    'category' => 0,
    'tag' => 0,
    'id' => 0,
  ),
  'outofstock' => 'true',
  'stopwords' => 'a, also, am, an, and, are, as, at, be, but, by, call, can, co, con, de, do, due, eg, eight, etc, even, ever, every, for, from, full, go, had, has, hasnt, have, he, hence, her, here, his, how, ie, if, in, inc, into, is, it, its, ltd, me, my, no, none, nor, not, now, of, off, on, once, one, only, onto, or, our, ours, out, over, own, part, per, put, re, see, so, some, ten, than, that, the, their, there, these, they, this, three, thru, thus, to, too, top, un, up, us, very, via, was, we, well, were, what, when, where, who, why, will',
  'synonyms' => 'buy, pay, purchase, acquire
box, housing, unit, package',
  'use_analytics' => 'true',
  'search_field_text' => 'Zoek producten...',
  'show_more_text' => 'Laat alle resultaten zien',
  'not_found_text' => 'Oeps, geen zoekresultaten.',
  'min_chars' => '1',
  'show_loader' => 'true',
  'show_clear' => 'true',
  'show_more' => 'true',
  'mobile_overlay' => 'false',
  'show_page' => 'true',
  'buttons_order' => '2',
  'desc_source' => 'excerpt',
  'mark_words' => 'true',
  'excerpt_length' => '20',
  'results_num' => '10',
  'highlight' => 'true',
  'show_image' => 'true',
  'show_excerpt' => 'false',
  'show_price' => 'true',
  'show_outofstock_price' => 'true',
  'show_cats' => 'false',
  'show_tags' => 'false',
  'show_sale' => 'true',
  'show_sku' => 'false',
  'show_stock' => 'false',
  'show_featured' => 'false',
  'search_archives' => 
  array (
    'archive_category' => 0,
    'archive_tag' => 0,
  ),
)


$ wp option pluck aws_settings search_field_text

Zoek producten...


$ wp option patch update aws_settings search_field_text "Search products"

Success: Updated 'aws_settings' option.

Voorbeeld: Numerieke waardes & aanhalingstekens

$ wp option pluck woocommerce_dhlpwc_settings price_option_home

6.95

$ wp option patch update woocommerce_dhlpwc_settings price_option_home "79.95"   # Met dubbele aanhalingstekens

Success: Updated 'woocommerce_dhlpwc_settings' option.


$ wp option pluck woocommerce_dhlpwc_settings price_option_home

79.95


$ wp option patch update woocommerce_dhlpwc_settings price_option_home "79.95"   # Zonder aanhalingstekens

Success: Value passed for 'woocommerce_dhlpwc_settings' option is unchanged.

Zie ook