ravinderk /
Give
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Admin Actions |
||
| 4 | * |
||
| 5 | * @package Give |
||
| 6 | * @subpackage Admin/Actions |
||
| 7 | * @copyright Copyright (c) 2016, WordImpress |
||
| 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 | /** |
||
| 19 | * Hide subscription notice if admin click on "Click here if already renewed" in subscription notice. |
||
| 20 | * |
||
| 21 | * @since 1.7 |
||
| 22 | * @return void |
||
| 23 | */ |
||
| 24 | function give_hide_subscription_notices() { |
||
| 25 | |||
| 26 | // Hide subscription notices permanently. |
||
| 27 | if ( ! empty( $_GET['_give_hide_license_notices_permanently'] ) ) { |
||
| 28 | $current_user = wp_get_current_user(); |
||
| 29 | |||
| 30 | // check previously disabled notice ids. |
||
| 31 | $already_dismiss_notices = ( $already_dismiss_notices = get_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', true ) ) |
||
| 32 | ? $already_dismiss_notices |
||
| 33 | : array(); |
||
| 34 | |||
| 35 | // Get notice id. |
||
| 36 | $notice_id = sanitize_text_field( $_GET['_give_hide_license_notices_permanently'] ); |
||
| 37 | |||
| 38 | if ( ! in_array( $notice_id, $already_dismiss_notices ) ) { |
||
| 39 | $already_dismiss_notices[] = $notice_id; |
||
| 40 | } |
||
| 41 | |||
| 42 | // Store subscription ids. |
||
| 43 | update_user_meta( $current_user->ID, '_give_hide_license_notices_permanently', $already_dismiss_notices ); |
||
| 44 | |||
| 45 | // Redirect user. |
||
| 46 | wp_safe_redirect( remove_query_arg( '_give_hide_license_notices_permanently', $_SERVER['REQUEST_URI'] ) ); |
||
| 47 | exit(); |
||
| 48 | } |
||
| 49 | |||
| 50 | // Hide subscription notices shortly. |
||
| 51 | if ( ! empty( $_GET['_give_hide_license_notices_shortly'] ) ) { |
||
| 52 | $current_user = wp_get_current_user(); |
||
| 53 | |||
| 54 | // Get notice id. |
||
| 55 | $notice_id = sanitize_text_field( $_GET['_give_hide_license_notices_shortly'] ); |
||
| 56 | |||
| 57 | // Transient key name. |
||
| 58 | $transient_key = "_give_hide_license_notices_shortly_{$current_user->ID}_{$notice_id}"; |
||
| 59 | |||
| 60 | if ( get_transient( $transient_key ) ) { |
||
| 61 | return; |
||
| 62 | } |
||
| 63 | |||
| 64 | // Hide notice for 24 hours. |
||
| 65 | set_transient( $transient_key, true, 24 * HOUR_IN_SECONDS ); |
||
| 66 | |||
| 67 | // Redirect user. |
||
| 68 | wp_safe_redirect( remove_query_arg( '_give_hide_license_notices_shortly', $_SERVER['REQUEST_URI'] ) ); |
||
| 69 | exit(); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | add_action( 'admin_init', 'give_hide_subscription_notices' ); |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Load wp editor by ajax. |
||
| 77 | * |
||
| 78 | * @since 1.8 |
||
| 79 | */ |
||
| 80 | function give_load_wp_editor() { |
||
| 81 | if ( ! isset( $_POST['wp_editor'] ) ) { |
||
| 82 | die(); |
||
| 83 | } |
||
| 84 | |||
| 85 | $wp_editor = json_decode( base64_decode( $_POST['wp_editor'] ), true ); |
||
| 86 | $wp_editor[2]['textarea_name'] = $_POST['textarea_name']; |
||
| 87 | |||
| 88 | wp_editor( $wp_editor[0], $_POST['wp_editor_id'], $wp_editor[2] ); |
||
| 89 | |||
| 90 | die(); |
||
| 91 | } |
||
| 92 | |||
| 93 | add_action( 'wp_ajax_give_load_wp_editor', 'give_load_wp_editor' ); |
||
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * Redirect admin to clean url give admin pages. |
||
| 98 | * |
||
| 99 | * @since 1.8 |
||
| 100 | * |
||
| 101 | * @return bool |
||
|
0 ignored issues
–
show
|
|||
| 102 | */ |
||
| 103 | function give_redirect_to_clean_url_admin_pages() { |
||
| 104 | // Give admin pages. |
||
| 105 | $give_pages = array( |
||
| 106 | 'give-payment-history', |
||
| 107 | 'give-donors', |
||
| 108 | 'give-reports' |
||
| 109 | ); |
||
| 110 | |||
| 111 | // Get current page. |
||
| 112 | $current_page = isset( $_GET['page'] ) ? esc_attr( $_GET['page'] ) : ''; |
||
| 113 | |||
| 114 | // Bailout. |
||
| 115 | if ( |
||
| 116 | empty( $current_page ) |
||
| 117 | || empty( $_GET['_wp_http_referer'] ) |
||
| 118 | || ! in_array( $current_page, $give_pages ) |
||
| 119 | ) { |
||
| 120 | return false; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Verify current page request. |
||
| 125 | * |
||
| 126 | * @since 1.8 |
||
| 127 | */ |
||
| 128 | $redirect = apply_filters( "give_validate_{$current_page}", true ); |
||
| 129 | |||
| 130 | if ( $redirect ) { |
||
| 131 | // Redirect. |
||
| 132 | wp_redirect( |
||
| 133 | remove_query_arg( |
||
| 134 | array( '_wp_http_referer', '_wpnonce' ), |
||
| 135 | wp_unslash( $_SERVER['REQUEST_URI'] ) |
||
| 136 | ) |
||
| 137 | ); |
||
| 138 | exit; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | add_action( 'admin_init', 'give_redirect_to_clean_url_admin_pages' ); |
||
| 143 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.