Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/cloudinary.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions php/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public function init() {
$this->components['metabox'] = new Meta_Box( $this );
$this->components['url'] = new URL( $this );
$this->components['wpml'] = new WPML( $this );
$this->components['special_offer'] = new Special_Offer( $this );
}

/**
Expand Down
113 changes: 113 additions & 0 deletions php/class-special-offer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* Special Offer Class.
*
* @package Cloudinary
*/

namespace Cloudinary;

/**
* Class Special_Offer
*/
class Special_Offer {
/**
* The plugin instance.
*
* @var Plugin
*/
protected $plugin;

/**
* Special_Offer constructor.
*
* @param Plugin $plugin The plugin instance.
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;

$this->register_hooks();
}

/**
* Register hooks for the Special Offer.
*/
public function register_hooks() {
add_filter( 'cloudinary_admin_sidebar', array( $this, 'filtered_settings' ) );
}

/**
* Filter the settings.
*
* @param array $settings The settings.
*
* @return array
*/
public function filtered_settings( $settings ) {
if ( ! $this->is_special_offer_available() ) {
return $settings;
}

$settings[0][] = array(
array(
'type' => 'tag',
'element' => 'div',
'content' => __( 'Special Offer', 'cloudinary' ),
'attributes' => array(
'class' => array(
'cld-special-offer',
),
),
),
array(
'type' => 'panel',
'title' => __( 'Get a small $29 plan', 'cloudinary' ),
'description' => __( 'Contact us', 'cloudinary' ),
'collapsible' => 'closed',
array(
'type' => 'tag',
'element' => 'div',
'content' => $this->get_special_offer_content(),
),
array(
'type' => 'link',
'content' => __( 'Get started', 'cloudinary' ),
'url' => static function () {
$args = array(
'tf_360017815680' => 'help_with_plans',
'tf_subject' => esc_attr( __( 'Request to Purchase the Small Plan', 'cloudinary' ) ),
'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' ) ),
);
return Utils::get_support_link( $args );
},
'target' => '_blank',
),
),
);

return $settings;
}

/**
* Check if the user is eligible for the $29 offer.
*
* @return bool
*/
protected function is_special_offer_available() {
$last_usage = get_option( Connect::META_KEYS['last_usage'], array( 'plan' => '' ) );

return 'free' === strtolower( $last_usage['plan'] );
}

/**
* Get Special Offer content.
*
* @return string
*/
protected function get_special_offer_content() {
ob_start();
include $this->plugin->dir_path . 'php/templates/special-offer.php'; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable

return ob_get_clean();
}
}
40 changes: 19 additions & 21 deletions php/class-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,35 +449,33 @@ public static function upgrade_3_1_9() {
/**
* Gets the URL for opening a Support Request.
*
* @param string $reason The reason option slug.
* @param string $subject The subject for the request.
* @param array $args The arguments.
*
* @return string
*/
public static function get_support_link( $reason = '', $subject = '' ) {
public static function get_support_link( $args = array() ) {
$user = wp_get_current_user();
$plugin = get_plugin_instance();
$url = 'https://support.cloudinary.com/hc/en-us/requests/new';

if ( empty( $reason ) ) {
$reason = 'other_help_needed';
}

if ( empty( $subject ) ) {
$subject = sprintf(
// translators: The plugin version.
__( 'I need help with Cloudinary WordPress plugin version %s', 'cloudinary' ),
$plugin->version
);
}
$default_args = array(
'tf_anonymous_requester_email' => $user->user_email,
'tf_22246877' => $user->display_name,
'tf_360007219560' => $plugin->components['connect']->get_cloud_name(),
'tf_360017815680' => 'other_help_needed',
'tf_subject' => esc_attr(
sprintf(
// translators: The plugin version.
__( 'I need help with Cloudinary WordPress plugin version %s', 'cloudinary' ),
$plugin->version
)
),
'tf_description' => esc_attr( __( 'Please, provide more details on your request, and if possible, attach a System Report', 'cloudinary' ) ),
);

$args = array(
'request_anonymous_requester_email' => $user->display_name,
'request_custom_fields_22246877' => $user->user_email,
'request_custom_fields_360007219560' => $plugin->components['connect']->get_cloud_name(),
'request_custom_fields_360017815680' => $reason,
'request_subject' => $subject,
'request_description' => __( 'Please, provide more details on your request, and if possible, attach a System Report', 'cloudinary' ),
$args = wp_parse_args(
$args,
$default_args
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 praise
I like this approach!


return add_query_arg( array_filter( $args ), $url );
Expand Down
23 changes: 23 additions & 0 deletions php/templates/special-offer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* The Special Offer contents.
*
* @package Cloudinary
*/

?>

<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>

<p>
<?php esc_html_e( 'As a note:', 'cloudinary' ); ?>
<br>
<?php esc_html_e( 'This offer is exclusive to free users. Existing paying users will continue with their current plan and pricing.', 'cloudinary' ); ?>
</p>

<strong><?php esc_html_e( 'Includes:', 'cloudinary' ); ?></strong>
<ul>
<li><?php esc_html_e( '3 users', 'cloudinary' ); ?></li>
<li><?php esc_html_e( '1 product environment', 'cloudinary' ); ?></li>
<li><?php esc_html_e( '60 monthly credits', 'cloudinary' ); ?></li>
</ul>
4 changes: 3 additions & 1 deletion php/ui/class-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,13 @@ public static function build_attributes( $attributes ) {
$value = implode( ' ', $value );
}
}
if ( ! is_string( $value ) && is_callable( $value ) ) {
$value = call_user_func( $value );
}
$return[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
}

return implode( ' ', $return );

}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/css/components/ui/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@
margin-bottom: 0;
}
}

.cld-ui-wrap {
.closed {
visibility: hidden;
max-height: 0;
padding: 0 !important;
border: none;
display: flex;
}
}
}
11 changes: 11 additions & 0 deletions src/css/components/ui/_ui-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,14 @@
}
}
}

&-special-offer {
background-color: $color-cld-blue;
color: #fff;
text-decoration: none;
padding: 5px 14px;
border-radius: 4px 4px 0 0;
font-weight: bold;
font-size: $size-button;
margin: 2em 0 0;
}
21 changes: 14 additions & 7 deletions ui-definitions/settings-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,12 @@
'type' => 'tag',
'element' => 'a',
'attributes' => array(
'href' => Utils::get_support_link( '-' ),
'href' => static function () {
$args = array(
'tf_360017815680' => '-',
);
return Utils::get_support_link( $args );
},
'target' => '_blank',
'rel' => 'noopener noreferrer',
'class' => array(
Expand Down Expand Up @@ -451,12 +456,14 @@
'type' => 'panel',
'title' => __( "I'm having an incompatibility issue with a theme, plugin, or hosting environment, what can I do?", 'cloudinary' ),
'collapsible' => 'closed',
'content' => sprintf(
// translators: The HTML markup.
__( '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' ),
'<a href="' . Utils::get_support_link() . '" target="_blank" rel="noopener noreferrer">',
'</a>'
),
'content' => static function () {
return sprintf(
// translators: The HTML markup.
__( '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' ),
'<a href="' . Utils::get_support_link() . '" target="_blank" rel="noopener noreferrer">',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥜 nitpick
Since there's translated text in the support link, this probably should be escaped.

'</a>'
);
},
),
array(
'type' => 'panel',
Expand Down