Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Danny Froberg
Polylang Cli
Commits
8bdd8c6c
Commit
8bdd8c6c
authored
Jun 11, 2017
by
Peter J. Herrel
Browse files
`wp pll widget list` subcommand
cf. #82
parent
22cc7a56
Changes
5
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
8bdd8c6c
...
...
@@ -1431,6 +1431,74 @@ Errors if the term doesn't exist, or there was a problem in deleting it.
Deleted post_tag 58.
Success: Deleted 3 of 3 terms.
### wp pll widget
Manage localized sidebar widgets.
~~~
wp pll widget
~~~
### wp pll widget list
List localized widgets associated with a sidebar.
~~~
wp pll widget list <language-code> <sidebar-id> [--fields=<fields>] [--format=<format>]
~~~
**OPTIONS**
<language-code>
The language code (slug) to get widgets for. Required.
<sidebar-id>
ID for the corresponding sidebar. Required.
[--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 pll widget list nl sidebar-1
+------+--------+----------+-------------------------------------------------------------------+
| name | id | position | options |
+------+--------+----------+-------------------------------------------------------------------+
| text | text-2 | 2 | {"title":"test","text":"test","filter":"content","pll_lang":"nl"} |
+------+--------+----------+-------------------------------------------------------------------+
## Contributing
We appreciate you taking the initiative to contribute to this project.
...
...
command.php
View file @
8bdd8c6c
...
...
@@ -44,6 +44,7 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
require
__DIR__
.
'/src/Commands/Plugin.php'
;
require
__DIR__
.
'/src/Commands/Menu.php'
;
require
__DIR__
.
'/src/Commands/String.php'
;
require
__DIR__
.
'/src/Commands/Widget.php'
;
WP_CLI
::
add_hook
(
'before_wp_load'
,
function
()
{
...
...
@@ -83,5 +84,6 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI
::
add_command
(
'pll string'
,
Polylang_CLI\Commands\StringCommand
::
class
);
WP_CLI
::
add_command
(
'pll taxonomy'
,
Polylang_CLI\Commands\TaxonomyCommand
::
class
);
WP_CLI
::
add_command
(
'pll term'
,
Polylang_CLI\Commands\TermCommand
::
class
);
WP_CLI
::
add_command
(
'pll widget'
,
Polylang_CLI\Commands\WidgetCommand
::
class
);
}
composer.json
View file @
8bdd8c6c
...
...
@@ -76,7 +76,9 @@
"pll term"
,
"pll term generate"
,
"pll term get"
,
"pll term delete"
"pll term delete"
,
"pll widget"
,
"pll widget list"
],
"readme"
:
{
"sections"
:
[
...
...
composer.lock
View file @
8bdd8c6c
...
...
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "
419eb8e23f530b373d6bd16623771727
",
"content-hash": "
127572b6a6bb976909195975e2c8de83
",
"packages": [
{
"name": "composer/ca-bundle",
...
...
src/Commands/Widget.php
0 → 100644
View file @
8bdd8c6c
<?php
namespace
Polylang_CLI\Commands
;
if
(
!
class_exists
(
'Polylang_CLI\Commands\WidgetCommand'
)
)
{
/**
* Manage localized sidebar widgets.
*
* @package Polylang_CLI
*/
class
WidgetCommand
extends
BaseCommand
{
/**
* List localized widgets associated with a sidebar.
*
* ## OPTIONS
*
* <language-code>
* : The language code (slug) to get widgets for. Required.
*
* <sidebar-id>
* : ID for the corresponding sidebar. Required.
*
* [--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 pll widget list nl sidebar-1
* +------+--------+----------+-------------------------------------------------------------------+
* | name | id | position | options |
* +------+--------+----------+-------------------------------------------------------------------+
* | text | text-2 | 2 | {"title":"test","text":"test","filter":"content","pll_lang":"nl"} |
* +------+--------+----------+-------------------------------------------------------------------+
*
* @subcommand list
*/
public
function
list_
(
$args
,
$assoc_args
)
{
list
(
$language_slug
,
$sidebar_id
)
=
$args
;
# get widget fields
$properties
=
new
\
ReflectionClass
(
new
\
Widget_Command
()
);
$fields
=
$properties
->
getDefaultProperties
()[
'fields'
];
# validate sidebar
$validate
=
new
\
ReflectionMethod
(
'Widget_Command'
,
'validate_sidebar'
);
$validate
->
setAccessible
(
true
);
$validate
->
invokeArgs
(
new
\
Widget_Command
(),
array
(
$sidebar_id
)
);
# get sidebar widgets
$validate
=
new
\
ReflectionMethod
(
'Widget_Command'
,
'get_sidebar_widgets'
);
$validate
->
setAccessible
(
true
);
$output_widgets
=
$validate
->
invokeArgs
(
new
\
Widget_Command
(),
array
(
$sidebar_id
)
);
# filter widgets by language
$output_widgets_filtered
=
array
();
foreach
(
$output_widgets
as
$obj
)
{
if
(
isset
(
$obj
->
options
[
'pll_lang'
]
)
&&
$obj
->
options
[
'pll_lang'
]
===
$language_slug
)
{
$output_widgets_filtered
[]
=
$obj
;
}
}
if
(
!
empty
(
$assoc_args
[
'format'
]
)
&&
'ids'
===
$assoc_args
[
'format'
]
)
{
$output_widgets
=
wp_list_pluck
(
$output_widgets_filtered
,
'id'
);
}
$formatter
=
$this
->
cli
->
formatter
(
$assoc_args
,
$fields
);
$formatter
->
display_items
(
$output_widgets_filtered
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment