Version Description
- Updated FB API to work with new graph API
Download this release
Release Info
Developer | Access Keys |
Plugin | Social Counter for WordPress – AccessPress Social Counter |
Version | 1.5.2 |
Comparing to | |
See all releases |
Code changes from version 1.5.1 to 1.5.2
- accesspress-social-counter.php +58 -212
- inc/backend/boards/social-profiles.php +17 -0
- inc/frontend/api.php +219 -0
- readme.txt +4 -1
accesspress-social-counter.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: AccessPress Social Counter
|
4 |
* Plugin URI: https://accesspressthemes.com/wordpress-plugins/accesspress-social-counter/
|
5 |
* Description: A plugin to display your social accounts fans, subscribers and followers number on your website with handful of backend settings and interface.
|
6 |
-
* Version: 1.5.
|
7 |
* Author: AccessPress Themes
|
8 |
* Author URI: http://accesspressthemes.com
|
9 |
* Text Domain: aps-counter
|
@@ -24,7 +24,7 @@ if (!defined('SC_CSS_DIR')) {
|
|
24 |
define('SC_CSS_DIR', plugin_dir_url(__FILE__) . 'css');
|
25 |
}
|
26 |
if (!defined('SC_VERSION')) {
|
27 |
-
define('SC_VERSION', '1.5.
|
28 |
}
|
29 |
/**
|
30 |
* Register of widgets
|
@@ -385,216 +385,7 @@ if (!class_exists('SC_Class')) {
|
|
385 |
}
|
386 |
|
387 |
function get_count($social_media){
|
388 |
-
|
389 |
-
$apsc_settings = $this->apsc_settings;
|
390 |
-
$cache_period = ($apsc_settings['cache_period'] != '') ? $apsc_settings['cache_period']*60*60 : 24 * 60 * 60;
|
391 |
-
switch($social_media){
|
392 |
-
case 'facebook':
|
393 |
-
$facebook_page_id = $apsc_settings['social_profile']['facebook']['page_id'];
|
394 |
-
$facebook_count = get_transient('apsc_facebook');
|
395 |
-
if (false === $facebook_count) {
|
396 |
-
|
397 |
-
$api_url = 'https://www.facebook.com/' . $facebook_page_id;
|
398 |
-
|
399 |
-
$count = $this->facebook_count($api_url);
|
400 |
-
set_transient('apsc_facebook', $count, $cache_period);
|
401 |
-
|
402 |
-
} else {
|
403 |
-
$count = $facebook_count;
|
404 |
-
}
|
405 |
-
|
406 |
-
$default_count = isset($apsc_settings['social_profile']['facebook']['default_count'])?$apsc_settings['social_profile']['facebook']['default_count']:0;
|
407 |
-
$count = ($count==0)?$default_count:$count;
|
408 |
-
if($count!=0){
|
409 |
-
set_transient('apsc_facebook',$count,$cache_period);
|
410 |
-
}
|
411 |
-
break;
|
412 |
-
case 'twitter':
|
413 |
-
|
414 |
-
$twitter_count = get_transient('apsc_twitter');
|
415 |
-
if (false === $twitter_count) {
|
416 |
-
$count = ($this->get_twitter_count());
|
417 |
-
set_transient('apsc_twitter', $count, $cache_period);
|
418 |
-
} else {
|
419 |
-
$count = $twitter_count;
|
420 |
-
}
|
421 |
-
|
422 |
-
|
423 |
-
break;
|
424 |
-
case 'googlePlus':
|
425 |
-
$social_profile_url = 'https://plus.google.com/' . $apsc_settings['social_profile']['googlePlus']['page_id'];
|
426 |
-
|
427 |
-
$googlePlus_count = get_transient('apsc_googlePlus');
|
428 |
-
if (false === $googlePlus_count) {
|
429 |
-
$api_url = 'https://www.googleapis.com/plus/v1/people/' . $apsc_settings['social_profile']['googlePlus']['page_id'] . '?key=' . $apsc_settings['social_profile']['googlePlus']['api_key'];
|
430 |
-
$params = array(
|
431 |
-
'sslverify' => false,
|
432 |
-
'timeout' => 60
|
433 |
-
);
|
434 |
-
$connection = wp_remote_get($api_url, $params);
|
435 |
-
|
436 |
-
if (is_wp_error($connection)) {
|
437 |
-
$count = 0;
|
438 |
-
} else {
|
439 |
-
$_data = json_decode($connection['body'], true);
|
440 |
-
|
441 |
-
if (isset($_data['circledByCount'])) {
|
442 |
-
$count = (intval($_data['circledByCount']));
|
443 |
-
set_transient('apsc_googlePlus', $count,$cache_period);
|
444 |
-
} else {
|
445 |
-
$count = 0;
|
446 |
-
}
|
447 |
-
}
|
448 |
-
} else {
|
449 |
-
$count = $googlePlus_count;
|
450 |
-
}
|
451 |
-
|
452 |
-
break;
|
453 |
-
case 'instagram':
|
454 |
-
$username = $apsc_settings['social_profile']['instagram']['username'];
|
455 |
-
$user_id = $apsc_settings['social_profile']['instagram']['user_id'];
|
456 |
-
$social_profile_url = 'https://instagram.com/' . $username;
|
457 |
-
|
458 |
-
$instagram_count = get_transient('apsc_instagram');
|
459 |
-
if (false === $instagram_count) {
|
460 |
-
$access_token = $apsc_settings['social_profile']['instagram']['access_token'];
|
461 |
-
|
462 |
-
$api_url = 'https://api.instagram.com/v1/users/' . $user_id . '?access_token=' . $access_token;
|
463 |
-
$params = array(
|
464 |
-
'sslverify' => false,
|
465 |
-
'timeout' => 60
|
466 |
-
);
|
467 |
-
$connection = wp_remote_get($api_url, $params);
|
468 |
-
if (is_wp_error($connection)) {
|
469 |
-
$count = 0;
|
470 |
-
} else {
|
471 |
-
$response = json_decode($connection['body'], true);
|
472 |
-
if (
|
473 |
-
isset($response['meta']['code']) && 200 == $response['meta']['code'] && isset($response['data']['counts']['followed_by'])
|
474 |
-
) {
|
475 |
-
$count = (intval($response['data']['counts']['followed_by']));
|
476 |
-
set_transient('apsc_instagram',$count,$cache_period);
|
477 |
-
} else {
|
478 |
-
$count = 0;
|
479 |
-
}
|
480 |
-
}
|
481 |
-
} else {
|
482 |
-
$count = $instagram_count;
|
483 |
-
}
|
484 |
-
|
485 |
-
break;
|
486 |
-
case 'youtube':
|
487 |
-
$social_profile_url = esc_url($apsc_settings['social_profile']['youtube']['channel_url']);
|
488 |
-
$count = get_transient('apsc_youtube');
|
489 |
-
|
490 |
-
if(false === $count){
|
491 |
-
$count = $apsc_settings['social_profile']['youtube']['subscribers_count'];
|
492 |
-
if(
|
493 |
-
isset($apsc_settings['social_profile']['youtube']['channel_id'],$apsc_settings['social_profile']['youtube']['api_key']) &&
|
494 |
-
$apsc_settings['social_profile']['youtube']['channel_id']!='' && $apsc_settings['social_profile']['youtube']['api_key']
|
495 |
-
)
|
496 |
-
{
|
497 |
-
|
498 |
-
$api_key = $apsc_settings['social_profile']['youtube']['api_key'];
|
499 |
-
$channel_id = $apsc_settings['social_profile']['youtube']['channel_id'];
|
500 |
-
$api_url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&id='.$channel_id.'&key='.$api_key;
|
501 |
-
$connection = wp_remote_get($api_url, array('timeout'=>60));
|
502 |
-
|
503 |
-
if (!is_wp_error($connection)) {
|
504 |
-
$response = json_decode($connection['body'], true);
|
505 |
-
if (isset($response['items'][0]['statistics']['subscriberCount'])) {
|
506 |
-
$count = $response['items'][0]['statistics']['subscriberCount'];
|
507 |
-
set_transient('apsc_youtube',$count,$cache_period);
|
508 |
-
}
|
509 |
-
}
|
510 |
-
}
|
511 |
-
}
|
512 |
-
break;
|
513 |
-
case 'soundcloud':
|
514 |
-
$username = $apsc_settings['social_profile']['soundcloud']['username'];
|
515 |
-
$social_profile_url = 'https://soundcloud.com/' . $username;
|
516 |
-
|
517 |
-
$soundcloud_count = get_transient('apsc_soundcloud');
|
518 |
-
if (false === $soundcloud_count) {
|
519 |
-
$api_url = 'https://api.soundcloud.com/users/' . $username . '.json?client_id=' . $apsc_settings['social_profile']['soundcloud']['client_id'];
|
520 |
-
$params = array(
|
521 |
-
'sslverify' => false,
|
522 |
-
'timeout' => 60
|
523 |
-
);
|
524 |
-
|
525 |
-
$connection = wp_remote_get($api_url, $params);
|
526 |
-
if (is_wp_error($connection)) {
|
527 |
-
$count = 0;
|
528 |
-
} else {
|
529 |
-
$response = json_decode($connection['body'], true);
|
530 |
-
|
531 |
-
if (isset($response['followers_count'])) {
|
532 |
-
$count = (intval($response['followers_count']));
|
533 |
-
set_transient( 'apsc_soundcloud',$count,$cache_period );
|
534 |
-
} else {
|
535 |
-
$count = 0;
|
536 |
-
}
|
537 |
-
}
|
538 |
-
} else {
|
539 |
-
$count = $soundcloud_count;
|
540 |
-
}
|
541 |
-
|
542 |
-
break;
|
543 |
-
case 'dribbble':
|
544 |
-
$social_profile_url = 'http://dribbble.com/'.$apsc_settings['social_profile']['dribbble']['username'];
|
545 |
-
|
546 |
-
$dribbble_count = get_transient('apsc_dribbble');
|
547 |
-
if (false === $dribbble_count) {
|
548 |
-
$username = $apsc_settings['social_profile']['dribbble']['username'];
|
549 |
-
$api_url = 'http://api.dribbble.com/' . $username;
|
550 |
-
$params = array(
|
551 |
-
'sslverify' => false,
|
552 |
-
'timeout' => 60
|
553 |
-
);
|
554 |
-
$connection = wp_remote_get($api_url, $params);
|
555 |
-
if (is_wp_error($connection)) {
|
556 |
-
$count = 0;
|
557 |
-
} else {
|
558 |
-
$response = json_decode($connection['body'], true);
|
559 |
-
if (isset($response['followers_count'])) {
|
560 |
-
$count = (intval($response['followers_count']));
|
561 |
-
set_transient('apsc_dribbble',$count,$cache_period );
|
562 |
-
} else {
|
563 |
-
$count = 0;
|
564 |
-
}
|
565 |
-
}
|
566 |
-
} else {
|
567 |
-
$count = $dribbble_count;
|
568 |
-
}
|
569 |
-
|
570 |
-
break;
|
571 |
-
case 'posts':
|
572 |
-
|
573 |
-
$posts_count = get_transient('apsc_posts');
|
574 |
-
if (false === $posts_count) {
|
575 |
-
$posts_count = wp_count_posts();
|
576 |
-
$count = $posts_count->publish;
|
577 |
-
set_transient('apsc_posts', $count, $cache_period);
|
578 |
-
} else {
|
579 |
-
$count = $posts_count;
|
580 |
-
}
|
581 |
-
|
582 |
-
break;
|
583 |
-
case 'comments':
|
584 |
-
|
585 |
-
$comments_count = get_transient('apsc_comments');
|
586 |
-
if (false === $comments_count) {
|
587 |
-
$data = wp_count_comments();
|
588 |
-
$count = ($data->approved);
|
589 |
-
set_transient('apsc_comments', $count, $cache_period);
|
590 |
-
} else {
|
591 |
-
$count = $comments_count;
|
592 |
-
}
|
593 |
-
|
594 |
-
break;
|
595 |
-
default:
|
596 |
-
break;
|
597 |
-
}
|
598 |
return $count;
|
599 |
}
|
600 |
|
@@ -611,6 +402,61 @@ if (!class_exists('SC_Class')) {
|
|
611 |
return $count;
|
612 |
}
|
613 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
614 |
|
615 |
|
616 |
}
|
3 |
* Plugin Name: AccessPress Social Counter
|
4 |
* Plugin URI: https://accesspressthemes.com/wordpress-plugins/accesspress-social-counter/
|
5 |
* Description: A plugin to display your social accounts fans, subscribers and followers number on your website with handful of backend settings and interface.
|
6 |
+
* Version: 1.5.2
|
7 |
* Author: AccessPress Themes
|
8 |
* Author URI: http://accesspressthemes.com
|
9 |
* Text Domain: aps-counter
|
24 |
define('SC_CSS_DIR', plugin_dir_url(__FILE__) . 'css');
|
25 |
}
|
26 |
if (!defined('SC_VERSION')) {
|
27 |
+
define('SC_VERSION', '1.5.2');
|
28 |
}
|
29 |
/**
|
30 |
* Register of widgets
|
385 |
}
|
386 |
|
387 |
function get_count($social_media){
|
388 |
+
include('inc/frontend/api.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
return $count;
|
390 |
}
|
391 |
|
402 |
return $count;
|
403 |
}
|
404 |
}
|
405 |
+
|
406 |
+
/**
|
407 |
+
* Get Facebook Access Token
|
408 |
+
* */
|
409 |
+
function get_fb_access_token(){
|
410 |
+
$apsc_settings = $this->apsc_settings;
|
411 |
+
$api_url = 'https://graph.facebook.com/';
|
412 |
+
$url = sprintf(
|
413 |
+
'%s/oauth/access_token?client_id=%s&client_secret=%s&grant_type=client_credentials',
|
414 |
+
$api_url,
|
415 |
+
$apsc_settings['social_profile']['facebook']['app_id'] ,
|
416 |
+
$apsc_settings['social_profile']['facebook']['app_secret']
|
417 |
+
);
|
418 |
+
$access_token = wp_remote_get( $url, array( 'timeout' => 60 ) );
|
419 |
+
|
420 |
+
if ( is_wp_error( $access_token ) || ( isset( $access_token['response']['code'] ) && 200 != $access_token['response']['code'] ) ) {
|
421 |
+
return '';
|
422 |
+
} else {
|
423 |
+
return sanitize_text_field( $access_token['body'] );
|
424 |
+
}
|
425 |
+
}
|
426 |
+
|
427 |
+
/**
|
428 |
+
* Get New Facebook Count
|
429 |
+
* */
|
430 |
+
function new_fb_count(){
|
431 |
+
$apsc_settings = $this->apsc_settings;
|
432 |
+
$access_token = $this->get_fb_access_token( );
|
433 |
+
$api_url = 'https://graph.facebook.com/';
|
434 |
+
$url = sprintf(
|
435 |
+
'%s%s?fields=likes&%s',
|
436 |
+
$api_url,
|
437 |
+
$apsc_settings['social_profile']['facebook']['page_id'] ,
|
438 |
+
$access_token
|
439 |
+
);
|
440 |
+
|
441 |
+
$connection = wp_remote_get( $url, array( 'timeout' => 60 ) );
|
442 |
+
|
443 |
+
if ( is_wp_error( $connection ) || ( isset( $connection['response']['code'] ) && 200 != $connection['response']['code'] ) ) {
|
444 |
+
$total = 0;
|
445 |
+
} else {
|
446 |
+
$_data = json_decode( $connection['body'], true );
|
447 |
+
|
448 |
+
if ( isset( $_data['likes'] ) ) {
|
449 |
+
$count = intval( $_data['likes'] );
|
450 |
+
|
451 |
+
$total = $count;
|
452 |
+
} else {
|
453 |
+
$total = 0;
|
454 |
+
}
|
455 |
+
}
|
456 |
+
|
457 |
+
|
458 |
+
return $total;
|
459 |
+
}
|
460 |
|
461 |
|
462 |
}
|
inc/backend/boards/social-profiles.php
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<div class="apsc-boards-tabs" id="apsc-board-social-profile-settings">
|
|
|
2 |
<div class="apsc-tab-wrapper">
|
3 |
<!---Facebook-->
|
4 |
<div class="apsc-option-outer-wrapper">
|
@@ -16,6 +17,22 @@
|
|
16 |
|
17 |
</div>
|
18 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
<div class="apsc-option-inner-wrapper">
|
20 |
<label><?php _e('Facebook Default Count', 'accesspress-social-counter'); ?></label>
|
21 |
<div class="apsc-option-field">
|
1 |
<div class="apsc-boards-tabs" id="apsc-board-social-profile-settings">
|
2 |
+
|
3 |
<div class="apsc-tab-wrapper">
|
4 |
<!---Facebook-->
|
5 |
<div class="apsc-option-outer-wrapper">
|
17 |
|
18 |
</div>
|
19 |
</div>
|
20 |
+
<div class="apsc-option-inner-wrapper">
|
21 |
+
<label><?php _e('Facebook App ID', 'accesspress-social-counter'); ?></label>
|
22 |
+
<div class="apsc-option-field">
|
23 |
+
<input type="text" name="social_profile[facebook][app_id]" value="<?php echo isset($apsc_settings['social_profile']['facebook']['app_id'])?esc_attr($apsc_settings['social_profile']['facebook']['app_id']):'';?>"/>
|
24 |
+
<div class="apsc-option-note"><?php _e('Please go to <a href="https://developers.facebook.com/" target="_blank">https://developers.facebook.com/</a> and create an app and get the App ID', 'accesspress-social-counter'); ?></div>
|
25 |
+
|
26 |
+
</div>
|
27 |
+
</div>
|
28 |
+
<div class="apsc-option-inner-wrapper">
|
29 |
+
<label><?php _e('Facebook App Secret', 'accesspress-social-counter'); ?></label>
|
30 |
+
<div class="apsc-option-field">
|
31 |
+
<input type="text" name="social_profile[facebook][app_secret]" value="<?php echo isset($apsc_settings['social_profile']['facebook']['app_secret'])?esc_attr($apsc_settings['social_profile']['facebook']['app_secret']):'';?>"/>
|
32 |
+
<div class="apsc-option-note"><?php _e('Please go to <a href="https://developers.facebook.com/" target="_blank">https://developers.facebook.com/</a> and create an app and get the App Secret', 'accesspress-social-counter'); ?></div>
|
33 |
+
|
34 |
+
</div>
|
35 |
+
</div>
|
36 |
<div class="apsc-option-inner-wrapper">
|
37 |
<label><?php _e('Facebook Default Count', 'accesspress-social-counter'); ?></label>
|
38 |
<div class="apsc-option-field">
|
inc/frontend/api.php
ADDED
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$count = 0;
|
3 |
+
$apsc_settings = $this->apsc_settings;
|
4 |
+
$cache_period = ($apsc_settings['cache_period'] != '') ? $apsc_settings['cache_period']*60*60 : 24 * 60 * 60;
|
5 |
+
switch($social_media){
|
6 |
+
case 'facebook':
|
7 |
+
$facebook_page_id = $apsc_settings['social_profile']['facebook']['page_id'];
|
8 |
+
$facebook_count = get_transient('apsc_facebook');
|
9 |
+
if (false === $facebook_count) {
|
10 |
+
if(isset($apsc_settings['social_profile']['facebook']['app_id'],$apsc_settings['social_profile']['facebook']['app_secret']) && $apsc_settings['social_profile']['facebook']['app_id']!='' && $apsc_settings['social_profile']['facebook']['app_secret']!=''){
|
11 |
+
$count = $this->new_fb_count();
|
12 |
+
|
13 |
+
|
14 |
+
}else{
|
15 |
+
$api_url = 'https://www.facebook.com/' . $facebook_page_id;
|
16 |
+
|
17 |
+
$count = $this->facebook_count($api_url);
|
18 |
+
|
19 |
+
}
|
20 |
+
|
21 |
+
set_transient('apsc_facebook', $count, $cache_period);
|
22 |
+
|
23 |
+
} else {
|
24 |
+
$count = $facebook_count;
|
25 |
+
}
|
26 |
+
|
27 |
+
$default_count = isset($apsc_settings['social_profile']['facebook']['default_count'])?$apsc_settings['social_profile']['facebook']['default_count']:0;
|
28 |
+
$count = ($count==0)?$default_count:$count;
|
29 |
+
if($count!=0){
|
30 |
+
set_transient('apsc_facebook',$count,$cache_period);
|
31 |
+
}
|
32 |
+
break;
|
33 |
+
case 'twitter':
|
34 |
+
|
35 |
+
$twitter_count = get_transient('apsc_twitter');
|
36 |
+
if (false === $twitter_count) {
|
37 |
+
$count = ($this->get_twitter_count());
|
38 |
+
set_transient('apsc_twitter', $count, $cache_period);
|
39 |
+
} else {
|
40 |
+
$count = $twitter_count;
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
break;
|
45 |
+
case 'googlePlus':
|
46 |
+
$social_profile_url = 'https://plus.google.com/' . $apsc_settings['social_profile']['googlePlus']['page_id'];
|
47 |
+
|
48 |
+
$googlePlus_count = get_transient('apsc_googlePlus');
|
49 |
+
if (false === $googlePlus_count) {
|
50 |
+
$api_url = 'https://www.googleapis.com/plus/v1/people/' . $apsc_settings['social_profile']['googlePlus']['page_id'] . '?key=' . $apsc_settings['social_profile']['googlePlus']['api_key'];
|
51 |
+
$params = array(
|
52 |
+
'sslverify' => false,
|
53 |
+
'timeout' => 60
|
54 |
+
);
|
55 |
+
$connection = wp_remote_get($api_url, $params);
|
56 |
+
|
57 |
+
if (is_wp_error($connection)) {
|
58 |
+
$count = 0;
|
59 |
+
} else {
|
60 |
+
$_data = json_decode($connection['body'], true);
|
61 |
+
|
62 |
+
if (isset($_data['circledByCount'])) {
|
63 |
+
$count = (intval($_data['circledByCount']));
|
64 |
+
set_transient('apsc_googlePlus', $count,$cache_period);
|
65 |
+
} else {
|
66 |
+
$count = 0;
|
67 |
+
}
|
68 |
+
}
|
69 |
+
} else {
|
70 |
+
$count = $googlePlus_count;
|
71 |
+
}
|
72 |
+
|
73 |
+
break;
|
74 |
+
case 'instagram':
|
75 |
+
$username = $apsc_settings['social_profile']['instagram']['username'];
|
76 |
+
$user_id = $apsc_settings['social_profile']['instagram']['user_id'];
|
77 |
+
$social_profile_url = 'https://instagram.com/' . $username;
|
78 |
+
|
79 |
+
$instagram_count = get_transient('apsc_instagram');
|
80 |
+
if (false === $instagram_count) {
|
81 |
+
$access_token = $apsc_settings['social_profile']['instagram']['access_token'];
|
82 |
+
|
83 |
+
$api_url = 'https://api.instagram.com/v1/users/' . $user_id . '?access_token=' . $access_token;
|
84 |
+
$params = array(
|
85 |
+
'sslverify' => false,
|
86 |
+
'timeout' => 60
|
87 |
+
);
|
88 |
+
$connection = wp_remote_get($api_url, $params);
|
89 |
+
if (is_wp_error($connection)) {
|
90 |
+
$count = 0;
|
91 |
+
} else {
|
92 |
+
$response = json_decode($connection['body'], true);
|
93 |
+
if (
|
94 |
+
isset($response['meta']['code']) && 200 == $response['meta']['code'] && isset($response['data']['counts']['followed_by'])
|
95 |
+
) {
|
96 |
+
$count = (intval($response['data']['counts']['followed_by']));
|
97 |
+
set_transient('apsc_instagram',$count,$cache_period);
|
98 |
+
} else {
|
99 |
+
$count = 0;
|
100 |
+
}
|
101 |
+
}
|
102 |
+
} else {
|
103 |
+
$count = $instagram_count;
|
104 |
+
}
|
105 |
+
|
106 |
+
break;
|
107 |
+
case 'youtube':
|
108 |
+
$social_profile_url = esc_url($apsc_settings['social_profile']['youtube']['channel_url']);
|
109 |
+
$count = get_transient('apsc_youtube');
|
110 |
+
|
111 |
+
if(false === $count){
|
112 |
+
$count = $apsc_settings['social_profile']['youtube']['subscribers_count'];
|
113 |
+
if(
|
114 |
+
isset($apsc_settings['social_profile']['youtube']['channel_id'],$apsc_settings['social_profile']['youtube']['api_key']) &&
|
115 |
+
$apsc_settings['social_profile']['youtube']['channel_id']!='' && $apsc_settings['social_profile']['youtube']['api_key']
|
116 |
+
)
|
117 |
+
{
|
118 |
+
|
119 |
+
$api_key = $apsc_settings['social_profile']['youtube']['api_key'];
|
120 |
+
$channel_id = $apsc_settings['social_profile']['youtube']['channel_id'];
|
121 |
+
$api_url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&id='.$channel_id.'&key='.$api_key;
|
122 |
+
$connection = wp_remote_get($api_url, array('timeout'=>60));
|
123 |
+
|
124 |
+
if (!is_wp_error($connection)) {
|
125 |
+
$response = json_decode($connection['body'], true);
|
126 |
+
if (isset($response['items'][0]['statistics']['subscriberCount'])) {
|
127 |
+
$count = $response['items'][0]['statistics']['subscriberCount'];
|
128 |
+
set_transient('apsc_youtube',$count,$cache_period);
|
129 |
+
}
|
130 |
+
}
|
131 |
+
}
|
132 |
+
}
|
133 |
+
break;
|
134 |
+
case 'soundcloud':
|
135 |
+
$username = $apsc_settings['social_profile']['soundcloud']['username'];
|
136 |
+
$social_profile_url = 'https://soundcloud.com/' . $username;
|
137 |
+
|
138 |
+
$soundcloud_count = get_transient('apsc_soundcloud');
|
139 |
+
if (false === $soundcloud_count) {
|
140 |
+
$api_url = 'https://api.soundcloud.com/users/' . $username . '.json?client_id=' . $apsc_settings['social_profile']['soundcloud']['client_id'];
|
141 |
+
$params = array(
|
142 |
+
'sslverify' => false,
|
143 |
+
'timeout' => 60
|
144 |
+
);
|
145 |
+
|
146 |
+
$connection = wp_remote_get($api_url, $params);
|
147 |
+
if (is_wp_error($connection)) {
|
148 |
+
$count = 0;
|
149 |
+
} else {
|
150 |
+
$response = json_decode($connection['body'], true);
|
151 |
+
|
152 |
+
if (isset($response['followers_count'])) {
|
153 |
+
$count = (intval($response['followers_count']));
|
154 |
+
set_transient( 'apsc_soundcloud',$count,$cache_period );
|
155 |
+
} else {
|
156 |
+
$count = 0;
|
157 |
+
}
|
158 |
+
}
|
159 |
+
} else {
|
160 |
+
$count = $soundcloud_count;
|
161 |
+
}
|
162 |
+
|
163 |
+
break;
|
164 |
+
case 'dribbble':
|
165 |
+
$social_profile_url = 'http://dribbble.com/'.$apsc_settings['social_profile']['dribbble']['username'];
|
166 |
+
|
167 |
+
$dribbble_count = get_transient('apsc_dribbble');
|
168 |
+
if (false === $dribbble_count) {
|
169 |
+
$username = $apsc_settings['social_profile']['dribbble']['username'];
|
170 |
+
$api_url = 'http://api.dribbble.com/' . $username;
|
171 |
+
$params = array(
|
172 |
+
'sslverify' => false,
|
173 |
+
'timeout' => 60
|
174 |
+
);
|
175 |
+
$connection = wp_remote_get($api_url, $params);
|
176 |
+
if (is_wp_error($connection)) {
|
177 |
+
$count = 0;
|
178 |
+
} else {
|
179 |
+
$response = json_decode($connection['body'], true);
|
180 |
+
if (isset($response['followers_count'])) {
|
181 |
+
$count = (intval($response['followers_count']));
|
182 |
+
set_transient('apsc_dribbble',$count,$cache_period );
|
183 |
+
} else {
|
184 |
+
$count = 0;
|
185 |
+
}
|
186 |
+
}
|
187 |
+
} else {
|
188 |
+
$count = $dribbble_count;
|
189 |
+
}
|
190 |
+
|
191 |
+
break;
|
192 |
+
case 'posts':
|
193 |
+
|
194 |
+
$posts_count = get_transient('apsc_posts');
|
195 |
+
if (false === $posts_count) {
|
196 |
+
$posts_count = wp_count_posts();
|
197 |
+
$count = $posts_count->publish;
|
198 |
+
set_transient('apsc_posts', $count, $cache_period);
|
199 |
+
} else {
|
200 |
+
$count = $posts_count;
|
201 |
+
}
|
202 |
+
|
203 |
+
break;
|
204 |
+
case 'comments':
|
205 |
+
|
206 |
+
$comments_count = get_transient('apsc_comments');
|
207 |
+
if (false === $comments_count) {
|
208 |
+
$data = wp_count_comments();
|
209 |
+
$count = ($data->approved);
|
210 |
+
set_transient('apsc_comments', $count, $cache_period);
|
211 |
+
} else {
|
212 |
+
$count = $comments_count;
|
213 |
+
}
|
214 |
+
|
215 |
+
break;
|
216 |
+
default:
|
217 |
+
break;
|
218 |
+
}
|
219 |
+
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: social count, social counter, social counters, social media counters, soci
|
|
4 |
Donate link: http://accesspressthemes.com/donation/
|
5 |
Requires at least: 3.8
|
6 |
Tested up to: 4.4
|
7 |
-
Stable tag: 1.5.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -125,6 +125,9 @@ Once you install the plugin , you can check some general documentation about how
|
|
125 |
5. Backend Cache Settings Section
|
126 |
|
127 |
== Changelog ==
|
|
|
|
|
|
|
128 |
= 1.5.1 =
|
129 |
* Updated language file
|
130 |
|
4 |
Donate link: http://accesspressthemes.com/donation/
|
5 |
Requires at least: 3.8
|
6 |
Tested up to: 4.4
|
7 |
+
Stable tag: 1.5.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
125 |
5. Backend Cache Settings Section
|
126 |
|
127 |
== Changelog ==
|
128 |
+
= 1.5.2 =
|
129 |
+
* Updated FB API to work with new graph API
|
130 |
+
|
131 |
= 1.5.1 =
|
132 |
* Updated language file
|
133 |
|