| 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\Engine\Base; |
| 16 |
|
| 17 |
/** |
| 18 |
* Create the settings page in the backend |
| 19 |
*/ |
| 20 |
class Settings_Page extends Base { |
| 21 |
|
| 22 |
/** |
| 23 |
* Initialize the class. |
| 24 |
* |
| 25 |
* @return void|bool |
| 26 |
*/ |
| 27 |
public function initialize() { |
| 28 |
if ( ! parent::initialize() ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
// Add the options page and menu item. |
| 33 |
\add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) ); |
| 34 |
|
| 35 |
$realpath = (string) \realpath( __DIR__ ); |
| 36 |
$plugin_basename = \plugin_basename( \plugin_dir_path( $realpath ) . DISCO_TEXTDOMAIN . '.php' ); |
| 37 |
|
| 38 |
add_filter( "plugin_action_links_{$plugin_basename}", array( $this, 'disco_add_action_plugin_links' ) ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Add settings link on plugin page |
| 43 |
* |
| 44 |
* @param array $links links. |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function disco_add_action_plugin_links( $links ) { |
| 48 |
|
| 49 |
$is_pro_active = class_exists( '\Disco_Pro' ); |
| 50 |
|
| 51 |
$custom_links = [ |
| 52 |
[ |
| 53 |
'label' => __( 'Settings', 'disco' ), |
| 54 |
'url' => admin_url( 'admin.php?page=disco-create-discount' ), |
| 55 |
'class' => 'disco-settings-link', |
| 56 |
], |
| 57 |
[ |
| 58 |
'label' => __( 'Get Pro', 'disco' ), |
| 59 |
'url' => 'https://discoplugin.com/pricing/?utm_source=plugin_dashboard&utm_medium=free-to-pro&utm_campaign=free-to-pro&utm_id=1', |
| 60 |
'class' => 'disco-custom-pro-link', |
| 61 |
], |
| 62 |
[ |
| 63 |
'label' => __( 'Docs', 'disco' ), |
| 64 |
'url' => 'https://discoplugin.com/docs/', |
| 65 |
'class' => 'disco-custom-docs-link', |
| 66 |
], |
| 67 |
]; |
| 68 |
|
| 69 |
if ( $is_pro_active ) { |
| 70 |
array_splice( $custom_links, 1, 1 ); |
| 71 |
} |
| 72 |
|
| 73 |
$built_links = array(); |
| 74 |
|
| 75 |
foreach ( $custom_links as $item ) { |
| 76 |
$built_links[] = sprintf( |
| 77 |
'<a href="%s" class="%s" target="_blank" rel="noopener">%s</a>', |
| 78 |
esc_url( $item['url'] ), |
| 79 |
esc_attr( $item['class'] ), |
| 80 |
esc_html( $item['label'] ) |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
$new_links = array(); |
| 85 |
|
| 86 |
foreach ( $links as $link ) { |
| 87 |
$new_links[] = $link; |
| 88 |
|
| 89 |
// Insert after Deactivate |
| 90 |
if ( strpos( $link, 'deactivate' ) !== false ) { |
| 91 |
foreach ( $built_links as $custom_link ) { |
| 92 |
$new_links[] = $custom_link; |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
return $new_links; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Register the administration menu for this plugin into the WordPress Dashboard menu. |
| 102 |
* |
| 103 |
* @return void |
| 104 |
* @since 1.0.0 |
| 105 |
*/ |
| 106 |
public function add_plugin_admin_menu() { |
| 107 |
/* |
| 108 |
* Add a settings page for this plugin to the Settings menu |
| 109 |
* |
| 110 |
* |
| 111 |
* |
| 112 |
* - Change 'manage_options' to the capability you see fit |
| 113 |
* For reference: http://codex.wordpress.org/Roles_and_Capabilities |
| 114 |
|
| 115 |
add_options_page( __( 'Page Title', DISCO_TEXTDOMAIN ), DISCO_NAME, 'manage_options', DISCO_TEXTDOMAIN, array( $this, 'display_plugin_admin_page' ) ); |
| 116 |
* |
| 117 |
*/ |
| 118 |
/* |
| 119 |
* Add a settings page for this plugin to the main menu |
| 120 |
* |
| 121 |
*/ |
| 122 |
add_menu_page( |
| 123 |
'Disco', |
| 124 |
DISCO_NAME, |
| 125 |
'manage_woocommerce', |
| 126 |
'disco-create-discount', |
| 127 |
array( |
| 128 |
$this, |
| 129 |
'display_plugin_admin_page_create_discount', |
| 130 |
), |
| 131 |
plugins_url( 'disco/assets/img/disco-menu-icon.png' ), |
| 132 |
10 |
| 133 |
); |
| 134 |
add_submenu_page( |
| 135 |
DISCO_TEXTDOMAIN, |
| 136 |
__( 'Create a Discount', 'disco' ), |
| 137 |
__( 'Create a Discount', 'disco' ), |
| 138 |
'manage_woocommerce', |
| 139 |
'create-discount', |
| 140 |
array( |
| 141 |
$this, |
| 142 |
'display_plugin_admin_page_create_discount', |
| 143 |
) |
| 144 |
); |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Render the create discount page for this plugin. |
| 149 |
* |
| 150 |
* @return void |
| 151 |
* @since 1.0.0 |
| 152 |
*/ |
| 153 |
public function display_plugin_admin_page_create_discount() { |
| 154 |
// Create a nonce |
| 155 |
wp_create_nonce( 'disco_create_discount' ); |
| 156 |
|
| 157 |
include_once DISCO_PLUGIN_ROOT . 'backend/views/create_discount.php'; |
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
|