PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 3.2.1
Wp Social Login and Register Social Counter v3.2.1
3.2.1 trunk 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.4 1.4.5 1.4.6 1.4.8 1.4.9 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.8 2.2.9 3.0.0 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0
wp-social / app / api-routes.php
wp-social / app Last commit date
api-routes.php 1 week ago avatar.php 5 years ago counter-settings.php 5 years ago legacy.php 5 years ago login-settings.php 1 week ago providers.php 1 week ago route.php 1 week ago settings.php 5 years ago share-settings.php 1 week ago share.php 3 years ago
api-routes.php
161 lines
1 <?php
2
3 namespace WP_Social\App;
4
5 use WP_Social\Lib\Provider\Share_Factory;
6
7 defined('ABSPATH') || exit;
8
9 class API_Routes {
10
11 private static $instance;
12
13 protected $version = 1;
14
15 public function init() {
16
17 add_action('rest_api_init', function() {
18
19 register_rest_route('wp_social/v' . $this->version, '/counter/enable/(?P<key>\w+)', array(
20 'methods' => 'POST',
21 'callback' => [$this, 'enable_provider_counter'],
22 'permission_callback' => function() {
23 return true;
24 },
25 )
26 );
27
28 register_rest_route('wp_social/v' . $this->version, '/share/enable/(?P<key>\w+)', array(
29 'methods' => 'POST',
30 'callback' => [$this, 'enable_provider_share'],
31 'permission_callback' => function() {
32 return true;
33 },
34 )
35 );
36
37 register_rest_route('wp_social/v' . $this->version, '/login/enable/(?P<key>\w+)', array(
38 'methods' => 'POST',
39 'callback' => [$this, 'enable_provider_login'],
40 'permission_callback' => function() {
41 return true;
42 },
43 )
44 );
45
46
47 register_rest_route('wp_social/v' . $this->version, '/shared/url', array(
48 'methods' => 'POST',
49 'callback' => [$this, 'increase_url_share_count'],
50 'permission_callback' => function() {
51 return true;
52 },
53 )
54 );
55
56 });
57 }
58
59
60 public function enable_provider_counter(\WP_REST_Request $request) {
61
62 if ( !wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest') || !is_user_logged_in() || !current_user_can('manage_options') ) {
63 wp_send_json(array('msg' => 'Access Denied', 'success' => false), 403);
64 }
65
66 $social_key = $request['key'];
67
68 // TikTok requires wp-social-pro plugin to be active
69 if($social_key === 'tiktok' && !\WP_Social::is_pro_active()) {
70 return array(
71 'msg' => 'TikTok requires WP Social Pro plugin to be active',
72 'success' => false,
73 );
74 }
75
76 $providers = \WP_Social\App\Settings::get_enabled_provider_conf_counter();
77 $parameters = $request->get_params();
78
79 $providers[$social_key]['enable'] = empty($parameters['val']) ? '' : 1;
80
81 $saved = \WP_Social\App\Settings::update_enabled_provider_conf_counter($providers);
82
83 return array(
84 'msg' => 'successful',
85 'success' => $saved,
86 );
87 }
88
89
90 public function enable_provider_share(\WP_REST_Request $request) {
91
92 if ( !wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest') || !is_user_logged_in() || !current_user_can('manage_options') ) {
93 wp_send_json(array('msg' => 'Access Denied', 'success' => false), 403);
94 }
95
96 $social_key = $request['social'];
97 $providers = \WP_Social\App\Settings::get_enabled_provider_conf_share();
98 $parameters = $request->get_params();
99
100 $providers[$social_key]['enable'] = empty($parameters['val']) ? '' : 1;
101
102 $saved = \WP_Social\App\Settings::update_enabled_provider_conf_share($providers);
103
104 return array(
105 'msg' => 'successful',
106 'success' => $saved,
107 );
108 }
109
110
111 public function enable_provider_login(\WP_REST_Request $request) {
112
113 if ( !wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest') || !is_user_logged_in() || !current_user_can('manage_options') ) {
114 wp_send_json(array('msg' => 'Access Denied', 'success' => false), 403);
115 }
116
117 $social_key = $request['key'];
118 $providers = \WP_Social\App\Settings::get_enabled_provider_conf_login();
119 $parameters = $request->get_params();
120
121 $providers[$social_key]['enable'] = empty($parameters['val']) ? '' : 1;
122
123 $saved = \WP_Social\App\Settings::update_enabled_provider_conf_login($providers);
124
125 return array(
126 'msg' => 'successful',
127 'success' => $saved,
128 );
129 }
130
131
132 public function increase_url_share_count(\WP_REST_Request $request) {
133
134 if ( !wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest') || !is_user_logged_in() || !current_user_can('manage_options') ) {
135 wp_send_json(array('msg' => 'Access Denied', 'success' => false), 403);
136 }
137
138 $key = $request['social'];
139 $pid = $request['pid'];
140 $hash = $request['hash'];
141
142 $factory = new Share_Factory($pid);
143 $obj = $factory->make($key);
144
145 $saved = $obj->set_uri_hash($hash)->increase_share_count_by_one();
146
147 return array(
148 'msg' => 'successful',
149 'success' => $saved,
150 );
151 }
152
153 public static function instance() {
154 if(!self::$instance) {
155 self::$instance = new static();
156 }
157
158 return self::$instance;
159 }
160 }
161