"""
1
"""
+
+ When I run `wp comment url 1`
+ Then STDOUT should be:
+ """
+ http://example.com/?p=1#comment-1
+ """
\ No newline at end of file
"""
This is some bunkum.
"""
+
+ When I run `wp post url {POST_ID}`
+ Then STDOUT should be:
+ """
+ http://example.com/?p=3
+ """
Scenario: Creating/listing posts
Feature: Manage sites in a multisite installation
+ Scenario: Create a site
+ Given a WP multisite install
+
+ When I try `wp site create --slug=first --network_id=1000`
+ Then STDERR should contain:
+ """
+ Network with id 1000 does not exist.
+ """
+
Scenario: Delete a site by id
Given a WP multisite install
When I try the previous command again
Then the return code should be 1
- Scenario: Empty a site
+ Scenario: Empty a site
Given a WP install
When I run `wp post create --post_title='Test post' --post_content='Test content.' --porcelain`
When I run `wp term list post_tag --format=ids`
Then STDOUT should be empty
+
+ Scenario: Get site info
+ Given a WP multisite install
+
+ When I run `wp site url 1`
+ Then STDOUT should be:
+ """
+ http://example.com
+ """
\ No newline at end of file
protected function get_formatter( &$assoc_args ) {
return new \WP_CLI\Formatter( $assoc_args, $this->obj_fields, $this->obj_type );
}
+
+ protected function _url( $args, $callback ) {
+ $object = $this->fetcher->get_check( $args[0] );
+ \WP_CLI::print_value( $callback( $object->{$this->obj_id_key} ) );
+ }
}
--- /dev/null
+<?php
+
+namespace WP_CLI\Fetchers;
+
+class Site extends Base {
+
+ protected $msg = "Could not find the site with ID %d.";
+
+ public function get( $site_id ) {
+ return $this->_get_site( $site_id );
+ }
+
+ /**
+ * Get site (network) data for a given id.
+ *
+ * @param int $site_id
+ * @return bool|array False if no network found with given id, array otherwise
+ */
+ private function _get_site( $site_id ) {
+ global $wpdb;
+
+ // Load site data
+ $sites = $wpdb->get_results( $wpdb->prepare(
+ "SELECT * FROM $wpdb->site WHERE id = %d", $site_id ) );
+
+ if ( !empty( $sites ) ) {
+ // Only care about domain and path which are set here
+ return $sites[0];
+ }
+
+ return false;
+ }
+}
\ No newline at end of file
WP_CLI::success( "Comment with ID $args[0] exists." );
}
}
+
+ /**
+ * Get comment url
+ *
+ * ## OPTIONS
+ *
+ * <id>
+ * : The ID of the comment to get the URL.
+ *
+ * ## EXAMPLES
+ *
+ * wp comment url 123
+ */
+ public function url( $args ) {
+ parent::_url( $args, 'get_comment_link' );
+ }
}
WP_CLI::add_command( 'comment', 'Comment_Command' );
// @codingStandardsIgnoreEnd
}
+ /**
+ * Get post url
+ *
+ * ## OPTIONS
+ *
+ * <id>
+ * : The ID of the post to get the URL.
+ *
+ * ## EXAMPLES
+ *
+ * wp post url 123
+ */
+ public function url( $args ) {
+ parent::_url( $args, 'get_permalink' );
+ }
+
private function maybe_make_child() {
// 50% chance of making child post
return ( mt_rand(1, 2) == 1 );
protected $obj_type = 'site';
+ public function __construct() {
+ $this->fetcher = new \WP_CLI\Fetchers\Site;
+ }
+
/**
* Delete comments.
*/
// Site
if ( !empty( $assoc_args['network_id'] ) ) {
- $site = $this->_get_site( $assoc_args['network_id'] );
+ $site = $this->fetcher->get( $assoc_args['network_id'] );
if ( $site === false ) {
WP_CLI::error( sprintf( 'Network with id %d does not exist.', $assoc_args['network_id'] ) );
}
}
/**
- * Get site (network) data for a given id.
+ * Get site url
+ *
+ * ## OPTIONS
+ *
+ * <id>
+ * : The ID of the site to get the URL.
+ *
+ * ## EXAMPLES
*
- * @param int $site_id
- * @return bool|array False if no network found with given id, array otherwise
+ * wp site url 123
*/
- private function _get_site( $site_id ) {
- global $wpdb;
-
- // Load site data
- $sites = $wpdb->get_results( $wpdb->prepare(
- "SELECT * FROM $wpdb->site WHERE id = %d", $site_id ) );
-
- if ( !empty( $sites ) ) {
- // Only care about domain and path which are set here
- return $sites[0];
- }
-
- return false;
+ public function url( $args ) {
+ parent::_url( $args, 'get_site_url' );
}
}