Skip to content

Commit

Permalink
Merge pull request #181 from alicolville/marketing
Browse files Browse the repository at this point in the history
Marketing
  • Loading branch information
alicolville authored Sep 15, 2024
2 parents b391921 + 38346f4 commit d5f0406
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 25 deletions.
17 changes: 17 additions & 0 deletions assets/js/dissmiss-notices.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
jQuery( document ).ready(function ($) {
$( '.yk-mt-update-notice' ).on('click', '.notice-dismiss', function ( event ) {

event.preventDefault();

if( false == $( this ).parent().hasClass( 'yk-mt-update-notice' ) ){
return;
}

$.post( ajaxurl, {
action: 'yk_mt_dismiss_notice',
url: ajaxurl,
security: $( this ).parent().data( 'nonce' ),
update_key: $( this ).parent().data('update-key')
});
});
});
39 changes: 22 additions & 17 deletions core/admin-pages/meals/meals-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,30 @@ function yk_mt_admin_page_meals_dashboard() {

yk_mt_admin_permission_check();

if ( false === YK_MT_IS_PREMIUM ) {
yk_mt_display_pro_upgrade_notice();
}

$user_id = yk_mt_querystring_value( 'user-id' );
$options = [ 'sort-order' => 'asc', 'use-cache' => false ];

if ( true === empty( $user_id ) ) {
$options[ 'admin-meals-only' ] = true;
}

?>
<div class="wrap ws-ls-user-meals ws-ls-admin-page">
<h2>
<span>
<?php
if ( false === empty( $user_id ) ) {
printf( '%s: <em>%s</em>', esc_html__( 'Meals added by', 'meal-tracker' ), yk_mt_user_display_name( $user_id ) );
} else {
printf( ' %s', esc_html__( 'Meal collection', 'meal-tracker' ) );
}
?>
</span>
</h2>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
Expand All @@ -18,25 +40,8 @@ function yk_mt_admin_page_meals_dashboard() {
yk_mt_display_pro_upgrade_notice();
}

$user_id = yk_mt_querystring_value( 'user-id' );
$options = [ 'sort-order' => 'asc', 'use-cache' => false ];

if ( true === empty( $user_id ) ) {
$options[ 'admin-meals-only' ] = true;
}
?>
<div class="postbox">
<h2 class="hndle">
<span>
<?php
if ( false === empty( $user_id ) ) {
printf( '%s: <em>%s</em>', esc_html__( 'Meals added by', 'meal-tracker' ), yk_mt_user_display_name( $user_id ) );
} else {
printf( ' %s', esc_html__( 'Meal collection', 'meal-tracker' ) );
}
?>
</span>
</h2>
<div class="inside">
<?php

Expand Down
4 changes: 2 additions & 2 deletions core/admin-pages/meals/meals-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function yk_mt_admin_page_meals_import() {

?>
<div class="wrap ws-ls-user-meals ws-ls-admin-page">
<h2><?php echo esc_html__( 'Import CSV', 'meal-tracker' ); ?></h2>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
Expand All @@ -32,8 +33,7 @@ function yk_mt_admin_page_meals_import() {

?>
<div class="postbox">
<h2 class="hndle"><?php echo esc_html__( 'Import CSV', 'meal-tracker' ); ?></h2>
<div class="inside">
<div class="inside">
<?php if ( false === $importing ): ?>
<div class="yk-mt-form-row">
<p>
Expand Down
1 change: 1 addition & 0 deletions core/admin-pages/user/data-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function yk_mt_admin_page_dashboard() {

?>
<div class="wrap ws-ls-user-data ws-ls-admin-page">
<h2><span><?php echo esc_html__( 'User Data', 'meal-tracker' ) ?></span></h2>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
Expand Down
3 changes: 1 addition & 2 deletions core/admin-pages/user/data-search-results.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ function yk_mt_admin_page_search_results() {

?>
<div class="wrap">
<h1><?php echo esc_html__( 'Search Results', 'meal-tracker' ); ?></h1>
<h2><span><?php echo esc_html__( 'Search Results', 'meal-tracker' ) ?></span></h2>
<div id="poststuff">
<div id="post-body" class="metabox-holder">
<div id="post-body-content">
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<h2 class="hndle"><span><?php echo esc_html__( 'Search Results', 'meal-tracker' ); ?></span></h2>
<div class="inside">
<?php

Expand Down
2 changes: 1 addition & 1 deletion core/functions.pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ function yk_mt_user_header( $user_id ) {
$additional_links = apply_filters( 'yk_mt_user_profile_header_links', '', $user_id );

printf('
<h3>%s %s</h3>
<h2><span>%s %s</span></h2>
<div class="postbox yk-mt-user-data">
<div class="inside">
<a href="%s" class="button-secondary"><i class="fa fa-arrow-left"></i><span> %s</span></a>
Expand Down
214 changes: 214 additions & 0 deletions core/marketing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
<?php

defined('ABSPATH') or die('Jog on!');

/**
* Display admin notice for notification from yeken.uk
*/
function yk_mt_get_marketing_message() {

if ( $cache = get_transient( '_yeken_meal_tracker_update' ) ) {
return $cache;
}

$response = wp_remote_get( YK_MT_YEKEN_UPDATES_URL );

// All ok?
if ( 200 === wp_remote_retrieve_response_code( $response ) ) {

$body = wp_remote_retrieve_body( $response );

if ( false === empty( $body ) ) {

$body = json_decode( $body, true );

set_transient( '_yeken_meal_tracker_update', $body, HOUR_IN_SECONDS );

return $body;
}
}

return NULL;
}

/**
* Get/Set key of notice last dismissed.
*/
function yk_mt_marketing_update_key_last_dismissed( $key = NULL ) {

if ( NULL !== $key ) {
set_transient( '_yeken_meal_tracker_update_key_last_dismissed', $key );
}

return get_transient( '_yeken_meal_tracker_update_key_last_dismissed' ) ;

}

/**
* Display HTML for admin notice
*/
function yk_mt_updates_display_notice( $json ) {

if ( false === is_array( $json ) ) {
return;
}

wp_enqueue_script( 'mt-dismiss-notices', YK_MT_BASE_URL . 'assets/js/dissmiss-notices.js', [ 'jquery' ], YK_MT_PLUGIN_VERSION );

$button = '';

if ( !empty( $json[ 'url'] ) && !empty( $json[ 'url-title' ] ) ) {
$button = sprintf( '<p>
<a href="%1$s" class="button button-primary" target="_blank" rel="noopener">%2$s</a>
</p>',
esc_url( $json[ 'url' ] ),
yk_mt_wp_kses( $json[ 'url-title' ] )
);
}


printf('<div class="updated notice is-dismissible yk-mt-update-notice" data-update-key="%4$s" data-nonce="%5$s">
<p><strong>%1$s</strong>: %2$s.</p>
%3$s
</div>',
'Meal Tracker',
!empty( $json[ 'message' ] ) ? esc_html( $json[ 'message' ] ) : '',
$button,
esc_html( $json[ '_update_key' ] ),
esc_attr( wp_create_nonce( 'yk-mt-nonce' ) )
);
}

/**
* display and admin notice if one exists and hasn't been dismissed already.
*/
function yk_mt_updates_admin_notice() {

$json = yk_mt_get_marketing_message();

if ( $json[ '_update_key' ] <> yk_mt_marketing_update_key_last_dismissed() ) {

yk_mt_updates_display_notice( $json );
}
}
add_action( 'admin_notices', 'yk_mt_updates_admin_notice' );

/**
* Ajax handler to dismiss setup wizard
*/
function yk_mt_updates_ajax_dismiss() {

check_ajax_referer( 'yk-mt-nonce', 'security' );

$update_key = sanitize_text_field( yk_mt_post_value( 'update_key' ) );

if ( false === empty( $update_key ) ) {
yk_mt_marketing_update_key_last_dismissed( $update_key );
}
}
add_action( 'wp_ajax_yk_mt_dismiss_notice', 'yk_mt_updates_ajax_dismiss' );

/**
* Render a list of features
* @param array features
* @param bool $echo
* @param string $format 'table' or 'ul' or 'markdown'
*/
function yk_mt_display_features( $features, $echo = true, $format = 'table' ) {

if ( true === empty( $features ) ) {
return;
}

switch( $format ) {
case 'table':
$html = '';
break;
case 'ul':
$html = '';
break;
default:
$html = '';
}

$html = 'table' === $format ? '<table class="form-table yk-mt-features-table">' : '<ul>';

$class = '';

foreach ( $features as $feature ) {

$class = ('alternate' == $class) ? '' : 'alternate';

switch( $format ) {
case 'table':
$html_template = '<tr class="%1$s">
<td>
&middot; <strong>%2$s</strong> - %3$s
</td>
</tr>';
break;
case 'ul':
$html_template = '<li><strong>%2$s</strong> - %3$s</li>';
break;
default:
$html_template = '* **%2$s** - %3$s' . PHP_EOL;
}

$row = sprintf( $html_template,
$class,
$feature[ 'title' ],
$feature[ 'description' ] );

$html .= $row;
}

switch( $format ) {
case 'table':
$html .= '</table>';
break;
case 'ul':
$html .= '</ul>';
break;
default:
$html .= '';
}

if ( false === $echo ) {
return $html;
}

yk_mt_echo_wp_kses( $html );
}

/**
* Render a list of features
* @param array features
*/
function yk_mt_shortcode_display_features() {
//return yk_mt_display_features( yk_mt_feature_list_pro(), false, 'ul' );
}
add_shortcode( 'wt-features-table', 'yk_mt_shortcode_display_features' );

/**
* Render a list of pro features
* @param array features
*/
function yk_mt_shortcode_display_pro_features() {
//return yk_mt_display_features( yk_mt_feature_list_pro_plus(), false, 'ul' );
}
add_shortcode( 'wt-pro-features-table', 'yk_mt_shortcode_display_pro_features' );

/**
* Display WP Version
* @return text
*/
function yk_mt_shortcode_version() {
return esc_html( YK_MT_PLUGIN_VERSION );
}
add_shortcode( 'wt-version', 'yk_mt_shortcode_version' );

// add_action( 'init', function() {
// yk_mt_display_features( yk_mt_feature_list_pro(), true, $format = 'markdown' );
// yk_mt_display_features( yk_mt_feature_list_pro_plus(), true, $format = 'markdown' );
// die;
// });
6 changes: 4 additions & 2 deletions meal-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Plugin Name: Meal Tracker
* Description: Allow your users to track their meals and calorie intake for a given day.
* Version: 3.2.1
* Version: 3.2.2
* Requires at least: 5.7
* Tested up to: 6.5
* Requires PHP: 7.2
Expand All @@ -18,12 +18,13 @@
*/

define( 'YK_MT_ABSPATH', plugin_dir_path( __FILE__ ) );
define( 'YK_MT_PLUGIN_VERSION', '3.2.1' );
define( 'YK_MT_PLUGIN_VERSION', '3.2.2' );
define( 'YK_MT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'YK_MT_SLUG', 'meal-tracker' );
define( 'YK_MT_BASE_URL', plugin_dir_url( __FILE__ ) );
define( 'YK_MT_CDN_CHART_JS', YK_MT_BASE_URL . 'assets/js/chart-4.4.4.min.js' );
define( 'YK_MT_CDN_FONT_AWESOME_CSS', YK_MT_BASE_URL . 'assets/css/fontawesome-4.7.0.min.css' );
define( 'YK_MT_YEKEN_UPDATES_URL', 'https://yeken.uk/downloads/_updates/meal-tracker.json' );

// -----------------------------------------------------------------------------------------
// AC: Include all relevant PHP files
Expand All @@ -37,6 +38,7 @@
include_once YK_MT_ABSPATH . 'core/functions.chart.php';
include_once YK_MT_ABSPATH . 'core/license.php';
include_once YK_MT_ABSPATH . 'core/setup.wizard.php';
include_once YK_MT_ABSPATH . 'core/marketing.php';

$is_premium = yk_mt_license_is_premium();

Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/yeken
Tags: meal, tracker, calories, weight, food
Requires at least: 5.7
Tested up to: 6.5
Stable tag: 3.2.1
Stable tag: 3.2.2
Requires PHP: 7.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -108,6 +108,11 @@ The plugin is written in English (UK) but is ready for translation. If you wish

== Changelog ==

= 3.2.2 =

* Improvement: Added messaging from YeKen.uk.
* Bug fix: Changed location of page titles.

= 3.2.1 =

* Bug fix: Can now set a user's calorie limit via admin screens.
Expand Down

0 comments on commit d5f0406

Please sign in to comment.