Skip to content

Commit 06bcbf5

Browse files
authored
Merge pull request #968 from cloudinary/feature/29-offer
Special offer
2 parents fa41290 + b328f3a commit 06bcbf5

File tree

9 files changed

+195
-30
lines changed

9 files changed

+195
-30
lines changed

css/cloudinary.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

php/class-plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public function init() {
145145
$this->components['metabox'] = new Meta_Box( $this );
146146
$this->components['url'] = new URL( $this );
147147
$this->components['wpml'] = new WPML( $this );
148+
$this->components['special_offer'] = new Special_Offer( $this );
148149
}
149150

150151
/**

php/class-special-offer.php

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Special Offer Class.
4+
*
5+
* @package Cloudinary
6+
*/
7+
8+
namespace Cloudinary;
9+
10+
/**
11+
* Class Special_Offer
12+
*/
13+
class Special_Offer {
14+
/**
15+
* The plugin instance.
16+
*
17+
* @var Plugin
18+
*/
19+
protected $plugin;
20+
21+
/**
22+
* Special_Offer constructor.
23+
*
24+
* @param Plugin $plugin The plugin instance.
25+
*/
26+
public function __construct( $plugin ) {
27+
$this->plugin = $plugin;
28+
29+
$this->register_hooks();
30+
}
31+
32+
/**
33+
* Register hooks for the Special Offer.
34+
*/
35+
public function register_hooks() {
36+
add_filter( 'cloudinary_admin_sidebar', array( $this, 'filtered_settings' ) );
37+
}
38+
39+
/**
40+
* Filter the settings.
41+
*
42+
* @param array $settings The settings.
43+
*
44+
* @return array
45+
*/
46+
public function filtered_settings( $settings ) {
47+
if ( ! $this->is_special_offer_available() ) {
48+
return $settings;
49+
}
50+
51+
$settings[0][] = array(
52+
array(
53+
'type' => 'tag',
54+
'element' => 'div',
55+
'content' => __( 'Special Offer', 'cloudinary' ),
56+
'attributes' => array(
57+
'class' => array(
58+
'cld-special-offer',
59+
),
60+
),
61+
),
62+
array(
63+
'type' => 'panel',
64+
'title' => __( 'Get a small $29 plan', 'cloudinary' ),
65+
'description' => __( 'Contact us', 'cloudinary' ),
66+
'collapsible' => 'closed',
67+
array(
68+
'type' => 'tag',
69+
'element' => 'div',
70+
'content' => $this->get_special_offer_content(),
71+
),
72+
array(
73+
'type' => 'link',
74+
'content' => __( 'Get started', 'cloudinary' ),
75+
'url' => static function () {
76+
$args = array(
77+
'tf_360017815680' => 'help_with_plans',
78+
'tf_subject' => esc_attr( __( 'Request to Purchase the Small Plan', 'cloudinary' ) ),
79+
'tf_description' => esc_attr( __( "Hello,<br><br>I'm interested in purchasing the Small plan for $29. Could you please provide me with the next steps to complete the purchase?<br><br>Thank you!", 'cloudinary' ) ),
80+
);
81+
return Utils::get_support_link( $args );
82+
},
83+
'target' => '_blank',
84+
),
85+
),
86+
);
87+
88+
return $settings;
89+
}
90+
91+
/**
92+
* Check if the user is eligible for the $29 offer.
93+
*
94+
* @return bool
95+
*/
96+
protected function is_special_offer_available() {
97+
$last_usage = get_option( Connect::META_KEYS['last_usage'], array( 'plan' => '' ) );
98+
99+
return 'free' === strtolower( $last_usage['plan'] );
100+
}
101+
102+
/**
103+
* Get Special Offer content.
104+
*
105+
* @return string
106+
*/
107+
protected function get_special_offer_content() {
108+
ob_start();
109+
include $this->plugin->dir_path . 'php/templates/special-offer.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
110+
111+
return ob_get_clean();
112+
}
113+
}

php/class-utils.php

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -449,35 +449,33 @@ public static function upgrade_3_1_9() {
449449
/**
450450
* Gets the URL for opening a Support Request.
451451
*
452-
* @param string $reason The reason option slug.
453-
* @param string $subject The subject for the request.
452+
* @param array $args The arguments.
454453
*
455454
* @return string
456455
*/
457-
public static function get_support_link( $reason = '', $subject = '' ) {
456+
public static function get_support_link( $args = array() ) {
458457
$user = wp_get_current_user();
459458
$plugin = get_plugin_instance();
460459
$url = 'https://support.cloudinary.com/hc/en-us/requests/new';
461460

462-
if ( empty( $reason ) ) {
463-
$reason = 'other_help_needed';
464-
}
465-
466-
if ( empty( $subject ) ) {
467-
$subject = sprintf(
468-
// translators: The plugin version.
469-
__( 'I need help with Cloudinary WordPress plugin version %s', 'cloudinary' ),
470-
$plugin->version
471-
);
472-
}
461+
$default_args = array(
462+
'tf_anonymous_requester_email' => $user->user_email,
463+
'tf_22246877' => $user->display_name,
464+
'tf_360007219560' => $plugin->components['connect']->get_cloud_name(),
465+
'tf_360017815680' => 'other_help_needed',
466+
'tf_subject' => esc_attr(
467+
sprintf(
468+
// translators: The plugin version.
469+
__( 'I need help with Cloudinary WordPress plugin version %s', 'cloudinary' ),
470+
$plugin->version
471+
)
472+
),
473+
'tf_description' => esc_attr( __( 'Please, provide more details on your request, and if possible, attach a System Report', 'cloudinary' ) ),
474+
);
473475

474-
$args = array(
475-
'request_anonymous_requester_email' => $user->display_name,
476-
'request_custom_fields_22246877' => $user->user_email,
477-
'request_custom_fields_360007219560' => $plugin->components['connect']->get_cloud_name(),
478-
'request_custom_fields_360017815680' => $reason,
479-
'request_subject' => $subject,
480-
'request_description' => __( 'Please, provide more details on your request, and if possible, attach a System Report', 'cloudinary' ),
476+
$args = wp_parse_args(
477+
$args,
478+
$default_args
481479
);
482480

483481
return add_query_arg( array_filter( $args ), $url );

php/templates/special-offer.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* The Special Offer contents.
4+
*
5+
* @package Cloudinary
6+
*/
7+
8+
?>
9+
10+
<p><?php esc_html_e( 'Running out of space on your free account? Upgrade for just $29 and supercharge your WordPress site with Cloudinary for unlimited awesomeness!', 'cloudinary' ); ?></p>
11+
12+
<p>
13+
<?php esc_html_e( 'As a note:', 'cloudinary' ); ?>
14+
<br>
15+
<?php esc_html_e( 'This offer is exclusive to free users. Existing paying users will continue with their current plan and pricing.', 'cloudinary' ); ?>
16+
</p>
17+
18+
<strong><?php esc_html_e( 'Includes:', 'cloudinary' ); ?></strong>
19+
<ul>
20+
<li><?php esc_html_e( '3 users', 'cloudinary' ); ?></li>
21+
<li><?php esc_html_e( '1 product environment', 'cloudinary' ); ?></li>
22+
<li><?php esc_html_e( '60 monthly credits', 'cloudinary' ); ?></li>
23+
</ul>

php/ui/class-component.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,13 @@ public static function build_attributes( $attributes ) {
757757
$value = implode( ' ', $value );
758758
}
759759
}
760+
if ( ! is_string( $value ) && is_callable( $value ) ) {
761+
$value = call_user_func( $value );
762+
}
760763
$return[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
761764
}
762765

763766
return implode( ' ', $return );
764-
765767
}
766768

767769
/**

src/css/components/ui/_sidebar.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,14 @@
101101
margin-bottom: 0;
102102
}
103103
}
104+
105+
.cld-ui-wrap {
106+
.closed {
107+
visibility: hidden;
108+
max-height: 0;
109+
padding: 0 !important;
110+
border: none;
111+
display: flex;
112+
}
113+
}
104114
}

src/css/components/ui/_ui-components.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,14 @@
109109
}
110110
}
111111
}
112+
113+
&-special-offer {
114+
background-color: $color-cld-blue;
115+
color: #fff;
116+
text-decoration: none;
117+
padding: 5px 14px;
118+
border-radius: 4px 4px 0 0;
119+
font-weight: bold;
120+
font-size: $size-button;
121+
margin: 2em 0 0;
122+
}

ui-definitions/settings-pages.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,12 @@
333333
'type' => 'tag',
334334
'element' => 'a',
335335
'attributes' => array(
336-
'href' => Utils::get_support_link( '-' ),
336+
'href' => static function () {
337+
$args = array(
338+
'tf_360017815680' => '-',
339+
);
340+
return Utils::get_support_link( $args );
341+
},
337342
'target' => '_blank',
338343
'rel' => 'noopener noreferrer',
339344
'class' => array(
@@ -451,12 +456,14 @@
451456
'type' => 'panel',
452457
'title' => __( "I'm having an incompatibility issue with a theme, plugin, or hosting environment, what can I do?", 'cloudinary' ),
453458
'collapsible' => 'closed',
454-
'content' => sprintf(
455-
// translators: The HTML markup.
456-
__( 'We’re compatible with most other plugins so we expect it to work absolutely fine. If you do have any issues, please %1$scontact our support team%2$s who will help resolve your issue.', 'cloudinary' ),
457-
'<a href="' . Utils::get_support_link() . '" target="_blank" rel="noopener noreferrer">',
458-
'</a>'
459-
),
459+
'content' => static function () {
460+
return sprintf(
461+
// translators: The HTML markup.
462+
__( 'We’re compatible with most other plugins so we expect it to work absolutely fine. If you do have any issues, please %1$scontact our support team%2$s who will help resolve your issue.', 'cloudinary' ),
463+
'<a href="' . Utils::get_support_link() . '" target="_blank" rel="noopener noreferrer">',
464+
'</a>'
465+
);
466+
},
460467
),
461468
array(
462469
'type' => 'panel',

0 commit comments

Comments
 (0)