Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Syndication
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
WP Plugins
Syndication
Commits
4769309b
Commit
4769309b
authored
10 years ago
by
Nick Daugherty
Browse files
Options
Downloads
Patches
Plain Diff
Add the push-all-posts CLI command
Simply gets all posts of `—post_type` and runs any necessary syndication.
parent
1faa39c2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
includes/class-wp-cli.php
+56
-0
56 additions, 0 deletions
includes/class-wp-cli.php
with
56 additions
and
0 deletions
includes/class-wp-cli.php
+
56
−
0
View file @
4769309b
...
...
@@ -5,6 +5,45 @@ WP_CLI::add_command( 'syndication', 'Syndication_CLI_Command' );
class
Syndication_CLI_Command
extends
WP_CLI_Command
{
var
$enabled_verbosity
=
false
;
/**
* Pushes all posts of a given type
*
* @subcommand push-all-posts
* @synopsis [--post_type=<post-type>] [--paged=<page>]
*/
function
push_all_posts
(
$args
,
$assoc_args
)
{
$assoc_args
=
wp_parse_args
(
$assoc_args
,
array
(
'post_type'
=>
'post'
,
'paged'
=>
1
)
);
$query_args
=
array
(
'post_type'
=>
$assoc_args
[
'post_type'
],
'posts_per_page'
=>
150
,
'paged'
=>
$assoc_args
[
'paged'
]
);
$query
=
new
WP_Query
(
$query_args
);
while
(
$query
->
post_count
)
{
WP_CLI
::
line
(
sprintf
(
'Processing page %d'
,
$query_args
[
'paged'
]
)
);
foreach
(
$query
->
posts
as
$post
)
{
WP_CLI
::
line
(
sprintf
(
'Processing post %d (%s)'
,
$post
->
ID
,
$post
->
post_title
)
);
$this
->
push_post
(
array
(),
array
(
'post_id'
=>
$post
->
ID
)
);
}
$this
->
stop_the_insanity
();
sleep
(
2
);
$query_args
[
'paged'
]
++
;
$query
=
new
WP_Query
(
$query_args
);
}
}
function
push_post
(
$args
,
$assoc_args
)
{
$assoc_args
=
wp_parse_args
(
$assoc_args
,
array
(
'post_id'
=>
0
,
...
...
@@ -115,4 +154,21 @@ class Syndication_CLI_Command extends WP_CLI_Command {
global
$push_syndication_server
;
return
$push_syndication_server
;
}
protected
function
stop_the_insanity
()
{
global
$wpdb
,
$wp_object_cache
;
$wpdb
->
queries
=
array
();
// or define( 'WP_IMPORTING', true );
if
(
!
is_object
(
$wp_object_cache
)
)
return
;
$wp_object_cache
->
group_ops
=
array
();
$wp_object_cache
->
stats
=
array
();
$wp_object_cache
->
memcache_debug
=
array
();
$wp_object_cache
->
cache
=
array
();
if
(
is_callable
(
$wp_object_cache
,
'__remoteset'
)
)
$wp_object_cache
->
__remoteset
();
// important
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment