Wp widget (WP-CLI)

Uit De Vliegende Brigade
Versie door Jeroen Strompf (overleg | bijdragen) op 16 jun 2022 om 21:46 (Nieuwe pagina aangemaakt met '''wp widget'' manages widgets, including adding and moving them within sidebars. * Commando <code>wp sidebar list</code> kan van pas komen om de id's van de diver...')
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Naar navigatie springen Naar zoeken springen

wp widget manages widgets, including adding and moving them within sidebars.

  • Commando wp sidebar list kan van pas komen om de id's van de diverse sidebars te achterhalen
  • Ik heb het gevoel dat ik een commando mis om de specifieke waardes van de options van een widget te achterhalen. Zie ik iets over het hoofd?

Help-tekst:

$ wp help widget

NAME

  wp widget

DESCRIPTION

  Manages widgets, including adding and moving them within sidebars.

SYNOPSIS

  wp widget <command>

SUBCOMMANDS

  add             Adds a widget to a sidebar.
  deactivate      Deactivates one or more widgets from an active sidebar.
  delete          Deletes one or more widgets from a sidebar.
  list            Lists widgets associated with a sidebar.
  move            Moves the position of a widget.
  reset           Resets sidebar.
  update          Updates options for an existing widget.

  A [widget][1] adds content and features to a widget area (also called a [sidebar][2]).

  ---
  [1] https://developer.wordpress.org/themes/functionality/widgets/
  [2] https://developer.wordpress.org/themes/functionality/sidebars/

EXAMPLES

    # List widgets on a given sidebar
    $ wp widget list sidebar-1
    +----------+------------+----------+----------------------+
    | name     | id         | position | options              |
    +----------+------------+----------+----------------------+
    | meta     | meta-6     | 1        | {"title":"Meta"}     |
    | calendar | calendar-2 | 2        | {"title":"Calendar"} |
    +----------+------------+----------+----------------------+

    # Add a calendar widget to the second position on the sidebar
    $ wp widget add calendar sidebar-1 2
    Success: Added widget to sidebar.

    # Update option(s) associated with a given widget
    $ wp widget update calendar-1 --title="Calendar"
    Success: Widget updated.

    # Delete one or more widgets entirely
    $ wp widget delete calendar-2 archive-1
    Success: 2 widgets removed from sidebar.

wp widget add

wp widget deactivate

wp widget delete

wp widget list

$ wp help widget list

NAME

  wp widget list

DESCRIPTION

  Lists widgets associated with a sidebar.

SYNOPSIS

  wp widget list <sidebar-id> [--fields=<fields>] [--format=<format>]

OPTIONS

  <sidebar-id>
    ID for the corresponding sidebar.

  [--fields=<fields>]
    Limit the output to specific object fields.

  [--format=<format>]
    Render output in a particular format.
    ---
    default: table
    options:
      - table
      - csv
      - ids
      - json
      - count
      - yaml
    ---

AVAILABLE FIELDS

  These fields will be displayed by default for each widget:

  * name
  * id
  * position
  * options

  There are no optionally available fields.

EXAMPLES

    $ wp widget list sidebar-1 --fields=name,id --format=csv
    name,id
    meta,meta-5
    search,search-3

Voorbeeld

$ wp sidebar list

+---------------------+---------------------+---------------------------------------------------------------------------+
| name                | id                  | description                                                               |
+---------------------+---------------------+---------------------------------------------------------------------------+
| Primary Widget Area | sidebar-1           |                                                                           |
| Header Widget Area  | mini-cart-widget    |                                                                           |
| Inactive Widgets    | wp_inactive_widgets | Drag widgets here to remove them from the sidebar but keep their settings |
+---------------------+---------------------+---------------------------------------------------------------------------+

$ wp widget list sidebar-1

+----------------------------------+----------------------------------+----------+-----------------------------------+
| name                             | id                               | position | options                           |
+----------------------------------+----------------------------------+----------+-----------------------------------+
| woocommerce_layered_nav_filters  | woocommerce_layered_nav_filters- | 1        | {"title":"Filters"}               |
|                                  | 3                                |          |                                   |
| woocommerce_layered_nav          | woocommerce_layered_nav-19       | 2        | {"title":"Blub code","attribute"  |
|                                  |                                  |          | :"blub-code","display_type":"lis  |
|                                  |                                  |          | t","query_type":"and"}            |
| woocommerce_layered_nav          | woocommerce_layered_nav-13       | 3        | {"title":"Model","attribute":"mod |
|                                  |                                  |          | el","display_type":"list","query_ |
|                                  |                                  |          | type":"and"}                      |
| woocommerce_layered_nav          | woocommerce_layered_nav-14       | 4        | {"title":"Submodel","attribute":" |
|                                  |                                  |          | submodel","display_type":"list"," |
|                                  |                                  |          | query_type":"and"}                |
| woocommerce_layered_nav          | woocommerce_layered_nav-17       | 5        | {"title":"Diagram","attribute":"d |
|                                  |                                  |          | iagram","display_type":"list","qu |
|                                  |                                  |          | ery_type":"and"}                  |
| woocommerce_layered_nav          | woocommerce_layered_nav-5        | 6        | {"title":"Breedte (mm)","attribut |
|                                  |                                  |          | e":"breedte","display_type":"list |
|                                  |                                  |          | ","query_type":"and"}             |
| woocommerce_layered_nav          | woocommerce_layered_nav-6        | 7        | {"title":"Diepte (mm)","attribute |
|                                  |                                  |          | ":"diepte","display_type":"list", |
|                                  |                                  |          | "query_type":"and"}               |
| woocommerce_layered_nav          | woocommerce_layered_nav-7        | 8        | {"title":"Lengte (mm)","attribute |
|                                  |                                  |          | ":"lengte","display_type":"list", |
|                                  |                                  |          | "query_type":"and"}               |
| woocommerce_layered_nav          | woocommerce_layered_nav-8        | 9        | {"title":"Automatische flop?","at |
|                                  |                                  |          | tribute":"automatic-flop","displa |
|                                  |                                  |          | y_type":"list","query_type":"and" |
|                                  |                                  |          | }                                 |
| woocommerce_layered_nav          | woocommerce_layered_nav-9        | 10       | {"title":"Wire?","attribute":"wir |
|                                  |                                  |          | e","display_type":"list","query_t |
|                                  |                                  |          | ype":"and"}                       |
| woocommerce_layered_nav          | woocommerce_layered_nav-10       | 11       | {"title":"Connector?","attribute" |
|                                  |                                  |          | :"connector","display_type":"list |
|                                  |                                  |          | ","query_type":"and"}             |
| woocommerce_layered_nav          | woocommerce_layered_nav-11       | 12       | {"title":"Veer?","attribute":"vee |
|                                  |                                  |          | r","display_type":"list","query_t |
|                                  |                                  |          | ype":"and"}                       |
| woocommerce_layered_nav          | woocommerce_layered_nav-4        | 13       | {"title":"Original blub",         |
|                                  |                                  |          | "attribute":"original-blub",      |
|                                  |                                  |          | "display_type":"list","query_t    |
|                                  |                                  |          | ype":"and"}                       |
| woocommerce_layered_nav          | woocommerce_layered_nav-12       | 14       | {"title":"Diagram","attribute":"d |
|                                  |                                  |          | iagram","display_type":"list","qu |
|                                  |                                  |          | ery_type":"and"}                  |
| woocommerce_layered_nav          | woocommerce_layered_nav-16       | 15       | {"title":"Product line","attribut |
|                                  |                                  |          | e":"product-line","display_type": |
|                                  |                                  |          | "list","query_type":"and"}        |
| woocommerce_layered_nav          | woocommerce_layered_nav-15       | 16       | {"title":"blujb-productcode","att |
|                                  |                                  |          | ribute":"blub_code","display_typ  |
|                                  |                                  |          | e":"list","query_type":"and"}     |
+----------------------------------+----------------------------------+----------+-----------------------------------+

--fields

Met de flag --fields heb je vermoedelijk de keuze uit

  • name
  • id
  • position
  • options

en niet de keuze uit de diverse velden die onder options worden getoond. De velden scheid je met een komma, zonder spatie. Voorbeeld:

$ wp widget list sidebar-1 --fields=id,options

+-----------------------------------+----------------------------------------------------------------------------------------------------------------+
| id                                | options                                                                                                        |
+-----------------------------------+----------------------------------------------------------------------------------------------------------------+
| woocommerce_layered_nav_filters-3 | {"title":"Filters"}                                                                                            |
| woocommerce_layered_nav-19        | {"title":"Apparaat","attribute":"apparaat","display_type":"list","query_type":"and"}                           |
| woocommerce_layered_nav-13        | {"title":"Model","attribute":"model","display_type":"list","query_type":"and"}                                 |
| woocommerce_layered_nav-14        | {"title":"Submodel","attribute":"submodel","display_type":"list","query_type":"and"}                           |
+-----------------------------------+----------------------------------------------------------------------------------------------------------------+

wp widget move

wp widget reset

wp widget update

Bewerk de instellingen voor bestaande widgets:

  • Merk op dat je een widget-id moet meegeven, maar niet een sidebar-id
  • De namen bij --attribute zijn de slugs, dus doorgaans met dashes en niet met underscores. Je kunt de namen ook achterhalen middels select distinct taxonomy from wp_term_taxonomy;

Helptekst:

$ wp help widget update

NAME

  wp widget update

DESCRIPTION

  Updates options for an existing widget.

SYNOPSIS

  wp widget update <widget-id> [--<field>=<value>]

OPTIONS

  <widget-id>
    Unique ID for the widget

  [--<field>=<value>]
    Field to update, with its new value

EXAMPLES

    # Change calendar-1 widget title to "Our Calendar"
    $ wp widget update calendar-1 --title="Our Calendar"
    Success: Widget updated.

Voorbeeld - 2021.08.14

################################################################################
# Update widgets
################################################################################
#
wp widget update woocommerce_layered_nav-19 --title="Device"     --attribute="device"
wp widget update woocommerce_layered_nav-13 --title="Model"      --attribute="model"
wp widget update woocommerce_layered_nav-14 --title="Submodel"     --attribute="submodel"
wp widget update woocommerce_layered_nav-5  --title="Width (mm)"   --attribute="width-mm"
wp widget update woocommerce_layered_nav-6  --title="Depth (mm)"   --attribute="depth-mm"
wp widget update woocommerce_layered_nav-7  --title="Length (mm)"  --attribute="length-mm"
wp widget update woocommerce_layered_nav-16 --title="Product line" --attribute="product-line"