Completed
Push — issues/1817 ( 12f6f1...27df7d )
by Ravinder
19:58
created

payments-history.php ➔ give_payment_history_page()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 50
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 27
nc 2
nop 0
dl 0
loc 50
rs 9.3333
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 26 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Admin Payment History
4
 *
5
 * @package     Give
6
 * @subpackage  Admin/Payments
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
 * Payment History Page
19
 *
20
 * Renders the payment history page contents.
21
 *
22
 * @access      private
23
 * @since       1.0
24
 * @return      void
25
*/
26
function give_payment_history_page() {
27
28
	$give_payment = get_post_type_object( 'give_payment' );
29
30
	if ( isset( $_GET['view'] ) && 'view-payment-details' == $_GET['view'] ) {
31
		require_once GIVE_PLUGIN_DIR . 'includes/admin/payments/view-payment-details.php';
32
	} else {
33
		require_once GIVE_PLUGIN_DIR . 'includes/admin/payments/class-payments-table.php';
34
		$payments_table = new Give_Payment_History_Table();
35
		$payments_table->prepare_items();
36
	?>
37
	<div class="wrap">
38
39
		<h1><?php echo get_admin_page_title(); ?></h1>
40
41
		<?php
42
		/**
43
		 * Fires in payment history screen, at the top of the page.
44
		 *
45
		 * @since 1.7
46
		 */
47
		do_action( 'give_payments_page_top' );
48
		?>
49
50
		<form id="give-payments-advanced-filter" method="get" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>">
51
			<input type="hidden" name="post_type" value="give_forms" />
52
			<input type="hidden" name="page" value="give-payment-history" />
53
			<?php $payments_table->views() ?>
54
			<?php $payments_table->advanced_filters(); ?>
55
		</form>
56
57
		<form id="give-payments-filter" method="get" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>">
58
			<input type="hidden" name="post_type" value="give_forms" />
59
			<input type="hidden" name="page" value="give-payment-history" />
60
			<?php $payments_table->display() ?>
61
		</form>
62
63
		<?php
64
		/**
65
		 * Fires in payment history screen, at the bottom of the page.
66
		 *
67
		 * @since 1.7
68
		 */
69
		do_action( 'give_payments_page_bottom' );
70
		?>
71
72
	</div>
73
<?php
74
	}
75
}
76
77
/**
78
 * Payment History admin titles
79
 *
80
 * @since 1.0
81
 *
82
 * @param $admin_title
83
 * @param $title
84
 * @return string
85
 */
86
function give_view_order_details_title( $admin_title, $title ) {
0 ignored issues
show
Unused Code introduced by
The parameter $title is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
88
	if ( 'give_forms_page_give-payment-history' != get_current_screen()->base ) {
89
		return $admin_title;
90
	}
91
92
	if( ! isset( $_GET['give-action'] ) ) {
93
		return $admin_title;
94
	}
95
96
	switch( $_GET['give-action'] ) :
97
98
		case 'view-payment-details' :
99
			$title = sprintf(
100
				/* translators: %s: admin title */
101
				esc_html__( 'View Donation Details - %s', 'give' ),
102
				$admin_title
103
			);
104
			break;
105
		case 'edit-payment' :
106
			$title = sprintf(
107
				/* translators: %s: admin title */
108
				esc_html__( 'Edit Donation - %s', 'give' ),
109
				$admin_title
110
			);
111
			break;
112
		default:
113
			$title = $admin_title;
114
			break;
115
	endswitch;
116
117
	return $title;
118
}
119
add_filter( 'admin_title', 'give_view_order_details_title', 10, 2 );
120
121
/**
122
 * Intercept default Edit post links for Give payments and rewrite them to the View Order Details screen.
123
 *
124
 * @since 1.0
125
 *
126
 * @param $url
127
 * @param $post_id
128
 * @param $context
129
 * @return string
130
 */
131
function give_override_edit_post_for_payment_link( $url, $post_id = 0, $context ) {
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
132
133
	$post = get_post( $post_id );
134
135
	if( ! $post ) {
136
		return $url;
137
	}
138
139
	if( 'give_payment' != $post->post_type ) {
140
		return $url;
141
	}
142
143
	$url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $post_id );
144
145
	return $url;
146
}
147
add_filter( 'get_edit_post_link', 'give_override_edit_post_for_payment_link', 10, 3 );
148