| 1 |
<?php |
| 2 |
/** |
| 3 |
* Assist admin page. |
| 4 |
*/ |
| 5 |
|
| 6 |
namespace Extendify\Assist; |
| 7 |
|
| 8 |
use Extendify\Config; |
| 9 |
|
| 10 |
/** |
| 11 |
* This class handles the Assist admin page. |
| 12 |
*/ |
| 13 |
class AdminPage |
| 14 |
{ |
| 15 |
/** |
| 16 |
* Adds various actions to set up the page |
| 17 |
* |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
public function __construct() |
| 21 |
{ |
| 22 |
if (Config::$showAssist) { |
| 23 |
\add_filter('wp_redirect', function ($url) { |
| 24 |
// No nonce for _GET. |
| 25 |
// phpcs:ignore WordPress.Security.NonceVerification |
| 26 |
if (isset($_GET['extendify-launch-successful'])) { |
| 27 |
return \admin_url() . 'admin.php?page=extendify-assist'; |
| 28 |
} |
| 29 |
|
| 30 |
return $url; |
| 31 |
}, 9999); |
| 32 |
|
| 33 |
\add_action('admin_menu', [ $this, 'addAdminMenu' ]); |
| 34 |
$this->loadScripts(); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Adds Extendify menu to admin panel. |
| 40 |
* |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
public function addAdminMenu() |
| 44 |
{ |
| 45 |
add_menu_page( |
| 46 |
'Extendify', |
| 47 |
'Extendify', |
| 48 |
Config::$requiredCapability, |
| 49 |
'extendify-assist', |
| 50 |
[ |
| 51 |
$this, |
| 52 |
'createAdminPage', |
| 53 |
], |
| 54 |
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
| 55 |
'data:image/svg+xml;base64,' . base64_encode('<svg width="20" height="20" viewBox="0 0 60 62" fill="black" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M36.0201 0H49.2377C52.9815 0 54.3365 0.391104 55.7061 1.12116C57.0756 1.85412 58.1469 2.92893 58.8795 4.29635C59.612 5.66666 60 7.02248 60 10.7684V23.9935C60 27.7394 59.6091 29.0952 58.8795 30.4655C58.1469 31.8358 57.0727 32.9078 55.7061 33.6407C55.0938 33.9684 54.4831 34.2381 53.661 34.4312V44.9564C53.661 50.7417 53.0573 52.8356 51.9305 54.952C50.7991 57.0683 49.1401 58.7238 47.0294 59.8558C44.9143 60.9878 42.8215 61.5873 37.0395 61.5873H16.626C10.844 61.5873 8.75122 60.9833 6.63608 59.8558C4.52094 58.7238 2.86639 57.0638 1.73504 54.952C0.603687 52.8401 0 50.7417 0 44.9564V24.5358C0 18.7506 0.603687 16.6566 1.73057 14.5403C2.86192 12.424 4.52094 10.764 6.63608 9.63201C8.74675 8.5045 10.844 7.90047 16.626 7.90047H25.3664C25.5303 6.18172 25.8724 5.24393 26.3754 4.29924C27.1079 2.92893 28.1821 1.85412 29.5517 1.12116C30.9183 0.391104 32.2763 0 36.0201 0ZM29.2266 8.41812C29.2266 5.96352 31.2155 3.97368 33.6689 3.97368H51.5859C54.0393 3.97368 56.0282 5.96352 56.0282 8.41812V26.3438C56.0282 28.7984 54.0393 30.7882 51.5859 30.7882H33.6689C31.2155 30.7882 29.2266 28.7984 29.2266 26.3438V8.41812Z" fill="black"/></svg>') |
| 56 |
); |
| 57 |
|
| 58 |
if (Config::$environment === 'PRODUCTION') { |
| 59 |
add_submenu_page( |
| 60 |
'extendify-assist', |
| 61 |
'Assist', |
| 62 |
'Assist', |
| 63 |
Config::$requiredCapability, |
| 64 |
'extendify-assist', |
| 65 |
'', |
| 66 |
300 |
| 67 |
); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Settings page output |
| 73 |
* |
| 74 |
* @since 1.0.0 |
| 75 |
* |
| 76 |
* @return void |
| 77 |
*/ |
| 78 |
public function createAdminPage() |
| 79 |
{ |
| 80 |
?> |
| 81 |
<div class="extendify-outer-container"> |
| 82 |
<div class="wrap" style="max-width:1000px;margin:-16px auto 24px;"> |
| 83 |
<ul class="extendify-welcome-tabs"> |
| 84 |
<li class="active"><a href="<?php echo \esc_url(\admin_url('admin.php?page=extendify-assist')); ?>">Assist</a></li> |
| 85 |
<li><a href="<?php echo \esc_url(\admin_url('admin.php?page=extendify-welcome')); ?>">Library</a></li> |
| 86 |
<?php if (Config::$showOnboarding) : ?> |
| 87 |
<li><a href="<?php echo \esc_url(\admin_url('post-new.php?extendify=onboarding')); ?>">Launch</a></li> |
| 88 |
<?php endif; ?> |
| 89 |
<li class="cta-button"><a href="<?php echo \esc_url_raw(\get_home_url()); ?>" target="_blank"><?php echo \esc_html(__('View Site', 'extendify')); ?></a></li> |
| 90 |
</ul> |
| 91 |
<div id="extendify-assist-landing-page" class="extendify-assist"></div> |
| 92 |
</div> |
| 93 |
</div> |
| 94 |
<?php |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Adds admin styles if on the assist page |
| 99 |
* |
| 100 |
* @return void |
| 101 |
*/ |
| 102 |
public function loadScripts() |
| 103 |
{ |
| 104 |
// No nonce for _GET. |
| 105 |
// phpcs:ignore WordPress.Security.NonceVerification |
| 106 |
if (isset($_GET['page']) && $_GET['page'] === 'extendify-assist') { |
| 107 |
\add_action( |
| 108 |
'in_admin_header', |
| 109 |
function () { |
| 110 |
\remove_all_actions('admin_notices'); |
| 111 |
\remove_all_actions('all_admin_notices'); |
| 112 |
}, |
| 113 |
1000 |
| 114 |
); |
| 115 |
|
| 116 |
\add_action( |
| 117 |
'admin_enqueue_scripts', |
| 118 |
function () { |
| 119 |
\wp_enqueue_style( |
| 120 |
'extendify-assist', |
| 121 |
EXTENDIFY_URL . 'public/admin-page/welcome.css', |
| 122 |
[], |
| 123 |
Config::$environment === 'PRODUCTION' ? Config::$version : uniqid() |
| 124 |
); |
| 125 |
} |
| 126 |
); |
| 127 |
}//end if |
| 128 |
} |
| 129 |
} |
| 130 |
|