SoundCloud Is Gold - Version 2.4.2

Version Description

  • Updated plugin to reflect Soundcloud API changes. Please update to fix any issues in version 2.4.1
Download this release

Release Info

Developer realTM
Plugin Icon wp plugin SoundCloud Is Gold
Version 2.4.2
Comparing to
See all releases

Code changes from version 2.4.1 to 2.4.2

readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.mightymess.com/soundcloud-is-gold-wordpress-plugin
4
  Tags: soundcloud, simple, shortcode, music, sound
5
  Requires at least: 3.2
6
  Tested up to: 4.7.2
7
- Stable tag: 2.4.1
8
 
9
  Browse through your soundcloud tracks, playlists and favorites. Add tracks, playlists and favorites to your posts. Live preview, easy to use.
10
 
@@ -148,6 +148,9 @@ Sometimes, I generally keep a eye on my plugin's forums and website's comments.
148
 
149
  == Changelog ==
150
 
 
 
 
151
  = 2.4.1 =
152
  * Fixed a bug in the Widget not properly displaying Playlists after updating from 2.3.3. Thanks to Jan Middelkoop and @gnorf for helping out.
153
  * Added shortcode attr to show latest track from a specific, see FAQs for how to do it manually.
4
  Tags: soundcloud, simple, shortcode, music, sound
5
  Requires at least: 3.2
6
  Tested up to: 4.7.2
7
+ Stable tag: 2.4.2
8
 
9
  Browse through your soundcloud tracks, playlists and favorites. Add tracks, playlists and favorites to your posts. Live preview, easy to use.
10
 
148
 
149
  == Changelog ==
150
 
151
+ = 2.4.2 =
152
+ * Updated plugin to reflect Soundcloud API changes. Please update to fix any issues in version 2.4.1
153
+
154
  = 2.4.1 =
155
  * Fixed a bug in the Widget not properly displaying Playlists after updating from 2.3.3. Thanks to Jan Middelkoop and @gnorf for helping out.
156
  * Added shortcode attr to show latest track from a specific, see FAQs for how to do it manually.
soundcloud-is-gold-functions.php CHANGED
@@ -62,17 +62,18 @@ function get_soundcloud_is_gold_username_interface($options, $soundcloudIsGoldUs
62
  ?>
63
  <!-- Active User -->
64
  <ul id="soundcloudIsGoldActiveUserContainer">
65
- <li class="soundcloudIsGoldUserContainer" style="background-image:URL('<?php echo $options['soundcloud_is_gold_users'][$options['soundcloud_is_gold_active_user']][1] ?>')">
66
  <span id="soundcloudIsGoldActiveLabel">&nbsp;</span>
67
  <div>
68
  <span class="soundcloudIsGoldRemoveUser" />&nbsp;</span>
69
  <input type="hidden" value="<?php echo $options['soundcloud_is_gold_users'][$options['soundcloud_is_gold_active_user']][0]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $options['soundcloud_is_gold_active_user'] ?>][0]" />
70
  <input type="hidden" value="<?php echo $options['soundcloud_is_gold_users'][$options['soundcloud_is_gold_active_user']][1]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $options['soundcloud_is_gold_active_user'] ?>][1]" />
71
- <p><?php echo $options['soundcloud_is_gold_active_user'] ?></p>
 
72
  </div>
73
  </li>
74
  <li class="hidden">
75
- <input type="hidden" id="soundcloudIsGoldActiveUser" value="<?php echo $options['soundcloud_is_gold_active_user'] ?>" name="soundcloud_is_gold_options[soundcloud_is_gold_active_user]" />
76
  </li>
77
  </ul>
78
  <!-- Add user -->
@@ -92,12 +93,13 @@ function get_soundcloud_is_gold_username_interface($options, $soundcloudIsGoldUs
92
  <ul id="soundcloudIsGoldUsernameCarousel">
93
  <?php foreach($soundcloudIsGoldUsers as $key => $user): ?>
94
  <?php if($user[0] != $options['soundcloud_is_gold_active_user']) :?>
95
- <li class="soundcloudIsGoldUserContainer" style="background-image:URL('<?php echo $user[1] ?>')">
96
  <span class="soundcloudIsGoldRemoveUser" />&nbsp;</span>
97
  <div>
98
  <input type="hidden" value="<?php echo $user[0]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $key ?>][0]" />
99
  <input type="hidden" value="<?php echo $user[1]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $key ?>][1]" />
100
- <p><?php echo $user[0] ?></p>
 
101
  </div>
102
  </li>
103
  <?php endif; endforeach; ?>
@@ -113,16 +115,21 @@ function get_soundcloud_is_gold_username_interface($options, $soundcloudIsGoldUs
113
  **/
114
  function get_soundcloud_is_gold_latest_track_id($soundcloudIsGoldUser, $format = "tracks"){
115
  $soundcouldMMId = "";
116
- $soundcloudIsGoldApiCall = 'https://api.soundcloud.com/users/'.$soundcloudIsGoldUser.'/tracks.json?limit=1&client_id='.CLIENT_ID;
117
- if($format == "playlists") $soundcloudIsGoldApiCall = 'https://api.soundcloud.com/users/'.$soundcloudIsGoldUser.'/playlists.json?limit=1&client_id='.CLIENT_ID;
118
- if($format == "favorites") $soundcloudIsGoldApiCall = 'https://api.soundcloud.com/users/'.$soundcloudIsGoldUser.'/favorites.json?limit=1&client_id='.CLIENT_ID;
119
-
120
- $soundcloudIsGoldApiResponse = get_soundcloud_is_gold_api_response($soundcloudIsGoldApiCall);
121
- if(isset($soundcloudIsGoldApiResponse['response']) && $soundcloudIsGoldApiResponse['response']){
122
- foreach($soundcloudIsGoldApiResponse['response'] as $soundcloudMMLatestTrack){
123
- $soundcouldMMId = $soundcloudMMLatestTrack['id'];
124
- }
125
- }
 
 
 
 
 
126
  return $soundcouldMMId;
127
  }
128
 
@@ -157,6 +164,66 @@ function get_soundcloud_is_gold_multiple_tracks_id($soundcloudIsGoldUser, $nbr =
157
  if($random) return array_random($soundcouldMMIds, $nbr);
158
  return $soundcouldMMIds;
159
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  /**
161
  * Get Soundcloud API Response (Json version)
162
  * $soundcloudIsGoldApiCall: API request (url)
@@ -164,7 +231,7 @@ function get_soundcloud_is_gold_multiple_tracks_id($soundcloudIsGoldUser, $nbr =
164
  function get_soundcloud_is_gold_api_response($soundcloudIsGoldApiCall){
165
  //Set Error default message && default Json state
166
  $soundcloudIsGoldRespError = false;
167
- //Check is cURL extension is loaded
168
  if(extension_loaded("curl")){
169
  // create a new cURL resource
170
  $soundcloudIsGoldCURL = curl_init();
@@ -355,6 +422,8 @@ add_filter('media_buttons_context', 'plugin_media_button');
355
  function get_soundcloud_is_gold_user_tracks(){
356
  //Default Settings
357
  $options = get_option('soundcloud_is_gold_options');
 
 
358
  //printl($options);
359
  $soundcloudIsGoldActiveUser = isset($options['soundcloud_is_gold_active_user']) ? $options['soundcloud_is_gold_active_user'] : '';
360
  $soundcloudIsGoldUsers = isset($options['soundcloud_is_gold_users']) ? $options['soundcloud_is_gold_users'] : '';
@@ -388,7 +457,7 @@ function get_soundcloud_is_gold_user_tracks(){
388
 
389
  //Usernames
390
  echo '<div class="soundcloudMMWrapper">';
391
- echo '<div id="soundcloudMMUsernameHeader"><img src="'.$soundcloudIsGoldUsers[$soundcloudIsGoldActiveUser][1].'" width="50" height="50"/><span>'.$soundcloudIsGoldUsers[$soundcloudIsGoldActiveUser][0].'</span> <a href="#" id="soundcloudMMShowUsernames">show users options</a><a href="#" id="soundcloudMMHideUsernames" class="hidden">hide users options</a></div>';
392
  echo '<div id="soundcloudMMUsermameTab">';
393
  get_soundcloud_is_gold_username_interface($options, $soundcloudIsGoldUsers);
394
  echo '</div></div>';
@@ -710,35 +779,44 @@ function get_soundcloud_player(){
710
  add_action('wp_ajax_soundcloud_is_gold_add_user', 'soundcloud_is_gold_add_user');
711
  function soundcloud_is_gold_add_user(){
712
  if(isset($_POST['request'])){
713
- $options = get_option('soundcloud_is_gold_options');
714
- if(isset($options['soundcloud_is_gold_users'])){
715
- $return = 'error';
716
- //Check if username doesn't exist already and is not blank
717
- if(!empty($_POST['username']) && !array_key_exists($_POST['username'], $options['soundcloud_is_gold_users'])){
718
- $newUsername = str_replace(" ", "-", trim($_POST['username']));
719
- //Get user info
720
- $userInfo = get_soundcloud_is_gold_api_response("https://api.soundcloud.com/users/".$newUsername.".json?client_id=".CLIENT_ID);
721
- //printl($userInfo);
722
- if(isset($userInfo) && isset($userInfo['response']['permalink'])){
723
- $newUsername = $userInfo['response']['permalink'];
724
- $newUsernameImg = $userInfo['response']['avatar_url'];
725
-
 
 
 
 
 
 
 
 
726
  $return = '<li class="soundcloudIsGoldUserContainer" style="background-image:URL('.$newUsernameImg.')">';
727
  $return .= '<span class="soundcloudIsGoldRemoveUser" />&nbsp;</span>';
728
  $return .= '<div>';
729
- $return .= '<input type="hidden" value="'.$newUsername.'" name="soundcloud_is_gold_options[soundcloud_is_gold_users]['.$newUsername.'][0]" />';
730
- $return .= '<input type="hidden" value="'.$newUsernameImg.'" name="soundcloud_is_gold_options[soundcloud_is_gold_users]['.$newUsername.'][1]" />';
 
731
  $return .= '<p>'.$newUsername.'</p>';
732
  $return .= '</div>';
733
  $return .= '</li>';
734
 
735
  //Tab: extra actions
736
  if($_POST['updateOption'] == '1'){
737
- $options['soundcloud_is_gold_users'][$newUsername][0] = $newUsername;
738
- $options['soundcloud_is_gold_users'][$newUsername][1] = $newUsernameImg;
 
739
  update_option( 'soundcloud_is_gold_options', $options );
740
  }
741
- }
742
  }
743
  echo $return;
744
  }
@@ -752,9 +830,9 @@ function soundcloud_is_gold_set_active_user(){
752
  if(isset($_POST['request'])){
753
  $options = get_option('soundcloud_is_gold_options');
754
  if(isset($options['soundcloud_is_gold_active_user'])){
755
- //Check if username exist and is not blank
756
- if(!empty($_POST['username']) && array_key_exists($_POST['username'], $options['soundcloud_is_gold_users'])){
757
- $options['soundcloud_is_gold_active_user'] = $_POST['username'];
758
  update_option( 'soundcloud_is_gold_options', $options );
759
  $message = 'done';
760
  }
@@ -771,11 +849,11 @@ function soundcloud_is_gold_delete_user(){
771
  $options = get_option('soundcloud_is_gold_options');
772
  if(isset($options['soundcloud_is_gold_active_user'])){
773
  //Check username exist and isn't blank
774
- if(!empty($_POST['username']) && array_key_exists($_POST['username'], $options['soundcloud_is_gold_users'])){
775
  //Remove from users
776
- unset($options['soundcloud_is_gold_users'][$_POST['username']]);
777
  //If active user, set the first element to be active
778
- if($options['soundcloud_is_gold_active_user'] == $_POST['username']){
779
  $newActiveUser = array_shift(array_values($options['soundcloud_is_gold_users']));
780
  $options['soundcloud_is_gold_active_user'] = $newActiveUser[0];
781
  }
@@ -841,6 +919,9 @@ class Soundcloud_Is_Gold_Widget extends WP_Widget {
841
  //Random User
842
  if($user == "randomUser") {
843
  $options = get_option('soundcloud_is_gold_options');
 
 
 
844
  $soundcloudIsGoldUsers = isset($options['soundcloud_is_gold_users']) ? array_random($options['soundcloud_is_gold_users'], 1) : '';
845
  //printl($soundcloudIsGoldUsers[0][0]);
846
  if(isset($soundcloudIsGoldUsers)) $user = $soundcloudIsGoldUsers[0][0];
@@ -852,6 +933,9 @@ class Soundcloud_Is_Gold_Widget extends WP_Widget {
852
  //Random User per Track
853
  if($user == "randomUsers") {
854
  $options = get_option('soundcloud_is_gold_options');
 
 
 
855
  if(isset($options['soundcloud_is_gold_users'])){
856
  //Never select more tracks than there is users.
857
  $number = (count($options['soundcloud_is_gold_users']) <= $number) ? count($options['soundcloud_is_gold_users']) : $number;
@@ -923,6 +1007,10 @@ class Soundcloud_Is_Gold_Widget extends WP_Widget {
923
  else {
924
  $title = __( 'Latest', 'text_domain' );
925
  }
 
 
 
 
926
  ?>
927
  <!-- Title -->
928
  <p>
@@ -934,9 +1022,8 @@ class Soundcloud_Is_Gold_Widget extends WP_Widget {
934
  <label for="<?php echo $this->get_field_id('user'); ?>"><?php _e( 'Username:' ); ?></label>
935
  <select name="<?php echo $this->get_field_name('user'); ?>" id="<?php echo $this->get_field_id('user'); ?>" class="widefat">
936
  <?php
937
- $options = get_option('soundcloud_is_gold_options');
938
  foreach($options['soundcloud_is_gold_users'] as $user) : ?>
939
- <option value="<?php echo $user[0] ?>"<?php selected( $instance['user'], $user[0] ); ?>><?php _e($user[0]); ?></option>
940
  <?php endforeach; ?>
941
  <option value="randomUser"<?php selected( $instance['user'], "randomUser" ); ?>><?php _e("Pick a Random User"); ?></option>
942
  <option value="randomUsers"<?php selected( $instance['user'], "randomUsers" ); ?>><?php _e("Pick a Random User per Track"); ?></option>
62
  ?>
63
  <!-- Active User -->
64
  <ul id="soundcloudIsGoldActiveUserContainer">
65
+ <li class="soundcloudIsGoldUserContainer" style="background-image:URL('<?php echo $options['soundcloud_is_gold_users'][$options['soundcloud_is_gold_active_user']][2] ?>')">
66
  <span id="soundcloudIsGoldActiveLabel">&nbsp;</span>
67
  <div>
68
  <span class="soundcloudIsGoldRemoveUser" />&nbsp;</span>
69
  <input type="hidden" value="<?php echo $options['soundcloud_is_gold_users'][$options['soundcloud_is_gold_active_user']][0]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $options['soundcloud_is_gold_active_user'] ?>][0]" />
70
  <input type="hidden" value="<?php echo $options['soundcloud_is_gold_users'][$options['soundcloud_is_gold_active_user']][1]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $options['soundcloud_is_gold_active_user'] ?>][1]" />
71
+ <input type="hidden" value="<?php echo $options['soundcloud_is_gold_users'][$options['soundcloud_is_gold_active_user']][2]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $options['soundcloud_is_gold_active_user'] ?>][2]" />
72
+ <p><?php echo $options['soundcloud_is_gold_users'][$options['soundcloud_is_gold_active_user']][1]?></p>
73
  </div>
74
  </li>
75
  <li class="hidden">
76
+ <input type="hidden" id="soundcloudIsGoldActiveUser" value="<?php echo $options['soundcloud_is_gold_active_user'] ?>" name="soundcloud_is_gold_options[soundcloud_is_gold_active_user]" />
77
  </li>
78
  </ul>
79
  <!-- Add user -->
93
  <ul id="soundcloudIsGoldUsernameCarousel">
94
  <?php foreach($soundcloudIsGoldUsers as $key => $user): ?>
95
  <?php if($user[0] != $options['soundcloud_is_gold_active_user']) :?>
96
+ <li class="soundcloudIsGoldUserContainer" style="background-image:URL('<?php echo $user[2] ?>')">
97
  <span class="soundcloudIsGoldRemoveUser" />&nbsp;</span>
98
  <div>
99
  <input type="hidden" value="<?php echo $user[0]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $key ?>][0]" />
100
  <input type="hidden" value="<?php echo $user[1]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $key ?>][1]" />
101
+ <input type="hidden" value="<?php echo $user[2]?>" name="soundcloud_is_gold_options[soundcloud_is_gold_users][<?php echo $key ?>][2]" />
102
+ <p><?php echo $user[1] ?></p>
103
  </div>
104
  </li>
105
  <?php endif; endforeach; ?>
115
  **/
116
  function get_soundcloud_is_gold_latest_track_id($soundcloudIsGoldUser, $format = "tracks"){
117
  $soundcouldMMId = "";
118
+ //Get user id from name
119
+ $userInfo = soundcloud_is_gold_user_info($soundcloudIsGoldUser);
120
+ if(isset($userInfo['response']['id'])){
121
+ $soundcloudIsGoldUser = $userInfo['response']['id'];
122
+ $soundcloudIsGoldApiCall = 'https://api.soundcloud.com/users/'.$soundcloudIsGoldUser.'/tracks.json?limit=1&client_id='.CLIENT_ID;
123
+ if($format == "playlists") $soundcloudIsGoldApiCall = 'https://api.soundcloud.com/users/'.$soundcloudIsGoldUser.'/playlists.json?limit=1&client_id='.CLIENT_ID;
124
+ if($format == "favorites") $soundcloudIsGoldApiCall = 'https://api.soundcloud.com/users/'.$soundcloudIsGoldUser.'/favorites.json?limit=1&client_id='.CLIENT_ID;
125
+
126
+ $soundcloudIsGoldApiResponse = get_soundcloud_is_gold_api_response($soundcloudIsGoldApiCall);
127
+ if(isset($soundcloudIsGoldApiResponse['response']) && $soundcloudIsGoldApiResponse['response']){
128
+ foreach($soundcloudIsGoldApiResponse['response'] as $soundcloudMMLatestTrack){
129
+ $soundcouldMMId = $soundcloudMMLatestTrack['id'];
130
+ }
131
+ }
132
+ }
133
  return $soundcouldMMId;
134
  }
135
 
164
  if($random) return array_random($soundcouldMMIds, $nbr);
165
  return $soundcouldMMIds;
166
  }
167
+
168
+ /**
169
+ * Update usernames to ids
170
+ * $soundcloudIsGoldApiCall: API request (url)
171
+ **/
172
+ function soundcloud_is_gold_update_users($options){
173
+ $updateNeeded = true;
174
+ if(isset($options['soundcloud_is_gold_users'])){
175
+ foreach ($options['soundcloud_is_gold_users'] as $key => $user) {
176
+ if(!is_numeric($key)){
177
+ $soundcloudIsGoldApiResponse = soundcloud_is_gold_user_info($key);
178
+ if(isset($soundcloudIsGoldApiResponse['response'])){
179
+ //Update options
180
+ $id = $soundcloudIsGoldApiResponse['response']['id'];
181
+ $options['soundcloud_is_gold_users'][$id][0] = $soundcloudIsGoldApiResponse['response']['id'];
182
+ $options['soundcloud_is_gold_users'][$id][1] = $soundcloudIsGoldApiResponse['response']['permalink'];
183
+ $options['soundcloud_is_gold_users'][$id][2] = $soundcloudIsGoldApiResponse['response']['avatar_url'];
184
+ //Delete old options
185
+ unset($options['soundcloud_is_gold_users'][$key]);
186
+ //Set Active User if match
187
+ if($options['soundcloud_is_gold_active_user'] == $options['soundcloud_is_gold_users'][$id][1]) {
188
+ $options['soundcloud_is_gold_active_user'] = $options['soundcloud_is_gold_users'][$id][0];
189
+ }
190
+ }
191
+ }else{
192
+ //If one key is numeric than we're good, just break the loop
193
+ $updateNeeded = false;
194
+ break;
195
+ }
196
+ }
197
+ //Update Settings
198
+ if($updateNeeded) update_option('soundcloud_is_gold_options', $options);
199
+ return $options;
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Resolve usernames to get ids
205
+ * $username: soundcloud username
206
+ **/
207
+ function soundcloud_is_gold_user_info($username){
208
+ //Get user id based on username
209
+ $resolvedAPIurl = soundcloud_is_gold_resolve('https://www.soundcloud.com/'.$username);
210
+ $soundcloudIsGoldApiResponse = get_soundcloud_is_gold_api_response($resolvedAPIurl);
211
+ //Return user info
212
+ return $soundcloudIsGoldApiResponse;
213
+ }
214
+
215
+ /**
216
+ * Resolve
217
+ * $url: url to resolve
218
+ **/
219
+ function soundcloud_is_gold_resolve($url){
220
+ //Get the new API url
221
+ $soundcloudIsGoldApiCall = 'https://api.soundcloud.com/resolve.json?url='.$url.'&client_id='.CLIENT_ID;
222
+ $soundcloudIsGoldApiResponse = get_soundcloud_is_gold_api_response($soundcloudIsGoldApiCall);
223
+ //Return resolved url
224
+ return $soundcloudIsGoldApiResponse['response']['location'];
225
+ }
226
+
227
  /**
228
  * Get Soundcloud API Response (Json version)
229
  * $soundcloudIsGoldApiCall: API request (url)
231
  function get_soundcloud_is_gold_api_response($soundcloudIsGoldApiCall){
232
  //Set Error default message && default Json state
233
  $soundcloudIsGoldRespError = false;
234
+ //Check is cURL extension is loaded
235
  if(extension_loaded("curl")){
236
  // create a new cURL resource
237
  $soundcloudIsGoldCURL = curl_init();
422
  function get_soundcloud_is_gold_user_tracks(){
423
  //Default Settings
424
  $options = get_option('soundcloud_is_gold_options');
425
+ //Fix bug when updating to 2.4.2 where API requests can only use user id
426
+ $options = soundcloud_is_gold_update_users($options);
427
  //printl($options);
428
  $soundcloudIsGoldActiveUser = isset($options['soundcloud_is_gold_active_user']) ? $options['soundcloud_is_gold_active_user'] : '';
429
  $soundcloudIsGoldUsers = isset($options['soundcloud_is_gold_users']) ? $options['soundcloud_is_gold_users'] : '';
457
 
458
  //Usernames
459
  echo '<div class="soundcloudMMWrapper">';
460
+ echo '<div id="soundcloudMMUsernameHeader"><img src="'.$soundcloudIsGoldUsers[$soundcloudIsGoldActiveUser][2].'" width="50" height="50"/><span>'.$soundcloudIsGoldUsers[$soundcloudIsGoldActiveUser][1].'</span> <a href="#" id="soundcloudMMShowUsernames">show users options</a><a href="#" id="soundcloudMMHideUsernames" class="hidden">hide users options</a></div>';
461
  echo '<div id="soundcloudMMUsermameTab">';
462
  get_soundcloud_is_gold_username_interface($options, $soundcloudIsGoldUsers);
463
  echo '</div></div>';
779
  add_action('wp_ajax_soundcloud_is_gold_add_user', 'soundcloud_is_gold_add_user');
780
  function soundcloud_is_gold_add_user(){
781
  if(isset($_POST['request'])){
782
+ //Set return to error by default
783
+ $return = 'error';
784
+ //If username is blank kill it
785
+ if (empty($_POST['username'])) {
786
+ echo $return;
787
+ die;
788
+ }
789
+ //Get options
790
+ $options = get_option('soundcloud_is_gold_options');
791
+ //Replace spaces with hyphen in case users enter their name without it
792
+ $newUsername = str_replace(" ", "-", trim($_POST['username']));
793
+ //Get user info
794
+ $userInfo = soundcloud_is_gold_user_info($newUsername);
795
+ //Check that plugin's options are in place and that we've got $userinfo
796
+ if(isset($options['soundcloud_is_gold_users']) && isset($userInfo)){
797
+ //Set Info to keep
798
+ $newUserId = $userInfo['response']['id'];
799
+ $newUsername = $userInfo['response']['permalink'];
800
+ $newUsernameImg = $userInfo['response']['avatar_url'];
801
+ //Check if id doesn't exist already
802
+ if(!array_key_exists($newUserId, $options['soundcloud_is_gold_users'])){
803
  $return = '<li class="soundcloudIsGoldUserContainer" style="background-image:URL('.$newUsernameImg.')">';
804
  $return .= '<span class="soundcloudIsGoldRemoveUser" />&nbsp;</span>';
805
  $return .= '<div>';
806
+ $return .= '<input type="hidden" value="'.$newUserId.'" name="soundcloud_is_gold_options[soundcloud_is_gold_users]['.$newUserId.'][0]" />';
807
+ $return .= '<input type="hidden" value="'.$newUsername.'" name="soundcloud_is_gold_options[soundcloud_is_gold_users]['.$newUserId.'][1]" />';
808
+ $return .= '<input type="hidden" value="'.$newUsernameImg.'" name="soundcloud_is_gold_options[soundcloud_is_gold_users]['.$newUserId.'][2]" />';
809
  $return .= '<p>'.$newUsername.'</p>';
810
  $return .= '</div>';
811
  $return .= '</li>';
812
 
813
  //Tab: extra actions
814
  if($_POST['updateOption'] == '1'){
815
+ $options['soundcloud_is_gold_users'][$newUserId][0] = $newUserId;
816
+ $options['soundcloud_is_gold_users'][$newUserId][1] = $newUsername;
817
+ $options['soundcloud_is_gold_users'][$newUserId][2] = $newUsernameImg;
818
  update_option( 'soundcloud_is_gold_options', $options );
819
  }
 
820
  }
821
  echo $return;
822
  }
830
  if(isset($_POST['request'])){
831
  $options = get_option('soundcloud_is_gold_options');
832
  if(isset($options['soundcloud_is_gold_active_user'])){
833
+ //Check if userid exist and is not blank
834
+ if(!empty($_POST['userid']) && array_key_exists($_POST['userid'], $options['soundcloud_is_gold_users'])){
835
+ $options['soundcloud_is_gold_active_user'] = $_POST['userid'];
836
  update_option( 'soundcloud_is_gold_options', $options );
837
  $message = 'done';
838
  }
849
  $options = get_option('soundcloud_is_gold_options');
850
  if(isset($options['soundcloud_is_gold_active_user'])){
851
  //Check username exist and isn't blank
852
+ if(!empty($_POST['userid']) && array_key_exists($_POST['userid'], $options['soundcloud_is_gold_users'])){
853
  //Remove from users
854
+ unset($options['soundcloud_is_gold_users'][$_POST['userid']]);
855
  //If active user, set the first element to be active
856
+ if($options['soundcloud_is_gold_active_user'] == $_POST['userid']){
857
  $newActiveUser = array_shift(array_values($options['soundcloud_is_gold_users']));
858
  $options['soundcloud_is_gold_active_user'] = $newActiveUser[0];
859
  }
919
  //Random User
920
  if($user == "randomUser") {
921
  $options = get_option('soundcloud_is_gold_options');
922
+ //Fix bug when updating to 2.4.2 where API requests can only use user id
923
+ $options = soundcloud_is_gold_update_users($options);
924
+ //Pick Random User
925
  $soundcloudIsGoldUsers = isset($options['soundcloud_is_gold_users']) ? array_random($options['soundcloud_is_gold_users'], 1) : '';
926
  //printl($soundcloudIsGoldUsers[0][0]);
927
  if(isset($soundcloudIsGoldUsers)) $user = $soundcloudIsGoldUsers[0][0];
933
  //Random User per Track
934
  if($user == "randomUsers") {
935
  $options = get_option('soundcloud_is_gold_options');
936
+ //Fix bug when updating to 2.4.2 where API requests can only use user id
937
+ $options = soundcloud_is_gold_update_users($options);
938
+ //Set Random User per Track
939
  if(isset($options['soundcloud_is_gold_users'])){
940
  //Never select more tracks than there is users.
941
  $number = (count($options['soundcloud_is_gold_users']) <= $number) ? count($options['soundcloud_is_gold_users']) : $number;
1007
  else {
1008
  $title = __( 'Latest', 'text_domain' );
1009
  }
1010
+ //Get Plugin Options
1011
+ $options = get_option('soundcloud_is_gold_options');
1012
+ //Fix bug when updating to 2.4.2 where API requests can only use user id
1013
+ $options = soundcloud_is_gold_update_users($options);
1014
  ?>
1015
  <!-- Title -->
1016
  <p>
1022
  <label for="<?php echo $this->get_field_id('user'); ?>"><?php _e( 'Username:' ); ?></label>
1023
  <select name="<?php echo $this->get_field_name('user'); ?>" id="<?php echo $this->get_field_id('user'); ?>" class="widefat">
1024
  <?php
 
1025
  foreach($options['soundcloud_is_gold_users'] as $user) : ?>
1026
+ <option value="<?php echo $user[0] ?>"<?php selected( $instance['user'], $user[0] ); ?>><?php _e($user[1]); ?></option>
1027
  <?php endforeach; ?>
1028
  <option value="randomUser"<?php selected( $instance['user'], "randomUser" ); ?>><?php _e("Pick a Random User"); ?></option>
1029
  <option value="randomUsers"<?php selected( $instance['user'], "randomUsers" ); ?>><?php _e("Pick a Random User per Track"); ?></option>
soundcloud-is-gold-js.js CHANGED
@@ -66,19 +66,19 @@ jQuery(document).ready(function($){
66
  });
67
  }
68
  /** Remove User From Options (Tab only) **/
69
- function removeUserFromOptions(usernameToRemove, reload){
70
- if($("#soundcloudMMUsermameTab").length){
71
- //console.log(usernameToRemove);
72
- //Set request
73
- var myData = {
74
- action: 'soundcloud_is_gold_delete_user',
75
- request: 'soundcloudIsGoldDeleteUser',
76
- username: usernameToRemove
77
- };
78
- jQuery.post(ajaxurl, myData, function(response) {
79
- if(response == 'done' && reload) location.reload();
80
- });
81
- }
82
  }
83
  /** Add new User **/
84
  $("#soundcloudIsGoldAddUser").click(function(e){
@@ -113,7 +113,7 @@ jQuery(document).ready(function($){
113
  //Copy new Active User to the Active User container and move active user label
114
  newActiveUser.clone().css("margin", "5px 4px").appendTo("#soundcloudIsGoldActiveUserContainer").prepend($("#soundcloudIsGoldActiveLabel")).fadeIn();
115
  //Update hidden field for active user
116
- $("#soundcloudIsGoldActiveUser").val($('p', newActiveUser).html());
117
  //Remove it from carousel
118
  $("#soundcloudIsGoldUsernameCarousel").trigger("removeItem", $(this));
119
  //Move old active user to carousel
@@ -128,7 +128,7 @@ jQuery(document).ready(function($){
128
  var myData = {
129
  action: 'soundcloud_is_gold_set_active_user',
130
  request: 'soundcloudIsGoldSetActiveUser',
131
- username: $("#soundcloudIsGoldActiveUser").val()
132
  };
133
  jQuery.post(ajaxurl, myData, function(response) {
134
  if(response != "error"){
@@ -160,7 +160,7 @@ jQuery(document).ready(function($){
160
  //Remove it from carousel
161
  removeUser($(this));
162
  //Update hidden field for active user
163
- $("#soundcloudIsGoldActiveUser").val($('#soundcloudIsGoldActiveUserContainer .soundcloudIsGoldUserContainer div p').html());
164
  });
165
  });
166
  });
66
  });
67
  }
68
  /** Remove User From Options (Tab only) **/
69
+ function removeUserFromOptions(useridToRemove, reload){
70
+ if($("#soundcloudMMUsermameTab").length){
71
+ //console.log(useridToRemove);
72
+ //Set request
73
+ var myData = {
74
+ action: 'soundcloud_is_gold_delete_user',
75
+ request: 'soundcloudIsGoldDeleteUser',
76
+ userid: useridToRemove
77
+ };
78
+ jQuery.post(ajaxurl, myData, function(response) {
79
+ if(response == 'done' && reload) location.reload();
80
+ });
81
+ }
82
  }
83
  /** Add new User **/
84
  $("#soundcloudIsGoldAddUser").click(function(e){
113
  //Copy new Active User to the Active User container and move active user label
114
  newActiveUser.clone().css("margin", "5px 4px").appendTo("#soundcloudIsGoldActiveUserContainer").prepend($("#soundcloudIsGoldActiveLabel")).fadeIn();
115
  //Update hidden field for active user
116
+ $("#soundcloudIsGoldActiveUser").val($('input:first', newActiveUser).val());
117
  //Remove it from carousel
118
  $("#soundcloudIsGoldUsernameCarousel").trigger("removeItem", $(this));
119
  //Move old active user to carousel
128
  var myData = {
129
  action: 'soundcloud_is_gold_set_active_user',
130
  request: 'soundcloudIsGoldSetActiveUser',
131
+ userid: $("#soundcloudIsGoldActiveUser").val()
132
  };
133
  jQuery.post(ajaxurl, myData, function(response) {
134
  if(response != "error"){
160
  //Remove it from carousel
161
  removeUser($(this));
162
  //Update hidden field for active user
163
+ $("#soundcloudIsGoldActiveUser").val($('#soundcloudIsGoldActiveUserContainer .soundcloudIsGoldUserContainer div input:first').val());
164
  });
165
  });
166
  });
soundcloud-is-gold.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Soundcloud is Gold
4
  Plugin URI: http://www.mightymess.com/soundcloud-is-gold-wordpress-plugin
5
  Description: <strong><a href="http://www.mightymess.com/soundcloud-is-gold-wordpress-plugin">Soundcloud is gold</a></strong> integrates perfectly into wordpress. Select, set and add track, playlists or favorites to your post using the soundcloud player. Live Preview, easy, smart and straightforward. You can set default settings in the option page, choose your defaut soundcloud player (Standard, Artwork, Visual), its width, extra Css classes for you CSS lovers and your favorite colors. You'll still be able to set players to different settings before adding to your post if you fancy a one off change!
6
- Version: 2.4.1
7
  Author: Thomas Michalak
8
  Author URI: http://www.mightymess.com/thomas-michalak
9
  License: GPL2 or Later
@@ -147,40 +147,6 @@ register_uninstall_hook(__FILE__, 'soundcloud_is_gold_delete_plugin_options');
147
  function soundcloud_is_gold_delete_plugin_options() {
148
  delete_option("soundcloud_is_gold_options");
149
  }
150
- //Updating plugin
151
- //Update database if needed during Update
152
- //Updating plugin
153
- /*function soundcloud_is_gold_update_plugin($upgrader_object, $options){
154
- $current_plugin_path_name = plugin_basename( __FILE__ );
155
-
156
- if ($options['action'] == 'update' && $options['type'] == 'plugin' ){
157
- foreach($options['packages'] as $each_plugin){
158
- if ($each_plugin==$current_plugin_path_name){
159
- soundcloud_is_gold_update_plugin_options();
160
- }
161
- }
162
- }
163
- }
164
- add_action( 'upgrader_process_complete', 'soundcloud_is_gold_update_plugin',10, 2);
165
- */
166
-
167
- //Update plugin options
168
- function soundcloud_is_gold_update_plugin_options_userid(){
169
- $options = get_option('soundcloud_is_gold_options');
170
- $soundcloudIsGoldUsers = isset($options['soundcloud_is_gold_users']) ? $options['soundcloud_is_gold_users'] : '';
171
- foreach ($soundcloudIsGoldUsers as $key => $user) {
172
- if(!is_numeric($user[0])){
173
- //Get user id based on username
174
- $soundcloudIsGoldApiCall = 'https://api.soundcloud.com/resolve.json?url=https://www.soundcloud.com/'.$user[0].'&client_id='.CLIENT_ID;
175
- $soundcloudIsGoldApiResponse = get_soundcloud_is_gold_api_response($soundcloudIsGoldApiCall);
176
- //Update options with user id
177
- if(isset($soundcloudIsGoldApiResponse['response']['location'])){
178
- $soundcloudIsGoldApiResponse = get_soundcloud_is_gold_api_response($soundcloudIsGoldApiResponse['response']['location']);
179
- //update options
180
- }
181
- }
182
- }
183
- }
184
 
185
  // display default admin notice
186
  function soundcloud_is_gold_add_settings_errors() {
@@ -196,7 +162,9 @@ add_action('admin_notices', 'soundcloud_is_gold_add_settings_errors');
196
  /**********************************************/
197
  function soundcloud_is_gold_options(){
198
  $options = get_option('soundcloud_is_gold_options');
199
- //printl($options);
 
 
200
  $soundcloudIsGoldActiveUser = isset($options['soundcloud_is_gold_active_user']) ? $options['soundcloud_is_gold_active_user'] : '';
201
  $soundcloudIsGoldUsers = isset($options['soundcloud_is_gold_users']) ? $options['soundcloud_is_gold_users'] : '';
202
  $soundcloudIsGoldSettings = isset($options['soundcloud_is_gold_settings']) ? $options['soundcloud_is_gold_settings'] : '';
3
  Plugin Name: Soundcloud is Gold
4
  Plugin URI: http://www.mightymess.com/soundcloud-is-gold-wordpress-plugin
5
  Description: <strong><a href="http://www.mightymess.com/soundcloud-is-gold-wordpress-plugin">Soundcloud is gold</a></strong> integrates perfectly into wordpress. Select, set and add track, playlists or favorites to your post using the soundcloud player. Live Preview, easy, smart and straightforward. You can set default settings in the option page, choose your defaut soundcloud player (Standard, Artwork, Visual), its width, extra Css classes for you CSS lovers and your favorite colors. You'll still be able to set players to different settings before adding to your post if you fancy a one off change!
6
+ Version: 2.4.2
7
  Author: Thomas Michalak
8
  Author URI: http://www.mightymess.com/thomas-michalak
9
  License: GPL2 or Later
147
  function soundcloud_is_gold_delete_plugin_options() {
148
  delete_option("soundcloud_is_gold_options");
149
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  // display default admin notice
152
  function soundcloud_is_gold_add_settings_errors() {
162
  /**********************************************/
163
  function soundcloud_is_gold_options(){
164
  $options = get_option('soundcloud_is_gold_options');
165
+ //Fix bug when updating to 2.4.2 where API requests can only use user id
166
+ $options = soundcloud_is_gold_update_users($options);
167
+ //printl($options);
168
  $soundcloudIsGoldActiveUser = isset($options['soundcloud_is_gold_active_user']) ? $options['soundcloud_is_gold_active_user'] : '';
169
  $soundcloudIsGoldUsers = isset($options['soundcloud_is_gold_users']) ? $options['soundcloud_is_gold_users'] : '';
170
  $soundcloudIsGoldSettings = isset($options['soundcloud_is_gold_settings']) ? $options['soundcloud_is_gold_settings'] : '';