| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Oauth\Classes; |
| 4 |
|
| 5 |
use ImageOptimization\Classes\Route; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class Route_Base extends Route { |
| 12 |
const SITE_URL = 'https://my.elementor.com/connect/v1/'; |
| 13 |
|
| 14 |
protected $auth = true; |
| 15 |
protected string $path = ''; |
| 16 |
public function get_methods(): array { |
| 17 |
return []; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_endpoint(): string { |
| 21 |
return 'connect/' . $this->get_path(); |
| 22 |
} |
| 23 |
|
| 24 |
public function get_path(): string { |
| 25 |
return $this->path; |
| 26 |
} |
| 27 |
|
| 28 |
public function get_name(): string { |
| 29 |
return ''; |
| 30 |
} |
| 31 |
|
| 32 |
public function get_permission_callback( \WP_REST_Request $request ): bool { |
| 33 |
$valid = $this->permission_callback( $request ); |
| 34 |
|
| 35 |
return $valid && user_can( $this->current_user_id, 'manage_options' ); |
| 36 |
} |
| 37 |
|
| 38 |
public function verify_nonce( $nonce = '', $name = '' ) { |
| 39 |
if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $nonce ) ), $name ) ) { |
| 40 |
wp_die( 'Invalid nonce', 'image-optimization' ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
public function verify_nonce_and_capability( $nonce = '', $name = '', $capability = 'manage_options' ) { |
| 45 |
$this->verify_nonce( $nonce, $name ); |
| 46 |
|
| 47 |
if ( ! current_user_can( $capability ) ) { |
| 48 |
wp_die( 'You do not have sufficient permissions to access this page.' ); |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|