| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* SOFTWARE LICENSE INFORMATION |
| 5 |
* |
| 6 |
* Copyright (c) 2017 Buttonizer, all rights reserved. |
| 7 |
* |
| 8 |
* This file is part of Buttonizer |
| 9 |
* |
| 10 |
* For detailed information regarding to the licensing of |
| 11 |
* this software, please review the license.txt or visit: |
| 12 |
* https://buttonizer.pro/license/ |
| 13 |
*/ |
| 14 |
namespace Buttonizer\Legacy\Admin; |
| 15 |
|
| 16 |
use Buttonizer\Admin\Admin as NewAdmin; |
| 17 |
use Buttonizer\Core\Utils\Editor; |
| 18 |
use Buttonizer\Core\Utils\PermissionCheck; |
| 19 |
use Buttonizer\Core\Utils\Settings; |
| 20 |
# No script kiddies |
| 21 |
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
| 22 |
class Admin { |
| 23 |
private static $showMigrationPage = false; |
| 24 |
|
| 25 |
/** |
| 26 |
* Admin constructor. |
| 27 |
*/ |
| 28 |
public function __construct() { |
| 29 |
// Lets do some admin stuff for Buttonizer |
| 30 |
add_action( 'admin_init', [$this, 'adminInit'] ); |
| 31 |
// Add admin assets for migration |
| 32 |
add_action( 'admin_enqueue_scripts', [$this, 'adminAssets'] ); |
| 33 |
// Add admin menu |
| 34 |
add_action( 'admin_menu', [$this, 'pluginAdminMenu'] ); |
| 35 |
// Add deprecation notice for legacy users |
| 36 |
add_action( 'admin_notices', [$this, 'legacyDeprecationNotice'] ); |
| 37 |
// Add AJAX handler for dismissing notice |
| 38 |
add_action( 'wp_ajax_buttonizer_dismiss_legacy_notice', [$this, 'dismissLegacyNotice'] ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Create Admin menu |
| 43 |
*/ |
| 44 |
public function pluginAdminMenu() { |
| 45 |
if ( !PermissionCheck::hasPermission() ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
// Admin menu - now points directly to migration page |
| 49 |
add_menu_page( |
| 50 |
'Buttonizer - Migrate to 3.0', |
| 51 |
'Buttonizer', |
| 52 |
'read', |
| 53 |
'Buttonizer', |
| 54 |
[$this, 'migrationAdminPage'], |
| 55 |
plugins_url( '/assets/images/wp-icon.png', BUTTONIZER_PLUGIN_DIR ), |
| 56 |
81 |
| 57 |
); |
| 58 |
// Add community link |
| 59 |
add_submenu_page( |
| 60 |
'Buttonizer', |
| 61 |
__( 'Community', 'buttonizer-multifunctional-button' ), |
| 62 |
__( 'Community', 'buttonizer-multifunctional-button' ), |
| 63 |
'read', |
| 64 |
'https://community.buttonizer.pro/?referral=buttonizer-plugin-menu' |
| 65 |
); |
| 66 |
// Add knowledge base link |
| 67 |
add_submenu_page( |
| 68 |
'Buttonizer', |
| 69 |
__( 'Knowledge base', 'buttonizer-multifunctional-button' ), |
| 70 |
__( 'Knowledge base', 'buttonizer-multifunctional-button' ), |
| 71 |
'read', |
| 72 |
'https://community.buttonizer.pro/knowledgebase?referral=buttonizer-plugin-menu' |
| 73 |
); |
| 74 |
// Add support link |
| 75 |
add_submenu_page( |
| 76 |
'Buttonizer', |
| 77 |
__( 'I need support', 'buttonizer-multifunctional-button' ), |
| 78 |
__( 'I need support', 'buttonizer-multifunctional-button' ), |
| 79 |
'read', |
| 80 |
'https://community.buttonizer.pro/t/support?referral=buttonizer-plugin-menu' |
| 81 |
); |
| 82 |
// Plugin information, add links |
| 83 |
add_filter( "plugin_action_links_" . plugin_basename( BUTTONIZER_PLUGIN_DIR ), function ( $aLinks ) { |
| 84 |
$aButtonizerLinks = ['<a href="https://community.buttonizer.pro/" target="_blank">' . __( 'Community forums', 'buttonizer-multifunctional-button' ) . '</a>', '<a href="https://community.buttonizer.pro/knowledgebase" target="_blank">' . __( 'Knowledge base', 'buttonizer-multifunctional-button' ) . '</a>', '<a href="' . admin_url( 'admin.php?page=Buttonizer' ) . '">' . __( 'Migrate to 3.0', 'buttonizer-multifunctional-button' ) . '</a>']; |
| 85 |
return array_merge( $aLinks, $aButtonizerLinks ); |
| 86 |
} ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Show new Buttonizer admin dashboard |
| 91 |
*/ |
| 92 |
public function adminAssets() { |
| 93 |
// Make sure only admins see this page |
| 94 |
if ( !self::$showMigrationPage ) { |
| 95 |
return; |
| 96 |
} |
| 97 |
( new NewAdmin() )->adminAssets(); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Populate admin HTML content |
| 102 |
*/ |
| 103 |
public function migrationAdminPage() { |
| 104 |
// Make sure only admins see this page |
| 105 |
if ( !self::$showMigrationPage ) { |
| 106 |
return; |
| 107 |
} |
| 108 |
( new NewAdmin() )->page(); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Remove stylesheets when on Buttonizer page |
| 113 |
*/ |
| 114 |
public function adminInit() { |
| 115 |
// Only show migration page to admins |
| 116 |
if ( defined( "\\BUTTONIZER_LEGACY_REQUESTED_MIGRATION" ) && \BUTTONIZER_LEGACY_REQUESTED_MIGRATION === false && PermissionCheck::hasPermission( true ) ) { |
| 117 |
self::$showMigrationPage = true; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Show deprecation notice for legacy Buttonizer users |
| 123 |
*/ |
| 124 |
public function legacyDeprecationNotice() { |
| 125 |
// Only show to administrators |
| 126 |
if ( !PermissionCheck::hasPermission( true ) ) { |
| 127 |
return; |
| 128 |
} |
| 129 |
// Check if notice was dismissed and when |
| 130 |
$dismissedTime = get_option( 'buttonizer_legacy_notice_dismissed', 0 ); |
| 131 |
$currentTime = time(); |
| 132 |
$oneWeek = 7 * 24 * 60 * 60; |
| 133 |
// 7 days in seconds |
| 134 |
// If dismissed less than a week ago, don't show |
| 135 |
if ( $dismissedTime && $currentTime - $dismissedTime < $oneWeek ) { |
| 136 |
return; |
| 137 |
} |
| 138 |
$migrateUrl = admin_url( 'admin.php?page=Buttonizer&buttonizer_migrate=true' ); |
| 139 |
$nonce = wp_create_nonce( 'buttonizer_dismiss_legacy_notice' ); |
| 140 |
echo ' |
| 141 |
<div id="buttonizer-legacy-notice" class="notice notice-warning is-dismissible"> |
| 142 |
<p> |
| 143 |
<strong>⚠️ ' . esc_html__( 'Your Buttonizer version is outdated', 'buttonizer-multifunctional-button' ) . '</strong> |
| 144 |
</p> |
| 145 |
<p> |
| 146 |
' . esc_html__( 'You\'re currently using an outdated version of Buttonizer that is not actively maintained anymore.', 'buttonizer-multifunctional-button' ) . '<br>' . esc_html__( 'As of', 'buttonizer-multifunctional-button' ) . ' <strong>' . esc_html__( 'July 2026', 'buttonizer-multifunctional-button' ) . '</strong>' . esc_html__( ', this version has limited functionality and no button editing capabilities. Please migrate to our Buttonizer standalone version as soon as possible, and your buttons will automatically transfer.', 'buttonizer-multifunctional-button' ) . ' |
| 147 |
</p> |
| 148 |
<p> |
| 149 |
<a href="' . esc_url( $migrateUrl ) . '" class="button button-primary">' . esc_html__( 'Migrate to 3.0', 'buttonizer-multifunctional-button' ) . '</a> |
| 150 |
<a href="https://community.buttonizer.pro/knowledgebase/1122-standalone-vs-wordpress" target="_blank" class="button">' . esc_html__( 'Learn more', 'buttonizer-multifunctional-button' ) . '</a> |
| 151 |
</p> |
| 152 |
</div> |
| 153 |
<script> |
| 154 |
(function() { |
| 155 |
var notice = document.getElementById("buttonizer-legacy-notice"); |
| 156 |
if (notice) { |
| 157 |
notice.addEventListener("click", function(e) { |
| 158 |
if (e.target.classList.contains("notice-dismiss")) { |
| 159 |
fetch("' . admin_url( 'admin-ajax.php' ) . '", { |
| 160 |
method: "POST", |
| 161 |
headers: { |
| 162 |
"Content-Type": "application/x-www-form-urlencoded", |
| 163 |
}, |
| 164 |
body: "action=buttonizer_dismiss_legacy_notice&nonce=' . esc_js( $nonce ) . '" |
| 165 |
}); |
| 166 |
} |
| 167 |
}); |
| 168 |
} |
| 169 |
})(); |
| 170 |
</script> |
| 171 |
'; |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* AJAX handler to dismiss legacy notice |
| 176 |
*/ |
| 177 |
public function dismissLegacyNotice() { |
| 178 |
// Verify nonce |
| 179 |
if ( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'buttonizer_dismiss_legacy_notice' ) ) { |
| 180 |
wp_send_json_error( 'Invalid nonce' ); |
| 181 |
return; |
| 182 |
} |
| 183 |
// Only administrators can dismiss |
| 184 |
if ( !PermissionCheck::hasPermission( true ) ) { |
| 185 |
wp_send_json_error( 'Permission denied' ); |
| 186 |
return; |
| 187 |
} |
| 188 |
// Store the current time when dismissed |
| 189 |
update_option( 'buttonizer_legacy_notice_dismissed', time() ); |
| 190 |
wp_send_json_success(); |
| 191 |
} |
| 192 |
|
| 193 |
} |
| 194 |
|