PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Controllers / Ajax / SubscriberAjaxController.php

SubscriberAjaxController.php in Depicter — Popup & Slider Builder trunk, at app/src/Controllers/Ajax/SubscriberAjaxController.php

46 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Controllers\Ajax;
3
4 use Averta\WordPress\Utility\Sanitize;
5 use WPEmerge\Requests\RequestInterface;
6
7 class SubscriberAjaxController
8 {
9 /**
10 * store subscriber
11 * @param RequestInterface $request
12 * @param $view
13 *
14 * @return \Psr\Http\Message\ResponseInterface
15 * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
16 */
17 public function store( RequestInterface $request, $view ) {
18
19 $bodyParams = [
20 'email' => Sanitize::email( $request->body('email') ),
21 'group' => Sanitize::textfield( $request->body('group') ),
22 'name' => Sanitize::textfield( $request->body('name') ),
23 ];
24
25 try {
26 if ( \Depicter::client()->subscribe( $bodyParams ) ) {
27 // Set the user is subscribed to the newsletter
28 \Depicter::options()->set('has_subscribed', 1);
29
30 return \Depicter::json([
31 "hits" => 1,
32 'message' => "You are successfully subscribed to the newsletter."
33 ])->withStatus(200 );
34 } else {
35 return \Depicter::json([
36 'errors' => "Error while sending subscriber, please try again later"
37 ])->withStatus(400 );
38 }
39 } catch ( \Exception $exception ){
40 return \Depicter::json([
41 'errors' => [ $exception->getMessage() ]
42 ])->withStatus(400);
43 }
44 }
45 }
46