| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Pages |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @subpackage Admin/Pages |
| 7 |
* @copyright Copyright (c) 2016, GiveWP |
| 8 |
* @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 |
* @since 1.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Creates the admin submenu pages under the Give menu and assigns their |
| 19 |
* links to global variables |
| 20 |
* |
| 21 |
* @since 1.0 |
| 22 |
* |
| 23 |
* @global $give_settings_page |
| 24 |
* @global $give_payments_page |
| 25 |
* @global $give_reports_page |
| 26 |
* @global $give_donors_page |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
function give_add_options_links() { |
| 31 |
global $give_settings_page, $give_payments_page, $give_reports_page, $give_donors_page, $give_tools_page; |
| 32 |
|
| 33 |
//Payments |
| 34 |
/* @var WP_Post_Type $give_payment */ |
| 35 |
$give_payment = get_post_type_object( 'give_payment' ); |
| 36 |
$give_payments_page = add_submenu_page( |
| 37 |
'edit.php?post_type=give_forms', |
| 38 |
$give_payment->labels->name, |
| 39 |
$give_payment->labels->menu_name, |
| 40 |
'edit_give_payments', |
| 41 |
'give-payment-history', |
| 42 |
'give_payment_history_page' |
| 43 |
); |
| 44 |
|
| 45 |
//Donors |
| 46 |
$give_donors_page = add_submenu_page( |
| 47 |
'edit.php?post_type=give_forms', |
| 48 |
esc_html__( 'Donors', 'give' ), |
| 49 |
esc_html__( 'Donors', 'give' ), |
| 50 |
'view_give_reports', |
| 51 |
'give-donors', |
| 52 |
'give_donors_page' |
| 53 |
); |
| 54 |
|
| 55 |
//Reports |
| 56 |
$give_reports_page = add_submenu_page( |
| 57 |
'edit.php?post_type=give_forms', |
| 58 |
esc_html__( 'Donation Reports', 'give' ), |
| 59 |
esc_html__( 'Reports', 'give' ), |
| 60 |
'view_give_reports', |
| 61 |
'give-reports', |
| 62 |
array( |
| 63 |
Give()->give_settings, |
| 64 |
'output', |
| 65 |
) |
| 66 |
); |
| 67 |
|
| 68 |
//Settings |
| 69 |
$give_settings_page = add_submenu_page( |
| 70 |
'edit.php?post_type=give_forms', |
| 71 |
esc_html__( 'Give Settings', 'give' ), |
| 72 |
esc_html__( 'Settings', 'give' ), |
| 73 |
'manage_give_settings', |
| 74 |
'give-settings', |
| 75 |
array( |
| 76 |
Give()->give_settings, |
| 77 |
'output', |
| 78 |
) |
| 79 |
); |
| 80 |
|
| 81 |
//Tools. |
| 82 |
$give_tools_page = add_submenu_page( |
| 83 |
'edit.php?post_type=give_forms', |
| 84 |
esc_html__( 'Give Tools', 'give' ), |
| 85 |
esc_html__( 'Tools', 'give' ), |
| 86 |
'manage_give_settings', |
| 87 |
'give-tools', |
| 88 |
array( |
| 89 |
Give()->give_settings, |
| 90 |
'output', |
| 91 |
) |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
add_action( 'admin_menu', 'give_add_options_links', 10 ); |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
/** |
| 100 |
* Creates the admin add-ons submenu page under the Give menu and assigns their |
| 101 |
* link to global variable |
| 102 |
* |
| 103 |
* @since 2.5.0 |
| 104 |
* |
| 105 |
* @global $give_add_ons_page |
| 106 |
* |
| 107 |
* @return void |
| 108 |
*/ |
| 109 |
function give_add_add_ons_option_link(){ |
| 110 |
global $give_add_ons_page; |
| 111 |
|
| 112 |
//Add-ons |
| 113 |
$give_add_ons_page = add_submenu_page( |
| 114 |
'edit.php?post_type=give_forms', |
| 115 |
esc_html__( 'Give Add-ons', 'give' ), |
| 116 |
esc_html__( 'Add-ons', 'give' ), |
| 117 |
'install_plugins', |
| 118 |
'give-addons', |
| 119 |
'give_add_ons_page' |
| 120 |
); |
| 121 |
|
| 122 |
} |
| 123 |
add_action( 'admin_menu', 'give_add_add_ons_option_link', 999999 ); |
| 124 |
|
| 125 |
/** |
| 126 |
* Determines whether the current admin page is a Give admin page. |
| 127 |
* |
| 128 |
* Only works after the `wp_loaded` hook, & most effective |
| 129 |
* starting on `admin_menu` hook. |
| 130 |
* |
| 131 |
* @since 1.0 |
| 132 |
* @since 2.1 Simplified function. |
| 133 |
* |
| 134 |
* @param string $passed_page Optional. Main page's slug |
| 135 |
* @param string $passed_view Optional. Page view ( ex: `edit` or `delete` ) |
| 136 |
* |
| 137 |
* @return bool True if Give admin page. |
| 138 |
*/ |
| 139 |
function give_is_admin_page( $passed_page = '', $passed_view = '' ) { |
| 140 |
global $pagenow, $typenow; |
| 141 |
|
| 142 |
$found = true; |
| 143 |
$get_query_args = ! empty( $_GET ) ? @array_map( 'strtolower', $_GET ) : array(); |
| 144 |
|
| 145 |
// Set default argument, if not passed. |
| 146 |
$query_args = wp_parse_args( $get_query_args, array_fill_keys( array( 'post_type', 'action', 'taxonomy', 'page', 'view', 'tab' ), false ) ); |
| 147 |
|
| 148 |
switch ( $passed_page ) { |
| 149 |
case 'categories': |
| 150 |
case 'tags': |
| 151 |
$has_view = in_array( $passed_view, array( 'list-table', 'edit', 'new' ), true ); |
| 152 |
|
| 153 |
if ( |
| 154 |
! in_array( $query_args['taxonomy'], array( 'give_forms_category', 'give_forms_tag' ), true ) && |
| 155 |
'edit-tags.php' !== $pagenow && |
| 156 |
( |
| 157 |
$has_view || |
| 158 |
( |
| 159 |
( in_array( $passed_view, array( 'list-table', 'new' ), true ) && 'edit' === $query_args['action'] ) || |
| 160 |
( 'edit' !== $passed_view && 'edit' !== $query_args['action'] ) && |
| 161 |
! $has_view |
| 162 |
) |
| 163 |
) |
| 164 |
) { |
| 165 |
$found = false; |
| 166 |
} |
| 167 |
break; |
| 168 |
// Give Donation form page. |
| 169 |
case 'give_forms': |
| 170 |
$has_view = in_array( $passed_view, array( 'new', 'list-table', 'edit' ), true ); |
| 171 |
|
| 172 |
if ( |
| 173 |
'give_forms' !== $typenow && |
| 174 |
( |
| 175 |
( 'list-table' !== $passed_view && 'edit.php' !== $pagenow ) && |
| 176 |
( 'edit' !== $passed_view && 'post.php' !== $pagenow ) && |
| 177 |
( 'new' !== $passed_view && 'post-new.php' !== $pagenow ) |
| 178 |
) || |
| 179 |
( |
| 180 |
! $has_view && |
| 181 |
( 'post-new.php' !== $pagenow && 'give_forms' !== $query_args['post_type'] ) |
| 182 |
) |
| 183 |
) { |
| 184 |
$found = false; |
| 185 |
} |
| 186 |
break; |
| 187 |
// Give Donors page. |
| 188 |
case 'donors': |
| 189 |
$has_view = array_intersect( array( $passed_view, $query_args['view'] ), array( 'list-table', 'overview', 'notes' ) ); |
| 190 |
|
| 191 |
if ( |
| 192 |
( 'give-donors' !== $query_args['page'] || 'edit.php' !== $pagenow ) && |
| 193 |
( |
| 194 |
( $passed_view !== $query_args['view'] || ! empty( $has_view ) ) || |
| 195 |
( false !== $query_args['view'] && 'list-table' !== $passed_view ) |
| 196 |
) |
| 197 |
) { |
| 198 |
$found = false; |
| 199 |
} |
| 200 |
break; |
| 201 |
// Give Donations page. |
| 202 |
case 'payments': |
| 203 |
if ( |
| 204 |
( 'give-payment-history' !== $query_args['page'] || 'edit.php' !== $pagenow ) && |
| 205 |
( |
| 206 |
! in_array( $passed_view, array( 'list-table', 'edit' ), true ) || |
| 207 |
( |
| 208 |
( 'list-table' !== $passed_view && false !== $query_args['view'] ) || |
| 209 |
( 'edit' !== $passed_view && 'view-payment-details' !== $query_args['view'] ) |
| 210 |
) |
| 211 |
) |
| 212 |
) { |
| 213 |
$found = false; |
| 214 |
} |
| 215 |
break; |
| 216 |
case 'reports': |
| 217 |
case 'settings': |
| 218 |
case 'addons': |
| 219 |
// Get current tab. |
| 220 |
$current_tab = empty( $passed_view ) ? $query_args['tab'] : $passed_view; |
| 221 |
$give_setting_page = in_array( $query_args['page'], array( 'give-reports', 'give-settings', 'give-addons' ), true ); |
| 222 |
|
| 223 |
// Check if it's Give Setting page or not. |
| 224 |
if ( |
| 225 |
( 'edit.php' !== $pagenow || ! $give_setting_page ) && |
| 226 |
! Give_Admin_Settings::is_setting_page( $current_tab ) |
| 227 |
) { |
| 228 |
$found = false; |
| 229 |
} |
| 230 |
break; |
| 231 |
default: |
| 232 |
global $give_payments_page, $give_settings_page, $give_reports_page, $give_system_info_page, $give_add_ons_page, $give_settings_export, $give_donors_page, $give_tools_page; |
| 233 |
$admin_pages = apply_filters( 'give_admin_pages', array( |
| 234 |
$give_payments_page, |
| 235 |
$give_settings_page, |
| 236 |
$give_reports_page, |
| 237 |
$give_system_info_page, |
| 238 |
$give_add_ons_page, |
| 239 |
$give_settings_export, |
| 240 |
$give_donors_page, |
| 241 |
$give_tools_page, |
| 242 |
'widgets.php', |
| 243 |
) ); |
| 244 |
|
| 245 |
$found = ( 'give_forms' === $typenow || in_array( $pagenow, array_merge( $admin_pages, array( 'index.php', 'post-new.php', 'post.php' ) ), true ) ) ? true : false; |
| 246 |
} |
| 247 |
return (bool) apply_filters( 'give_is_admin_page', $found, $query_args['page'], $query_args['view'], $passed_page, $passed_view ); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Add setting tab to give-settings page |
| 252 |
* |
| 253 |
* @since 1.8 |
| 254 |
* @param array $settings |
| 255 |
* @return array |
| 256 |
*/ |
| 257 |
function give_settings_page_pages( $settings ) { |
| 258 |
include( 'abstract-admin-settings-page.php' ); |
| 259 |
|
| 260 |
$settings = array( |
| 261 |
// General settings. |
| 262 |
include( GIVE_PLUGIN_DIR . 'includes/admin/settings/class-settings-general.php' ), |
| 263 |
|
| 264 |
// Payment Gateways Settings. |
| 265 |
include( GIVE_PLUGIN_DIR . 'includes/admin/settings/class-settings-gateways.php' ), |
| 266 |
|
| 267 |
// Display settings. |
| 268 |
include( GIVE_PLUGIN_DIR . 'includes/admin/settings/class-settings-display.php' ), |
| 269 |
|
| 270 |
// Emails settings. |
| 271 |
include( GIVE_PLUGIN_DIR . 'includes/admin/settings/class-settings-email.php' ), |
| 272 |
|
| 273 |
// Addons settings. |
| 274 |
include( GIVE_PLUGIN_DIR . 'includes/admin/settings/class-settings-addon.php' ), |
| 275 |
|
| 276 |
// License settings. |
| 277 |
include( GIVE_PLUGIN_DIR . 'includes/admin/settings/class-settings-license.php' ), |
| 278 |
|
| 279 |
// Advanced settings. |
| 280 |
include( GIVE_PLUGIN_DIR . 'includes/admin/settings/class-settings-advanced.php' ), |
| 281 |
); |
| 282 |
|
| 283 |
// Output. |
| 284 |
return $settings; |
| 285 |
} |
| 286 |
add_filter( 'give-settings_get_settings_pages', 'give_settings_page_pages', 0, 1 ); |
| 287 |
|
| 288 |
|
| 289 |
/** |
| 290 |
* Add setting tab to give-settings page |
| 291 |
* |
| 292 |
* @since 1.8 |
| 293 |
* @param array $settings |
| 294 |
* @return array |
| 295 |
*/ |
| 296 |
function give_reports_page_pages( $settings ) { |
| 297 |
include( 'abstract-admin-settings-page.php' ); |
| 298 |
|
| 299 |
$settings = array( |
| 300 |
// Earnings. |
| 301 |
include( 'reports/class-earnings-report.php' ), |
| 302 |
|
| 303 |
// Forms. |
| 304 |
include( 'reports/class-forms-report.php' ), |
| 305 |
|
| 306 |
// Gateways. |
| 307 |
include( 'reports/class-gateways-report.php' ), |
| 308 |
|
| 309 |
); |
| 310 |
|
| 311 |
// Output. |
| 312 |
return $settings; |
| 313 |
} |
| 314 |
add_filter( 'give-reports_get_settings_pages', 'give_reports_page_pages', 0, 1 ); |
| 315 |
|
| 316 |
/** |
| 317 |
* Add setting tab to give-settings page |
| 318 |
* |
| 319 |
* @since 1.8 |
| 320 |
* @param array $settings |
| 321 |
* @return array |
| 322 |
*/ |
| 323 |
function give_tools_page_pages( $settings ) { |
| 324 |
include( 'abstract-admin-settings-page.php' ); |
| 325 |
|
| 326 |
$settings = array( |
| 327 |
|
| 328 |
// Export. |
| 329 |
include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-export.php' ), |
| 330 |
|
| 331 |
// Import |
| 332 |
include_once( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-import.php' ), |
| 333 |
|
| 334 |
// Logs. |
| 335 |
include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-logs.php' ), |
| 336 |
|
| 337 |
// API. |
| 338 |
include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-api.php' ), |
| 339 |
|
| 340 |
// Data. |
| 341 |
include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-data.php' ), |
| 342 |
|
| 343 |
// System Info. |
| 344 |
include( GIVE_PLUGIN_DIR . 'includes/admin/tools/class-settings-system-info.php' ), |
| 345 |
); |
| 346 |
|
| 347 |
// Output. |
| 348 |
return $settings; |
| 349 |
} |
| 350 |
add_filter( 'give-tools_get_settings_pages', 'give_tools_page_pages', 0, 1 ); |
| 351 |
|
| 352 |
/** |
| 353 |
* Set default tools page tab. |
| 354 |
* |
| 355 |
* @since 1.8 |
| 356 |
* @param string $default_tab Default tab name. |
| 357 |
* @return string |
| 358 |
*/ |
| 359 |
function give_set_default_tab_form_tools_page( $default_tab ) { |
| 360 |
return 'export'; |
| 361 |
} |
| 362 |
add_filter( 'give_default_setting_tab_give-tools', 'give_set_default_tab_form_tools_page', 10, 1 ); |
| 363 |
|
| 364 |
|
| 365 |
/** |
| 366 |
* Set default reports page tab. |
| 367 |
* |
| 368 |
* @since 1.8 |
| 369 |
* @param string $default_tab Default tab name. |
| 370 |
* @return string |
| 371 |
*/ |
| 372 |
function give_set_default_tab_form_reports_page( $default_tab ) { |
| 373 |
return 'earnings'; |
| 374 |
} |
| 375 |
add_filter( 'give_default_setting_tab_give-reports', 'give_set_default_tab_form_reports_page', 10, 1 ); |
| 376 |
|
| 377 |
|
| 378 |
/** |
| 379 |
* Add a page display state for special Give pages in the page list table. |
| 380 |
* |
| 381 |
* @since 1.8.18 |
| 382 |
* |
| 383 |
* @param array $post_states An array of post display states. |
| 384 |
* @param WP_Post $post The current post object. |
| 385 |
* |
| 386 |
* @return array |
| 387 |
*/ |
| 388 |
function give_add_display_page_states( $post_states, $post ) { |
| 389 |
|
| 390 |
switch ( $post->ID ) { |
| 391 |
case give_get_option( 'success_page' ): |
| 392 |
$post_states['give_successfully_page'] = __( 'Donation Success Page', 'give' ); |
| 393 |
break; |
| 394 |
|
| 395 |
case give_get_option( 'failure_page' ): |
| 396 |
$post_states['give_failure_page'] = __( 'Donation Failed Page', 'give' ); |
| 397 |
break; |
| 398 |
|
| 399 |
case give_get_option( 'history_page' ): |
| 400 |
$post_states['give_history_page'] = __( 'Donation History Page', 'give' ); |
| 401 |
break; |
| 402 |
} |
| 403 |
|
| 404 |
return $post_states; |
| 405 |
} |
| 406 |
|
| 407 |
// Add a post display state for special Give pages. |
| 408 |
add_filter( 'display_post_states', 'give_add_display_page_states', 10, 2 ); |
| 409 |
|