Skip to content

Commit

Permalink
added missing file check
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsayan committed Mar 22, 2024
1 parent 36d31f6 commit e074c3e
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 117 deletions.
202 changes: 108 additions & 94 deletions includes/class-instawp-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,100 +217,6 @@ public function add_api_routes() {
) );
}

/**
* Handle response for create user
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public function add_user( WP_REST_Request $request ) {

$response = $this->validate_api_request( $request );
if ( is_wp_error( $response ) ) {
return $this->throw_error( $response );
}

$params = $this->filter_params( $request );

if ( empty( $params['user_login'] ) ) {
return $this->send_response( array(
'success' => false,
'message' => 'Username can\'t be empty!',
) );
}

$user_id = wp_insert_user( wp_parse_args( $params, array(
'user_pass' => wp_generate_password(),
) ) );

if ( is_wp_error( $user_id ) ) {
return $this->throw_error( $user_id );
}

$user = get_user_by( 'id', $user_id );

return $this->send_response( array(
'success' => true,
'userdata' => $user
) );
}

/**
* Handle response for update user
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public function update_user( WP_REST_Request $request ) {

$response = $this->validate_api_request( $request );
if ( is_wp_error( $response ) ) {
return $this->throw_error( $response );
}

$params = $this->filter_params( $request );
$user_id = wp_update_user( $params );

if ( is_wp_error( $user_id ) ) {
return $this->throw_error( $user_id );
}

$user = get_user_by( 'id', $user_id );

return $this->send_response( array(
'success' => true,
'userdata' => $user
) );
}

/**
* Handle response for delete user
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public function delete_user( WP_REST_Request $request ) {

$response = $this->validate_api_request( $request );
if ( is_wp_error( $response ) ) {
return $this->throw_error( $response );
}

$params = $this->filter_params( $request );
$params = wp_parse_args( $params, array(
'reassign' => null
) );
$status = wp_delete_user( $params['user_id'], $params['reassign'] );

return $this->send_response( array(
'success' => $status,
'userdata' => $params
) );
}

/**
* Handle response for pull api
*
Expand Down Expand Up @@ -1420,6 +1326,114 @@ public function delete_configuration( WP_REST_Request $request ) {
return $this->send_response( $response );
}


/**
* Handle response for create user
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public function add_user( WP_REST_Request $request ) {

$response = $this->validate_api_request( $request );
if ( is_wp_error( $response ) ) {
return $this->throw_error( $response );
}

$params = $this->filter_params( $request );

if ( empty( $params['user_login'] ) ) {
return $this->send_response( array(
'success' => false,
'message' => 'Username can\'t be empty!',
) );
}

if ( ! function_exists( 'wp_insert_user' ) ) {
require_once ABSPATH . 'wp-includes/user.php';
}

$user_id = wp_insert_user( wp_parse_args( $params, array(
'user_pass' => wp_generate_password(),
) ) );

if ( is_wp_error( $user_id ) ) {
return $this->throw_error( $user_id );
}

$user = get_user_by( 'id', $user_id );

return $this->send_response( array(
'success' => true,
'userdata' => $user
) );
}

/**
* Handle response for update user
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public function update_user( WP_REST_Request $request ) {

$response = $this->validate_api_request( $request );
if ( is_wp_error( $response ) ) {
return $this->throw_error( $response );
}

if ( ! function_exists( 'wp_update_user' ) ) {
require_once ABSPATH . 'wp-includes/user.php';
}

$params = $this->filter_params( $request );
$user_id = wp_update_user( $params );

if ( is_wp_error( $user_id ) ) {
return $this->throw_error( $user_id );
}

$user = get_user_by( 'id', $user_id );

return $this->send_response( array(
'success' => true,
'userdata' => $user
) );
}

/**
* Handle response for delete user
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public function delete_user( WP_REST_Request $request ) {

$response = $this->validate_api_request( $request );
if ( is_wp_error( $response ) ) {
return $this->throw_error( $response );
}

if ( ! function_exists( 'wp_delete_user' ) ) {
require_once ABSPATH . 'wp-admin/includes/user.php';
}

$params = $this->filter_params( $request );
$params = wp_parse_args( $params, array(
'reassign' => null
) );
$status = wp_delete_user( $params['user_id'], $params['reassign'] );

return $this->send_response( array(
'success' => $status,
'userdata' => $params
) );
}


/**
* Handle file manager system.
*
Expand Down
46 changes: 23 additions & 23 deletions languages/instawp-connect.pot
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
reInstaWP
InstaWP
msgid ""
msgstr ""
"Project-Id-Version: InstaWP Connect\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-03-22 08:54+0000\n"
"POT-Creation-Date: 2024-03-22 09:45+0000\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: __;_e;_ex:1,2c;_n:1,2;_n_noop:1,2;_nx:1,2,4c;_nx_noop:1,2,3c;_x:1,2c;esc_attr__;esc_attr_e;esc_attr_x:1,2c;esc_html__;esc_html_e;esc_html_x:1,2c\n"
"X-Poedit-SearchPath-0: .\n"
Expand Down Expand Up @@ -117,11 +117,11 @@ msgstr ""
msgid "Purge All Cache"
msgstr ""

#: includes/class-instawp-hooks.php:111, includes/class-instawp-rest-api.php:1687, includes/class-instawp-setting.php:210, includes/class-instawp-setting.php:547
#: includes/class-instawp-hooks.php:111, includes/class-instawp-rest-api.php:1701, includes/class-instawp-setting.php:210, includes/class-instawp-setting.php:547
msgid "File Manager"
msgstr ""

#: includes/class-instawp-hooks.php:122, includes/class-instawp-rest-api.php:1688, includes/class-instawp-setting.php:211, includes/class-instawp-setting.php:555
#: includes/class-instawp-hooks.php:122, includes/class-instawp-rest-api.php:1702, includes/class-instawp-setting.php:211, includes/class-instawp-setting.php:555
msgid "Database Manager"
msgstr ""

Expand Down Expand Up @@ -157,79 +157,79 @@ msgstr ""
msgid "Cache cleared for %s."
msgstr ""

#: includes/class-instawp-rest-api.php:567
#: includes/class-instawp-rest-api.php:473
msgid "Could not create destination file."
msgstr ""

#: includes/class-instawp-rest-api.php:623
#: includes/class-instawp-rest-api.php:529
msgid "Plugin reset Successful."
msgstr ""

#: includes/class-instawp-rest-api.php:807
#: includes/class-instawp-rest-api.php:713
msgid "Already Configured"
msgstr ""

#: includes/class-instawp-rest-api.php:815
#: includes/class-instawp-rest-api.php:721
msgid "Api key is required"
msgstr ""

#: includes/class-instawp-rest-api.php:871
#: includes/class-instawp-rest-api.php:777
msgid "Empty bearer token."
msgstr ""

#: includes/class-instawp-rest-api.php:888
#: includes/class-instawp-rest-api.php:794
msgid "Invalid bearer token."
msgstr ""

#: includes/class-instawp-rest-api.php:1195
#: includes/class-instawp-rest-api.php:1101
msgid "Please deactivate the theme first."
msgstr ""

#: includes/class-instawp-rest-api.php:1170
#: includes/class-instawp-rest-api.php:1076
msgid "Please deactivate the plugin first."
msgstr ""

#: includes/class-instawp-rest-api.php:1552
#: includes/class-instawp-rest-api.php:1566
msgid "Setting does not exist."
msgstr ""

#: includes/class-instawp-rest-api.php:1535
#: includes/class-instawp-rest-api.php:1549
msgid "Success!"
msgstr ""

#: includes/class-instawp-rest-api.php:1544
#: includes/class-instawp-rest-api.php:1558
msgid "You can not enable this setting through API."
msgstr ""

#: includes/class-instawp-rest-api.php:1541
#: includes/class-instawp-rest-api.php:1555
msgid "Setting is already disabled."
msgstr ""

#: includes/class-instawp-rest-api.php:1686, includes/class-instawp-setting.php:509, includes/class-instawp-setting.php:515
#: includes/class-instawp-rest-api.php:1700, includes/class-instawp-setting.php:509, includes/class-instawp-setting.php:515
msgid "Heartbeat"
msgstr ""

#: includes/class-instawp-rest-api.php:1689, includes/class-instawp-setting.php:563
#: includes/class-instawp-rest-api.php:1703, includes/class-instawp-setting.php:563
msgid "Install Plugin / Themes"
msgstr ""

#: includes/class-instawp-rest-api.php:1690, includes/class-instawp-setting.php:571
#: includes/class-instawp-rest-api.php:1704, includes/class-instawp-setting.php:571
msgid "Update Core / Plugin / Themes"
msgstr ""

#: includes/class-instawp-rest-api.php:1691, includes/class-instawp-setting.php:579
#: includes/class-instawp-rest-api.php:1705, includes/class-instawp-setting.php:579
msgid "Activate / Deactivate"
msgstr ""

#: includes/class-instawp-rest-api.php:1692, includes/class-instawp-setting.php:587
#: includes/class-instawp-rest-api.php:1706, includes/class-instawp-setting.php:587
msgid "Config Management"
msgstr ""

#: includes/class-instawp-rest-api.php:1693, includes/class-instawp-setting.php:595
#: includes/class-instawp-rest-api.php:1707, includes/class-instawp-setting.php:595
msgid "Site Inventory"
msgstr ""

#: includes/class-instawp-rest-api.php:1694, includes/class-instawp-setting.php:212, includes/class-instawp-setting.php:603
#: includes/class-instawp-rest-api.php:1708, includes/class-instawp-setting.php:212, includes/class-instawp-setting.php:603
msgid "Debug Log"
msgstr ""

Expand Down

0 comments on commit e074c3e

Please sign in to comment.