| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\REST; |
| 4 |
|
| 5 |
use WPDeveloper\BetterDocs\Admin\ReportEmail; |
| 6 |
use WP_REST_Request; |
| 7 |
use WPDeveloper\BetterDocs\Core\BaseAPI; |
| 8 |
|
| 9 |
class Settings extends BaseAPI { |
| 10 |
|
| 11 |
public function permission_check() { |
| 12 |
return current_user_can( 'edit_docs_settings' ); |
| 13 |
} |
| 14 |
|
| 15 |
public function register() { |
| 16 |
$this->get( 'settings', [$this, 'get_settings'] ); |
| 17 |
$this->post( 'settings', [$this, 'save_settings'] ); |
| 18 |
|
| 19 |
$this->post( 'reporting-test', [$this, 'test_reporting'] ); |
| 20 |
} |
| 21 |
|
| 22 |
public function get_settings() { |
| 23 |
return betterdocs()->settings->get_all( true ); |
| 24 |
} |
| 25 |
|
| 26 |
public function save_settings( WP_REST_Request $request ) { |
| 27 |
if ( betterdocs()->settings->save_settings( $request->get_params() ) ) { |
| 28 |
return $this->success( __( 'Settings Saved!', 'betterdocs' ) ); |
| 29 |
} |
| 30 |
|
| 31 |
return $this->error( 'nothing_changed', __( 'There are no changes to be saved.', 'betterdocs' ), 200 ); |
| 32 |
} |
| 33 |
|
| 34 |
public function test_reporting( $request ){ |
| 35 |
return $this->container->get(ReportEmail::class)->test_email_report( $request ); |
| 36 |
} |
| 37 |
} |
| 38 |
|