PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 2.2.4
Wp Social Login and Register Social Counter v2.2.4
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 5 years ago avatar.php 4 years ago counter-settings.php 5 years ago legacy.php 5 years ago login-settings.php 3 years ago providers.php 3 years ago route.php 4 years ago settings.php 5 years ago share-settings.php 4 years ago share.php 3 years ago
api-routes.php
136 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 $social_key = $request['key'];
63 $providers = \WP_Social\App\Settings::get_enabled_provider_conf_counter();
64 $parameters = $request->get_params();
65
66 $providers[$social_key]['enable'] = empty($parameters['val']) ? '' : 1;
67
68 $saved = \WP_Social\App\Settings::update_enabled_provider_conf_counter($providers);
69
70 return array(
71 'msg' => 'successful',
72 'success' => $saved,
73 );
74 }
75
76
77 public function enable_provider_share(\WP_REST_Request $request) {
78
79 $social_key = $request['social'];
80 $providers = \WP_Social\App\Settings::get_enabled_provider_conf_share();
81 $parameters = $request->get_params();
82
83 $providers[$social_key]['enable'] = empty($parameters['val']) ? '' : 1;
84
85 $saved = \WP_Social\App\Settings::update_enabled_provider_conf_share($providers);
86
87 return array(
88 'msg' => 'successful',
89 'success' => $saved,
90 );
91 }
92
93
94 public function enable_provider_login(\WP_REST_Request $request) {
95
96 $social_key = $request['key'];
97 $providers = \WP_Social\App\Settings::get_enabled_provider_conf_login();
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_login($providers);
103
104 return array(
105 'msg' => 'successful',
106 'success' => $saved,
107 );
108 }
109
110
111 public function increase_url_share_count(\WP_REST_Request $request) {
112
113 $key = $request['social'];
114 $pid = $request['pid'];
115 $hash = $request['hash'];
116
117 $factory = new Share_Factory($pid);
118 $obj = $factory->make($key);
119
120 $saved = $obj->set_uri_hash($hash)->increase_share_count_by_one();
121
122 return array(
123 'msg' => 'successful',
124 'success' => $saved,
125 );
126 }
127
128 public static function instance() {
129 if(!self::$instance) {
130 self::$instance = new static();
131 }
132
133 return self::$instance;
134 }
135 }
136