55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
if (!defined('ABSPATH')) exit;
|
|
|
|
function sro_menu() {
|
|
add_options_page(
|
|
"Spotify Recent",
|
|
"Spotify Recent",
|
|
"manage_options",
|
|
"sro",
|
|
"sro_page"
|
|
);
|
|
}
|
|
add_action('admin_menu', 'sro_menu');
|
|
|
|
|
|
function sro_page() {
|
|
$client_id = get_option('sro_client_id');
|
|
$client_secret = get_option('sro_client_secret');
|
|
|
|
if (isset($_POST['sro_save'])) {
|
|
update_option('sro_client_id', sanitize_text_field($_POST['client_id']));
|
|
update_option('sro_client_secret', sanitize_text_field($_POST['client_secret']));
|
|
echo "<div class='updated'><p>Saved.</p></div>";
|
|
}
|
|
|
|
$redirect_uri = admin_url('options-general.php?page=sro&oauth=1');
|
|
?>
|
|
<h1>Spotify OAuth Settings</h1>
|
|
|
|
<form method="post">
|
|
<label>Client ID</label><br>
|
|
<input type="text" name="client_id" value="<?php echo esc_attr($client_id); ?>" size="60"><br><br>
|
|
|
|
<label>Client Secret</label><br>
|
|
<input type="text" name="client_secret" value="<?php echo esc_attr($client_secret); ?>" size="60"><br><br>
|
|
|
|
<button class="button-primary" name="sro_save">Save</button>
|
|
</form>
|
|
|
|
<hr>
|
|
|
|
<h2>Step 2: Connect Spotify</h2>
|
|
<p>Add this redirect URI in your Spotify App:</p>
|
|
|
|
<code><?php echo $redirect_uri; ?></code>
|
|
|
|
<br><br>
|
|
|
|
<a href="https://accounts.spotify.com/authorize?client_id=<?php echo $client_id; ?>&response_type=code&redirect_uri=<?php echo urlencode($redirect_uri); ?>&scope=user-read-recently-played"
|
|
class="button button-primary">
|
|
Connect Spotify
|
|
</a>
|
|
|
|
<?php
|
|
}
|