Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions php/WP_CLI/Fetchers/Signup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace WP_CLI\Fetchers;

/**
* Fetch a signup based on one of its attributes.
*/
class Signup extends Base {

/**
* The message to display when an item is not found.
*
* @var string
*/
protected $msg = "Invalid signup ID, email, login, or activation key: '%s'";

/**
* Get a signup.
*
* @param int|string $signup
* @return stdClass|false
*/
public function get( $signup ) {
return $this->get_signup( $signup );
}

/**
* Get a signup by one of its identifying attributes.
*
* @param string $arg The raw CLI argument.
* @return stdClass|false The item if found; false otherwise.
*/
protected function get_signup( $arg ) {
global $wpdb;

$signup_object = null;

// Fetch signup with signup_id.
if ( is_numeric( $arg ) ) {
$result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE signup_id = %d", $arg ) );

if ( $result ) {
$signup_object = $result;
}
}

if ( ! $signup_object ) {
// Try to fetch with other keys.
foreach ( array( 'user_login', 'user_email', 'activation_key' ) as $field ) {
// phpcs:ignore WordPress.DB.PreparedSQL
$result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE $field = %s", $arg ) );

if ( $result ) {
$signup_object = $result;
break;
}
}
}

if ( $signup_object ) {
return $signup_object;
}

return false;
}
}