| 1 |
<?php |
| 2 |
|
| 3 |
namespace Buddypress\CLI\Command; |
| 4 |
|
| 5 |
use WP_CLI; |
| 6 |
|
| 7 |
/** |
| 8 |
* Manage BuddyPress Tools. |
| 9 |
* |
| 10 |
* ## EXAMPLES |
| 11 |
* |
| 12 |
* # Repair the friend count. |
| 13 |
* $ wp bp tool repair friend-count |
| 14 |
* Success: Counting the number of friends for each user. Complete! |
| 15 |
* |
| 16 |
* # Display BuddyPress version. |
| 17 |
* $ wp bp tool version |
| 18 |
* BuddyPress: 6.0.0 |
| 19 |
* |
| 20 |
* # Activate the signup tool. |
| 21 |
* $ wp bp tool signup 1 |
| 22 |
* Success: Signup tool updated. |
| 23 |
* |
| 24 |
* @since 1.5.0 |
| 25 |
*/ |
| 26 |
class Tool extends BuddyPressCommand { |
| 27 |
|
| 28 |
/** |
| 29 |
* Dependency check for this CLI command. |
| 30 |
*/ |
| 31 |
public static function check_dependencies() { |
| 32 |
parent::check_dependencies(); |
| 33 |
|
| 34 |
require_once buddypress()->plugin_dir . 'bp-core/admin/bp-core-admin-tools.php'; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Repair. |
| 39 |
* |
| 40 |
* ## OPTIONS |
| 41 |
* |
| 42 |
* <type> |
| 43 |
* : Name of the repair tool. |
| 44 |
* --- |
| 45 |
* options: |
| 46 |
* - friend-count |
| 47 |
* - group-count |
| 48 |
* - blog-records |
| 49 |
* - count-members |
| 50 |
* --- |
| 51 |
* |
| 52 |
* ## EXAMPLES |
| 53 |
* |
| 54 |
* # Repair the friend count. |
| 55 |
* $ wp bp tool repair friend-count |
| 56 |
* Success: Counting the number of friends for each user. Complete! |
| 57 |
* |
| 58 |
* @alias fix |
| 59 |
*/ |
| 60 |
public function repair( $args ) { |
| 61 |
$repair = 'bp_admin_repair_' . $this->sanitize_string( $args[0] ); |
| 62 |
|
| 63 |
if ( ! function_exists( $repair ) ) { |
| 64 |
WP_CLI::error( 'There is no repair tool with that name.' ); |
| 65 |
} |
| 66 |
|
| 67 |
// Run the callable repair function. |
| 68 |
$result = $repair(); |
| 69 |
|
| 70 |
if ( empty( $repair ) ) { |
| 71 |
WP_CLI::error( 'The component of the tool is not active.' ); |
| 72 |
} |
| 73 |
|
| 74 |
if ( 0 === $result[0] ) { |
| 75 |
WP_CLI::success( $result[1] ); |
| 76 |
} else { |
| 77 |
WP_CLI::error( $result[1] ); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Display BuddyPress version currently installed. |
| 83 |
* |
| 84 |
* ## EXAMPLE |
| 85 |
* |
| 86 |
* # Display BuddyPress version. |
| 87 |
* $ wp bp tool version |
| 88 |
* BuddyPress: 6.0.0 |
| 89 |
*/ |
| 90 |
public function version() { |
| 91 |
WP_CLI::log( 'BuddyPress: ' . bp_get_version() ); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* (De)Activate the signup feature. |
| 96 |
* |
| 97 |
* <status> |
| 98 |
* : Status of the feature. |
| 99 |
* |
| 100 |
* ## EXAMPLES |
| 101 |
* |
| 102 |
* # Activate the signup tool. |
| 103 |
* $ wp bp tool signup 1 |
| 104 |
* Success: Signup tool updated. |
| 105 |
* |
| 106 |
* # Deactivate the signup tool. |
| 107 |
* $ wp bp tool signup 0 |
| 108 |
* Success: Signup tool updated. |
| 109 |
*/ |
| 110 |
public function signup( $args ) { |
| 111 |
$status = wp_validate_boolean( $args[0] ); |
| 112 |
|
| 113 |
if ( is_multisite() ) { |
| 114 |
$retval = get_site_option( 'registration' ); |
| 115 |
|
| 116 |
if ( 'all' === $retval && $status ) { |
| 117 |
WP_CLI::error( 'Both sites and user accounts registration is already allowed.' ); |
| 118 |
} |
| 119 |
|
| 120 |
$current = $status ? 'all' : 'none'; |
| 121 |
update_site_option( 'registration', $current ); |
| 122 |
} else { |
| 123 |
if ( bp_get_signup_allowed() && $status ) { |
| 124 |
WP_CLI::error( 'The BuddyPress signup feature is already allowed.' ); |
| 125 |
} |
| 126 |
|
| 127 |
bp_update_option( 'users_can_register', $status ); |
| 128 |
} |
| 129 |
|
| 130 |
WP_CLI::success( 'Signup tool updated.' ); |
| 131 |
} |
| 132 |
} |
| 133 |
|