Skip to content

Commit a996013

Browse files
authored
Merge pull request #3 from codebard/add_notice_and_first_activated
Add notice and first activated
2 parents b673614 + d475af9 commit a996013

File tree

8 files changed

+187
-19
lines changed

8 files changed

+187
-19
lines changed
208 KB
Loading

index.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Patreon Button, Widgets and Plugin by CodeBard
44
Plugin URI: https://wordpress.org/plugins/patron-button-and-widgets-by-codebard/
55
Description: Patreon Patron Buttons, Widgets and Patreon Functions
6-
Version: 2.1.0
6+
Version: 2.1.1
77
Author: CodeBard
88
Author URI: http://codebard.com
99
Text Domain: cb_p6
@@ -3809,6 +3809,11 @@ public function update_settings_c($v1)
38093809

38103810
require('plugin/plugin.php');
38113811

3812+
register_activation_hook($cb_p6->internal['plugin_path'].'index.php',array(&$cb_p6,'activate'));
3813+
3814+
register_deactivation_hook( $cb_p6->internal['plugin_path'].'index.php', array(&$cb_p6,'deactivate'));
3815+
3816+
38123817
require('plugin/includes/direct_includes.php');
38133818

38143819
require('plugin/includes/widgets.php');

plugin/includes/css/admin.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,14 @@ max-width : 800px;
325325
text-decoration : underline;
326326

327327
}
328-
.cb_addon_status{
328+
.cb_addon_status_local{
329329

330330
display:block;
331331
width : 100%;
332332
height : auto;
333333
text-align:center;
334334
vertical-align:top;
335+
font-size: 150%;
335336

336337
}
337338
.cb_addons_list{

plugin/includes/default_internal_vars.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'id' => 'cb_p6',
1111
'plugin_id' => 'patron-button-and-widgets-by-codebard',
1212
'prefix' => 'cb_p6_',
13-
'version' => '2.1.0',
13+
'version' => '2.1.1',
1414
'plugin_name' => 'Patreon Button, Widgets and Plugin by CodeBard',
1515

1616
'callable_from_request' => array(

plugin/includes/direct_includes.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,5 @@
33
/* This include is for functions and directives that need to be loaded outside class structure */
44

55

6-
/* Runs when plugin is activated */
7-
register_activation_hook($cb_p6->internal['plugin_path'].'index.php',array(&$cb_p6,'activate'));
8-
9-
/* Runs on plugin deactivation*/
10-
register_deactivation_hook( $cb_p6->internal['plugin_path'].'index.php', array(&$cb_p6,'deactivate'));
11-
12-
13-
146

157
?>

plugin/includes/scripts/admin.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ jQuery(document).ready(function($) {
7777
});
7878
});
7979

80+
81+
82+
jQuery(document).on( 'click', '.cb_p6_notice .notice-dismiss', function(e) {
83+
84+
jQuery.ajax({
85+
url: ajaxurl,
86+
type:"POST",
87+
dataType : 'html',
88+
data: {
89+
action: 'cb_p6_dismiss_admin_notice',
90+
notice_id: jQuery( this ).parent().attr( "id" ),
91+
}
92+
});
93+
});
94+
8095
jQuery(document).on('click', '.cb_p6_clear_prevfield', function(e) {
8196
e.preventDefault();
8297

plugin/plugin.php

Lines changed: 155 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function plugin_construct()
2222
{
2323
add_action('init', array(&$this, 'frontend_init'),99);
2424
}
25-
25+
26+
add_action( 'init', array( &$this, 'check_plugin_activation_date_for_existing_installs' ) );
2627
add_action('admin_init',array(&$this,'check_redirect_to_setup_wizard'),99);
2728

2829
}
@@ -42,6 +43,7 @@ public function admin_init_p() {
4243
add_action( 'admin_enqueue_scripts', array(&$this, 'load_pointers' ) );
4344
add_filter( $this->internal['prefix'].'admin_pointers-dashboard', array( &$this, 'widgets_pointer' ) );
4445
add_action( 'cb_p6_action_before_do_admin_page_tabs', array( &$this, 'pro_pitch' ) );
46+
add_action( 'wp_ajax_cb_p6_dismiss_admin_notice', array( $this, 'dismiss_admin_notice' ), 10, 1 );
4547

4648
/* Old Widget notice - can be used to show new notices.
4749
if(!isset($this->opt['widget_update_notice_shown']) AND !$this->opt['setup_is_being_done']) {
@@ -54,7 +56,9 @@ public function admin_init_p() {
5456
if( isset( $this->opt['setup_is_being_done'] ) AND $this->opt['setup_is_being_done'] )
5557
{
5658
add_action($this->internal['prefix'].'action_before_do_settings_pages',array(&$this,'do_setup_wizard'),99,1);
57-
}
59+
}
60+
61+
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
5862

5963
}
6064
public function frontend_init_p()
@@ -88,7 +92,8 @@ public function init_p()
8892
add_action( 'edit_user_profile', array(&$this, 'add_custom_user_field') );
8993

9094
add_action( 'personal_options_update', array(&$this, 'save_custom_user_field') );
91-
add_action( 'edit_user_profile_update', array(&$this, 'save_custom_user_field') );
95+
add_action( 'edit_user_profile_update', array(&$this, 'save_custom_user_field') );
96+
9297

9398

9499
}
@@ -152,10 +157,16 @@ public function setup_languages_p()
152157
$this->opt=$current_options;
153158

154159
}
155-
public function activate_p()
160+
public function activate_p()
156161
{
157-
162+
// Not setting the default return to 0 like the one in init check here because we dont want to overwrite the value 0 for installs existing at the date this code was implemented
163+
$plugin_first_activated = get_option( 'cb_p6_first_activated', false );
164+
165+
if ( !$plugin_first_activated ) {
166+
167+
update_option( 'cb_p6_first_activated', time() );
158168

169+
}
159170
}
160171

161172
public function check_redirect_to_setup_wizard_p()
@@ -1414,8 +1425,146 @@ public function widgets_pointer_p( $p ) {
14141425
);
14151426
return $p;
14161427
}
1417-
}
1428+
1429+
public static function check_plugin_activation_date_for_existing_installs_p() {
1430+
1431+
// Checks if plugin first activation date is saved for existing installs. Its here for backwards compatibility for existing installs before this version (2.1.1), and in case this meta info is lost in the db for any reason
1432+
1433+
$plugin_first_activated = get_option( 'cb_p6_first_activated', 'NONE' );
1434+
1435+
if ( $plugin_first_activated == 'NONE' ) {
1436+
// If no date was set, set it to 0. This will mark existing installs
1437+
update_option( 'cb_p6_first_activated', 0 );
1438+
}
1439+
1440+
}
1441+
1442+
1443+
public function check_days_after_last_non_system_notice_p( $days ) {
1444+
// Calculates if $days many days passed after last non system notice was showed. Used in deciding if and when to show admin wide notices
1445+
1446+
$last_non_system_notice_shown_date = get_option( 'cb_p6_last_non_system_notice_shown_date', 0 );
1447+
1448+
// Calculate if $days days passed since last notice was shown
1449+
if ( ( time() - $last_non_system_notice_shown_date ) > ( $days * 24 * 3600 ) ) {
1450+
// More than $days days. Set flag
1451+
return true;
1452+
}
14181453

1454+
return false;
1455+
1456+
}
1457+
1458+
1459+
public function check_days_after_last_system_notice_p( $days ) {
1460+
// Calculates if $days many days passed after last non system notice was showed. Used in deciding if and when to show admin wide notices
1461+
1462+
$last_non_system_notice_shown_date = get_option( 'cb_p6_last_system_notice_shown_date', 0 );
1463+
1464+
// Calculate if $days days passed since last notice was shown
1465+
if ( ( time() - $last_non_system_notice_shown_date ) > ( $days * 24 * 3600 ) ) {
1466+
// More than $days days. Set flag
1467+
return true;
1468+
}
1469+
1470+
return false;
1471+
1472+
}
1473+
1474+
public function calculate_days_after_first_activation_p( $days ) {
1475+
1476+
// Used to calculate days passed after first plugin activation.
1477+
1478+
$plugin_first_activated = get_option( 'cb_p6_first_activated', 0 );
1479+
1480+
// Calculate if $days days passed since last notice was shown
1481+
if ( ( time() - $plugin_first_activated ) > ( $days * 24 * 3600 ) ) {
1482+
// More than $days days. Set flag
1483+
return true;
1484+
}
1485+
1486+
return false;
1487+
1488+
}
1489+
1490+
public function admin_notices_p() {
1491+
1492+
1493+
if ( isset( $_REQUEST['page'] ) AND $_REQUEST['page'] == 'patreon_wordpress_setup_wizard' ) {
1494+
return;
1495+
}
1496+
1497+
if ( $this->opt['setup_is_being_done'] ) {
1498+
return;
1499+
}
1500+
1501+
// Wp org wants non-error / non-functionality related notices to be shown infrequently and one per admin-wide page load, and be dismissable permanently.
1502+
1503+
$patron_content_manager_pitch_shown = get_option( 'patron_content_manager_pitch_shown', false );
1504+
1505+
$already_showed_non_system_notice = false;
1506+
$current_screen = get_current_screen();
1507+
1508+
// The addon upsell must be admin wide, permanently dismissable, and must not appear in plugin manager page in admin
1509+
1510+
if( !$patron_content_manager_pitch_shown AND !$this->check_plugin_exists('patron-content-manager') AND $current_screen->id != 'plugins' AND ( ($this->check_days_after_last_non_system_notice( 7 ) AND $this->calculate_days_after_first_activation( 30 ) ) ) AND !$already_showed_non_system_notice ) {
1511+
1512+
?>
1513+
<div class="notice notice-success is-dismissible cb_p6_notice" id="cb_p6_patron_content_manager_pitch"><p><div style="display: flex; flex-wrap: wrap; flex-direction: row;"><a href="<?php echo $this->internal['plugin_url']."images/Easily-manage-gated-posts.jpg"?>" target="_blank"><img class="addon_upsell" src="<?php echo $this->internal['plugin_url']."images/Easily-manage-gated-posts.jpg"?>" style="width:200px; height:106px;margin: 10px; border: 1px solid #000000; margin-right: 20px;" alt="Patron Content Manager" /></a><div style="max-width: 700px; width: 100%;"><div style="max-width:500px; width: auto; float:left; display:inline-box"><h2 style="margin-top: 0px; font-size: 150%; font-weight: bold;">Easily manage your patron only content with Patron Content Manager</h2></div><div style="width:100%; font-size: 125% !important;clear:both; ">Get new <a href="https://codebard.com/patron-content-manager?utm_source=<?php urlencode( site_url() ) ?>&utm_medium=cb_p6&utm_campaign=&utm_content=cb_p6_addon_upsell_notice_patron_content_manager&utm_term=" target="_blank">Patron Content Manager</a> plugin for Patreon and easily re-gate content, gate old content, use detailed locking options, use content locking wizard to manage your patron only content & increase your patrons and pledges.<br /><br /><a href="https://codebard.com/patron-content-manager?utm_source=<?php urlencode( site_url() ) ?>&utm_medium=cb_p6&utm_campaign=&utm_content=cb_p6_addon_upsell_notice_patron_content_manager&utm_term=" target="_blank">Check out all features here</a></div></div></div></p>
1514+
</div>
1515+
<?php
1516+
1517+
$already_showed_non_system_notice = true;
1518+
1519+
}
1520+
1521+
}
1522+
1523+
public function check_plugin_exists_p( $plugin_dir ) {
1524+
1525+
// Simple function to check if a plugin is installed (may be active, or not active) in the WP instalation
1526+
1527+
// Plugin dir is the wp's plugin dir together with the plugin's dir
1528+
1529+
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_dir ) ) {
1530+
return true;
1531+
}
1532+
}
1533+
public function dismiss_admin_notice_p() {
1534+
1535+
if( !( is_admin() && current_user_can( 'manage_options' ) ) ) {
1536+
return;
1537+
}
1538+
1539+
// Mapping what comes from REQUEST to a given value avoids potential security problems and allows custom actions depending on notice
1540+
1541+
if ( $_REQUEST['notice_id'] == 'cb_p6_patron_content_manager_pitch' ) {
1542+
1543+
update_option( 'patron_content_manager_pitch_shown', true);
1544+
1545+
// Set the last notice shown date
1546+
$this->set_last_non_system_notice_shown_date();
1547+
}
1548+
1549+
1550+
}
1551+
1552+
public function set_last_non_system_notice_shown_date_p() {
1553+
1554+
// Sets the last non system notice shown date to now whenever called. Used for decicing when to show admin wide notices that are not related to functionality.
1555+
1556+
update_option( 'cb_p6_last_non_system_notice_shown_date', time() );
1557+
1558+
}
1559+
public function set_last_system_notice_shown_date_p() {
1560+
1561+
// Sets the last non system notice shown date to now whenever called. Used for decicing when to show admin wide notices that are not related to functionality.
1562+
1563+
update_option( 'cb_p6_system_notice_shown_date', time() );
1564+
1565+
}
1566+
1567+
}
14191568

14201569
$cb_p6 = cb_p6_plugin::get_instance();
14211570

readme.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Tags: plugins, patreon, widgets, crowdfunding, crowdfund, crowd fund, crowd fund
77
License: GPL
88
Requires at least: 4.0
99
Tested up to: 5.8
10-
Stable Tag: 2.1.0
10+
Stable Tag: 2.1.1
1111

1212
Patreon Button and Plugin allows you to add Patreon Buttons to your content and sidebars, along with offering other Patreon functions. Upgradable to Patron Plugin Pro with patron-only posts and powerful features.
1313

@@ -25,7 +25,7 @@ In addition, all authors will be able to add their own Patreon username in their
2525

2626
More features are planned as they become available in Patreon API.
2727

28-
You can upgrade to Patron Plugin Pro and enable powerful content-locking options to serve Patron only content from your own website! Patron Plugin Pro will also allow you to put your patrons directly to patron pipeline instead of your profile. Check it out below:
28+
You can upgrade to Patron Plugin Pro, add the Patron Content Manager addon and enable powerful content-locking options to serve Patron only content from your own website! Patron Plugin Pro will also allow you to put your patrons directly to patron pipeline instead of your profile. Check it out below:
2929

3030
https://codebard.com/patron-plugin-pro
3131

@@ -59,6 +59,12 @@ To be updated
5959

6060
== Changelog ==
6161

62+
= 2.1.1 =
63+
64+
* Added a notice system. Adjusted notices to show 30 days after last notice is shown. Made notices appear in sequential order. Separated system notices and non system notices. Notices are permanently dismissable.
65+
* Made plugin save time of activation when activated
66+
* Added notice for new Patreon plugin
67+
6268
= 2.1.0 =
6369

6470
* Updated update_usermeta to update_user_meta to address warnings

0 commit comments

Comments
 (0)