| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Disco |
| 5 |
* |
| 6 |
* @package Disco |
| 7 |
* @author Ohidul Islam <wahid0003@gmail.com> |
| 8 |
* @link http://domain.tld |
| 9 |
* @license GPL 2.0+ |
| 10 |
* @copyright 2022 WebAppick |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace Disco\Backend; |
| 14 |
|
| 15 |
use Disco\App\Disco; |
| 16 |
use Disco\Engine\Base; |
| 17 |
|
| 18 |
/** |
| 19 |
* Create the settings page in the backend |
| 20 |
*/ |
| 21 |
class Settings_Page extends Base { |
| 22 |
|
| 23 |
/** |
| 24 |
* Initialize the class. |
| 25 |
* |
| 26 |
* @return void|bool |
| 27 |
*/ |
| 28 |
public function initialize() { |
| 29 |
if ( ! parent::initialize() ) { |
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
// Add the options page and menu item. |
| 34 |
\add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) ); |
| 35 |
|
| 36 |
$realpath = (string) \realpath( __DIR__ ); |
| 37 |
$plugin_basename = \plugin_basename( \plugin_dir_path( $realpath ) . DISCO_TEXTDOMAIN . '.php' ); |
| 38 |
|
| 39 |
add_filter( "plugin_action_links_{$plugin_basename}", array( $this, 'disco_add_action_plugin_links' ) ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Add settings link on plugin page |
| 44 |
* |
| 45 |
* @param array $links links. |
| 46 |
* @return array |
| 47 |
*/ |
| 48 |
public function disco_add_action_plugin_links( $links ) { |
| 49 |
|
| 50 |
$is_pro_active = class_exists( '\Disco_Pro' ); |
| 51 |
|
| 52 |
$custom_links = [ |
| 53 |
[ |
| 54 |
'label' => __( 'Settings', 'disco' ), |
| 55 |
'url' => admin_url( 'admin.php?page=disco-create-discount' ), |
| 56 |
'class' => 'disco-settings-link', |
| 57 |
], |
| 58 |
[ |
| 59 |
'label' => __( 'Get Pro', 'disco' ), |
| 60 |
'url' => 'https://discoplugin.com/pricing/?utm_source=plugin_dashboard&utm_medium=free-to-pro&utm_campaign=free-to-pro&utm_id=1', |
| 61 |
'class' => 'disco-custom-pro-link', |
| 62 |
], |
| 63 |
[ |
| 64 |
'label' => __( 'Docs', 'disco' ), |
| 65 |
'url' => 'https://discoplugin.com/docs/', |
| 66 |
'class' => 'disco-custom-docs-link', |
| 67 |
], |
| 68 |
]; |
| 69 |
|
| 70 |
if ( $is_pro_active ) { |
| 71 |
array_splice( $custom_links, 1, 1 ); |
| 72 |
} |
| 73 |
|
| 74 |
$built_links = array(); |
| 75 |
|
| 76 |
foreach ( $custom_links as $item ) { |
| 77 |
$built_links[] = sprintf( |
| 78 |
'<a href="%s" class="%s" target="_blank" rel="noopener">%s</a>', |
| 79 |
esc_url( $item['url'] ), |
| 80 |
esc_attr( $item['class'] ), |
| 81 |
esc_html( $item['label'] ) |
| 82 |
); |
| 83 |
} |
| 84 |
|
| 85 |
$new_links = array(); |
| 86 |
|
| 87 |
foreach ( $links as $link ) { |
| 88 |
$new_links[] = $link; |
| 89 |
|
| 90 |
// Insert after Deactivate |
| 91 |
if ( strpos( $link, 'deactivate' ) !== false ) { |
| 92 |
foreach ( $built_links as $custom_link ) { |
| 93 |
$new_links[] = $custom_link; |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
return $new_links; |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Register the administration menu for this plugin into the WordPress Dashboard menu. |
| 103 |
* |
| 104 |
* @return void |
| 105 |
* @since 1.0.0 |
| 106 |
*/ |
| 107 |
public function add_plugin_admin_menu() { |
| 108 |
/* |
| 109 |
* Add a settings page for this plugin to the Settings menu |
| 110 |
* |
| 111 |
* |
| 112 |
* |
| 113 |
* - Change 'manage_options' to the capability you see fit |
| 114 |
* For reference: http://codex.wordpress.org/Roles_and_Capabilities |
| 115 |
|
| 116 |
add_options_page( __( 'Page Title', DISCO_TEXTDOMAIN ), DISCO_NAME, 'manage_options', DISCO_TEXTDOMAIN, array( $this, 'display_plugin_admin_page' ) ); |
| 117 |
* |
| 118 |
*/ |
| 119 |
/* |
| 120 |
* Add a settings page for this plugin to the main menu |
| 121 |
* |
| 122 |
*/ |
| 123 |
add_menu_page( |
| 124 |
'Disco', |
| 125 |
DISCO_NAME, |
| 126 |
'manage_woocommerce', |
| 127 |
'disco-create-discount', |
| 128 |
array( |
| 129 |
$this, |
| 130 |
'display_plugin_admin_page_create_discount', |
| 131 |
), |
| 132 |
plugins_url( 'disco/assets/img/disco-menu-icon.png' ), |
| 133 |
10 |
| 134 |
); |
| 135 |
add_submenu_page( |
| 136 |
'disco-create-discount', |
| 137 |
__( 'Campaigns', 'disco' ), |
| 138 |
__( 'Campaigns', 'disco' ), |
| 139 |
'manage_woocommerce', |
| 140 |
'disco-create-discount', |
| 141 |
array( |
| 142 |
$this, |
| 143 |
'display_plugin_admin_page_create_discount', |
| 144 |
) |
| 145 |
); |
| 146 |
add_submenu_page( |
| 147 |
'disco-create-discount', |
| 148 |
__( 'Create Campaign', 'disco' ), |
| 149 |
__( 'Create Campaign', 'disco' ), |
| 150 |
'manage_woocommerce', |
| 151 |
'disco-create-campaign', |
| 152 |
array( |
| 153 |
$this, |
| 154 |
'disco_display_plugin_admin_page_create_campaign', |
| 155 |
) |
| 156 |
); |
| 157 |
|
| 158 |
add_submenu_page( |
| 159 |
'disco-create-discount', |
| 160 |
__( 'Analytics', 'disco' ), |
| 161 |
__( 'Analytics', 'disco' ) . ' <span class="disco-beta-badge">' . __( 'Beta', 'disco' ) . '</span>', |
| 162 |
'manage_woocommerce', |
| 163 |
'disco-analytics', |
| 164 |
array( |
| 165 |
$this, |
| 166 |
'disco_display_plugin_admin_page_analytics', |
| 167 |
) |
| 168 |
); |
| 169 |
|
| 170 |
add_submenu_page( |
| 171 |
'disco-create-discount', |
| 172 |
__( 'Settings', 'disco' ), |
| 173 |
__( 'Settings', 'disco' ), |
| 174 |
'manage_woocommerce', |
| 175 |
'disco-settings', |
| 176 |
array( |
| 177 |
$this, |
| 178 |
'disco_display_plugin_admin_page_settings', |
| 179 |
) |
| 180 |
); |
| 181 |
add_submenu_page( |
| 182 |
'disco-create-discount', |
| 183 |
__( 'Compatibles', 'disco' ), |
| 184 |
__( 'Compatibles', 'disco' ), |
| 185 |
'manage_woocommerce', |
| 186 |
'compatible-plugin-list', |
| 187 |
array( |
| 188 |
$this, |
| 189 |
'disco_display_plugin_admin_page_compatible_plugin_list', |
| 190 |
) |
| 191 |
); |
| 192 |
add_submenu_page( |
| 193 |
'disco-create-discount', |
| 194 |
__( 'Help & Docs', 'disco' ), |
| 195 |
__( 'Help & Docs', 'disco' ), |
| 196 |
'manage_woocommerce', |
| 197 |
'help-and-docs', |
| 198 |
array( |
| 199 |
$this, |
| 200 |
'disco_display_plugin_admin_page_help_and_docs', |
| 201 |
) |
| 202 |
); |
| 203 |
|
| 204 |
if ( ! Disco::is_pro() ) { |
| 205 |
add_submenu_page( |
| 206 |
'disco-create-discount', |
| 207 |
__( 'Pro Plan', 'disco' ), |
| 208 |
__( 'Pro Plan', 'disco' ), |
| 209 |
'manage_woocommerce', |
| 210 |
'pro-plan', |
| 211 |
array( |
| 212 |
$this, |
| 213 |
'disco_display_plugin_admin_page_pro_plan', |
| 214 |
) |
| 215 |
); |
| 216 |
} |
| 217 |
|
| 218 |
if ( ! Disco::is_pro() ) { |
| 219 |
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 220 |
$GLOBALS['submenu']['disco-create-discount'][] = array( |
| 221 |
'<span class="disco-pro-submenu-badge"> |
| 222 |
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 15 15" fill="none"> |
| 223 |
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.2814 5.98453H5.72436V4.1044C5.72436 3.12776 6.52343 2.32872 7.50004 2.32872C8.30225 2.32872 8.98463 2.86784 9.2028 3.60167C9.37029 4.16505 10.1124 4.2808 10.4549 3.82187C10.592 3.6382 10.6307 3.42103 10.5655 3.20133C10.1734 1.87951 8.94467 0.908203 7.50004 0.908203C5.74211 0.908203 4.30381 2.3465 4.30381 4.10443V5.98453H3.71872C3.0734 5.98453 2.54541 6.51252 2.54541 7.15784V12.9185C2.54541 13.5638 3.0734 14.0918 3.71872 14.0918H11.2814C11.9267 14.0918 12.4547 13.5638 12.4547 12.9185V7.15784C12.4547 6.51252 11.9267 5.98453 11.2814 5.98453ZM7.93952 10.0434V11.5296C7.93952 11.7723 7.74276 11.969 7.50007 11.969C7.25737 11.969 7.06062 11.7723 7.06062 11.5296V10.0434C6.71849 9.87938 6.48224 9.52983 6.48224 9.1251C6.48224 8.56298 6.93792 8.10727 7.50007 8.10727C8.06222 8.10727 8.5179 8.56298 8.5179 9.1251C8.5179 9.52986 8.28165 9.8794 7.93952 10.0434Z" fill="white"/> |
| 224 |
</svg> ' . esc_html__( 'Unlock Pro', 'disco' ) . |
| 225 |
'</span>', |
| 226 |
'manage_woocommerce', |
| 227 |
admin_url( 'admin.php?page=pro-plan' ), |
| 228 |
esc_html__( 'Unlock Pro', 'disco' ), |
| 229 |
); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* Render the create discount page for this plugin. |
| 235 |
* |
| 236 |
* @return void |
| 237 |
* @since 1.0.0 |
| 238 |
*/ |
| 239 |
public function display_plugin_admin_page_create_discount() { |
| 240 |
// Create a nonce |
| 241 |
wp_create_nonce( 'disco_create_discount' ); |
| 242 |
|
| 243 |
include_once DISCO_PLUGIN_ROOT . 'backend/views/create_discount.php'; |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Render the create campaign page for this plugin. |
| 248 |
* |
| 249 |
* @return void |
| 250 |
*/ |
| 251 |
public function disco_display_plugin_admin_page_create_campaign() { |
| 252 |
wp_create_nonce( 'disco_create_discount' ); |
| 253 |
echo '<script>window.location.hash="#/disco";</script>'; |
| 254 |
include_once DISCO_PLUGIN_ROOT . 'backend/views/create_discount.php'; |
| 255 |
} |
| 256 |
|
| 257 |
/** |
| 258 |
* Render the settings page for this plugin. |
| 259 |
* |
| 260 |
* @return void |
| 261 |
*/ |
| 262 |
public function disco_display_plugin_admin_page_settings() { |
| 263 |
wp_create_nonce( 'disco_create_discount' ); |
| 264 |
echo '<script>window.location.hash="#/settings";</script>'; |
| 265 |
include_once DISCO_PLUGIN_ROOT . 'backend/views/create_discount.php'; |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* Render the help and docs page for this plugin. |
| 270 |
* |
| 271 |
* @return void |
| 272 |
* @since 1.0.0 |
| 273 |
*/ |
| 274 |
public function disco_display_plugin_admin_page_help_and_docs() { |
| 275 |
include_once DISCO_PLUGIN_ROOT . 'backend/views/help_and_docs.php'; |
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Render the pro plan page for this plugin. |
| 280 |
* |
| 281 |
* @return void |
| 282 |
* @since 1.0.0 |
| 283 |
*/ |
| 284 |
public function disco_display_plugin_admin_page_pro_plan() { |
| 285 |
include_once DISCO_PLUGIN_ROOT . 'backend/views/pro_plan.php'; |
| 286 |
} |
| 287 |
|
| 288 |
/** |
| 289 |
* Render the compatible plugin list page for this plugin. |
| 290 |
* |
| 291 |
* @return void |
| 292 |
* @since 1.0.0 |
| 293 |
*/ |
| 294 |
public function disco_display_plugin_admin_page_compatible_plugin_list() { |
| 295 |
include_once DISCO_PLUGIN_ROOT . 'backend/views/compatible_plugin_list.php'; |
| 296 |
} |
| 297 |
|
| 298 |
/** |
| 299 |
* Render the Analytics page for this plugin. |
| 300 |
* |
| 301 |
* @return void |
| 302 |
* @since 1.0.0 |
| 303 |
*/ |
| 304 |
public function disco_display_plugin_admin_page_analytics() { |
| 305 |
include_once DISCO_PLUGIN_ROOT . 'backend/views/analytics.php'; |
| 306 |
} |
| 307 |
|
| 308 |
} |
| 309 |
|