Passed
Pull Request — master (#862)
by Kiran
06:12
created
wp-ayecode-ui/includes/components/class-aui-component-pagination.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,112 +11,112 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Pagination {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function get( $args = array() ) {
22
-		global $wp_query, $aui_bs5;
23
-
24
-		$defaults = array(
25
-			'class'              => '',
26
-			'mid_size'           => 2,
27
-			'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28
-			'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
-			'screen_reader_text' => __( 'Posts navigation', 'ayecode-connect' ),
30
-			'before_paging'      => '',
31
-			'after_paging'       => '',
32
-			'type'               => 'array',
33
-			'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
34
-			'links'              => array(), // an array of links if using custom links, this includes the a tag.
35
-			'rounded_style'      => false,
36
-			'custom_next_text'   => '', // Custom next page text
37
-			'custom_prev_text'   => '', // Custom prev page text
38
-		);
39
-
40
-		/**
41
-		 * Parse incoming $args into an array and merge it with $defaults
42
-		 */
43
-		$args = wp_parse_args( $args, $defaults );
44
-
45
-		$output = '';
46
-
47
-		// Don't print empty markup if there's only one page.
48
-		if ( $args['total'] > 1 ) {
49
-			// Set up paginated links.
50
-			$links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
51
-
52
-			$class = !empty($args['class']) ? $args['class'] : '';
53
-
54
-			$custom_prev_link = '';
55
-			$custom_next_link = '';
56
-
57
-			// make the output bootstrap ready
58
-			$links_html = "<ul class='pagination m-0 p-0 $class'>";
59
-			if ( ! empty( $links ) ) {
60
-				foreach ( $links as $link ) {
61
-					$_link = $link;
62
-
63
-					if ( $aui_bs5 ) {
64
-						$link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link';
65
-						$link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active';
66
-						$links_html .= "<li class='page-item mx-0'>";
67
-						$link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link );
68
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
69
-						$links_html .=  $link;
70
-						$links_html .= "</li>";
71
-					} else {
72
-						$active = strpos( $link, 'current' ) !== false ? 'active' : '';
73
-						$links_html .= "<li class='page-item $active'>";
74
-						$links_html .= str_replace( "page-numbers", "page-link", $link );
75
-						$links_html .= "</li>";
76
-					}
77
-
78
-					if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) {
79
-						$link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link );
80
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
81
-
82
-						if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) {
83
-							$custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link );
84
-						} else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) {
85
-							$custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link );
86
-						}
87
-					}
88
-				}
89
-			}
90
-			$links_html .= "</ul>";
91
-
92
-			if ( $links ) {
93
-				$output .= '<section class="px-0 py-2 w-100">';
94
-				$output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
95
-				$output .= '</section>';
96
-			}
97
-
98
-			$output = str_replace( "screen-reader-text", "screen-reader-text sr-only" . ( $aui_bs5 ? ' visually-hidden' : '' ), $output );
99
-			$output = str_replace( "nav-links", "aui-nav-links", $output );
100
-		}
101
-
102
-		if ( $output ) {
103
-			if ( $custom_next_link || $custom_prev_link ) {
104
-				$total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
105
-				$current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
106
-
107
-				$output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>';
108
-			}
109
-
110
-			if ( ! empty( $args['before_paging'] ) ) {
111
-				$output = $args['before_paging'] . $output;
112
-			}
113
-
114
-			if ( ! empty( $args['after_paging'] ) ) {
115
-				$output = $output . $args['after_paging'];
116
-			}
117
-		}
118
-
119
-		return $output;
120
-	}
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function get( $args = array() ) {
22
+        global $wp_query, $aui_bs5;
23
+
24
+        $defaults = array(
25
+            'class'              => '',
26
+            'mid_size'           => 2,
27
+            'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28
+            'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
+            'screen_reader_text' => __( 'Posts navigation', 'ayecode-connect' ),
30
+            'before_paging'      => '',
31
+            'after_paging'       => '',
32
+            'type'               => 'array',
33
+            'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
34
+            'links'              => array(), // an array of links if using custom links, this includes the a tag.
35
+            'rounded_style'      => false,
36
+            'custom_next_text'   => '', // Custom next page text
37
+            'custom_prev_text'   => '', // Custom prev page text
38
+        );
39
+
40
+        /**
41
+         * Parse incoming $args into an array and merge it with $defaults
42
+         */
43
+        $args = wp_parse_args( $args, $defaults );
44
+
45
+        $output = '';
46
+
47
+        // Don't print empty markup if there's only one page.
48
+        if ( $args['total'] > 1 ) {
49
+            // Set up paginated links.
50
+            $links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
51
+
52
+            $class = !empty($args['class']) ? $args['class'] : '';
53
+
54
+            $custom_prev_link = '';
55
+            $custom_next_link = '';
56
+
57
+            // make the output bootstrap ready
58
+            $links_html = "<ul class='pagination m-0 p-0 $class'>";
59
+            if ( ! empty( $links ) ) {
60
+                foreach ( $links as $link ) {
61
+                    $_link = $link;
62
+
63
+                    if ( $aui_bs5 ) {
64
+                        $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link';
65
+                        $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active';
66
+                        $links_html .= "<li class='page-item mx-0'>";
67
+                        $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link );
68
+                        $link = str_replace( 'text-dark link-primary current', 'current', $link );
69
+                        $links_html .=  $link;
70
+                        $links_html .= "</li>";
71
+                    } else {
72
+                        $active = strpos( $link, 'current' ) !== false ? 'active' : '';
73
+                        $links_html .= "<li class='page-item $active'>";
74
+                        $links_html .= str_replace( "page-numbers", "page-link", $link );
75
+                        $links_html .= "</li>";
76
+                    }
77
+
78
+                    if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) {
79
+                        $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link );
80
+                        $link = str_replace( 'text-dark link-primary current', 'current', $link );
81
+
82
+                        if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) {
83
+                            $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link );
84
+                        } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) {
85
+                            $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link );
86
+                        }
87
+                    }
88
+                }
89
+            }
90
+            $links_html .= "</ul>";
91
+
92
+            if ( $links ) {
93
+                $output .= '<section class="px-0 py-2 w-100">';
94
+                $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
95
+                $output .= '</section>';
96
+            }
97
+
98
+            $output = str_replace( "screen-reader-text", "screen-reader-text sr-only" . ( $aui_bs5 ? ' visually-hidden' : '' ), $output );
99
+            $output = str_replace( "nav-links", "aui-nav-links", $output );
100
+        }
101
+
102
+        if ( $output ) {
103
+            if ( $custom_next_link || $custom_prev_link ) {
104
+                $total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
105
+                $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
106
+
107
+                $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>';
108
+            }
109
+
110
+            if ( ! empty( $args['before_paging'] ) ) {
111
+                $output = $args['before_paging'] . $output;
112
+            }
113
+
114
+            if ( ! empty( $args['after_paging'] ) ) {
115
+                $output = $output . $args['after_paging'];
116
+            }
117
+        }
118
+
119
+        return $output;
120
+    }
121 121
 
122 122
 }
123 123
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return string The rendered component.
20 20
 	 */
21
-	public static function get( $args = array() ) {
21
+	public static function get($args = array()) {
22 22
 		global $wp_query, $aui_bs5;
23 23
 
24 24
 		$defaults = array(
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
 			'mid_size'           => 2,
27 27
 			'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28 28
 			'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
-			'screen_reader_text' => __( 'Posts navigation', 'ayecode-connect' ),
29
+			'screen_reader_text' => __('Posts navigation', 'ayecode-connect'),
30 30
 			'before_paging'      => '',
31 31
 			'after_paging'       => '',
32 32
 			'type'               => 'array',
33
-			'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
33
+			'total'              => isset($wp_query->max_num_pages) ? $wp_query->max_num_pages : 1,
34 34
 			'links'              => array(), // an array of links if using custom links, this includes the a tag.
35 35
 			'rounded_style'      => false,
36 36
 			'custom_next_text'   => '', // Custom next page text
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
 		/**
41 41
 		 * Parse incoming $args into an array and merge it with $defaults
42 42
 		 */
43
-		$args = wp_parse_args( $args, $defaults );
43
+		$args = wp_parse_args($args, $defaults);
44 44
 
45 45
 		$output = '';
46 46
 
47 47
 		// Don't print empty markup if there's only one page.
48
-		if ( $args['total'] > 1 ) {
48
+		if ($args['total'] > 1) {
49 49
 			// Set up paginated links.
50
-			$links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
50
+			$links = !empty($args['links']) ? $args['links'] : paginate_links($args);
51 51
 
52 52
 			$class = !empty($args['class']) ? $args['class'] : '';
53 53
 
@@ -56,62 +56,62 @@  discard block
 block discarded – undo
56 56
 
57 57
 			// make the output bootstrap ready
58 58
 			$links_html = "<ul class='pagination m-0 p-0 $class'>";
59
-			if ( ! empty( $links ) ) {
60
-				foreach ( $links as $link ) {
59
+			if (!empty($links)) {
60
+				foreach ($links as $link) {
61 61
 					$_link = $link;
62 62
 
63
-					if ( $aui_bs5 ) {
63
+					if ($aui_bs5) {
64 64
 						$link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link';
65 65
 						$link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active';
66 66
 						$links_html .= "<li class='page-item mx-0'>";
67
-						$link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link );
68
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
69
-						$links_html .=  $link;
67
+						$link = str_replace(array("page-numbers", " current"), array($link_class, $link_class_active), $link);
68
+						$link = str_replace('text-dark link-primary current', 'current', $link);
69
+						$links_html .= $link;
70 70
 						$links_html .= "</li>";
71 71
 					} else {
72
-						$active = strpos( $link, 'current' ) !== false ? 'active' : '';
72
+						$active = strpos($link, 'current') !== false ? 'active' : '';
73 73
 						$links_html .= "<li class='page-item $active'>";
74
-						$links_html .= str_replace( "page-numbers", "page-link", $link );
74
+						$links_html .= str_replace("page-numbers", "page-link", $link);
75 75
 						$links_html .= "</li>";
76 76
 					}
77 77
 
78
-					if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) {
79
-						$link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link );
80
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
78
+					if (strpos($_link, 'next page-numbers') || strpos($_link, 'prev page-numbers')) {
79
+						$link = str_replace(array("page-numbers", " current"), array('btn btn-outline-primary rounded' . ($args['rounded_style'] ? '-pill' : '') . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill'), $_link);
80
+						$link = str_replace('text-dark link-primary current', 'current', $link);
81 81
 
82
-						if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) {
83
-							$custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link );
84
-						} else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) {
85
-							$custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link );
82
+						if (strpos($_link, 'next page-numbers') && !empty($args['custom_next_text'])) {
83
+							$custom_next_link = str_replace($args['next_text'], $args['custom_next_text'], $link);
84
+						} else if (strpos($_link, 'prev page-numbers') && !empty($args['custom_prev_text'])) {
85
+							$custom_prev_link = str_replace($args['prev_text'], $args['custom_prev_text'], $link);
86 86
 						}
87 87
 					}
88 88
 				}
89 89
 			}
90 90
 			$links_html .= "</ul>";
91 91
 
92
-			if ( $links ) {
92
+			if ($links) {
93 93
 				$output .= '<section class="px-0 py-2 w-100">';
94
-				$output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
94
+				$output .= _navigation_markup($links_html, 'aui-pagination', $args['screen_reader_text']);
95 95
 				$output .= '</section>';
96 96
 			}
97 97
 
98
-			$output = str_replace( "screen-reader-text", "screen-reader-text sr-only" . ( $aui_bs5 ? ' visually-hidden' : '' ), $output );
99
-			$output = str_replace( "nav-links", "aui-nav-links", $output );
98
+			$output = str_replace("screen-reader-text", "screen-reader-text sr-only" . ($aui_bs5 ? ' visually-hidden' : ''), $output);
99
+			$output = str_replace("nav-links", "aui-nav-links", $output);
100 100
 		}
101 101
 
102
-		if ( $output ) {
103
-			if ( $custom_next_link || $custom_prev_link ) {
104
-				$total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
105
-				$current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
102
+		if ($output) {
103
+			if ($custom_next_link || $custom_prev_link) {
104
+				$total   = isset($wp_query->max_num_pages) ? $wp_query->max_num_pages : 1;
105
+				$current = get_query_var('paged') ? (int) get_query_var('paged') : 1;
106 106
 
107 107
 				$output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>';
108 108
 			}
109 109
 
110
-			if ( ! empty( $args['before_paging'] ) ) {
110
+			if (!empty($args['before_paging'])) {
111 111
 				$output = $args['before_paging'] . $output;
112 112
 			}
113 113
 
114
-			if ( ! empty( $args['after_paging'] ) ) {
114
+			if (!empty($args['after_paging'])) {
115 115
 				$output = $output . $args['after_paging'];
116 116
 			}
117 117
 		}
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-helper.php 2 patches
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,489 +11,489 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Helper {
13 13
 
14
-	/**
15
-	 * A component helper for generating a input name.
16
-	 *
17
-	 * @param $text
18
-	 * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
-	 *
20
-	 * @return string
21
-	 */
22
-	public static function name( $text, $multiple = false ) {
23
-		$output = '';
24
-
25
-		if ( $text ) {
26
-			$is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : '';
27
-			$output      = ' name="' . esc_attr( $text ) . $is_multiple . '" ';
28
-		}
29
-
30
-		return $output;
31
-	}
32
-
33
-	/**
34
-	 * A component helper for generating a item id.
35
-	 *
36
-	 * @param $text string The text to be used as the value.
37
-	 *
38
-	 * @return string The sanitized item.
39
-	 */
40
-	public static function id( $text ) {
41
-		$output = '';
42
-
43
-		if ( $text ) {
44
-			$output = ' id="' . sanitize_html_class( $text ) . '" ';
45
-		}
46
-
47
-		return $output;
48
-	}
49
-
50
-	/**
51
-	 * A component helper for generating a item title.
52
-	 *
53
-	 * @param $text string The text to be used as the value.
54
-	 *
55
-	 * @return string The sanitized item.
56
-	 */
57
-	public static function title( $text ) {
58
-		$output = '';
59
-
60
-		if ( $text ) {
61
-			$output = ' title="' . esc_attr( $text ) . '" ';
62
-		}
63
-
64
-		return $output;
65
-	}
66
-
67
-	/**
68
-	 * A component helper for generating a item value.
69
-	 *
70
-	 * @param $text string The text to be used as the value.
71
-	 *
72
-	 * @return string The sanitized item.
73
-	 */
74
-	public static function value( $text ) {
75
-		$output = '';
76
-
77
-		if ( $text !== null && $text !== false ) {
78
-			$output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" ';
79
-		}
80
-
81
-		return $output;
82
-	}
83
-
84
-	/**
85
-	 * A component helper for generating a item class attribute.
86
-	 *
87
-	 * @param $text string The text to be used as the value.
88
-	 *
89
-	 * @return string The sanitized item.
90
-	 */
91
-	public static function class_attr( $text ) {
92
-		$output = '';
93
-
94
-		if ( $text ) {
95
-			$classes = self::esc_classes( $text );
96
-			if ( ! empty( $classes ) ) {
97
-				$output = ' class="' . $classes . '" ';
98
-			}
99
-		}
100
-
101
-		return $output;
102
-	}
103
-
104
-	/**
105
-	 * Escape a string of classes.
106
-	 *
107
-	 * @param $text
108
-	 *
109
-	 * @return string
110
-	 */
111
-	public static function esc_classes( $text ) {
112
-		$output = '';
113
-
114
-		if ( $text ) {
115
-			$classes = explode( " ", $text );
116
-			$classes = array_map( "trim", $classes );
117
-			$classes = array_map( "sanitize_html_class", $classes );
118
-			if ( ! empty( $classes ) ) {
119
-				$output = implode( " ", array_filter( $classes ) );
120
-			}
121
-		}
122
-
123
-		return $output;
124
-
125
-	}
126
-
127
-	/**
128
-	 * @param $args
129
-	 *
130
-	 * @return string
131
-	 */
132
-	public static function data_attributes( $args ) {
133
-		$output = '';
134
-
135
-		if ( ! empty( $args ) ) {
136
-
137
-			foreach ( $args as $key => $val ) {
138
-				if ( substr( $key, 0, 5 ) === "data-" ) {
139
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
140
-				}
141
-			}
142
-		}
143
-
144
-		return $output;
145
-	}
146
-
147
-	/**
148
-	 * @param $args
149
-	 *
150
-	 * @return string
151
-	 */
152
-	public static function aria_attributes( $args ) {
153
-		$output = '';
154
-
155
-		if ( ! empty( $args ) ) {
156
-
157
-			foreach ( $args as $key => $val ) {
158
-				if ( substr( $key, 0, 5 ) === "aria-" ) {
159
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
160
-				}
161
-			}
162
-		}
163
-
164
-		return $output;
165
-	}
166
-
167
-	/**
168
-	 * Build a font awesome icon from a class.
169
-	 *
170
-	 * @param $class
171
-	 * @param bool $space_after
172
-	 * @param array $extra_attributes An array of extra attributes.
173
-	 *
174
-	 * @return string
175
-	 */
176
-	public static function icon( $class, $space_after = false, $extra_attributes = array() ) {
177
-		$output = '';
178
-
179
-		if ( $class ) {
180
-			$classes = self::esc_classes( $class );
181
-			if ( ! empty( $classes ) ) {
182
-				$output = '<i class="' . $classes . '" ';
183
-				// extra attributes
184
-				if ( ! empty( $extra_attributes ) ) {
185
-					$output .= AUI_Component_Helper::extra_attributes( $extra_attributes );
186
-				}
187
-				$output .= '></i>';
188
-				if ( $space_after ) {
189
-					$output .= " ";
190
-				}
191
-			}
192
-		}
193
-
194
-		return $output;
195
-	}
196
-
197
-	/**
198
-	 * @param $args
199
-	 *
200
-	 * @return string
201
-	 */
202
-	public static function extra_attributes( $args ) {
203
-		$output = '';
204
-
205
-		if ( ! empty( $args ) ) {
206
-
207
-			if ( is_array( $args ) ) {
208
-				foreach ( $args as $key => $val ) {
209
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
210
-				}
211
-			} else {
212
-				$output .= ' ' . $args . ' ';
213
-			}
214
-
215
-		}
216
-
217
-		return $output;
218
-	}
219
-
220
-	/**
221
-	 * @param $args
222
-	 *
223
-	 * @return string
224
-	 */
225
-	public static function help_text( $text ) {
226
-		$output = '';
227
-
228
-		if ( $text ) {
229
-			$output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>';
230
-		}
231
-
232
-
233
-		return $output;
234
-	}
235
-
236
-	/**
237
-	 * Replace element require context with JS.
238
-	 *
239
-	 * @param $input
240
-	 *
241
-	 * @return string|void
242
-	 */
243
-	public static function element_require( $input ) {
244
-
245
-		$input = str_replace( "'", '"', $input );// we only want double quotes
246
-
247
-		$output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
-			"jQuery(form).find('[data-argument=\"",
249
-			"\"]').find('input,select,textarea').val()",
250
-			"\"]').find('input:checked').val()",
251
-		), $input ) );
252
-
253
-		if ( $output ) {
254
-			$output = ' data-element-require="' . $output . '" ';
255
-		}
256
-
257
-		return $output;
258
-	}
259
-
260
-	/**
261
-	 * Navigates through an array, object, or scalar, and removes slashes from the values.
262
-	 *
263
-	 * @since 0.1.41
264
-	 *
265
-	 * @param mixed $value The value to be stripped.
266
-	 * @param array $input Input Field.
267
-	 *
268
-	 * @return mixed Stripped value.
269
-	 */
270
-	public static function sanitize_html_field( $value, $input = array() ) {
271
-		$original = $value;
272
-
273
-		if ( is_array( $value ) ) {
274
-			foreach ( $value as $index => $item ) {
275
-				$value[ $index ] = self::_sanitize_html_field( $value, $input );
276
-			}
277
-		} elseif ( is_object( $value ) ) {
278
-			$object_vars = get_object_vars( $value );
279
-
280
-			foreach ( $object_vars as $property_name => $property_value ) {
281
-				$value->$property_name = self::_sanitize_html_field( $property_value, $input );
282
-			}
283
-		} else {
284
-			$value = self::_sanitize_html_field( $value, $input );
285
-		}
286
-
287
-		/**
288
-		 * Filters content and keeps only allowable HTML elements.
289
-		 *
290
-		 * @since 0.1.41
291
-		 *
292
-		 * @param string|array $value Content to filter through kses.
293
-		 * @param string|array $value Original content without filter.
294
-		 * @param array $input Input Field.
295
-		 */
296
-		return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
297
-	}
298
-
299
-	/**
300
-	 * Filters content and keeps only allowable HTML elements.
301
-	 *
302
-	 * This function makes sure that only the allowed HTML element names, attribute
303
-	 * names and attribute values plus only sane HTML entities will occur in
304
-	 * $string. You have to remove any slashes from PHP's magic quotes before you
305
-	 * call this function.
306
-	 *
307
-	 * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
308
-	 * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
309
-	 * covers all common link protocols, except for 'javascript' which should not
310
-	 * be allowed for untrusted users.
311
-	 *
312
-	 * @since 0.1.41
313
-	 *
314
-	 * @param string|array $value Content to filter through kses.
315
-	 * @param array $input Input Field.
316
-	 *
317
-	 * @return string Filtered content with only allowed HTML elements.
318
-	 */
319
-	public static function _sanitize_html_field( $value, $input = array() ) {
320
-		if ( $value === '' ) {
321
-			return $value;
322
-		}
323
-
324
-		$allowed_html = self::kses_allowed_html( 'post', $input );
325
-
326
-		if ( ! is_array( $allowed_html ) ) {
327
-			$allowed_html = wp_kses_allowed_html( 'post' );
328
-		}
329
-
330
-		$filtered = trim( wp_unslash( $value ) );
331
-		$filtered = wp_kses( $filtered, $allowed_html );
332
-		$filtered = balanceTags( $filtered ); // Balances tags
333
-
334
-		return $filtered;
335
-	}
336
-
337
-	/**
338
-	 * Returns an array of allowed HTML tags and attributes for a given context.
339
-	 *
340
-	 * @since 0.1.41
341
-	 *
342
-	 * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
343
-	 *                              'strip', 'data', 'entities', or the name of a field filter such as
344
-	 *                              'pre_user_description'.
345
-	 * @param array $input Input.
346
-	 *
347
-	 * @return array Array of allowed HTML tags and their allowed attributes.
348
-	 */
349
-	public static function kses_allowed_html( $context = 'post', $input = array() ) {
350
-		$allowed_html = wp_kses_allowed_html( $context );
351
-
352
-		if ( is_array( $allowed_html ) ) {
353
-			// <iframe>
354
-			if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
355
-				$allowed_html['iframe'] = array(
356
-					'class'           => true,
357
-					'id'              => true,
358
-					'src'             => true,
359
-					'width'           => true,
360
-					'height'          => true,
361
-					'frameborder'     => true,
362
-					'marginwidth'     => true,
363
-					'marginheight'    => true,
364
-					'scrolling'       => true,
365
-					'style'           => true,
366
-					'title'           => true,
367
-					'allow'           => true,
368
-					'allowfullscreen' => true,
369
-					'data-*'          => true,
370
-				);
371
-			}
372
-		}
373
-
374
-		/**
375
-		 * Filters the allowed html tags.
376
-		 *
377
-		 * @since 0.1.41
378
-		 *
379
-		 * @param array[]|string $allowed_html Allowed html tags.
380
-		 * @param @param string|array $context The context for which to retrieve tags.
381
-		 * @param array $input Input field.
382
-		 */
383
-		return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
384
-	}
385
-
386
-	public static function get_column_class( $label_number = 2, $type = 'label' ) {
387
-
388
-		$class = '';
389
-
390
-		// set default if empty
391
-		if( $label_number === '' ){
392
-			$label_number = 2;
393
-		}
394
-
395
-		if ( $label_number && $label_number < 12 && $label_number > 0 ) {
396
-			if ( $type == 'label' ) {
397
-				$class = 'col-sm-' . absint( $label_number );
398
-			} elseif ( $type == 'input' ) {
399
-				$class = 'col-sm-' . ( 12 - absint( $label_number ) );
400
-			}
401
-		}
402
-
403
-		return $class;
404
-	}
405
-
406
-	/**
407
-	 * Sanitizes a multiline string from user input or from the database.
408
-	 *
409
-	 * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way.
410
-	 *
411
-	 * @see   https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original
412
-	 *
413
-	 * @since 0.1.66
414
-	 *
415
-	 * @param string $str String to sanitize.
416
-	 * @return string Sanitized string.
417
-	 */
418
-	public static function sanitize_textarea_field( $str ) {
419
-		$filtered = self::_sanitize_text_fields( $str, true );
420
-
421
-		/**
422
-		 * Filters a sanitized textarea field string.
423
-		 *
424
-		 * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php
425
-		 *
426
-		 * @param string $filtered The sanitized string.
427
-		 * @param string $str      The string prior to being sanitized.
428
-		 */
429
-		return apply_filters( 'sanitize_textarea_field', $filtered, $str );
430
-	}
431
-
432
-	/**
433
-	 * Internal helper function to sanitize a string from user input or from the db.
434
-	 *
435
-	 * @since 0.1.66
436
-	 * @access private
437
-	 *
438
-	 * @param string $str           String to sanitize.
439
-	 * @param bool   $keep_newlines Optional. Whether to keep newlines. Default: false.
440
-	 * @return string Sanitized string.
441
-	 */
442
-	public static function _sanitize_text_fields( $str, $keep_newlines = false ) {
443
-		if ( is_object( $str ) || is_array( $str ) ) {
444
-			return '';
445
-		}
446
-
447
-		$str = (string) $str;
448
-
449
-		$filtered = wp_check_invalid_utf8( $str );
450
-
451
-		if ( strpos( $filtered, '<' ) !== false ) {
452
-			$filtered = wp_pre_kses_less_than( $filtered );
453
-			// This will strip extra whitespace for us.
454
-			$filtered = wp_strip_all_tags( $filtered, false );
455
-
456
-			// Use HTML entities in a special case to make sure no later
457
-			// newline stripping stage could lead to a functional tag.
458
-			$filtered = str_replace( "<\n", "&lt;\n", $filtered );
459
-		}
460
-
461
-		if ( ! $keep_newlines ) {
462
-			$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
463
-		}
464
-		$filtered = trim( $filtered );
465
-
466
-		$found = false;
467
-		while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) {
468
-			$filtered = str_replace( $match[1], '', $filtered );
469
-			$found = true;
470
-		}
471
-		unset( $match );
472
-
473
-		if ( $found ) {
474
-			// Strip out the whitespace that may now exist after removing the octets.
475
-			$filtered = trim( preg_replace( '` +`', ' ', $filtered ) );
476
-		}
477
-
478
-		return $filtered;
479
-	}
480
-
481
-	/**
482
-	 * Sanitize FontAwesome icon.
483
-	 *
484
-	 * @param string $icon Icon string.
485
-	 * @param array $args Extra args.
486
-	 * @return string Sanitized icon.
487
-	 */
488
-	public static function sanitize_fa_icon( $icon, $args = array() ) {
489
-		if ( ! is_scalar( $icon ) ) {
490
-			return "";
491
-		}
492
-
493
-		$pattern = '/[^0-9a-zA-Z\-_ ]/';
494
-
495
-		$sanitized_icon = preg_replace( $pattern, '', trim( $icon ) );
496
-
497
-		return apply_filters( 'ayecode_ui_sanitize_fa_icon', $sanitized_icon, $icon, $args );
498
-	}
14
+    /**
15
+     * A component helper for generating a input name.
16
+     *
17
+     * @param $text
18
+     * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
+     *
20
+     * @return string
21
+     */
22
+    public static function name( $text, $multiple = false ) {
23
+        $output = '';
24
+
25
+        if ( $text ) {
26
+            $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : '';
27
+            $output      = ' name="' . esc_attr( $text ) . $is_multiple . '" ';
28
+        }
29
+
30
+        return $output;
31
+    }
32
+
33
+    /**
34
+     * A component helper for generating a item id.
35
+     *
36
+     * @param $text string The text to be used as the value.
37
+     *
38
+     * @return string The sanitized item.
39
+     */
40
+    public static function id( $text ) {
41
+        $output = '';
42
+
43
+        if ( $text ) {
44
+            $output = ' id="' . sanitize_html_class( $text ) . '" ';
45
+        }
46
+
47
+        return $output;
48
+    }
49
+
50
+    /**
51
+     * A component helper for generating a item title.
52
+     *
53
+     * @param $text string The text to be used as the value.
54
+     *
55
+     * @return string The sanitized item.
56
+     */
57
+    public static function title( $text ) {
58
+        $output = '';
59
+
60
+        if ( $text ) {
61
+            $output = ' title="' . esc_attr( $text ) . '" ';
62
+        }
63
+
64
+        return $output;
65
+    }
66
+
67
+    /**
68
+     * A component helper for generating a item value.
69
+     *
70
+     * @param $text string The text to be used as the value.
71
+     *
72
+     * @return string The sanitized item.
73
+     */
74
+    public static function value( $text ) {
75
+        $output = '';
76
+
77
+        if ( $text !== null && $text !== false ) {
78
+            $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" ';
79
+        }
80
+
81
+        return $output;
82
+    }
83
+
84
+    /**
85
+     * A component helper for generating a item class attribute.
86
+     *
87
+     * @param $text string The text to be used as the value.
88
+     *
89
+     * @return string The sanitized item.
90
+     */
91
+    public static function class_attr( $text ) {
92
+        $output = '';
93
+
94
+        if ( $text ) {
95
+            $classes = self::esc_classes( $text );
96
+            if ( ! empty( $classes ) ) {
97
+                $output = ' class="' . $classes . '" ';
98
+            }
99
+        }
100
+
101
+        return $output;
102
+    }
103
+
104
+    /**
105
+     * Escape a string of classes.
106
+     *
107
+     * @param $text
108
+     *
109
+     * @return string
110
+     */
111
+    public static function esc_classes( $text ) {
112
+        $output = '';
113
+
114
+        if ( $text ) {
115
+            $classes = explode( " ", $text );
116
+            $classes = array_map( "trim", $classes );
117
+            $classes = array_map( "sanitize_html_class", $classes );
118
+            if ( ! empty( $classes ) ) {
119
+                $output = implode( " ", array_filter( $classes ) );
120
+            }
121
+        }
122
+
123
+        return $output;
124
+
125
+    }
126
+
127
+    /**
128
+     * @param $args
129
+     *
130
+     * @return string
131
+     */
132
+    public static function data_attributes( $args ) {
133
+        $output = '';
134
+
135
+        if ( ! empty( $args ) ) {
136
+
137
+            foreach ( $args as $key => $val ) {
138
+                if ( substr( $key, 0, 5 ) === "data-" ) {
139
+                    $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
140
+                }
141
+            }
142
+        }
143
+
144
+        return $output;
145
+    }
146
+
147
+    /**
148
+     * @param $args
149
+     *
150
+     * @return string
151
+     */
152
+    public static function aria_attributes( $args ) {
153
+        $output = '';
154
+
155
+        if ( ! empty( $args ) ) {
156
+
157
+            foreach ( $args as $key => $val ) {
158
+                if ( substr( $key, 0, 5 ) === "aria-" ) {
159
+                    $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
160
+                }
161
+            }
162
+        }
163
+
164
+        return $output;
165
+    }
166
+
167
+    /**
168
+     * Build a font awesome icon from a class.
169
+     *
170
+     * @param $class
171
+     * @param bool $space_after
172
+     * @param array $extra_attributes An array of extra attributes.
173
+     *
174
+     * @return string
175
+     */
176
+    public static function icon( $class, $space_after = false, $extra_attributes = array() ) {
177
+        $output = '';
178
+
179
+        if ( $class ) {
180
+            $classes = self::esc_classes( $class );
181
+            if ( ! empty( $classes ) ) {
182
+                $output = '<i class="' . $classes . '" ';
183
+                // extra attributes
184
+                if ( ! empty( $extra_attributes ) ) {
185
+                    $output .= AUI_Component_Helper::extra_attributes( $extra_attributes );
186
+                }
187
+                $output .= '></i>';
188
+                if ( $space_after ) {
189
+                    $output .= " ";
190
+                }
191
+            }
192
+        }
193
+
194
+        return $output;
195
+    }
196
+
197
+    /**
198
+     * @param $args
199
+     *
200
+     * @return string
201
+     */
202
+    public static function extra_attributes( $args ) {
203
+        $output = '';
204
+
205
+        if ( ! empty( $args ) ) {
206
+
207
+            if ( is_array( $args ) ) {
208
+                foreach ( $args as $key => $val ) {
209
+                    $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
210
+                }
211
+            } else {
212
+                $output .= ' ' . $args . ' ';
213
+            }
214
+
215
+        }
216
+
217
+        return $output;
218
+    }
219
+
220
+    /**
221
+     * @param $args
222
+     *
223
+     * @return string
224
+     */
225
+    public static function help_text( $text ) {
226
+        $output = '';
227
+
228
+        if ( $text ) {
229
+            $output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>';
230
+        }
231
+
232
+
233
+        return $output;
234
+    }
235
+
236
+    /**
237
+     * Replace element require context with JS.
238
+     *
239
+     * @param $input
240
+     *
241
+     * @return string|void
242
+     */
243
+    public static function element_require( $input ) {
244
+
245
+        $input = str_replace( "'", '"', $input );// we only want double quotes
246
+
247
+        $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
+            "jQuery(form).find('[data-argument=\"",
249
+            "\"]').find('input,select,textarea').val()",
250
+            "\"]').find('input:checked').val()",
251
+        ), $input ) );
252
+
253
+        if ( $output ) {
254
+            $output = ' data-element-require="' . $output . '" ';
255
+        }
256
+
257
+        return $output;
258
+    }
259
+
260
+    /**
261
+     * Navigates through an array, object, or scalar, and removes slashes from the values.
262
+     *
263
+     * @since 0.1.41
264
+     *
265
+     * @param mixed $value The value to be stripped.
266
+     * @param array $input Input Field.
267
+     *
268
+     * @return mixed Stripped value.
269
+     */
270
+    public static function sanitize_html_field( $value, $input = array() ) {
271
+        $original = $value;
272
+
273
+        if ( is_array( $value ) ) {
274
+            foreach ( $value as $index => $item ) {
275
+                $value[ $index ] = self::_sanitize_html_field( $value, $input );
276
+            }
277
+        } elseif ( is_object( $value ) ) {
278
+            $object_vars = get_object_vars( $value );
279
+
280
+            foreach ( $object_vars as $property_name => $property_value ) {
281
+                $value->$property_name = self::_sanitize_html_field( $property_value, $input );
282
+            }
283
+        } else {
284
+            $value = self::_sanitize_html_field( $value, $input );
285
+        }
286
+
287
+        /**
288
+         * Filters content and keeps only allowable HTML elements.
289
+         *
290
+         * @since 0.1.41
291
+         *
292
+         * @param string|array $value Content to filter through kses.
293
+         * @param string|array $value Original content without filter.
294
+         * @param array $input Input Field.
295
+         */
296
+        return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
297
+    }
298
+
299
+    /**
300
+     * Filters content and keeps only allowable HTML elements.
301
+     *
302
+     * This function makes sure that only the allowed HTML element names, attribute
303
+     * names and attribute values plus only sane HTML entities will occur in
304
+     * $string. You have to remove any slashes from PHP's magic quotes before you
305
+     * call this function.
306
+     *
307
+     * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
308
+     * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
309
+     * covers all common link protocols, except for 'javascript' which should not
310
+     * be allowed for untrusted users.
311
+     *
312
+     * @since 0.1.41
313
+     *
314
+     * @param string|array $value Content to filter through kses.
315
+     * @param array $input Input Field.
316
+     *
317
+     * @return string Filtered content with only allowed HTML elements.
318
+     */
319
+    public static function _sanitize_html_field( $value, $input = array() ) {
320
+        if ( $value === '' ) {
321
+            return $value;
322
+        }
323
+
324
+        $allowed_html = self::kses_allowed_html( 'post', $input );
325
+
326
+        if ( ! is_array( $allowed_html ) ) {
327
+            $allowed_html = wp_kses_allowed_html( 'post' );
328
+        }
329
+
330
+        $filtered = trim( wp_unslash( $value ) );
331
+        $filtered = wp_kses( $filtered, $allowed_html );
332
+        $filtered = balanceTags( $filtered ); // Balances tags
333
+
334
+        return $filtered;
335
+    }
336
+
337
+    /**
338
+     * Returns an array of allowed HTML tags and attributes for a given context.
339
+     *
340
+     * @since 0.1.41
341
+     *
342
+     * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
343
+     *                              'strip', 'data', 'entities', or the name of a field filter such as
344
+     *                              'pre_user_description'.
345
+     * @param array $input Input.
346
+     *
347
+     * @return array Array of allowed HTML tags and their allowed attributes.
348
+     */
349
+    public static function kses_allowed_html( $context = 'post', $input = array() ) {
350
+        $allowed_html = wp_kses_allowed_html( $context );
351
+
352
+        if ( is_array( $allowed_html ) ) {
353
+            // <iframe>
354
+            if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
355
+                $allowed_html['iframe'] = array(
356
+                    'class'           => true,
357
+                    'id'              => true,
358
+                    'src'             => true,
359
+                    'width'           => true,
360
+                    'height'          => true,
361
+                    'frameborder'     => true,
362
+                    'marginwidth'     => true,
363
+                    'marginheight'    => true,
364
+                    'scrolling'       => true,
365
+                    'style'           => true,
366
+                    'title'           => true,
367
+                    'allow'           => true,
368
+                    'allowfullscreen' => true,
369
+                    'data-*'          => true,
370
+                );
371
+            }
372
+        }
373
+
374
+        /**
375
+         * Filters the allowed html tags.
376
+         *
377
+         * @since 0.1.41
378
+         *
379
+         * @param array[]|string $allowed_html Allowed html tags.
380
+         * @param @param string|array $context The context for which to retrieve tags.
381
+         * @param array $input Input field.
382
+         */
383
+        return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
384
+    }
385
+
386
+    public static function get_column_class( $label_number = 2, $type = 'label' ) {
387
+
388
+        $class = '';
389
+
390
+        // set default if empty
391
+        if( $label_number === '' ){
392
+            $label_number = 2;
393
+        }
394
+
395
+        if ( $label_number && $label_number < 12 && $label_number > 0 ) {
396
+            if ( $type == 'label' ) {
397
+                $class = 'col-sm-' . absint( $label_number );
398
+            } elseif ( $type == 'input' ) {
399
+                $class = 'col-sm-' . ( 12 - absint( $label_number ) );
400
+            }
401
+        }
402
+
403
+        return $class;
404
+    }
405
+
406
+    /**
407
+     * Sanitizes a multiline string from user input or from the database.
408
+     *
409
+     * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way.
410
+     *
411
+     * @see   https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original
412
+     *
413
+     * @since 0.1.66
414
+     *
415
+     * @param string $str String to sanitize.
416
+     * @return string Sanitized string.
417
+     */
418
+    public static function sanitize_textarea_field( $str ) {
419
+        $filtered = self::_sanitize_text_fields( $str, true );
420
+
421
+        /**
422
+         * Filters a sanitized textarea field string.
423
+         *
424
+         * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php
425
+         *
426
+         * @param string $filtered The sanitized string.
427
+         * @param string $str      The string prior to being sanitized.
428
+         */
429
+        return apply_filters( 'sanitize_textarea_field', $filtered, $str );
430
+    }
431
+
432
+    /**
433
+     * Internal helper function to sanitize a string from user input or from the db.
434
+     *
435
+     * @since 0.1.66
436
+     * @access private
437
+     *
438
+     * @param string $str           String to sanitize.
439
+     * @param bool   $keep_newlines Optional. Whether to keep newlines. Default: false.
440
+     * @return string Sanitized string.
441
+     */
442
+    public static function _sanitize_text_fields( $str, $keep_newlines = false ) {
443
+        if ( is_object( $str ) || is_array( $str ) ) {
444
+            return '';
445
+        }
446
+
447
+        $str = (string) $str;
448
+
449
+        $filtered = wp_check_invalid_utf8( $str );
450
+
451
+        if ( strpos( $filtered, '<' ) !== false ) {
452
+            $filtered = wp_pre_kses_less_than( $filtered );
453
+            // This will strip extra whitespace for us.
454
+            $filtered = wp_strip_all_tags( $filtered, false );
455
+
456
+            // Use HTML entities in a special case to make sure no later
457
+            // newline stripping stage could lead to a functional tag.
458
+            $filtered = str_replace( "<\n", "&lt;\n", $filtered );
459
+        }
460
+
461
+        if ( ! $keep_newlines ) {
462
+            $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
463
+        }
464
+        $filtered = trim( $filtered );
465
+
466
+        $found = false;
467
+        while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) {
468
+            $filtered = str_replace( $match[1], '', $filtered );
469
+            $found = true;
470
+        }
471
+        unset( $match );
472
+
473
+        if ( $found ) {
474
+            // Strip out the whitespace that may now exist after removing the octets.
475
+            $filtered = trim( preg_replace( '` +`', ' ', $filtered ) );
476
+        }
477
+
478
+        return $filtered;
479
+    }
480
+
481
+    /**
482
+     * Sanitize FontAwesome icon.
483
+     *
484
+     * @param string $icon Icon string.
485
+     * @param array $args Extra args.
486
+     * @return string Sanitized icon.
487
+     */
488
+    public static function sanitize_fa_icon( $icon, $args = array() ) {
489
+        if ( ! is_scalar( $icon ) ) {
490
+            return "";
491
+        }
492
+
493
+        $pattern = '/[^0-9a-zA-Z\-_ ]/';
494
+
495
+        $sanitized_icon = preg_replace( $pattern, '', trim( $icon ) );
496
+
497
+        return apply_filters( 'ayecode_ui_sanitize_fa_icon', $sanitized_icon, $icon, $args );
498
+    }
499 499
 }
500 500
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @return string
21 21
 	 */
22
-	public static function name( $text, $multiple = false ) {
22
+	public static function name($text, $multiple = false) {
23 23
 		$output = '';
24 24
 
25
-		if ( $text ) {
26
-			$is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : '';
27
-			$output      = ' name="' . esc_attr( $text ) . $is_multiple . '" ';
25
+		if ($text) {
26
+			$is_multiple = strpos($text, '[') === false && $multiple ? '[]' : '';
27
+			$output      = ' name="' . esc_attr($text) . $is_multiple . '" ';
28 28
 		}
29 29
 
30 30
 		return $output;
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @return string The sanitized item.
39 39
 	 */
40
-	public static function id( $text ) {
40
+	public static function id($text) {
41 41
 		$output = '';
42 42
 
43
-		if ( $text ) {
44
-			$output = ' id="' . sanitize_html_class( $text ) . '" ';
43
+		if ($text) {
44
+			$output = ' id="' . sanitize_html_class($text) . '" ';
45 45
 		}
46 46
 
47 47
 		return $output;
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @return string The sanitized item.
56 56
 	 */
57
-	public static function title( $text ) {
57
+	public static function title($text) {
58 58
 		$output = '';
59 59
 
60
-		if ( $text ) {
61
-			$output = ' title="' . esc_attr( $text ) . '" ';
60
+		if ($text) {
61
+			$output = ' title="' . esc_attr($text) . '" ';
62 62
 		}
63 63
 
64 64
 		return $output;
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @return string The sanitized item.
73 73
 	 */
74
-	public static function value( $text ) {
74
+	public static function value($text) {
75 75
 		$output = '';
76 76
 
77
-		if ( $text !== null && $text !== false ) {
78
-			$output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" ';
77
+		if ($text !== null && $text !== false) {
78
+			$output = ' value="' . esc_attr(wp_unslash($text)) . '" ';
79 79
 		}
80 80
 
81 81
 		return $output;
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @return string The sanitized item.
90 90
 	 */
91
-	public static function class_attr( $text ) {
91
+	public static function class_attr($text) {
92 92
 		$output = '';
93 93
 
94
-		if ( $text ) {
95
-			$classes = self::esc_classes( $text );
96
-			if ( ! empty( $classes ) ) {
94
+		if ($text) {
95
+			$classes = self::esc_classes($text);
96
+			if (!empty($classes)) {
97 97
 				$output = ' class="' . $classes . '" ';
98 98
 			}
99 99
 		}
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return string
110 110
 	 */
111
-	public static function esc_classes( $text ) {
111
+	public static function esc_classes($text) {
112 112
 		$output = '';
113 113
 
114
-		if ( $text ) {
115
-			$classes = explode( " ", $text );
116
-			$classes = array_map( "trim", $classes );
117
-			$classes = array_map( "sanitize_html_class", $classes );
118
-			if ( ! empty( $classes ) ) {
119
-				$output = implode( " ", array_filter( $classes ) );
114
+		if ($text) {
115
+			$classes = explode(" ", $text);
116
+			$classes = array_map("trim", $classes);
117
+			$classes = array_map("sanitize_html_class", $classes);
118
+			if (!empty($classes)) {
119
+				$output = implode(" ", array_filter($classes));
120 120
 			}
121 121
 		}
122 122
 
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @return string
131 131
 	 */
132
-	public static function data_attributes( $args ) {
132
+	public static function data_attributes($args) {
133 133
 		$output = '';
134 134
 
135
-		if ( ! empty( $args ) ) {
135
+		if (!empty($args)) {
136 136
 
137
-			foreach ( $args as $key => $val ) {
138
-				if ( substr( $key, 0, 5 ) === "data-" ) {
139
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
137
+			foreach ($args as $key => $val) {
138
+				if (substr($key, 0, 5) === "data-") {
139
+					$output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" ';
140 140
 				}
141 141
 			}
142 142
 		}
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
 	 *
150 150
 	 * @return string
151 151
 	 */
152
-	public static function aria_attributes( $args ) {
152
+	public static function aria_attributes($args) {
153 153
 		$output = '';
154 154
 
155
-		if ( ! empty( $args ) ) {
155
+		if (!empty($args)) {
156 156
 
157
-			foreach ( $args as $key => $val ) {
158
-				if ( substr( $key, 0, 5 ) === "aria-" ) {
159
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
157
+			foreach ($args as $key => $val) {
158
+				if (substr($key, 0, 5) === "aria-") {
159
+					$output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" ';
160 160
 				}
161 161
 			}
162 162
 		}
@@ -173,19 +173,19 @@  discard block
 block discarded – undo
173 173
 	 *
174 174
 	 * @return string
175 175
 	 */
176
-	public static function icon( $class, $space_after = false, $extra_attributes = array() ) {
176
+	public static function icon($class, $space_after = false, $extra_attributes = array()) {
177 177
 		$output = '';
178 178
 
179
-		if ( $class ) {
180
-			$classes = self::esc_classes( $class );
181
-			if ( ! empty( $classes ) ) {
179
+		if ($class) {
180
+			$classes = self::esc_classes($class);
181
+			if (!empty($classes)) {
182 182
 				$output = '<i class="' . $classes . '" ';
183 183
 				// extra attributes
184
-				if ( ! empty( $extra_attributes ) ) {
185
-					$output .= AUI_Component_Helper::extra_attributes( $extra_attributes );
184
+				if (!empty($extra_attributes)) {
185
+					$output .= AUI_Component_Helper::extra_attributes($extra_attributes);
186 186
 				}
187 187
 				$output .= '></i>';
188
-				if ( $space_after ) {
188
+				if ($space_after) {
189 189
 					$output .= " ";
190 190
 				}
191 191
 			}
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return string
201 201
 	 */
202
-	public static function extra_attributes( $args ) {
202
+	public static function extra_attributes($args) {
203 203
 		$output = '';
204 204
 
205
-		if ( ! empty( $args ) ) {
205
+		if (!empty($args)) {
206 206
 
207
-			if ( is_array( $args ) ) {
208
-				foreach ( $args as $key => $val ) {
209
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
207
+			if (is_array($args)) {
208
+				foreach ($args as $key => $val) {
209
+					$output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" ';
210 210
 				}
211 211
 			} else {
212 212
 				$output .= ' ' . $args . ' ';
@@ -222,11 +222,11 @@  discard block
 block discarded – undo
222 222
 	 *
223 223
 	 * @return string
224 224
 	 */
225
-	public static function help_text( $text ) {
225
+	public static function help_text($text) {
226 226
 		$output = '';
227 227
 
228
-		if ( $text ) {
229
-			$output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>';
228
+		if ($text) {
229
+			$output .= '<small class="form-text text-muted d-block">' . wp_kses_post($text) . '</small>';
230 230
 		}
231 231
 
232 232
 
@@ -240,17 +240,17 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @return string|void
242 242
 	 */
243
-	public static function element_require( $input ) {
243
+	public static function element_require($input) {
244 244
 
245
-		$input = str_replace( "'", '"', $input );// we only want double quotes
245
+		$input = str_replace("'", '"', $input); // we only want double quotes
246 246
 
247
-		$output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
247
+		$output = esc_attr(str_replace(array("[%", "%]", "%:checked]"), array(
248 248
 			"jQuery(form).find('[data-argument=\"",
249 249
 			"\"]').find('input,select,textarea').val()",
250 250
 			"\"]').find('input:checked').val()",
251
-		), $input ) );
251
+		), $input));
252 252
 
253
-		if ( $output ) {
253
+		if ($output) {
254 254
 			$output = ' data-element-require="' . $output . '" ';
255 255
 		}
256 256
 
@@ -267,21 +267,21 @@  discard block
 block discarded – undo
267 267
 	 *
268 268
 	 * @return mixed Stripped value.
269 269
 	 */
270
-	public static function sanitize_html_field( $value, $input = array() ) {
270
+	public static function sanitize_html_field($value, $input = array()) {
271 271
 		$original = $value;
272 272
 
273
-		if ( is_array( $value ) ) {
274
-			foreach ( $value as $index => $item ) {
275
-				$value[ $index ] = self::_sanitize_html_field( $value, $input );
273
+		if (is_array($value)) {
274
+			foreach ($value as $index => $item) {
275
+				$value[$index] = self::_sanitize_html_field($value, $input);
276 276
 			}
277
-		} elseif ( is_object( $value ) ) {
278
-			$object_vars = get_object_vars( $value );
277
+		} elseif (is_object($value)) {
278
+			$object_vars = get_object_vars($value);
279 279
 
280
-			foreach ( $object_vars as $property_name => $property_value ) {
281
-				$value->$property_name = self::_sanitize_html_field( $property_value, $input );
280
+			foreach ($object_vars as $property_name => $property_value) {
281
+				$value->$property_name = self::_sanitize_html_field($property_value, $input);
282 282
 			}
283 283
 		} else {
284
-			$value = self::_sanitize_html_field( $value, $input );
284
+			$value = self::_sanitize_html_field($value, $input);
285 285
 		}
286 286
 
287 287
 		/**
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		 * @param string|array $value Original content without filter.
294 294
 		 * @param array $input Input Field.
295 295
 		 */
296
-		return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
296
+		return apply_filters('ayecode_ui_sanitize_html_field', $value, $original, $input);
297 297
 	}
298 298
 
299 299
 	/**
@@ -316,20 +316,20 @@  discard block
 block discarded – undo
316 316
 	 *
317 317
 	 * @return string Filtered content with only allowed HTML elements.
318 318
 	 */
319
-	public static function _sanitize_html_field( $value, $input = array() ) {
320
-		if ( $value === '' ) {
319
+	public static function _sanitize_html_field($value, $input = array()) {
320
+		if ($value === '') {
321 321
 			return $value;
322 322
 		}
323 323
 
324
-		$allowed_html = self::kses_allowed_html( 'post', $input );
324
+		$allowed_html = self::kses_allowed_html('post', $input);
325 325
 
326
-		if ( ! is_array( $allowed_html ) ) {
327
-			$allowed_html = wp_kses_allowed_html( 'post' );
326
+		if (!is_array($allowed_html)) {
327
+			$allowed_html = wp_kses_allowed_html('post');
328 328
 		}
329 329
 
330
-		$filtered = trim( wp_unslash( $value ) );
331
-		$filtered = wp_kses( $filtered, $allowed_html );
332
-		$filtered = balanceTags( $filtered ); // Balances tags
330
+		$filtered = trim(wp_unslash($value));
331
+		$filtered = wp_kses($filtered, $allowed_html);
332
+		$filtered = balanceTags($filtered); // Balances tags
333 333
 
334 334
 		return $filtered;
335 335
 	}
@@ -346,12 +346,12 @@  discard block
 block discarded – undo
346 346
 	 *
347 347
 	 * @return array Array of allowed HTML tags and their allowed attributes.
348 348
 	 */
349
-	public static function kses_allowed_html( $context = 'post', $input = array() ) {
350
-		$allowed_html = wp_kses_allowed_html( $context );
349
+	public static function kses_allowed_html($context = 'post', $input = array()) {
350
+		$allowed_html = wp_kses_allowed_html($context);
351 351
 
352
-		if ( is_array( $allowed_html ) ) {
352
+		if (is_array($allowed_html)) {
353 353
 			// <iframe>
354
-			if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
354
+			if (!isset($allowed_html['iframe']) && $context == 'post') {
355 355
 				$allowed_html['iframe'] = array(
356 356
 					'class'           => true,
357 357
 					'id'              => true,
@@ -380,23 +380,23 @@  discard block
 block discarded – undo
380 380
 		 * @param @param string|array $context The context for which to retrieve tags.
381 381
 		 * @param array $input Input field.
382 382
 		 */
383
-		return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
383
+		return apply_filters('ayecode_ui_kses_allowed_html', $allowed_html, $context, $input);
384 384
 	}
385 385
 
386
-	public static function get_column_class( $label_number = 2, $type = 'label' ) {
386
+	public static function get_column_class($label_number = 2, $type = 'label') {
387 387
 
388 388
 		$class = '';
389 389
 
390 390
 		// set default if empty
391
-		if( $label_number === '' ){
391
+		if ($label_number === '') {
392 392
 			$label_number = 2;
393 393
 		}
394 394
 
395
-		if ( $label_number && $label_number < 12 && $label_number > 0 ) {
396
-			if ( $type == 'label' ) {
397
-				$class = 'col-sm-' . absint( $label_number );
398
-			} elseif ( $type == 'input' ) {
399
-				$class = 'col-sm-' . ( 12 - absint( $label_number ) );
395
+		if ($label_number && $label_number < 12 && $label_number > 0) {
396
+			if ($type == 'label') {
397
+				$class = 'col-sm-' . absint($label_number);
398
+			} elseif ($type == 'input') {
399
+				$class = 'col-sm-' . (12 - absint($label_number));
400 400
 			}
401 401
 		}
402 402
 
@@ -415,8 +415,8 @@  discard block
 block discarded – undo
415 415
 	 * @param string $str String to sanitize.
416 416
 	 * @return string Sanitized string.
417 417
 	 */
418
-	public static function sanitize_textarea_field( $str ) {
419
-		$filtered = self::_sanitize_text_fields( $str, true );
418
+	public static function sanitize_textarea_field($str) {
419
+		$filtered = self::_sanitize_text_fields($str, true);
420 420
 
421 421
 		/**
422 422
 		 * Filters a sanitized textarea field string.
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 		 * @param string $filtered The sanitized string.
427 427
 		 * @param string $str      The string prior to being sanitized.
428 428
 		 */
429
-		return apply_filters( 'sanitize_textarea_field', $filtered, $str );
429
+		return apply_filters('sanitize_textarea_field', $filtered, $str);
430 430
 	}
431 431
 
432 432
 	/**
@@ -439,40 +439,40 @@  discard block
 block discarded – undo
439 439
 	 * @param bool   $keep_newlines Optional. Whether to keep newlines. Default: false.
440 440
 	 * @return string Sanitized string.
441 441
 	 */
442
-	public static function _sanitize_text_fields( $str, $keep_newlines = false ) {
443
-		if ( is_object( $str ) || is_array( $str ) ) {
442
+	public static function _sanitize_text_fields($str, $keep_newlines = false) {
443
+		if (is_object($str) || is_array($str)) {
444 444
 			return '';
445 445
 		}
446 446
 
447 447
 		$str = (string) $str;
448 448
 
449
-		$filtered = wp_check_invalid_utf8( $str );
449
+		$filtered = wp_check_invalid_utf8($str);
450 450
 
451
-		if ( strpos( $filtered, '<' ) !== false ) {
452
-			$filtered = wp_pre_kses_less_than( $filtered );
451
+		if (strpos($filtered, '<') !== false) {
452
+			$filtered = wp_pre_kses_less_than($filtered);
453 453
 			// This will strip extra whitespace for us.
454
-			$filtered = wp_strip_all_tags( $filtered, false );
454
+			$filtered = wp_strip_all_tags($filtered, false);
455 455
 
456 456
 			// Use HTML entities in a special case to make sure no later
457 457
 			// newline stripping stage could lead to a functional tag.
458
-			$filtered = str_replace( "<\n", "&lt;\n", $filtered );
458
+			$filtered = str_replace("<\n", "&lt;\n", $filtered);
459 459
 		}
460 460
 
461
-		if ( ! $keep_newlines ) {
462
-			$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
461
+		if (!$keep_newlines) {
462
+			$filtered = preg_replace('/[\r\n\t ]+/', ' ', $filtered);
463 463
 		}
464
-		$filtered = trim( $filtered );
464
+		$filtered = trim($filtered);
465 465
 
466 466
 		$found = false;
467
-		while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) {
468
-			$filtered = str_replace( $match[1], '', $filtered );
467
+		while (preg_match('`[^%](%[a-f0-9]{2})`i', $filtered, $match)) {
468
+			$filtered = str_replace($match[1], '', $filtered);
469 469
 			$found = true;
470 470
 		}
471
-		unset( $match );
471
+		unset($match);
472 472
 
473
-		if ( $found ) {
473
+		if ($found) {
474 474
 			// Strip out the whitespace that may now exist after removing the octets.
475
-			$filtered = trim( preg_replace( '` +`', ' ', $filtered ) );
475
+			$filtered = trim(preg_replace('` +`', ' ', $filtered));
476 476
 		}
477 477
 
478 478
 		return $filtered;
@@ -485,15 +485,15 @@  discard block
 block discarded – undo
485 485
 	 * @param array $args Extra args.
486 486
 	 * @return string Sanitized icon.
487 487
 	 */
488
-	public static function sanitize_fa_icon( $icon, $args = array() ) {
489
-		if ( ! is_scalar( $icon ) ) {
488
+	public static function sanitize_fa_icon($icon, $args = array()) {
489
+		if (!is_scalar($icon)) {
490 490
 			return "";
491 491
 		}
492 492
 
493 493
 		$pattern = '/[^0-9a-zA-Z\-_ ]/';
494 494
 
495
-		$sanitized_icon = preg_replace( $pattern, '', trim( $icon ) );
495
+		$sanitized_icon = preg_replace($pattern, '', trim($icon));
496 496
 
497
-		return apply_filters( 'ayecode_ui_sanitize_fa_icon', $sanitized_icon, $icon, $args );
497
+		return apply_filters('ayecode_ui_sanitize_fa_icon', $sanitized_icon, $icon, $args);
498 498
 	}
499 499
 }
500 500
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
  * Bail if we are not in WP.
8 8
  */
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit;
10
+    exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16 16
 add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
18
-	$this_version = "0.2.40";
19
-	if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
22
-	}
17
+    global $ayecode_ui_version,$ayecode_ui_file_key;
18
+    $this_version = "0.2.40";
19
+    if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
+        $ayecode_ui_version = $this_version ;
21
+        $ayecode_ui_file_key = wp_hash( __FILE__ );
22
+    }
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28 28
 add_action('after_setup_theme', function () {
29
-	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
-	}
29
+    global $ayecode_ui_file_key;
30
+    if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
+        include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
+        include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
+    }
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39 39
 if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
42
-			return false;
43
-		}
44
-		return AUI::instance();
45
-	}
40
+    function aui(){
41
+        if(!class_exists("AUI",false)){
42
+            return false;
43
+        }
44
+        return AUI::instance();
45
+    }
46 46
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -6,39 +6,39 @@
 block discarded – undo
6 6
 /**
7 7
  * Bail if we are not in WP.
8 8
  */
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16
-add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
16
+add_action('after_setup_theme', function() {
17
+	global $ayecode_ui_version, $ayecode_ui_file_key;
18 18
 	$this_version = "0.2.40";
19
-	if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
19
+	if (empty($ayecode_ui_version) || version_compare($this_version, $ayecode_ui_version, '>')) {
20
+		$ayecode_ui_version = $this_version;
21
+		$ayecode_ui_file_key = wp_hash(__FILE__);
22 22
 	}
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28
-add_action('after_setup_theme', function () {
28
+add_action('after_setup_theme', function() {
29 29
 	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
30
+	if ($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash(__FILE__)) {
31
+		include_once(dirname(__FILE__) . '/includes/class-aui.php');
32
+		include_once(dirname(__FILE__) . '/includes/ayecode-ui-settings.php');
33 33
 	}
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39
-if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
39
+if (!function_exists('aui')) {
40
+	function aui() {
41
+		if (!class_exists("AUI", false)) {
42 42
 			return false;
43 43
 		}
44 44
 		return AUI::instance();
Please login to merge, or discard this patch.
vendor/composer/platform_check.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,9 +14,9 @@
 block discarded – undo
14 14
     }
15 15
     if (!ini_get('display_errors')) {
16 16
         if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
17
-            fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
17
+            fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL . PHP_EOL);
18 18
         } elseif (!headers_sent()) {
19
-            echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
19
+            echo 'Composer detected issues in your platform:' . PHP_EOL . PHP_EOL . str_replace('You are running ' . PHP_VERSION . '.', '', implode(PHP_EOL, $issues)) . PHP_EOL . PHP_EOL;
20 20
         }
21 21
     }
22 22
     throw new \RuntimeException(
Please login to merge, or discard this patch.
vendor/composer/InstalledVersions.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -359,17 +359,17 @@
 block discarded – undo
359 359
                 $vendorDir = strtr($vendorDir, '\\', '/');
360 360
                 if (isset(self::$installedByVendor[$vendorDir])) {
361 361
                     $installed[] = self::$installedByVendor[$vendorDir];
362
-                } elseif (is_file($vendorDir.'/composer/installed.php')) {
362
+                } elseif (is_file($vendorDir . '/composer/installed.php')) {
363 363
                     /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
364
-                    $required = require $vendorDir.'/composer/installed.php';
364
+                    $required = require $vendorDir . '/composer/installed.php';
365 365
                     self::$installedByVendor[$vendorDir] = $required;
366 366
                     $installed[] = $required;
367
-                    if (self::$installed === null && $vendorDir.'/composer' === $selfDir) {
367
+                    if (self::$installed === null && $vendorDir . '/composer' === $selfDir) {
368 368
                         self::$installed = $required;
369 369
                         self::$installedIsLocalDir = true;
370 370
                     }
371 371
                 }
372
-                if (self::$installedIsLocalDir && $vendorDir.'/composer' === $selfDir) {
372
+                if (self::$installedIsLocalDir && $vendorDir . '/composer' === $selfDir) {
373 373
                     $copiedLocalDir = true;
374 374
                 }
375 375
             }
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 2 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+        $anchor = __( 'Deactivate', 'invoicing' );
61
+        $title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64 64
     } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) {
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+        $anchor = __( 'Activate', 'invoicing' );
77
+        $title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
             $types = wpinv_get_discount_types();
122 122
 
123 123
             foreach ( $types as $name => $type ) {
124
-			echo '<option value="' . esc_attr( $name ) . '"';
124
+            echo '<option value="' . esc_attr( $name ) . '"';
125 125
 
126
-			if ( isset( $_GET['discount_type'] ) ) {
127
-				selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
126
+            if ( isset( $_GET['discount_type'] ) ) {
127
+                selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
128 128
                 }
129 129
 
130
-			echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
130
+            echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
131 131
             }
132 132
         ?>
133 133
     </select>
@@ -154,15 +154,15 @@  discard block
 block discarded – undo
154 154
         // Filter vat rule type
155 155
         if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
156 156
             $meta_query[] = array(
157
-				'key'     => '_wpi_discount_type',
158
-				'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
159
-				'compare' => '=',
160
-			);
161
-			}
157
+                'key'     => '_wpi_discount_type',
158
+                'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
159
+                'compare' => '=',
160
+            );
161
+            }
162 162
 
163 163
         if ( ! empty( $meta_query ) ) {
164 164
             $vars['meta_query'] = $meta_query;
165
-			}
165
+            }
166 166
     }
167 167
 
168 168
     return $vars;
@@ -180,72 +180,72 @@  discard block
 block discarded – undo
180 180
  * @return int page ID
181 181
  */
182 182
 function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
183
-	global $wpdb;
184
-
185
-	$option_value = wpinv_get_option( $option );
186
-
187
-	if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) {
188
-		if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
189
-			// Valid page is already in place
190
-			return $page_object->ID;
191
-		}
192
-	}
193
-
194
-	if ( ! empty( $post_parent ) ) {
195
-		$page = get_page_by_path( $post_parent );
196
-		if ( $page ) {
197
-			$post_parent = $page->ID;
198
-		} else {
199
-			$post_parent = '';
200
-		}
201
-	}
202
-
203
-	// Search for an existing page with the specified page slug
204
-	$valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
205
-
206
-	$valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
207
-
208
-	if ( $valid_page_found ) {
209
-		if ( $option ) {
210
-			wpinv_update_option( $option, $valid_page_found );
211
-		}
212
-
213
-		return $valid_page_found;
214
-	}
215
-
216
-	// Search for an existing page with the specified page slug
217
-	$trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
218
-
219
-	if ( $trashed_page_found ) {
220
-		$page_id   = $trashed_page_found;
221
-
222
-		$page_data = array(
223
-			'ID'          => $page_id,
224
-			'post_status' => 'publish',
225
-			'post_parent' => $post_parent,
226
-		);
227
-
228
-		wp_update_post( $page_data );
229
-	} else {
230
-		$page_data = array(
231
-			'post_status'    => 'publish',
232
-			'post_type'      => 'page',
233
-			'post_author'    => 1,
234
-			'post_name'      => $slug,
235
-			'post_title'     => $page_title,
236
-			'post_content'   => $page_content,
237
-			'post_parent'    => $post_parent,
238
-			'comment_status' => 'closed',
239
-		);
240
-
241
-		$page_id = wp_insert_post( $page_data );
242
-	}
243
-
244
-	if ( $option ) {
245
-		wpinv_update_option( $option, (int) $page_id );
246
-	}
247
-
248
-	return $page_id;
183
+    global $wpdb;
184
+
185
+    $option_value = wpinv_get_option( $option );
186
+
187
+    if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) {
188
+        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
189
+            // Valid page is already in place
190
+            return $page_object->ID;
191
+        }
192
+    }
193
+
194
+    if ( ! empty( $post_parent ) ) {
195
+        $page = get_page_by_path( $post_parent );
196
+        if ( $page ) {
197
+            $post_parent = $page->ID;
198
+        } else {
199
+            $post_parent = '';
200
+        }
201
+    }
202
+
203
+    // Search for an existing page with the specified page slug
204
+    $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
205
+
206
+    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
207
+
208
+    if ( $valid_page_found ) {
209
+        if ( $option ) {
210
+            wpinv_update_option( $option, $valid_page_found );
211
+        }
212
+
213
+        return $valid_page_found;
214
+    }
215
+
216
+    // Search for an existing page with the specified page slug
217
+    $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
218
+
219
+    if ( $trashed_page_found ) {
220
+        $page_id   = $trashed_page_found;
221
+
222
+        $page_data = array(
223
+            'ID'          => $page_id,
224
+            'post_status' => 'publish',
225
+            'post_parent' => $post_parent,
226
+        );
227
+
228
+        wp_update_post( $page_data );
229
+    } else {
230
+        $page_data = array(
231
+            'post_status'    => 'publish',
232
+            'post_type'      => 'page',
233
+            'post_author'    => 1,
234
+            'post_name'      => $slug,
235
+            'post_title'     => $page_title,
236
+            'post_content'   => $page_content,
237
+            'post_parent'    => $post_parent,
238
+            'comment_status' => 'closed',
239
+        );
240
+
241
+        $page_id = wp_insert_post( $page_data );
242
+    }
243
+
244
+    if ( $option ) {
245
+        wpinv_update_option( $option, (int) $page_id );
246
+    }
247
+
248
+    return $page_id;
249 249
 }
250 250
 
251 251
 /**
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -1,51 +1,51 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( ! defined( 'WPINC' ) ) {
3
+if (!defined('WPINC')) {
4 4
     exit;
5 5
 }
6 6
 
7
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
8
-function wpinv_discount_custom_column( $column ) {
7
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
8
+function wpinv_discount_custom_column($column) {
9 9
     global $post;
10 10
 
11
-    $discount = new WPInv_Discount( $post );
11
+    $discount = new WPInv_Discount($post);
12 12
 
13
-    switch ( $column ) {
13
+    switch ($column) {
14 14
         case 'code':
15
-            echo esc_html( $discount->get_code() );
15
+            echo esc_html($discount->get_code());
16 16
             break;
17 17
         case 'amount':
18
-            echo wp_kses_post( $discount->get_formatted_amount() );
18
+            echo wp_kses_post($discount->get_formatted_amount());
19 19
             break;
20 20
         case 'usage':
21
-            echo wp_kses_post( $discount->get_usage() );
21
+            echo wp_kses_post($discount->get_usage());
22 22
             break;
23 23
         case 'start_date':
24
-            echo wp_kses_post( getpaid_format_date_value( $discount->get_start_date() ) );
24
+            echo wp_kses_post(getpaid_format_date_value($discount->get_start_date()));
25 25
             break;
26 26
         case 'expiry_date':
27
-            echo wp_kses_post( getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ) );
27
+            echo wp_kses_post(getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing')));
28 28
             break;
29 29
     }
30 30
 }
31 31
 
32
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 90, 2 );
33
-function wpinv_post_row_actions( $actions, $post ) {
34
-    $post_type = ! empty( $post->post_type ) ? $post->post_type : '';
32
+add_filter('post_row_actions', 'wpinv_post_row_actions', 90, 2);
33
+function wpinv_post_row_actions($actions, $post) {
34
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
35 35
 
36
-    if ( $post_type == 'wpi_discount' ) {
37
-        $actions = wpinv_discount_row_actions( $post, $actions );
36
+    if ($post_type == 'wpi_discount') {
37
+        $actions = wpinv_discount_row_actions($post, $actions);
38 38
     }
39 39
 
40 40
     return $actions;
41 41
 }
42 42
 
43
-function wpinv_discount_row_actions( $discount, $row_actions ) {
44
-    $row_actions  = array();
45
-    $edit_link = get_edit_post_link( $discount->ID );
46
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
43
+function wpinv_discount_row_actions($discount, $row_actions) {
44
+    $row_actions = array();
45
+    $edit_link = get_edit_post_link($discount->ID);
46
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
47 47
 
48
-    if ( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) && wpinv_current_user_can( 'deactivate_discount', array( 'discount' => (int) $discount->ID ) ) ) {
48
+    if (in_array(strtolower($discount->post_status), array('publish')) && wpinv_current_user_can('deactivate_discount', array('discount' => (int) $discount->ID))) {
49 49
 
50 50
         $url = wp_nonce_url(
51 51
             add_query_arg(
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+		$anchor = __('Deactivate', 'invoicing');
61
+		$title  = esc_attr__('Are you sure you want to deactivate this discount?', 'invoicing');
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64
-    } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) {
64
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft')) && wpinv_current_user_can('activate_discount', array('discount' => (int) $discount->ID))) {
65 65
 
66
-        $url    = wp_nonce_url(
66
+        $url = wp_nonce_url(
67 67
             add_query_arg(
68 68
                 array(
69 69
                     'getpaid-admin-action' => 'activate_discount',
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+		$anchor = __('Activate', 'invoicing');
77
+		$title  = esc_attr__('Are you sure you want to activate this discount?', 'invoicing');
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
81 81
 
82
-    if ( wpinv_current_user_can( 'delete_discount', array( 'discount' => (int) $discount->ID ) ) ) {
83
-        $url    = esc_url(
82
+    if (wpinv_current_user_can('delete_discount', array('discount' => (int) $discount->ID))) {
83
+        $url = esc_url(
84 84
             wp_nonce_url(
85 85
                 add_query_arg(
86 86
                     array(
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
             )
94 94
     );
95 95
 
96
-        $anchor = __( 'Delete', 'invoicing' );
97
-        $title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
96
+        $anchor = __('Delete', 'invoicing');
97
+        $title  = esc_attr__('Are you sure you want to delete this discount?', 'invoicing');
98 98
         $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
99 99
     }
100 100
 
101
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
101
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
102 102
 
103 103
     return $row_actions;
104 104
 }
@@ -106,68 +106,68 @@  discard block
 block discarded – undo
106 106
 function wpinv_restrict_manage_posts() {
107 107
     global $typenow;
108 108
 
109
-    if ( 'wpi_discount' == $typenow ) {
109
+    if ('wpi_discount' == $typenow) {
110 110
         wpinv_discount_filters();
111 111
     }
112 112
 }
113
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
113
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
114 114
 
115 115
 function wpinv_discount_filters() {
116 116
 
117 117
     ?>
118 118
     <select name="discount_type" id="dropdown_wpinv_discount_type">
119
-        <option value=""><?php esc_html_e( 'Show all types', 'invoicing' ); ?></option>
119
+        <option value=""><?php esc_html_e('Show all types', 'invoicing'); ?></option>
120 120
         <?php
121 121
             $types = wpinv_get_discount_types();
122 122
 
123
-            foreach ( $types as $name => $type ) {
124
-			echo '<option value="' . esc_attr( $name ) . '"';
123
+            foreach ($types as $name => $type) {
124
+			echo '<option value="' . esc_attr($name) . '"';
125 125
 
126
-			if ( isset( $_GET['discount_type'] ) ) {
127
-				selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
126
+			if (isset($_GET['discount_type'])) {
127
+				selected($name, sanitize_text_field($_GET['discount_type']));
128 128
                 }
129 129
 
130
-			echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
130
+			echo '>' . esc_html__($type, 'invoicing') . '</option>';
131 131
             }
132 132
         ?>
133 133
     </select>
134 134
     <?php
135 135
 }
136 136
 
137
-function wpinv_request( $vars ) {
137
+function wpinv_request($vars) {
138 138
     global $typenow, $wp_post_statuses;
139 139
 
140
-    if ( getpaid_is_invoice_post_type( $typenow ) ) {
141
-        if ( ! isset( $vars['post_status'] ) ) {
142
-            $post_statuses = wpinv_get_invoice_statuses( false, false, $typenow );
140
+    if (getpaid_is_invoice_post_type($typenow)) {
141
+        if (!isset($vars['post_status'])) {
142
+            $post_statuses = wpinv_get_invoice_statuses(false, false, $typenow);
143 143
 
144
-            foreach ( $post_statuses as $status => $value ) {
145
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
146
-                    unset( $post_statuses[ $status ] );
144
+            foreach ($post_statuses as $status => $value) {
145
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
146
+                    unset($post_statuses[$status]);
147 147
                 }
148 148
             }
149 149
 
150
-            $vars['post_status'] = array_keys( $post_statuses );
150
+            $vars['post_status'] = array_keys($post_statuses);
151 151
         }
152
-} elseif ( 'wpi_discount' == $typenow ) {
153
-        $meta_query = ! empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
152
+} elseif ('wpi_discount' == $typenow) {
153
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
154 154
         // Filter vat rule type
155
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
155
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
156 156
             $meta_query[] = array(
157 157
 				'key'     => '_wpi_discount_type',
158
-				'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
158
+				'value'   => sanitize_key(urldecode($_GET['discount_type'])),
159 159
 				'compare' => '=',
160 160
 			);
161 161
 			}
162 162
 
163
-        if ( ! empty( $meta_query ) ) {
163
+        if (!empty($meta_query)) {
164 164
             $vars['meta_query'] = $meta_query;
165 165
 			}
166 166
     }
167 167
 
168 168
     return $vars;
169 169
 }
170
-add_filter( 'request', 'wpinv_request' );
170
+add_filter('request', 'wpinv_request');
171 171
 
172 172
 /**
173 173
  * Create a page and store the ID in an option.
@@ -179,21 +179,21 @@  discard block
 block discarded – undo
179 179
  * @param int $post_parent (default: 0) Parent for the new page
180 180
  * @return int page ID
181 181
  */
182
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
182
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
183 183
 	global $wpdb;
184 184
 
185
-	$option_value = wpinv_get_option( $option );
185
+	$option_value = wpinv_get_option($option);
186 186
 
187
-	if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) {
188
-		if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
187
+	if (!empty($option_value) && ($page_object = get_post($option_value))) {
188
+		if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
189 189
 			// Valid page is already in place
190 190
 			return $page_object->ID;
191 191
 		}
192 192
 	}
193 193
 
194
-	if ( ! empty( $post_parent ) ) {
195
-		$page = get_page_by_path( $post_parent );
196
-		if ( $page ) {
194
+	if (!empty($post_parent)) {
195
+		$page = get_page_by_path($post_parent);
196
+		if ($page) {
197 197
 			$post_parent = $page->ID;
198 198
 		} else {
199 199
 			$post_parent = '';
@@ -201,22 +201,22 @@  discard block
 block discarded – undo
201 201
 	}
202 202
 
203 203
 	// Search for an existing page with the specified page slug
204
-	$valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
204
+	$valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
205 205
 
206
-	$valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
206
+	$valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
207 207
 
208
-	if ( $valid_page_found ) {
209
-		if ( $option ) {
210
-			wpinv_update_option( $option, $valid_page_found );
208
+	if ($valid_page_found) {
209
+		if ($option) {
210
+			wpinv_update_option($option, $valid_page_found);
211 211
 		}
212 212
 
213 213
 		return $valid_page_found;
214 214
 	}
215 215
 
216 216
 	// Search for an existing page with the specified page slug
217
-	$trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
217
+	$trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
218 218
 
219
-	if ( $trashed_page_found ) {
219
+	if ($trashed_page_found) {
220 220
 		$page_id   = $trashed_page_found;
221 221
 
222 222
 		$page_data = array(
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 			'post_parent' => $post_parent,
226 226
 		);
227 227
 
228
-		wp_update_post( $page_data );
228
+		wp_update_post($page_data);
229 229
 	} else {
230 230
 		$page_data = array(
231 231
 			'post_status'    => 'publish',
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
 			'comment_status' => 'closed',
239 239
 		);
240 240
 
241
-		$page_id = wp_insert_post( $page_data );
241
+		$page_id = wp_insert_post($page_data);
242 242
 	}
243 243
 
244
-	if ( $option ) {
245
-		wpinv_update_option( $option, (int) $page_id );
244
+	if ($option) {
245
+		wpinv_update_option($option, (int) $page_id);
246 246
 	}
247 247
 
248 248
 	return $page_id;
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
  *
256 256
  * @return array
257 257
  */
258
-function wpinv_add_aui_screens( $screen_ids ) {
258
+function wpinv_add_aui_screens($screen_ids) {
259 259
 
260 260
     // load on these pages if set
261
-    $screen_ids = array_merge( $screen_ids, wpinv_get_screen_ids() );
261
+    $screen_ids = array_merge($screen_ids, wpinv_get_screen_ids());
262 262
 
263 263
     return $screen_ids;
264 264
 }
265
-add_filter( 'aui_screen_ids', 'wpinv_add_aui_screens' );
265
+add_filter('aui_screen_ids', 'wpinv_add_aui_screens');
Please login to merge, or discard this patch.
includes/admin/class-getpaid-installer.php 2 patches
Indentation   +493 added lines, -493 removed lines patch added patch discarded remove patch
@@ -20,392 +20,392 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	private static $schema = null;
24
-	private static $schema_version = null;
25
-
26
-	/**
27
-	 * Upgrades the install.
28
-	 *
29
-	 * @param string $upgrade_from The current invoicing version.
30
-	 */
31
-	public function upgrade_db( $upgrade_from ) {
32
-
33
-		// Save the current invoicing version.
34
-		update_option( 'wpinv_version', WPINV_VERSION );
35
-
36
-		// Setup the invoice Custom Post Type.
37
-		GetPaid_Post_Types::register_post_types();
38
-
39
-		// Clear the permalinks
40
-		flush_rewrite_rules();
41
-
42
-		// Maybe create new/missing pages.
43
-		$this->create_pages();
44
-
45
-		// Maybe re(add) admin capabilities.
46
-		$this->add_capabilities();
47
-
48
-		// Maybe create the default payment form.
49
-		wpinv_get_default_payment_form();
50
-
51
-		// Create any missing database tables.
52
-		$method = "upgrade_from_$upgrade_from";
53
-
54
-		$installed = get_option( 'gepaid_installed_on' );
55
-
56
-		if ( empty( $installed ) ) {
57
-			update_option( 'gepaid_installed_on', time() );
58
-		}
59
-
60
-		if ( method_exists( $this, $method ) ) {
61
-			$this->$method();
62
-		}
63
-
64
-	}
65
-
66
-	/**
67
-	 * Do a fresh install.
68
-	 *
69
-	 */
70
-	public function upgrade_from_0() {
71
-
72
-		// Save default tax rates.
73
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
-	}
75
-
76
-	/**
77
-	 * Upgrade to 0.0.5
78
-	 *
79
-	 */
80
-	public function upgrade_from_004() {
81
-		global $wpdb;
82
-
83
-		// Invoices.
84
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
-		if ( ! empty( $results ) ) {
86
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
-
88
-			// Clean post cache
89
-			foreach ( $results as $row ) {
90
-				clean_post_cache( $row->ID );
91
-			}
92
-		}
93
-
94
-		// Item meta key changes
95
-		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
-		$results = $wpdb->get_results( $query );
97
-
98
-		if ( ! empty( $results ) ) {
99
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
-
103
-			foreach ( $results as $row ) {
104
-				clean_post_cache( $row->post_id );
105
-			}
106
-		}
107
-
108
-		$this->upgrade_from_118();
109
-	}
110
-
111
-	/**
112
-	 * Upgrade to version 2.0.0.
113
-	 *
114
-	 */
115
-	public function upgrade_from_118() {
116
-		$this->migrate_old_invoices();
117
-		$this->upgrade_from_279();
118
-	}
119
-
120
-	/**
121
-	 * Upgrade to version 2.0.0.
122
-	 *
123
-	 */
124
-	public function upgrade_from_279() {
125
-		self::migrate_old_customers();
126
-	}
127
-
128
-	/**
129
-	 * Give administrators the capability to manage GetPaid.
130
-	 *
131
-	 */
132
-	public function add_capabilities() {
133
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
134
-	}
135
-
136
-	/**
137
-	 * Retreives GetPaid pages.
138
-	 *
139
-	 */
140
-	public static function get_pages( $filtered = false ) {
141
-		$gutenberg = getpaid_is_gutenberg();
142
-
143
-		return apply_filters(
144
-			'wpinv_create_pages',
145
-			array(
146
-				// Checkout page.
147
-				'checkout_page' => array(
148
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
149
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
150
-					'content' => getpaid_page_content_checkout( $filtered, $gutenberg ),
151
-					'parent'  => ''
152
-				),
153
-
154
-				// Invoice history page.
155
-				'invoice_history_page' => array(
156
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
157
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
158
-					'content' => getpaid_page_content_invoice_history( $filtered, $gutenberg ),
159
-					'parent'  => ''
160
-				),
161
-
162
-				// Success page content.
163
-				'success_page' => array(
164
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
165
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
166
-					'content' => getpaid_page_content_receipt( $filtered, $gutenberg ),
167
-					'parent'  => 'gp-checkout'
168
-				),
169
-
170
-				// Failure page content.
171
-				'failure_page' => array(
172
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
173
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
174
-					'content' => getpaid_page_content_failure( $filtered, $gutenberg ),
175
-					'parent'  => 'gp-checkout'
176
-				),
177
-
178
-				// Subscriptions history page.
179
-				'invoice_subscription_page' => array(
180
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
181
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
182
-					'content' => getpaid_page_content_subscriptions( $filtered, $gutenberg ),
183
-					'parent'  => ''
184
-				)
185
-			)
186
-		);
187
-	}
188
-
189
-	/**
190
-	 * Re-create GetPaid pages.
191
-	 *
192
-	 */
193
-	public function create_pages() {
194
-		foreach ( self::get_pages() as $key => $page ) {
195
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
196
-		}
197
-
198
-	}
199
-
200
-	/**
201
-	 * Migrates old invoices to new invoices.
202
-	 *
203
-	 */
204
-	public function migrate_old_invoices() {
205
-		global $wpdb;
206
-
207
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
208
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
209
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
210
-		$invoices            = array_unique(
211
-			get_posts(
212
-				array(
213
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
214
-					'posts_per_page' => -1,
215
-					'fields'         => 'ids',
216
-					'post_status'    => array_keys( get_post_stati() ),
217
-					'exclude'        => (array) $migrated,
218
-				)
219
-			)
220
-		);
221
-
222
-		// Abort if we do not have any invoices.
223
-		if ( empty( $invoices ) ) {
224
-			return;
225
-		}
226
-
227
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
228
-
229
-		$invoice_rows = array();
230
-		foreach ( $invoices as $invoice ) {
231
-
232
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
233
-
234
-			if ( empty( $invoice->ID ) ) {
235
-				return;
236
-			}
237
-
238
-			$fields = array(
239
-				'post_id'            => $invoice->ID,
240
-				'number'             => $invoice->get_number(),
241
-				'key'                => $invoice->get_key(),
242
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
243
-				'mode'               => $invoice->mode,
244
-				'user_ip'            => $invoice->get_ip(),
245
-				'first_name'         => $invoice->get_first_name(),
246
-				'last_name'          => $invoice->get_last_name(),
247
-				'address'            => $invoice->get_address(),
248
-				'city'               => $invoice->city,
249
-				'state'              => $invoice->state,
250
-				'country'            => $invoice->country,
251
-				'zip'                => $invoice->zip,
252
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
253
-				'gateway'            => $invoice->get_gateway(),
254
-				'transaction_id'     => $invoice->get_transaction_id(),
255
-				'currency'           => $invoice->get_currency(),
256
-				'subtotal'           => $invoice->get_subtotal(),
257
-				'tax'                => $invoice->get_tax(),
258
-				'fees_total'         => $invoice->get_fees_total(),
259
-				'total'              => $invoice->get_total(),
260
-				'discount'           => $invoice->get_discount(),
261
-				'discount_code'      => $invoice->get_discount_code(),
262
-				'disable_taxes'      => $invoice->disable_taxes,
263
-				'due_date'           => $invoice->get_due_date(),
264
-				'completed_date'     => $invoice->get_completed_date(),
265
-				'company'            => $invoice->company,
266
-				'vat_number'         => $invoice->vat_number,
267
-				'vat_rate'           => $invoice->vat_rate,
268
-				'custom_meta'        => $invoice->payment_meta,
269
-			);
270
-
271
-			foreach ( $fields as $key => $val ) {
272
-				if ( is_null( $val ) ) {
273
-					$val = '';
274
-				}
275
-				$val = maybe_serialize( $val );
276
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
277
-			}
278
-
279
-			$fields = implode( ', ', $fields );
280
-			$invoice_rows[] = "($fields)";
281
-
282
-			$item_rows    = array();
283
-			$item_columns = array();
284
-			foreach ( $invoice->get_cart_details() as $details ) {
285
-				$fields = array(
286
-					'post_id'          => $invoice->ID,
287
-					'item_id'          => $details['id'],
288
-					'item_name'        => $details['name'],
289
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
290
-					'vat_rate'         => $details['vat_rate'],
291
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
292
-					'tax'              => $details['tax'],
293
-					'item_price'       => $details['item_price'],
294
-					'custom_price'     => $details['custom_price'],
295
-					'quantity'         => $details['quantity'],
296
-					'discount'         => $details['discount'],
297
-					'subtotal'         => $details['subtotal'],
298
-					'price'            => $details['price'],
299
-					'meta'             => $details['meta'],
300
-					'fees'             => $details['fees'],
301
-				);
302
-
303
-				$item_columns = array_keys( $fields );
304
-
305
-				foreach ( $fields as $key => $val ) {
306
-					if ( is_null( $val ) ) {
307
-						$val = '';
308
-					}
309
-					$val = maybe_serialize( $val );
310
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
311
-				}
312
-
313
-				$fields = implode( ', ', $fields );
314
-				$item_rows[] = "($fields)";
315
-			}
316
-
317
-			$item_rows    = implode( ', ', $item_rows );
318
-			$item_columns = implode( ', ', $item_columns );
319
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
320
-		}
321
-
322
-		if ( empty( $invoice_rows ) ) {
323
-			return;
324
-		}
325
-
326
-		$invoice_rows = implode( ', ', $invoice_rows );
327
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
328
-
329
-	}
330
-
331
-	/**
332
-	 * Migrates old customers to new table.
333
-	 *
334
-	 */
335
-	public static function migrate_old_customers() {
336
-		global $wpdb;
337
-
338
-		// Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
339
-		$invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
340
-
341
-		foreach ( $invoice_ids as $invoice_id ) {
342
-			$invoice = wpinv_get_invoice( $invoice_id );
343
-
344
-			if ( empty( $invoice ) ) {
345
-				continue;
346
-			}
347
-
348
-			// Fetch customer from the user ID.
349
-			$user_id = $invoice->get_user_id();
350
-
351
-			if ( empty( $user_id ) ) {
352
-				continue;
353
-			}
354
-
355
-			$customer = getpaid_get_customer_by_user_id( $user_id );
356
-
357
-			// Create if not exists.
358
-			if ( empty( $customer ) ) {
359
-				$customer = new GetPaid_Customer( 0 );
360
-				$customer->clone_user( $user_id );
361
-				$customer->save();
362
-			}
363
-
364
-			$invoice->set_customer_id( $customer->get_id() );
365
-			$invoice->save();
366
-		}
367
-
368
-	}
369
-
370
-	/**
371
-	 * Migrates old invoices to new invoices.
372
-	 *
373
-	 */
374
-	public static function rename_gateways_label() {
375
-		global $wpdb;
376
-
377
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
378
-
379
-			$wpdb->update(
380
-				$wpdb->prefix . 'getpaid_invoices',
381
-				array( 'gateway' => $gateway ),
382
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
383
-				'%s',
384
-				'%s'
385
-			);
386
-
387
-		}
388
-	}
389
-
390
-	/**
391
-	 * Returns the DB schema.
392
-	 *
393
-	 */
394
-	public static function get_db_schema() {
395
-		global $wpdb;
396
-
397
-		if ( ! empty( self::$schema ) ) {
398
-			return self::$schema;
399
-		}
23
+    private static $schema = null;
24
+    private static $schema_version = null;
25
+
26
+    /**
27
+     * Upgrades the install.
28
+     *
29
+     * @param string $upgrade_from The current invoicing version.
30
+     */
31
+    public function upgrade_db( $upgrade_from ) {
32
+
33
+        // Save the current invoicing version.
34
+        update_option( 'wpinv_version', WPINV_VERSION );
35
+
36
+        // Setup the invoice Custom Post Type.
37
+        GetPaid_Post_Types::register_post_types();
38
+
39
+        // Clear the permalinks
40
+        flush_rewrite_rules();
41
+
42
+        // Maybe create new/missing pages.
43
+        $this->create_pages();
44
+
45
+        // Maybe re(add) admin capabilities.
46
+        $this->add_capabilities();
47
+
48
+        // Maybe create the default payment form.
49
+        wpinv_get_default_payment_form();
50
+
51
+        // Create any missing database tables.
52
+        $method = "upgrade_from_$upgrade_from";
53
+
54
+        $installed = get_option( 'gepaid_installed_on' );
55
+
56
+        if ( empty( $installed ) ) {
57
+            update_option( 'gepaid_installed_on', time() );
58
+        }
59
+
60
+        if ( method_exists( $this, $method ) ) {
61
+            $this->$method();
62
+        }
63
+
64
+    }
65
+
66
+    /**
67
+     * Do a fresh install.
68
+     *
69
+     */
70
+    public function upgrade_from_0() {
71
+
72
+        // Save default tax rates.
73
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
+    }
75
+
76
+    /**
77
+     * Upgrade to 0.0.5
78
+     *
79
+     */
80
+    public function upgrade_from_004() {
81
+        global $wpdb;
82
+
83
+        // Invoices.
84
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
+        if ( ! empty( $results ) ) {
86
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
+
88
+            // Clean post cache
89
+            foreach ( $results as $row ) {
90
+                clean_post_cache( $row->ID );
91
+            }
92
+        }
93
+
94
+        // Item meta key changes
95
+        $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
+        $results = $wpdb->get_results( $query );
97
+
98
+        if ( ! empty( $results ) ) {
99
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
+
103
+            foreach ( $results as $row ) {
104
+                clean_post_cache( $row->post_id );
105
+            }
106
+        }
107
+
108
+        $this->upgrade_from_118();
109
+    }
110
+
111
+    /**
112
+     * Upgrade to version 2.0.0.
113
+     *
114
+     */
115
+    public function upgrade_from_118() {
116
+        $this->migrate_old_invoices();
117
+        $this->upgrade_from_279();
118
+    }
119
+
120
+    /**
121
+     * Upgrade to version 2.0.0.
122
+     *
123
+     */
124
+    public function upgrade_from_279() {
125
+        self::migrate_old_customers();
126
+    }
127
+
128
+    /**
129
+     * Give administrators the capability to manage GetPaid.
130
+     *
131
+     */
132
+    public function add_capabilities() {
133
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
134
+    }
135
+
136
+    /**
137
+     * Retreives GetPaid pages.
138
+     *
139
+     */
140
+    public static function get_pages( $filtered = false ) {
141
+        $gutenberg = getpaid_is_gutenberg();
142
+
143
+        return apply_filters(
144
+            'wpinv_create_pages',
145
+            array(
146
+                // Checkout page.
147
+                'checkout_page' => array(
148
+                    'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
149
+                    'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
150
+                    'content' => getpaid_page_content_checkout( $filtered, $gutenberg ),
151
+                    'parent'  => ''
152
+                ),
153
+
154
+                // Invoice history page.
155
+                'invoice_history_page' => array(
156
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
157
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
158
+                    'content' => getpaid_page_content_invoice_history( $filtered, $gutenberg ),
159
+                    'parent'  => ''
160
+                ),
161
+
162
+                // Success page content.
163
+                'success_page' => array(
164
+                    'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
165
+                    'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
166
+                    'content' => getpaid_page_content_receipt( $filtered, $gutenberg ),
167
+                    'parent'  => 'gp-checkout'
168
+                ),
169
+
170
+                // Failure page content.
171
+                'failure_page' => array(
172
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
173
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
174
+                    'content' => getpaid_page_content_failure( $filtered, $gutenberg ),
175
+                    'parent'  => 'gp-checkout'
176
+                ),
177
+
178
+                // Subscriptions history page.
179
+                'invoice_subscription_page' => array(
180
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
181
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
182
+                    'content' => getpaid_page_content_subscriptions( $filtered, $gutenberg ),
183
+                    'parent'  => ''
184
+                )
185
+            )
186
+        );
187
+    }
188
+
189
+    /**
190
+     * Re-create GetPaid pages.
191
+     *
192
+     */
193
+    public function create_pages() {
194
+        foreach ( self::get_pages() as $key => $page ) {
195
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
196
+        }
197
+
198
+    }
199
+
200
+    /**
201
+     * Migrates old invoices to new invoices.
202
+     *
203
+     */
204
+    public function migrate_old_invoices() {
205
+        global $wpdb;
206
+
207
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
208
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
209
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
210
+        $invoices            = array_unique(
211
+            get_posts(
212
+                array(
213
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
214
+                    'posts_per_page' => -1,
215
+                    'fields'         => 'ids',
216
+                    'post_status'    => array_keys( get_post_stati() ),
217
+                    'exclude'        => (array) $migrated,
218
+                )
219
+            )
220
+        );
221
+
222
+        // Abort if we do not have any invoices.
223
+        if ( empty( $invoices ) ) {
224
+            return;
225
+        }
226
+
227
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
228
+
229
+        $invoice_rows = array();
230
+        foreach ( $invoices as $invoice ) {
231
+
232
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
233
+
234
+            if ( empty( $invoice->ID ) ) {
235
+                return;
236
+            }
237
+
238
+            $fields = array(
239
+                'post_id'            => $invoice->ID,
240
+                'number'             => $invoice->get_number(),
241
+                'key'                => $invoice->get_key(),
242
+                'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
243
+                'mode'               => $invoice->mode,
244
+                'user_ip'            => $invoice->get_ip(),
245
+                'first_name'         => $invoice->get_first_name(),
246
+                'last_name'          => $invoice->get_last_name(),
247
+                'address'            => $invoice->get_address(),
248
+                'city'               => $invoice->city,
249
+                'state'              => $invoice->state,
250
+                'country'            => $invoice->country,
251
+                'zip'                => $invoice->zip,
252
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
253
+                'gateway'            => $invoice->get_gateway(),
254
+                'transaction_id'     => $invoice->get_transaction_id(),
255
+                'currency'           => $invoice->get_currency(),
256
+                'subtotal'           => $invoice->get_subtotal(),
257
+                'tax'                => $invoice->get_tax(),
258
+                'fees_total'         => $invoice->get_fees_total(),
259
+                'total'              => $invoice->get_total(),
260
+                'discount'           => $invoice->get_discount(),
261
+                'discount_code'      => $invoice->get_discount_code(),
262
+                'disable_taxes'      => $invoice->disable_taxes,
263
+                'due_date'           => $invoice->get_due_date(),
264
+                'completed_date'     => $invoice->get_completed_date(),
265
+                'company'            => $invoice->company,
266
+                'vat_number'         => $invoice->vat_number,
267
+                'vat_rate'           => $invoice->vat_rate,
268
+                'custom_meta'        => $invoice->payment_meta,
269
+            );
270
+
271
+            foreach ( $fields as $key => $val ) {
272
+                if ( is_null( $val ) ) {
273
+                    $val = '';
274
+                }
275
+                $val = maybe_serialize( $val );
276
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
277
+            }
278
+
279
+            $fields = implode( ', ', $fields );
280
+            $invoice_rows[] = "($fields)";
281
+
282
+            $item_rows    = array();
283
+            $item_columns = array();
284
+            foreach ( $invoice->get_cart_details() as $details ) {
285
+                $fields = array(
286
+                    'post_id'          => $invoice->ID,
287
+                    'item_id'          => $details['id'],
288
+                    'item_name'        => $details['name'],
289
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
290
+                    'vat_rate'         => $details['vat_rate'],
291
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
292
+                    'tax'              => $details['tax'],
293
+                    'item_price'       => $details['item_price'],
294
+                    'custom_price'     => $details['custom_price'],
295
+                    'quantity'         => $details['quantity'],
296
+                    'discount'         => $details['discount'],
297
+                    'subtotal'         => $details['subtotal'],
298
+                    'price'            => $details['price'],
299
+                    'meta'             => $details['meta'],
300
+                    'fees'             => $details['fees'],
301
+                );
302
+
303
+                $item_columns = array_keys( $fields );
304
+
305
+                foreach ( $fields as $key => $val ) {
306
+                    if ( is_null( $val ) ) {
307
+                        $val = '';
308
+                    }
309
+                    $val = maybe_serialize( $val );
310
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
311
+                }
312
+
313
+                $fields = implode( ', ', $fields );
314
+                $item_rows[] = "($fields)";
315
+            }
316
+
317
+            $item_rows    = implode( ', ', $item_rows );
318
+            $item_columns = implode( ', ', $item_columns );
319
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
320
+        }
321
+
322
+        if ( empty( $invoice_rows ) ) {
323
+            return;
324
+        }
325
+
326
+        $invoice_rows = implode( ', ', $invoice_rows );
327
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
328
+
329
+    }
330
+
331
+    /**
332
+     * Migrates old customers to new table.
333
+     *
334
+     */
335
+    public static function migrate_old_customers() {
336
+        global $wpdb;
337
+
338
+        // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
339
+        $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
340
+
341
+        foreach ( $invoice_ids as $invoice_id ) {
342
+            $invoice = wpinv_get_invoice( $invoice_id );
343
+
344
+            if ( empty( $invoice ) ) {
345
+                continue;
346
+            }
347
+
348
+            // Fetch customer from the user ID.
349
+            $user_id = $invoice->get_user_id();
350
+
351
+            if ( empty( $user_id ) ) {
352
+                continue;
353
+            }
354
+
355
+            $customer = getpaid_get_customer_by_user_id( $user_id );
356
+
357
+            // Create if not exists.
358
+            if ( empty( $customer ) ) {
359
+                $customer = new GetPaid_Customer( 0 );
360
+                $customer->clone_user( $user_id );
361
+                $customer->save();
362
+            }
363
+
364
+            $invoice->set_customer_id( $customer->get_id() );
365
+            $invoice->save();
366
+        }
367
+
368
+    }
369
+
370
+    /**
371
+     * Migrates old invoices to new invoices.
372
+     *
373
+     */
374
+    public static function rename_gateways_label() {
375
+        global $wpdb;
376
+
377
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
378
+
379
+            $wpdb->update(
380
+                $wpdb->prefix . 'getpaid_invoices',
381
+                array( 'gateway' => $gateway ),
382
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
383
+                '%s',
384
+                '%s'
385
+            );
386
+
387
+        }
388
+    }
389
+
390
+    /**
391
+     * Returns the DB schema.
392
+     *
393
+     */
394
+    public static function get_db_schema() {
395
+        global $wpdb;
396
+
397
+        if ( ! empty( self::$schema ) ) {
398
+            return self::$schema;
399
+        }
400 400
 
401
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
401
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
402 402
 
403
-		$charset_collate = $wpdb->get_charset_collate();
403
+        $charset_collate = $wpdb->get_charset_collate();
404 404
 
405
-		$schema = array();
405
+        $schema = array();
406 406
 
407
-		// Subscriptions.
408
-		$schema['subscriptions'] = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions (
407
+        // Subscriptions.
408
+        $schema['subscriptions'] = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions (
409 409
 			id bigint(20) unsigned NOT NULL auto_increment,
410 410
 			customer_id bigint(20) NOT NULL,
411 411
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
 			KEY customer_and_status (customer_id, status)
429 429
 		  ) $charset_collate;";
430 430
 
431
-		// Invoices.
432
-		$schema['invoices'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoices (
431
+        // Invoices.
432
+        $schema['invoices'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoices (
433 433
 			post_id BIGINT(20) NOT NULL,
434 434
 			customer_id BIGINT(20) NOT NULL DEFAULT 0,
435 435
             `number` VARCHAR(100),
@@ -467,8 +467,8 @@  discard block
 block discarded – undo
467 467
 			KEY invoice_key (invoice_key)
468 468
 		  ) $charset_collate;";
469 469
 
470
-		// Invoice items.
471
-		$schema['items'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items (
470
+        // Invoice items.
471
+        $schema['items'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items (
472 472
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
473 473
             post_id BIGINT(20) NOT NULL,
474 474
             item_id BIGINT(20) NOT NULL,
@@ -490,8 +490,8 @@  discard block
 block discarded – undo
490 490
 			KEY post_id (post_id)
491 491
 		  ) $charset_collate;";
492 492
 
493
-		// Customers.
494
-		$schema['customers'] = "CREATE TABLE {$wpdb->prefix}getpaid_customers (
493
+        // Customers.
494
+        $schema['customers'] = "CREATE TABLE {$wpdb->prefix}getpaid_customers (
495 495
 			id BIGINT(20) NOT NULL AUTO_INCREMENT,
496 496
 			user_id BIGINT(20) NOT NULL,
497 497
 			email VARCHAR(100) NOT NULL,
@@ -501,38 +501,38 @@  discard block
 block discarded – undo
501 501
 			purchase_count BIGINT(20) NOT NULL DEFAULT 0,
502 502
 			";
503 503
 
504
-		// Add address fields.
505
-		foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) {
506
-			// Skip id, user_id and email.
507
-			if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
508
-				continue;
509
-			}
510
-
511
-			$field   = sanitize_key( $field );
512
-			$length  = 100;
513
-			$default = '';
514
-
515
-			// Country.
516
-			if ( 'country' === $field ) {
517
-				$length  = 2;
518
-				$default = wpinv_get_default_country();
519
-			}
520
-
521
-			// State.
522
-			if ( 'state' === $field ) {
523
-				$default = wpinv_get_default_state();
524
-			}
525
-
526
-			// Phone, zip.
527
-			if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
528
-				$length = 20;
529
-			}
530
-
531
-			$schema['customers'] .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',
504
+        // Add address fields.
505
+        foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) {
506
+            // Skip id, user_id and email.
507
+            if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
508
+                continue;
509
+            }
510
+
511
+            $field   = sanitize_key( $field );
512
+            $length  = 100;
513
+            $default = '';
514
+
515
+            // Country.
516
+            if ( 'country' === $field ) {
517
+                $length  = 2;
518
+                $default = wpinv_get_default_country();
519
+            }
520
+
521
+            // State.
522
+            if ( 'state' === $field ) {
523
+                $default = wpinv_get_default_state();
524
+            }
525
+
526
+            // Phone, zip.
527
+            if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
528
+                $length = 20;
529
+            }
530
+
531
+            $schema['customers'] .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',
532 532
 			";
533
-		}
533
+        }
534 534
 
535
-		$schema['customers'] .= "date_created DATETIME NOT NULL,
535
+        $schema['customers'] .= "date_created DATETIME NOT NULL,
536 536
 			date_modified DATETIME NOT NULL,
537 537
 			uuid VARCHAR(100) NOT NULL,
538 538
 			is_anonymized INT(2) NOT NULL DEFAULT 0,
@@ -542,8 +542,8 @@  discard block
 block discarded – undo
542 542
 			KEY email (email)
543 543
 		  ) $charset_collate;";
544 544
 
545
-		// Customer meta.
546
-		$schema['customer_meta'] = "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta (
545
+        // Customer meta.
546
+        $schema['customer_meta'] = "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta (
547 547
 			meta_id BIGINT(20) NOT NULL AUTO_INCREMENT,
548 548
 			customer_id BIGINT(20) NOT NULL,
549 549
 			meta_key VARCHAR(255) NOT NULL,
@@ -553,8 +553,8 @@  discard block
 block discarded – undo
553 553
 			KEY meta_key (meta_key(191))
554 554
 		  ) $charset_collate;";
555 555
 
556
-		// Anonymization Logs.
557
-		$schema['anonymization_logs'] = "CREATE TABLE {$wpdb->prefix}getpaid_anonymization_logs (
556
+        // Anonymization Logs.
557
+        $schema['anonymization_logs'] = "CREATE TABLE {$wpdb->prefix}getpaid_anonymization_logs (
558 558
 			log_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
559 559
 			user_id BIGINT(20) UNSIGNED NOT NULL,
560 560
 			action VARCHAR(50) NOT NULL,
@@ -568,75 +568,75 @@  discard block
 block discarded – undo
568 568
 			KEY timestamp (timestamp)
569 569
 		) $charset_collate;";
570 570
 
571
-		// Filter.
572
-		$schema = apply_filters( 'getpaid_db_schema', $schema );
573
-
574
-		self::$schema         = implode( "\n", array_values( $schema ) );
575
-		self::$schema_version = md5( sanitize_key( self::$schema ) );
576
-
577
-		return self::$schema;
578
-	}
579
-
580
-	/**
581
-	 * Returns the DB schema version.
582
-	 *
583
-	 */
584
-	public static function get_db_schema_version() {
585
-		if ( ! empty( self::$schema_version ) ) {
586
-			return self::$schema_version;
587
-		}
588
-
589
-		self::get_db_schema();
590
-
591
-		return self::$schema_version;
592
-	}
593
-
594
-	/**
595
-	 * Checks if the db schema is up to date.
596
-	 *
597
-	 * @return bool
598
-	 */
599
-	public static function is_db_schema_up_to_date() {
600
-		return self::get_db_schema_version() === get_option( 'getpaid_db_schema' );
601
-	}
602
-
603
-	/**
604
-	 * Set up the database tables which the plugin needs to function.
605
-	 */
606
-	public static function create_db_tables() {
607
-		global $wpdb;
608
-
609
-		$wpdb->hide_errors();
610
-
611
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
612
-
613
-		$schema = self::get_db_schema();
614
-
615
-		// If invoices table exists, rename key to invoice_key.
616
-		$invoices_table = "{$wpdb->prefix}getpaid_invoices";
617
-
618
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) {
619
-			$fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" );
620
-
621
-			foreach ( $fields as $field ) {
622
-				if ( 'key' === $field->Field ) {
623
-					$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" );
624
-					break;
625
-				}
626
-			}
627
-		}
628
-
629
-		dbDelta( $schema );
630
-		wp_cache_flush();
631
-		update_option( 'getpaid_db_schema', self::get_db_schema_version() );
632
-	}
633
-
634
-	/**
635
-	 * Creates tables if schema is not up to date.
636
-	 */
637
-	public static function maybe_create_db_tables() {
638
-		if ( ! self::is_db_schema_up_to_date() ) {
639
-			self::create_db_tables();
640
-		}
641
-	}
571
+        // Filter.
572
+        $schema = apply_filters( 'getpaid_db_schema', $schema );
573
+
574
+        self::$schema         = implode( "\n", array_values( $schema ) );
575
+        self::$schema_version = md5( sanitize_key( self::$schema ) );
576
+
577
+        return self::$schema;
578
+    }
579
+
580
+    /**
581
+     * Returns the DB schema version.
582
+     *
583
+     */
584
+    public static function get_db_schema_version() {
585
+        if ( ! empty( self::$schema_version ) ) {
586
+            return self::$schema_version;
587
+        }
588
+
589
+        self::get_db_schema();
590
+
591
+        return self::$schema_version;
592
+    }
593
+
594
+    /**
595
+     * Checks if the db schema is up to date.
596
+     *
597
+     * @return bool
598
+     */
599
+    public static function is_db_schema_up_to_date() {
600
+        return self::get_db_schema_version() === get_option( 'getpaid_db_schema' );
601
+    }
602
+
603
+    /**
604
+     * Set up the database tables which the plugin needs to function.
605
+     */
606
+    public static function create_db_tables() {
607
+        global $wpdb;
608
+
609
+        $wpdb->hide_errors();
610
+
611
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
612
+
613
+        $schema = self::get_db_schema();
614
+
615
+        // If invoices table exists, rename key to invoice_key.
616
+        $invoices_table = "{$wpdb->prefix}getpaid_invoices";
617
+
618
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) {
619
+            $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" );
620
+
621
+            foreach ( $fields as $field ) {
622
+                if ( 'key' === $field->Field ) {
623
+                    $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" );
624
+                    break;
625
+                }
626
+            }
627
+        }
628
+
629
+        dbDelta( $schema );
630
+        wp_cache_flush();
631
+        update_option( 'getpaid_db_schema', self::get_db_schema_version() );
632
+    }
633
+
634
+    /**
635
+     * Creates tables if schema is not up to date.
636
+     */
637
+    public static function maybe_create_db_tables() {
638
+        if ( ! self::is_db_schema_up_to_date() ) {
639
+            self::create_db_tables();
640
+        }
641
+    }
642 642
 }
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.0.2
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * The main installer/updater class.
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param string $upgrade_from The current invoicing version.
30 30
 	 */
31
-	public function upgrade_db( $upgrade_from ) {
31
+	public function upgrade_db($upgrade_from) {
32 32
 
33 33
 		// Save the current invoicing version.
34
-		update_option( 'wpinv_version', WPINV_VERSION );
34
+		update_option('wpinv_version', WPINV_VERSION);
35 35
 
36 36
 		// Setup the invoice Custom Post Type.
37 37
 		GetPaid_Post_Types::register_post_types();
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 		// Create any missing database tables.
52 52
 		$method = "upgrade_from_$upgrade_from";
53 53
 
54
-		$installed = get_option( 'gepaid_installed_on' );
54
+		$installed = get_option('gepaid_installed_on');
55 55
 
56
-		if ( empty( $installed ) ) {
57
-			update_option( 'gepaid_installed_on', time() );
56
+		if (empty($installed)) {
57
+			update_option('gepaid_installed_on', time());
58 58
 		}
59 59
 
60
-		if ( method_exists( $this, $method ) ) {
60
+		if (method_exists($this, $method)) {
61 61
 			$this->$method();
62 62
 		}
63 63
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	public function upgrade_from_0() {
71 71
 
72 72
 		// Save default tax rates.
73
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
73
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
74 74
 	}
75 75
 
76 76
 	/**
@@ -81,27 +81,27 @@  discard block
 block discarded – undo
81 81
 		global $wpdb;
82 82
 
83 83
 		// Invoices.
84
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
-		if ( ! empty( $results ) ) {
86
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
84
+		$results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
85
+		if (!empty($results)) {
86
+			$wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
87 87
 
88 88
 			// Clean post cache
89
-			foreach ( $results as $row ) {
90
-				clean_post_cache( $row->ID );
89
+			foreach ($results as $row) {
90
+				clean_post_cache($row->ID);
91 91
 			}
92 92
 		}
93 93
 
94 94
 		// Item meta key changes
95 95
 		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
-		$results = $wpdb->get_results( $query );
96
+		$results = $wpdb->get_results($query);
97 97
 
98
-		if ( ! empty( $results ) ) {
99
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
98
+		if (!empty($results)) {
99
+			$wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
100
+			$wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
101
+			$wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
102 102
 
103
-			foreach ( $results as $row ) {
104
-				clean_post_cache( $row->post_id );
103
+			foreach ($results as $row) {
104
+				clean_post_cache($row->post_id);
105 105
 			}
106 106
 		}
107 107
 
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 	 *
131 131
 	 */
132 132
 	public function add_capabilities() {
133
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
133
+		$GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing');
134 134
 	}
135 135
 
136 136
 	/**
137 137
 	 * Retreives GetPaid pages.
138 138
 	 *
139 139
 	 */
140
-	public static function get_pages( $filtered = false ) {
140
+	public static function get_pages($filtered = false) {
141 141
 		$gutenberg = getpaid_is_gutenberg();
142 142
 
143 143
 		return apply_filters(
@@ -145,41 +145,41 @@  discard block
 block discarded – undo
145 145
 			array(
146 146
 				// Checkout page.
147 147
 				'checkout_page' => array(
148
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
149
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
150
-					'content' => getpaid_page_content_checkout( $filtered, $gutenberg ),
148
+					'name'    => _x('gp-checkout', 'Page slug', 'invoicing'),
149
+					'title'   => _x('Checkout', 'Page title', 'invoicing'),
150
+					'content' => getpaid_page_content_checkout($filtered, $gutenberg),
151 151
 					'parent'  => ''
152 152
 				),
153 153
 
154 154
 				// Invoice history page.
155 155
 				'invoice_history_page' => array(
156
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
157
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
158
-					'content' => getpaid_page_content_invoice_history( $filtered, $gutenberg ),
156
+					'name'    => _x('gp-invoices', 'Page slug', 'invoicing'),
157
+					'title'   => _x('My Invoices', 'Page title', 'invoicing'),
158
+					'content' => getpaid_page_content_invoice_history($filtered, $gutenberg),
159 159
 					'parent'  => ''
160 160
 				),
161 161
 
162 162
 				// Success page content.
163 163
 				'success_page' => array(
164
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
165
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
166
-					'content' => getpaid_page_content_receipt( $filtered, $gutenberg ),
164
+					'name'    => _x('gp-receipt', 'Page slug', 'invoicing'),
165
+					'title'   => _x('Payment Confirmation', 'Page title', 'invoicing'),
166
+					'content' => getpaid_page_content_receipt($filtered, $gutenberg),
167 167
 					'parent'  => 'gp-checkout'
168 168
 				),
169 169
 
170 170
 				// Failure page content.
171 171
 				'failure_page' => array(
172
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
173
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
174
-					'content' => getpaid_page_content_failure( $filtered, $gutenberg ),
172
+					'name'    => _x('gp-transaction-failed', 'Page slug', 'invoicing'),
173
+					'title'   => _x('Transaction Failed', 'Page title', 'invoicing'),
174
+					'content' => getpaid_page_content_failure($filtered, $gutenberg),
175 175
 					'parent'  => 'gp-checkout'
176 176
 				),
177 177
 
178 178
 				// Subscriptions history page.
179 179
 				'invoice_subscription_page' => array(
180
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
181
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
182
-					'content' => getpaid_page_content_subscriptions( $filtered, $gutenberg ),
180
+					'name'    => _x('gp-subscriptions', 'Page slug', 'invoicing'),
181
+					'title'   => _x('My Subscriptions', 'Page title', 'invoicing'),
182
+					'content' => getpaid_page_content_subscriptions($filtered, $gutenberg),
183 183
 					'parent'  => ''
184 184
 				)
185 185
 			)
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 	 *
192 192
 	 */
193 193
 	public function create_pages() {
194
-		foreach ( self::get_pages() as $key => $page ) {
195
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
194
+		foreach (self::get_pages() as $key => $page) {
195
+			wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']);
196 196
 		}
197 197
 
198 198
 	}
@@ -206,32 +206,32 @@  discard block
 block discarded – undo
206 206
 
207 207
 		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
208 208
 		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
209
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
209
+		$migrated            = $wpdb->get_col("SELECT post_id FROM $invoices_table");
210 210
 		$invoices            = array_unique(
211 211
 			get_posts(
212 212
 				array(
213
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
213
+					'post_type'      => array('wpi_invoice', 'wpi_quote'),
214 214
 					'posts_per_page' => -1,
215 215
 					'fields'         => 'ids',
216
-					'post_status'    => array_keys( get_post_stati() ),
216
+					'post_status'    => array_keys(get_post_stati()),
217 217
 					'exclude'        => (array) $migrated,
218 218
 				)
219 219
 			)
220 220
 		);
221 221
 
222 222
 		// Abort if we do not have any invoices.
223
-		if ( empty( $invoices ) ) {
223
+		if (empty($invoices)) {
224 224
 			return;
225 225
 		}
226 226
 
227 227
 		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
228 228
 
229 229
 		$invoice_rows = array();
230
-		foreach ( $invoices as $invoice ) {
230
+		foreach ($invoices as $invoice) {
231 231
 
232
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
232
+			$invoice = new WPInv_Legacy_Invoice($invoice);
233 233
 
234
-			if ( empty( $invoice->ID ) ) {
234
+			if (empty($invoice->ID)) {
235 235
 				return;
236 236
 			}
237 237
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 				'post_id'            => $invoice->ID,
240 240
 				'number'             => $invoice->get_number(),
241 241
 				'key'                => $invoice->get_key(),
242
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
242
+				'type'               => str_replace('wpi_', '', $invoice->post_type),
243 243
 				'mode'               => $invoice->mode,
244 244
 				'user_ip'            => $invoice->get_ip(),
245 245
 				'first_name'         => $invoice->get_first_name(),
@@ -268,27 +268,27 @@  discard block
 block discarded – undo
268 268
 				'custom_meta'        => $invoice->payment_meta,
269 269
 			);
270 270
 
271
-			foreach ( $fields as $key => $val ) {
272
-				if ( is_null( $val ) ) {
271
+			foreach ($fields as $key => $val) {
272
+				if (is_null($val)) {
273 273
 					$val = '';
274 274
 				}
275
-				$val = maybe_serialize( $val );
276
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
275
+				$val = maybe_serialize($val);
276
+				$fields[$key] = $wpdb->prepare('%s', $val);
277 277
 			}
278 278
 
279
-			$fields = implode( ', ', $fields );
279
+			$fields = implode(', ', $fields);
280 280
 			$invoice_rows[] = "($fields)";
281 281
 
282 282
 			$item_rows    = array();
283 283
 			$item_columns = array();
284
-			foreach ( $invoice->get_cart_details() as $details ) {
284
+			foreach ($invoice->get_cart_details() as $details) {
285 285
 				$fields = array(
286 286
 					'post_id'          => $invoice->ID,
287 287
 					'item_id'          => $details['id'],
288 288
 					'item_name'        => $details['name'],
289
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
289
+					'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
290 290
 					'vat_rate'         => $details['vat_rate'],
291
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
291
+					'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
292 292
 					'tax'              => $details['tax'],
293 293
 					'item_price'       => $details['item_price'],
294 294
 					'custom_price'     => $details['custom_price'],
@@ -300,31 +300,31 @@  discard block
 block discarded – undo
300 300
 					'fees'             => $details['fees'],
301 301
 				);
302 302
 
303
-				$item_columns = array_keys( $fields );
303
+				$item_columns = array_keys($fields);
304 304
 
305
-				foreach ( $fields as $key => $val ) {
306
-					if ( is_null( $val ) ) {
305
+				foreach ($fields as $key => $val) {
306
+					if (is_null($val)) {
307 307
 						$val = '';
308 308
 					}
309
-					$val = maybe_serialize( $val );
310
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
309
+					$val = maybe_serialize($val);
310
+					$fields[$key] = $wpdb->prepare('%s', $val);
311 311
 				}
312 312
 
313
-				$fields = implode( ', ', $fields );
313
+				$fields = implode(', ', $fields);
314 314
 				$item_rows[] = "($fields)";
315 315
 			}
316 316
 
317
-			$item_rows    = implode( ', ', $item_rows );
318
-			$item_columns = implode( ', ', $item_columns );
319
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
317
+			$item_rows    = implode(', ', $item_rows);
318
+			$item_columns = implode(', ', $item_columns);
319
+			$wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
320 320
 		}
321 321
 
322
-		if ( empty( $invoice_rows ) ) {
322
+		if (empty($invoice_rows)) {
323 323
 			return;
324 324
 		}
325 325
 
326
-		$invoice_rows = implode( ', ', $invoice_rows );
327
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
326
+		$invoice_rows = implode(', ', $invoice_rows);
327
+		$wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
328 328
 
329 329
 	}
330 330
 
@@ -336,32 +336,32 @@  discard block
 block discarded – undo
336 336
 		global $wpdb;
337 337
 
338 338
 		// Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
339
-		$invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
339
+		$invoice_ids = $wpdb->get_col("SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL");
340 340
 
341
-		foreach ( $invoice_ids as $invoice_id ) {
342
-			$invoice = wpinv_get_invoice( $invoice_id );
341
+		foreach ($invoice_ids as $invoice_id) {
342
+			$invoice = wpinv_get_invoice($invoice_id);
343 343
 
344
-			if ( empty( $invoice ) ) {
344
+			if (empty($invoice)) {
345 345
 				continue;
346 346
 			}
347 347
 
348 348
 			// Fetch customer from the user ID.
349 349
 			$user_id = $invoice->get_user_id();
350 350
 
351
-			if ( empty( $user_id ) ) {
351
+			if (empty($user_id)) {
352 352
 				continue;
353 353
 			}
354 354
 
355
-			$customer = getpaid_get_customer_by_user_id( $user_id );
355
+			$customer = getpaid_get_customer_by_user_id($user_id);
356 356
 
357 357
 			// Create if not exists.
358
-			if ( empty( $customer ) ) {
359
-				$customer = new GetPaid_Customer( 0 );
360
-				$customer->clone_user( $user_id );
358
+			if (empty($customer)) {
359
+				$customer = new GetPaid_Customer(0);
360
+				$customer->clone_user($user_id);
361 361
 				$customer->save();
362 362
 			}
363 363
 
364
-			$invoice->set_customer_id( $customer->get_id() );
364
+			$invoice->set_customer_id($customer->get_id());
365 365
 			$invoice->save();
366 366
 		}
367 367
 
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
 	public static function rename_gateways_label() {
375 375
 		global $wpdb;
376 376
 
377
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
377
+		foreach (array_keys(wpinv_get_payment_gateways()) as $gateway) {
378 378
 
379 379
 			$wpdb->update(
380 380
 				$wpdb->prefix . 'getpaid_invoices',
381
-				array( 'gateway' => $gateway ),
382
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
381
+				array('gateway' => $gateway),
382
+				array('gateway' => wpinv_get_gateway_admin_label($gateway)),
383 383
 				'%s',
384 384
 				'%s'
385 385
 			);
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 	public static function get_db_schema() {
395 395
 		global $wpdb;
396 396
 
397
-		if ( ! empty( self::$schema ) ) {
397
+		if (!empty(self::$schema)) {
398 398
 			return self::$schema;
399 399
 		}
400 400
 
@@ -502,29 +502,29 @@  discard block
 block discarded – undo
502 502
 			";
503 503
 
504 504
 		// Add address fields.
505
-		foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) {
505
+		foreach (array_keys(getpaid_user_address_fields(true)) as $field) {
506 506
 			// Skip id, user_id and email.
507
-			if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
507
+			if (in_array($field, array('id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid'), true)) {
508 508
 				continue;
509 509
 			}
510 510
 
511
-			$field   = sanitize_key( $field );
511
+			$field   = sanitize_key($field);
512 512
 			$length  = 100;
513 513
 			$default = '';
514 514
 
515 515
 			// Country.
516
-			if ( 'country' === $field ) {
516
+			if ('country' === $field) {
517 517
 				$length  = 2;
518 518
 				$default = wpinv_get_default_country();
519 519
 			}
520 520
 
521 521
 			// State.
522
-			if ( 'state' === $field ) {
522
+			if ('state' === $field) {
523 523
 				$default = wpinv_get_default_state();
524 524
 			}
525 525
 
526 526
 			// Phone, zip.
527
-			if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
527
+			if (in_array($field, array('phone', 'zip'), true)) {
528 528
 				$length = 20;
529 529
 			}
530 530
 
@@ -569,10 +569,10 @@  discard block
 block discarded – undo
569 569
 		) $charset_collate;";
570 570
 
571 571
 		// Filter.
572
-		$schema = apply_filters( 'getpaid_db_schema', $schema );
572
+		$schema = apply_filters('getpaid_db_schema', $schema);
573 573
 
574
-		self::$schema         = implode( "\n", array_values( $schema ) );
575
-		self::$schema_version = md5( sanitize_key( self::$schema ) );
574
+		self::$schema         = implode("\n", array_values($schema));
575
+		self::$schema_version = md5(sanitize_key(self::$schema));
576 576
 
577 577
 		return self::$schema;
578 578
 	}
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 	 *
583 583
 	 */
584 584
 	public static function get_db_schema_version() {
585
-		if ( ! empty( self::$schema_version ) ) {
585
+		if (!empty(self::$schema_version)) {
586 586
 			return self::$schema_version;
587 587
 		}
588 588
 
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
 	 * @return bool
598 598
 	 */
599 599
 	public static function is_db_schema_up_to_date() {
600
-		return self::get_db_schema_version() === get_option( 'getpaid_db_schema' );
600
+		return self::get_db_schema_version() === get_option('getpaid_db_schema');
601 601
 	}
602 602
 
603 603
 	/**
@@ -615,27 +615,27 @@  discard block
 block discarded – undo
615 615
 		// If invoices table exists, rename key to invoice_key.
616 616
 		$invoices_table = "{$wpdb->prefix}getpaid_invoices";
617 617
 
618
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) {
619
-			$fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" );
618
+		if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'") === $invoices_table) {
619
+			$fields = $wpdb->get_results("SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices");
620 620
 
621
-			foreach ( $fields as $field ) {
622
-				if ( 'key' === $field->Field ) {
623
-					$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" );
621
+			foreach ($fields as $field) {
622
+				if ('key' === $field->Field) {
623
+					$wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)");
624 624
 					break;
625 625
 				}
626 626
 			}
627 627
 		}
628 628
 
629
-		dbDelta( $schema );
629
+		dbDelta($schema);
630 630
 		wp_cache_flush();
631
-		update_option( 'getpaid_db_schema', self::get_db_schema_version() );
631
+		update_option('getpaid_db_schema', self::get_db_schema_version());
632 632
 	}
633 633
 
634 634
 	/**
635 635
 	 * Creates tables if schema is not up to date.
636 636
 	 */
637 637
 	public static function maybe_create_db_tables() {
638
-		if ( ! self::is_db_schema_up_to_date() ) {
638
+		if (!self::is_db_schema_up_to_date()) {
639 639
 			self::create_db_tables();
640 640
 		}
641 641
 	}
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 2 patches
Indentation   +848 added lines, -848 removed lines patch added patch discarded remove patch
@@ -13,755 +13,755 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
-
30
-		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-		add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
-		add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
-
36
-		// Items table columns.
37
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
-
44
-		// Payment forms columns.
45
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
-
49
-		// Discount table columns.
50
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
-
53
-		// Deleting posts.
54
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
-
57
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
-	}
59
-
60
-	/**
61
-	 * Post updated messages.
62
-	 */
63
-	public static function post_updated_messages( $messages ) {
64
-		global $post;
65
-
66
-		$messages['wpi_discount'] = array(
67
-			0  => '',
68
-			1  => __( 'Discount updated.', 'invoicing' ),
69
-			2  => __( 'Custom field updated.', 'invoicing' ),
70
-			3  => __( 'Custom field deleted.', 'invoicing' ),
71
-			4  => __( 'Discount updated.', 'invoicing' ),
72
-			5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
-			6  => __( 'Discount updated.', 'invoicing' ),
74
-			7  => __( 'Discount saved.', 'invoicing' ),
75
-			8  => __( 'Discount submitted.', 'invoicing' ),
76
-			9  => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
-			10 => __( 'Discount draft updated.', 'invoicing' ),
78
-		);
79
-
80
-		$messages['wpi_payment_form'] = array(
81
-			0  => '',
82
-			1  => __( 'Payment Form updated.', 'invoicing' ),
83
-			2  => __( 'Custom field updated.', 'invoicing' ),
84
-			3  => __( 'Custom field deleted.', 'invoicing' ),
85
-			4  => __( 'Payment Form updated.', 'invoicing' ),
86
-			5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
-			6  => __( 'Payment Form updated.', 'invoicing' ),
88
-			7  => __( 'Payment Form saved.', 'invoicing' ),
89
-			8  => __( 'Payment Form submitted.', 'invoicing' ),
90
-			9  => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
-			10 => __( 'Payment Form draft updated.', 'invoicing' ),
92
-		);
93
-
94
-		return $messages;
95
-
96
-	}
97
-
98
-	/**
99
-	 * Post row actions.
100
-	 */
101
-	public static function post_row_actions( $actions, $post ) {
102
-
103
-		$post = get_post( $post );
104
-
105
-		// We do not want to edit the default payment form.
106
-		if ( 'wpi_payment_form' == $post->post_type ) {
107
-
108
-			if ( wpinv_get_default_payment_form() === $post->ID ) {
109
-				unset( $actions['trash'] );
110
-				unset( $actions['inline hide-if-no-js'] );
111
-			}
112
-
113
-			$actions['duplicate'] = sprintf(
114
-				'<a href="%1$s">%2$s</a>',
115
-				esc_url(
116
-					wp_nonce_url(
117
-						add_query_arg(
118
-							array(
119
-								'getpaid-admin-action' => 'duplicate_form',
120
-								'form_id'              => $post->ID,
121
-							)
122
-						),
123
-						'getpaid-nonce',
124
-						'getpaid-nonce'
125
-					)
126
-				),
127
-				esc_html( __( 'Duplicate', 'invoicing' ) )
128
-			);
129
-
130
-			$actions['reset'] = sprintf(
131
-				'<a href="%1$s" style="color: #800">%2$s</a>',
132
-				esc_url(
133
-					wp_nonce_url(
134
-						add_query_arg(
135
-							array(
136
-								'getpaid-admin-action' => 'reset_form_stats',
137
-								'form_id'              => $post->ID,
138
-							)
139
-						),
140
-						'getpaid-nonce',
141
-						'getpaid-nonce'
142
-					)
143
-				),
144
-				esc_html( __( 'Reset Stats', 'invoicing' ) )
145
-			);
146
-		}
147
-
148
-		// Link to item payment form.
149
-		if ( 'wpi_item' == $post->post_type ) {
150
-			if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) {
151
-				$actions['buy'] = sprintf(
152
-					'<a href="%1$s">%2$s</a>',
153
-					esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ),
154
-					esc_html( __( 'Buy', 'invoicing' ) )
155
-				);
156
-			}
157
-		}
158
-
159
-		return $actions;
160
-	}
161
-
162
-	/**
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
19
+
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
22
+
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
+
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
29
+
30
+        // Invoice table columns.
31
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
+        add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
+        add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
35
+
36
+        // Items table columns.
37
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
43
+
44
+        // Payment forms columns.
45
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
48
+
49
+        // Discount table columns.
50
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
+        add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
52
+
53
+        // Deleting posts.
54
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
56
+
57
+        add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
58
+    }
59
+
60
+    /**
61
+     * Post updated messages.
62
+     */
63
+    public static function post_updated_messages( $messages ) {
64
+        global $post;
65
+
66
+        $messages['wpi_discount'] = array(
67
+            0  => '',
68
+            1  => __( 'Discount updated.', 'invoicing' ),
69
+            2  => __( 'Custom field updated.', 'invoicing' ),
70
+            3  => __( 'Custom field deleted.', 'invoicing' ),
71
+            4  => __( 'Discount updated.', 'invoicing' ),
72
+            5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
+            6  => __( 'Discount updated.', 'invoicing' ),
74
+            7  => __( 'Discount saved.', 'invoicing' ),
75
+            8  => __( 'Discount submitted.', 'invoicing' ),
76
+            9  => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
+            10 => __( 'Discount draft updated.', 'invoicing' ),
78
+        );
79
+
80
+        $messages['wpi_payment_form'] = array(
81
+            0  => '',
82
+            1  => __( 'Payment Form updated.', 'invoicing' ),
83
+            2  => __( 'Custom field updated.', 'invoicing' ),
84
+            3  => __( 'Custom field deleted.', 'invoicing' ),
85
+            4  => __( 'Payment Form updated.', 'invoicing' ),
86
+            5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
+            6  => __( 'Payment Form updated.', 'invoicing' ),
88
+            7  => __( 'Payment Form saved.', 'invoicing' ),
89
+            8  => __( 'Payment Form submitted.', 'invoicing' ),
90
+            9  => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
+            10 => __( 'Payment Form draft updated.', 'invoicing' ),
92
+        );
93
+
94
+        return $messages;
95
+
96
+    }
97
+
98
+    /**
99
+     * Post row actions.
100
+     */
101
+    public static function post_row_actions( $actions, $post ) {
102
+
103
+        $post = get_post( $post );
104
+
105
+        // We do not want to edit the default payment form.
106
+        if ( 'wpi_payment_form' == $post->post_type ) {
107
+
108
+            if ( wpinv_get_default_payment_form() === $post->ID ) {
109
+                unset( $actions['trash'] );
110
+                unset( $actions['inline hide-if-no-js'] );
111
+            }
112
+
113
+            $actions['duplicate'] = sprintf(
114
+                '<a href="%1$s">%2$s</a>',
115
+                esc_url(
116
+                    wp_nonce_url(
117
+                        add_query_arg(
118
+                            array(
119
+                                'getpaid-admin-action' => 'duplicate_form',
120
+                                'form_id'              => $post->ID,
121
+                            )
122
+                        ),
123
+                        'getpaid-nonce',
124
+                        'getpaid-nonce'
125
+                    )
126
+                ),
127
+                esc_html( __( 'Duplicate', 'invoicing' ) )
128
+            );
129
+
130
+            $actions['reset'] = sprintf(
131
+                '<a href="%1$s" style="color: #800">%2$s</a>',
132
+                esc_url(
133
+                    wp_nonce_url(
134
+                        add_query_arg(
135
+                            array(
136
+                                'getpaid-admin-action' => 'reset_form_stats',
137
+                                'form_id'              => $post->ID,
138
+                            )
139
+                        ),
140
+                        'getpaid-nonce',
141
+                        'getpaid-nonce'
142
+                    )
143
+                ),
144
+                esc_html( __( 'Reset Stats', 'invoicing' ) )
145
+            );
146
+        }
147
+
148
+        // Link to item payment form.
149
+        if ( 'wpi_item' == $post->post_type ) {
150
+            if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) {
151
+                $actions['buy'] = sprintf(
152
+                    '<a href="%1$s">%2$s</a>',
153
+                    esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ),
154
+                    esc_html( __( 'Buy', 'invoicing' ) )
155
+                );
156
+            }
157
+        }
158
+
159
+        return $actions;
160
+    }
161
+
162
+    /**
163 163
      * Remove bulk edit option from admin side quote listing
164 164
      *
165 165
      * @since    1.0.0
166 166
      * @param array $actions post actions
167
-	 * @param WP_Post $post
167
+     * @param WP_Post $post
168 168
      * @return array $actions actions without edit option
169 169
      */
170 170
     public static function filter_invoice_row_actions( $actions, $post ) {
171 171
 
172 172
         if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
173 173
 
174
-			$actions = array();
175
-			$invoice = new WPInv_Invoice( $post );
176
-
177
-			$actions['edit'] = sprintf(
178
-				'<a href="%1$s">%2$s</a>',
179
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
180
-				esc_html( __( 'Edit', 'invoicing' ) )
181
-			);
182
-
183
-			if ( ! $invoice->is_draft() ) {
184
-
185
-				$actions['view'] = sprintf(
186
-					'<a href="%1$s">%2$s</a>',
187
-					esc_url( $invoice->get_view_url() ),
188
-					sprintf(
189
-						// translators: %s is the invoice type
190
-						esc_html__( 'View %s', 'invoicing' ),
191
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
192
-					)
193
-				);
194
-
195
-				$actions['send'] = sprintf(
196
-					'<a href="%1$s">%2$s</a>',
197
-					esc_url(
198
-						wp_nonce_url(
199
-							add_query_arg(
200
-								array(
201
-									'getpaid-admin-action' => 'send_invoice',
202
-									'invoice_id'           => $invoice->get_id(),
203
-								)
204
-							),
205
-							'getpaid-nonce',
206
-							'getpaid-nonce'
207
-						)
208
-					),
209
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
210
-				);
211
-
212
-			}
213
-
214
-			$actions['duplicate'] = sprintf(
215
-				'<a href="%1$s">%2$s</a>',
216
-				esc_url(
217
-					wp_nonce_url(
218
-						add_query_arg(
219
-							array(
220
-								'getpaid-admin-action' => 'duplicate_invoice',
221
-								'invoice_id'           => $post->ID,
222
-							)
223
-						),
224
-						'getpaid-nonce',
225
-						'getpaid-nonce'
226
-					)
227
-				),
228
-				esc_html( __( 'Duplicate', 'invoicing' ) )
229
-			);
174
+            $actions = array();
175
+            $invoice = new WPInv_Invoice( $post );
176
+
177
+            $actions['edit'] = sprintf(
178
+                '<a href="%1$s">%2$s</a>',
179
+                esc_url( get_edit_post_link( $invoice->get_id() ) ),
180
+                esc_html( __( 'Edit', 'invoicing' ) )
181
+            );
182
+
183
+            if ( ! $invoice->is_draft() ) {
184
+
185
+                $actions['view'] = sprintf(
186
+                    '<a href="%1$s">%2$s</a>',
187
+                    esc_url( $invoice->get_view_url() ),
188
+                    sprintf(
189
+                        // translators: %s is the invoice type
190
+                        esc_html__( 'View %s', 'invoicing' ),
191
+                        getpaid_get_post_type_label( $invoice->get_post_type(), false )
192
+                    )
193
+                );
194
+
195
+                $actions['send'] = sprintf(
196
+                    '<a href="%1$s">%2$s</a>',
197
+                    esc_url(
198
+                        wp_nonce_url(
199
+                            add_query_arg(
200
+                                array(
201
+                                    'getpaid-admin-action' => 'send_invoice',
202
+                                    'invoice_id'           => $invoice->get_id(),
203
+                                )
204
+                            ),
205
+                            'getpaid-nonce',
206
+                            'getpaid-nonce'
207
+                        )
208
+                    ),
209
+                    esc_html( __( 'Send to Customer', 'invoicing' ) )
210
+                );
211
+
212
+            }
213
+
214
+            $actions['duplicate'] = sprintf(
215
+                '<a href="%1$s">%2$s</a>',
216
+                esc_url(
217
+                    wp_nonce_url(
218
+                        add_query_arg(
219
+                            array(
220
+                                'getpaid-admin-action' => 'duplicate_invoice',
221
+                                'invoice_id'           => $post->ID,
222
+                            )
223
+                        ),
224
+                        'getpaid-nonce',
225
+                        'getpaid-nonce'
226
+                    )
227
+                ),
228
+                esc_html( __( 'Duplicate', 'invoicing' ) )
229
+            );
230 230
 
231 231
         }
232 232
 
233 233
         return $actions;
234
-	}
235
-
236
-	/**
237
-	 * Returns an array of invoice table columns.
238
-	 */
239
-	public static function invoice_columns( $columns ) {
240
-
241
-		$columns = array(
242
-			'cb'           => $columns['cb'],
243
-			'number'       => __( 'Invoice', 'invoicing' ),
244
-			'customer'     => __( 'Customer', 'invoicing' ),
245
-			'invoice_date' => __( 'Created', 'invoicing' ),
246
-			'payment_date' => __( 'Completed', 'invoicing' ),
247
-			'amount'       => __( 'Amount', 'invoicing' ),
248
-			'recurring'    => __( 'Recurring', 'invoicing' ),
249
-			'status'       => __( 'Status', 'invoicing' ),
250
-		);
251
-
252
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
253
-	}
254
-
255
-	/**
256
-	 * Displays invoice table columns.
257
-	 */
258
-	public static function display_invoice_columns( $column_name, $post_id ) {
259
-
260
-		$invoice = new WPInv_Invoice( $post_id );
261
-
262
-		switch ( $column_name ) {
263
-
264
-			case 'invoice_date':
265
-				$date_time = esc_attr( $invoice->get_created_date() );
266
-				$date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
267
-				echo wp_kses_post( "<span title='$date_time'>$date</span>" );
268
-				break;
269
-
270
-			case 'payment_date':
271
-				if ( $invoice->is_paid() || $invoice->is_refunded() ) {
272
-					$date_time = esc_attr( $invoice->get_completed_date() );
273
-					$date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
274
-					echo wp_kses_post( "<span title='$date_time'>$date</span>" );
275
-
276
-					if ( $_gateway = $invoice->get_gateway() ) {
277
-						$gateway_label = wpinv_get_gateway_admin_label( $_gateway );
278
-
279
-						if ( $transaction_url = $invoice->get_transaction_url() ) {
280
-							$gateway_label = '<a href="' . esc_url( $transaction_url ) . '" target="_blank" title="' . esc_attr__( 'Open transaction link', 'invoicing' ) . '">' . $gateway_label . '</a>';
281
-						}
282
-
283
-						$gateway = '<small class="meta bsui"><span class="fs-xs text-muted fst-normal">' . wp_sprintf( _x( 'Via %s', 'Paid via gateway', 'invoicing' ), $gateway_label ) . '</span></small>';
284
-					} else {
285
-						$gateway = '';
286
-					}
287
-
288
-					$gateway = apply_filters( 'getpaid_admin_invoices_list_table_gateway', $gateway, $invoice );
289
-
290
-					if ( $gateway ) {
291
-						echo wp_kses_post( $gateway ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
292
-					}
293
-				} else {
294
-					echo '&mdash;';
295
-				}
296
-
297
-				break;
298
-
299
-			case 'amount':
300
-				$amount = $invoice->get_total();
301
-				$formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) );
302
-
303
-				if ( $invoice->is_refunded() ) {
304
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
305
-					echo wp_kses_post( "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>" );
306
-				} else {
307
-
308
-					$discount = $invoice->get_total_discount();
309
-
310
-					if ( ! empty( $discount ) ) {
311
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
312
-						echo wp_kses_post( "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>" );
313
-					} else {
314
-						echo wp_kses_post( $formated_amount );
315
-					}
316
-				}
317
-
318
-				break;
319
-
320
-			case 'status':
321
-				$status = esc_html( $invoice->get_status() );
322
-
323
-				// If it is paid, show the gateway title.
324
-				if ( $invoice->is_paid() ) {
325
-					$gateway = esc_html( $invoice->get_gateway_title() );
326
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
327
-
328
-					echo wp_kses_post( "<span class='bsui wpi-help-tip getpaid-invoice-statuss $status' title='$gateway'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" );
329
-				} else {
330
-					echo wp_kses_post( "<span class='bsui getpaid-invoice-statuss $status'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" );
331
-				}
332
-
333
-				// If it is not paid, display the overdue and view status.
334
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
335
-
336
-					// Invoice view status.
337
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
338
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>';
339
-					} else {
340
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>';
341
-					}
342
-
343
-					// Display the overview status.
344
-					if ( wpinv_get_option( 'overdue_active' ) ) {
345
-						$due_date = $invoice->get_due_date();
346
-						$fomatted = getpaid_format_date( $due_date );
347
-
348
-						if ( ! empty( $fomatted ) ) {
349
-							$date = wp_sprintf(
350
-								// translators: %s is the due date.
351
-								__( 'Due %s', 'invoicing' ),
352
-								$fomatted
353
-							);
354
-							echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" );
355
-						}
356
-					}
357
-				}
358
-
359
-				break;
360
-
361
-			case 'recurring':
362
-				if ( $invoice->is_recurring() ) {
363
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
364
-				} else {
365
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
366
-				}
367
-				break;
368
-
369
-			case 'number':
370
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
371
-				$invoice_number  = esc_html( $invoice->get_number() );
372
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
373
-
374
-				echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" );
375
-
376
-				do_action( 'getpaid_admin_table_invoice_number_column', $invoice );
377
-				break;
378
-
379
-			case 'customer':
380
-				$customer_name = $invoice->get_user_full_name();
381
-
382
-				if ( empty( $customer_name ) ) {
383
-					$customer_name = $invoice->get_email();
384
-				}
385
-
386
-				if ( ! empty( $customer_name ) ) {
387
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
388
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
389
-					echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" );
390
-				} else {
391
-					echo '<div>&mdash;</div>';
392
-				}
393
-
394
-				break;
395
-
396
-		}
397
-
398
-	}
399
-
400
-	/**
401
-	 * Displays invoice bulk actions.
402
-	 */
403
-	public static function invoice_bulk_actions( $actions ) {
404
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
405
-		return $actions;
406
-	}
407
-
408
-	/**
409
-	 * Processes invoice bulk actions.
410
-	 */
411
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
412
-
413
-		if ( 'resend-invoice' === $action ) {
414
-			foreach ( $post_ids as $post_id ) {
415
-				getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
416
-			}
417
-		}
418
-
419
-		return $redirect_url;
420
-
421
-	}
422
-
423
-	/**
424
-	 * Returns an array of payment forms table columns.
425
-	 */
426
-	public static function payment_form_columns( $columns ) {
427
-
428
-		$columns = array(
429
-			'cb'        => $columns['cb'],
430
-			'title'     => __( 'Name', 'invoicing' ),
431
-			'shortcode' => __( 'Shortcode', 'invoicing' ),
432
-			'earnings'  => __( 'Revenue', 'invoicing' ),
433
-			'refunds'   => __( 'Refunded', 'invoicing' ),
434
-			'items'     => __( 'Items', 'invoicing' ),
435
-			'date'      => __( 'Date', 'invoicing' ),
436
-		);
437
-
438
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
439
-
440
-	}
441
-
442
-	/**
443
-	 * Displays payment form table columns.
444
-	 */
445
-	public static function display_payment_form_columns( $column_name, $post_id ) {
446
-
447
-		// Retrieve the payment form.
448
-		$form = new GetPaid_Payment_Form( $post_id );
449
-
450
-		switch ( $column_name ) {
451
-
452
-			case 'earnings':
453
-				echo wp_kses_post( wpinv_price( $form->get_earned() ) );
454
-				break;
455
-
456
-			case 'refunds':
457
-				echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
458
-				break;
459
-
460
-			case 'refunds':
461
-				echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
462
-				break;
463
-
464
-			case 'shortcode':
465
-				if ( $form->is_default() ) {
466
-					echo '&mdash;';
467
-				} else {
468
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
469
-				}
470
-
471
-				break;
234
+    }
235
+
236
+    /**
237
+     * Returns an array of invoice table columns.
238
+     */
239
+    public static function invoice_columns( $columns ) {
240
+
241
+        $columns = array(
242
+            'cb'           => $columns['cb'],
243
+            'number'       => __( 'Invoice', 'invoicing' ),
244
+            'customer'     => __( 'Customer', 'invoicing' ),
245
+            'invoice_date' => __( 'Created', 'invoicing' ),
246
+            'payment_date' => __( 'Completed', 'invoicing' ),
247
+            'amount'       => __( 'Amount', 'invoicing' ),
248
+            'recurring'    => __( 'Recurring', 'invoicing' ),
249
+            'status'       => __( 'Status', 'invoicing' ),
250
+        );
251
+
252
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
253
+    }
254
+
255
+    /**
256
+     * Displays invoice table columns.
257
+     */
258
+    public static function display_invoice_columns( $column_name, $post_id ) {
259
+
260
+        $invoice = new WPInv_Invoice( $post_id );
261
+
262
+        switch ( $column_name ) {
263
+
264
+            case 'invoice_date':
265
+                $date_time = esc_attr( $invoice->get_created_date() );
266
+                $date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
267
+                echo wp_kses_post( "<span title='$date_time'>$date</span>" );
268
+                break;
269
+
270
+            case 'payment_date':
271
+                if ( $invoice->is_paid() || $invoice->is_refunded() ) {
272
+                    $date_time = esc_attr( $invoice->get_completed_date() );
273
+                    $date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
274
+                    echo wp_kses_post( "<span title='$date_time'>$date</span>" );
275
+
276
+                    if ( $_gateway = $invoice->get_gateway() ) {
277
+                        $gateway_label = wpinv_get_gateway_admin_label( $_gateway );
278
+
279
+                        if ( $transaction_url = $invoice->get_transaction_url() ) {
280
+                            $gateway_label = '<a href="' . esc_url( $transaction_url ) . '" target="_blank" title="' . esc_attr__( 'Open transaction link', 'invoicing' ) . '">' . $gateway_label . '</a>';
281
+                        }
282
+
283
+                        $gateway = '<small class="meta bsui"><span class="fs-xs text-muted fst-normal">' . wp_sprintf( _x( 'Via %s', 'Paid via gateway', 'invoicing' ), $gateway_label ) . '</span></small>';
284
+                    } else {
285
+                        $gateway = '';
286
+                    }
287
+
288
+                    $gateway = apply_filters( 'getpaid_admin_invoices_list_table_gateway', $gateway, $invoice );
289
+
290
+                    if ( $gateway ) {
291
+                        echo wp_kses_post( $gateway ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
292
+                    }
293
+                } else {
294
+                    echo '&mdash;';
295
+                }
296
+
297
+                break;
298
+
299
+            case 'amount':
300
+                $amount = $invoice->get_total();
301
+                $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) );
302
+
303
+                if ( $invoice->is_refunded() ) {
304
+                    $refunded_amount = wpinv_price( 0, $invoice->get_currency() );
305
+                    echo wp_kses_post( "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>" );
306
+                } else {
307
+
308
+                    $discount = $invoice->get_total_discount();
309
+
310
+                    if ( ! empty( $discount ) ) {
311
+                        $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
312
+                        echo wp_kses_post( "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>" );
313
+                    } else {
314
+                        echo wp_kses_post( $formated_amount );
315
+                    }
316
+                }
317
+
318
+                break;
319
+
320
+            case 'status':
321
+                $status = esc_html( $invoice->get_status() );
322
+
323
+                // If it is paid, show the gateway title.
324
+                if ( $invoice->is_paid() ) {
325
+                    $gateway = esc_html( $invoice->get_gateway_title() );
326
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
327
+
328
+                    echo wp_kses_post( "<span class='bsui wpi-help-tip getpaid-invoice-statuss $status' title='$gateway'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" );
329
+                } else {
330
+                    echo wp_kses_post( "<span class='bsui getpaid-invoice-statuss $status'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" );
331
+                }
332
+
333
+                // If it is not paid, display the overdue and view status.
334
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
335
+
336
+                    // Invoice view status.
337
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
338
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>';
339
+                    } else {
340
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>';
341
+                    }
342
+
343
+                    // Display the overview status.
344
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
345
+                        $due_date = $invoice->get_due_date();
346
+                        $fomatted = getpaid_format_date( $due_date );
347
+
348
+                        if ( ! empty( $fomatted ) ) {
349
+                            $date = wp_sprintf(
350
+                                // translators: %s is the due date.
351
+                                __( 'Due %s', 'invoicing' ),
352
+                                $fomatted
353
+                            );
354
+                            echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" );
355
+                        }
356
+                    }
357
+                }
358
+
359
+                break;
360
+
361
+            case 'recurring':
362
+                if ( $invoice->is_recurring() ) {
363
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
364
+                } else {
365
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
366
+                }
367
+                break;
368
+
369
+            case 'number':
370
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
371
+                $invoice_number  = esc_html( $invoice->get_number() );
372
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
373
+
374
+                echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" );
375
+
376
+                do_action( 'getpaid_admin_table_invoice_number_column', $invoice );
377
+                break;
378
+
379
+            case 'customer':
380
+                $customer_name = $invoice->get_user_full_name();
381
+
382
+                if ( empty( $customer_name ) ) {
383
+                    $customer_name = $invoice->get_email();
384
+                }
385
+
386
+                if ( ! empty( $customer_name ) ) {
387
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
388
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
389
+                    echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" );
390
+                } else {
391
+                    echo '<div>&mdash;</div>';
392
+                }
393
+
394
+                break;
395
+
396
+        }
397
+
398
+    }
399
+
400
+    /**
401
+     * Displays invoice bulk actions.
402
+     */
403
+    public static function invoice_bulk_actions( $actions ) {
404
+        $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
405
+        return $actions;
406
+    }
407
+
408
+    /**
409
+     * Processes invoice bulk actions.
410
+     */
411
+    public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
412
+
413
+        if ( 'resend-invoice' === $action ) {
414
+            foreach ( $post_ids as $post_id ) {
415
+                getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
416
+            }
417
+        }
418
+
419
+        return $redirect_url;
420
+
421
+    }
422
+
423
+    /**
424
+     * Returns an array of payment forms table columns.
425
+     */
426
+    public static function payment_form_columns( $columns ) {
427
+
428
+        $columns = array(
429
+            'cb'        => $columns['cb'],
430
+            'title'     => __( 'Name', 'invoicing' ),
431
+            'shortcode' => __( 'Shortcode', 'invoicing' ),
432
+            'earnings'  => __( 'Revenue', 'invoicing' ),
433
+            'refunds'   => __( 'Refunded', 'invoicing' ),
434
+            'items'     => __( 'Items', 'invoicing' ),
435
+            'date'      => __( 'Date', 'invoicing' ),
436
+        );
437
+
438
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
439
+
440
+    }
441
+
442
+    /**
443
+     * Displays payment form table columns.
444
+     */
445
+    public static function display_payment_form_columns( $column_name, $post_id ) {
446
+
447
+        // Retrieve the payment form.
448
+        $form = new GetPaid_Payment_Form( $post_id );
449
+
450
+        switch ( $column_name ) {
451
+
452
+            case 'earnings':
453
+                echo wp_kses_post( wpinv_price( $form->get_earned() ) );
454
+                break;
455
+
456
+            case 'refunds':
457
+                echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
458
+                break;
459
+
460
+            case 'refunds':
461
+                echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
462
+                break;
463
+
464
+            case 'shortcode':
465
+                if ( $form->is_default() ) {
466
+                    echo '&mdash;';
467
+                } else {
468
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
469
+                }
470
+
471
+                break;
472
+
473
+            case 'items':
474
+                $items = $form->get_items();
475
+
476
+                if ( $form->is_default() || empty( $items ) ) {
477
+                    echo '&mdash;';
478
+                    return;
479
+                }
472 480
 
473
-			case 'items':
474
-				$items = $form->get_items();
475
-
476
-				if ( $form->is_default() || empty( $items ) ) {
477
-					echo '&mdash;';
478
-					return;
479
-				}
480
-
481
-				$_items = array();
482
-
483
-				foreach ( $items as $item ) {
484
-					$url = $item->get_edit_url();
485
-
486
-					if ( empty( $url ) ) {
487
-						$_items[] = esc_html( $item->get_name() );
488
-					} else {
489
-						$_items[] = sprintf(
490
-							'<a href="%s">%s</a>',
491
-							esc_url( $url ),
492
-							esc_html( $item->get_name() )
493
-						);
494
-					}
481
+                $_items = array();
482
+
483
+                foreach ( $items as $item ) {
484
+                    $url = $item->get_edit_url();
485
+
486
+                    if ( empty( $url ) ) {
487
+                        $_items[] = esc_html( $item->get_name() );
488
+                    } else {
489
+                        $_items[] = sprintf(
490
+                            '<a href="%s">%s</a>',
491
+                            esc_url( $url ),
492
+                            esc_html( $item->get_name() )
493
+                        );
494
+                    }
495 495
 }
496 496
 
497
-				echo wp_kses_post( implode( '<br>', $_items ) );
497
+                echo wp_kses_post( implode( '<br>', $_items ) );
498 498
 
499
-				break;
499
+                break;
500 500
 
501
-		}
501
+        }
502 502
 
503
-	}
503
+    }
504 504
 
505
-	/**
506
-	 * Filters post states.
507
-	 */
508
-	public static function filter_payment_form_state( $post_states, $post ) {
505
+    /**
506
+     * Filters post states.
507
+     */
508
+    public static function filter_payment_form_state( $post_states, $post ) {
509 509
 
510
-		if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) {
511
-			$post_states['default_form'] = __( 'Default Payment Form', 'invoicing' );
512
-		}
510
+        if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) {
511
+            $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' );
512
+        }
513 513
 
514
-		return $post_states;
514
+        return $post_states;
515 515
 
516
-	}
516
+    }
517 517
 
518
-	/**
519
-	 * Returns an array of coupon table columns.
520
-	 */
521
-	public static function discount_columns( $columns ) {
518
+    /**
519
+     * Returns an array of coupon table columns.
520
+     */
521
+    public static function discount_columns( $columns ) {
522
+
523
+        $columns = array(
524
+            'cb'          => $columns['cb'],
525
+            'title'       => __( 'Name', 'invoicing' ),
526
+            'code'        => __( 'Code', 'invoicing' ),
527
+            'amount'      => __( 'Amount', 'invoicing' ),
528
+            'usage'       => __( 'Usage / Limit', 'invoicing' ),
529
+            'start_date'  => __( 'Start Date', 'invoicing' ),
530
+            'expiry_date' => __( 'Expiry Date', 'invoicing' ),
531
+        );
532
+
533
+        return apply_filters( 'wpi_discount_table_columns', $columns );
534
+    }
522 535
 
523
-		$columns = array(
524
-			'cb'          => $columns['cb'],
525
-			'title'       => __( 'Name', 'invoicing' ),
526
-			'code'        => __( 'Code', 'invoicing' ),
527
-			'amount'      => __( 'Amount', 'invoicing' ),
528
-			'usage'       => __( 'Usage / Limit', 'invoicing' ),
529
-			'start_date'  => __( 'Start Date', 'invoicing' ),
530
-			'expiry_date' => __( 'Expiry Date', 'invoicing' ),
531
-		);
536
+    /**
537
+     * Filters post states.
538
+     */
539
+    public static function filter_discount_state( $post_states, $post ) {
532 540
 
533
-		return apply_filters( 'wpi_discount_table_columns', $columns );
534
-	}
541
+        if ( 'wpi_discount' === $post->post_type ) {
535 542
 
536
-	/**
537
-	 * Filters post states.
538
-	 */
539
-	public static function filter_discount_state( $post_states, $post ) {
543
+            $discount = new WPInv_Discount( $post );
540 544
 
541
-		if ( 'wpi_discount' === $post->post_type ) {
545
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
542 546
 
543
-			$discount = new WPInv_Discount( $post );
547
+            if ( 'publish' !== $status ) {
548
+                return array(
549
+                    'discount_status' => wpinv_discount_status( $status ),
550
+                );
551
+            }
544 552
 
545
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
553
+            return array();
546 554
 
547
-			if ( 'publish' !== $status ) {
548
-				return array(
549
-					'discount_status' => wpinv_discount_status( $status ),
550
-				);
551
-			}
555
+        }
552 556
 
553
-			return array();
557
+        return $post_states;
554 558
 
555
-		}
559
+    }
556 560
 
557
-		return $post_states;
561
+    /**
562
+     * Returns an array of items table columns.
563
+     */
564
+    public static function item_columns( $columns ) {
565
+
566
+        $columns = array(
567
+            'cb'        => $columns['cb'],
568
+            'title'     => __( 'Name', 'invoicing' ),
569
+            'price'     => __( 'Price', 'invoicing' ),
570
+            'vat_rule'  => __( 'Tax Rule', 'invoicing' ),
571
+            'vat_class' => __( 'Tax Class', 'invoicing' ),
572
+            'type'      => __( 'Type', 'invoicing' ),
573
+            'shortcode' => __( 'Shortcode', 'invoicing' ),
574
+        );
575
+
576
+        if ( ! wpinv_use_taxes() ) {
577
+            unset( $columns['vat_rule'] );
578
+            unset( $columns['vat_class'] );
579
+        }
558 580
 
559
-	}
581
+        return apply_filters( 'wpi_item_table_columns', $columns );
582
+    }
560 583
 
561
-	/**
562
-	 * Returns an array of items table columns.
563
-	 */
564
-	public static function item_columns( $columns ) {
584
+    /**
585
+     * Returns an array of sortable items table columns.
586
+     */
587
+    public static function sortable_item_columns( $columns ) {
588
+
589
+        return array_merge(
590
+            $columns,
591
+            array(
592
+                'price'     => 'price',
593
+                'vat_rule'  => 'vat_rule',
594
+                'vat_class' => 'vat_class',
595
+                'type'      => 'type',
596
+            )
597
+        );
565 598
 
566
-		$columns = array(
567
-			'cb'        => $columns['cb'],
568
-			'title'     => __( 'Name', 'invoicing' ),
569
-			'price'     => __( 'Price', 'invoicing' ),
570
-			'vat_rule'  => __( 'Tax Rule', 'invoicing' ),
571
-			'vat_class' => __( 'Tax Class', 'invoicing' ),
572
-			'type'      => __( 'Type', 'invoicing' ),
573
-			'shortcode' => __( 'Shortcode', 'invoicing' ),
574
-		);
599
+    }
575 600
 
576
-		if ( ! wpinv_use_taxes() ) {
577
-			unset( $columns['vat_rule'] );
578
-			unset( $columns['vat_class'] );
579
-		}
601
+    /**
602
+     * Displays items table columns.
603
+     */
604
+    public static function display_item_columns( $column_name, $post_id ) {
605
+
606
+        $item = new WPInv_Item( $post_id );
607
+
608
+        switch ( $column_name ) {
609
+
610
+            case 'price':
611
+                if ( ! $item->is_recurring() ) {
612
+                    echo wp_kses_post( $item->get_the_price() );
613
+                    break;
614
+                }
615
+
616
+                $price = wp_sprintf(
617
+                    __( '%1$s / %2$s', 'invoicing' ),
618
+                    $item->get_the_price(),
619
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
620
+                );
621
+
622
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
623
+                    echo wp_kses_post( $price );
624
+                    break;
625
+                }
626
+
627
+                echo wp_kses_post( $item->get_the_initial_price() );
628
+
629
+                echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>';
630
+                break;
631
+
632
+            case 'vat_rule':
633
+                echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) );
634
+                break;
635
+
636
+            case 'vat_class':
637
+                echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) );
638
+                break;
639
+
640
+            case 'shortcode':
641
+                if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
642
+                    echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
643
+                } else {
644
+                    echo '&mdash;';
645
+                }
646
+
647
+                break;
648
+
649
+            case 'type':
650
+                echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' );
651
+                break;
652
+
653
+        }
654
+
655
+    }
656
+
657
+    /**
658
+     * Lets users filter items using taxes.
659
+     */
660
+    public static function add_item_filters( $post_type ) {
661
+
662
+        // Abort if we're not dealing with items.
663
+        if ( 'wpi_item' !== $post_type ) {
664
+            return;
665
+        }
666
+
667
+        // Filter by vat rules.
668
+        if ( wpinv_use_taxes() ) {
669
+
670
+            // Sanitize selected vat rule.
671
+            $vat_rule   = '';
672
+            $vat_rules  = getpaid_get_tax_rules();
673
+            if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
674
+                $vat_rule   = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
675
+            }
676
+
677
+            // Filter by VAT rule.
678
+            wpinv_html_select(
679
+                array(
680
+                    'options'          => array_merge(
681
+                        array(
682
+                            '' => __( 'All Tax Rules', 'invoicing' ),
683
+                        ),
684
+                        $vat_rules
685
+                    ),
686
+                    'name'             => 'vat_rule',
687
+                    'id'               => 'vat_rule',
688
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '',
689
+                    'show_option_all'  => false,
690
+                    'show_option_none' => false,
691
+                )
692
+            );
693
+
694
+            // Filter by VAT class.
695
+
696
+            // Sanitize selected vat rule.
697
+            $vat_class   = '';
698
+            $vat_classes = getpaid_get_tax_classes();
699
+            if ( isset( $_GET['vat_class'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
700
+                $vat_class   = sanitize_text_field( $_GET['vat_class'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
701
+            }
702
+
703
+            wpinv_html_select(
704
+                array(
705
+                    'options'          => array_merge(
706
+                        array(
707
+                            '' => __( 'All Tax Classes', 'invoicing' ),
708
+                        ),
709
+                        $vat_classes
710
+                    ),
711
+                    'name'             => 'vat_class',
712
+                    'id'               => 'vat_class',
713
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '',
714
+                    'show_option_all'  => false,
715
+                    'show_option_none' => false,
716
+                )
717
+            );
718
+
719
+        }
720
+
721
+        // Filter by item type.
722
+        $type   = '';
723
+        if ( isset( $_GET['type'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
724
+            $type   = sanitize_text_field( $_GET['type'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
725
+        }
726
+
727
+        wpinv_html_select(
728
+            array(
729
+                'options'          => array_merge(
730
+                    array(
731
+                        '' => __( 'All item types', 'invoicing' ),
732
+                    ),
733
+                    wpinv_get_item_types()
734
+                ),
735
+                'name'             => 'type',
736
+                'id'               => 'type',
737
+                'selected'         => in_array( $type, wpinv_item_types(), true ) ? $type : '',
738
+                'show_option_all'  => false,
739
+                'show_option_none' => false,
740
+            )
741
+        );
742
+
743
+    }
580 744
 
581
-		return apply_filters( 'wpi_item_table_columns', $columns );
582
-	}
745
+    /**
746
+     * Filters the item query.
747
+     */
748
+    public static function filter_item_query( $query ) {
583 749
 
584
-	/**
585
-	 * Returns an array of sortable items table columns.
586
-	 */
587
-	public static function sortable_item_columns( $columns ) {
588
-
589
-		return array_merge(
590
-			$columns,
591
-			array(
592
-				'price'     => 'price',
593
-				'vat_rule'  => 'vat_rule',
594
-				'vat_class' => 'vat_class',
595
-				'type'      => 'type',
596
-			)
597
-		);
598
-
599
-	}
600
-
601
-	/**
602
-	 * Displays items table columns.
603
-	 */
604
-	public static function display_item_columns( $column_name, $post_id ) {
605
-
606
-		$item = new WPInv_Item( $post_id );
607
-
608
-		switch ( $column_name ) {
609
-
610
-			case 'price':
611
-				if ( ! $item->is_recurring() ) {
612
-					echo wp_kses_post( $item->get_the_price() );
613
-					break;
614
-				}
615
-
616
-				$price = wp_sprintf(
617
-					__( '%1$s / %2$s', 'invoicing' ),
618
-					$item->get_the_price(),
619
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
620
-				);
621
-
622
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
623
-					echo wp_kses_post( $price );
624
-					break;
625
-				}
626
-
627
-				echo wp_kses_post( $item->get_the_initial_price() );
628
-
629
-				echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>';
630
-				break;
631
-
632
-			case 'vat_rule':
633
-				echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) );
634
-				break;
635
-
636
-			case 'vat_class':
637
-				echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) );
638
-				break;
639
-
640
-			case 'shortcode':
641
-				if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
642
-					echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
643
-				} else {
644
-					echo '&mdash;';
645
-				}
646
-
647
-				break;
648
-
649
-			case 'type':
650
-				echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' );
651
-				break;
652
-
653
-		}
654
-
655
-	}
656
-
657
-	/**
658
-	 * Lets users filter items using taxes.
659
-	 */
660
-	public static function add_item_filters( $post_type ) {
661
-
662
-		// Abort if we're not dealing with items.
663
-		if ( 'wpi_item' !== $post_type ) {
664
-			return;
665
-		}
666
-
667
-		// Filter by vat rules.
668
-		if ( wpinv_use_taxes() ) {
669
-
670
-			// Sanitize selected vat rule.
671
-			$vat_rule   = '';
672
-			$vat_rules  = getpaid_get_tax_rules();
673
-			if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
674
-				$vat_rule   = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
675
-			}
676
-
677
-			// Filter by VAT rule.
678
-			wpinv_html_select(
679
-				array(
680
-					'options'          => array_merge(
681
-						array(
682
-							'' => __( 'All Tax Rules', 'invoicing' ),
683
-						),
684
-						$vat_rules
685
-					),
686
-					'name'             => 'vat_rule',
687
-					'id'               => 'vat_rule',
688
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '',
689
-					'show_option_all'  => false,
690
-					'show_option_none' => false,
691
-				)
692
-			);
693
-
694
-			// Filter by VAT class.
695
-
696
-			// Sanitize selected vat rule.
697
-			$vat_class   = '';
698
-			$vat_classes = getpaid_get_tax_classes();
699
-			if ( isset( $_GET['vat_class'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
700
-				$vat_class   = sanitize_text_field( $_GET['vat_class'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
701
-			}
702
-
703
-			wpinv_html_select(
704
-				array(
705
-					'options'          => array_merge(
706
-						array(
707
-							'' => __( 'All Tax Classes', 'invoicing' ),
708
-						),
709
-						$vat_classes
710
-					),
711
-					'name'             => 'vat_class',
712
-					'id'               => 'vat_class',
713
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '',
714
-					'show_option_all'  => false,
715
-					'show_option_none' => false,
716
-				)
717
-			);
718
-
719
-		}
720
-
721
-		// Filter by item type.
722
-		$type   = '';
723
-		if ( isset( $_GET['type'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
724
-			$type   = sanitize_text_field( $_GET['type'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
725
-		}
726
-
727
-		wpinv_html_select(
728
-			array(
729
-				'options'          => array_merge(
730
-					array(
731
-						'' => __( 'All item types', 'invoicing' ),
732
-					),
733
-					wpinv_get_item_types()
734
-				),
735
-				'name'             => 'type',
736
-				'id'               => 'type',
737
-				'selected'         => in_array( $type, wpinv_item_types(), true ) ? $type : '',
738
-				'show_option_all'  => false,
739
-				'show_option_none' => false,
740
-			)
741
-		);
742
-
743
-	}
744
-
745
-	/**
746
-	 * Filters the item query.
747
-	 */
748
-	public static function filter_item_query( $query ) {
749
-
750
-		// modify the query only if it admin and main query.
751
-		if ( ! ( is_admin() && $query->is_main_query() ) ) {
752
-			return $query;
753
-		}
754
-
755
-		// we want to modify the query for our items.
756
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) {
757
-			return $query;
758
-		}
759
-
760
-		if ( empty( $query->query_vars['meta_query'] ) ) {
761
-			$query->query_vars['meta_query'] = array();
762
-		}
763
-
764
-		// Filter vat rule type
750
+        // modify the query only if it admin and main query.
751
+        if ( ! ( is_admin() && $query->is_main_query() ) ) {
752
+            return $query;
753
+        }
754
+
755
+        // we want to modify the query for our items.
756
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) {
757
+            return $query;
758
+        }
759
+
760
+        if ( empty( $query->query_vars['meta_query'] ) ) {
761
+            $query->query_vars['meta_query'] = array();
762
+        }
763
+
764
+        // Filter vat rule type
765 765
         if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
766 766
             $query->query_vars['meta_query'][] = array(
767 767
                 'key'     => '_wpinv_vat_rule',
@@ -786,146 +786,146 @@  discard block
 block discarded – undo
786 786
                 'value'   => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
787 787
                 'compare' => '=',
788 788
             );
789
-		}
790
-
791
-		$query->query_vars['meta_query'][] = array(
792
-			'key'     => '_wpinv_one_time',
793
-			'compare' => 'NOT EXISTS',
794
-		);
795
-	}
796
-
797
-	/**
798
-	 * Reorders items.
799
-	 */
800
-	public static function reorder_items( $vars ) {
801
-		global $typenow;
802
-
803
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
804
-			return $vars;
805
-		}
806
-
807
-		// By item type.
808
-		if ( 'type' === $vars['orderby'] ) {
809
-			return array_merge(
810
-				$vars,
811
-				array(
812
-					'meta_key' => '_wpinv_type',
813
-					'orderby'  => 'meta_value',
814
-				)
815
-			);
816
-		}
817
-
818
-		// By vat class.
819
-		if ( 'vat_class' === $vars['orderby'] ) {
820
-			return array_merge(
821
-				$vars,
822
-				array(
823
-					'meta_key' => '_wpinv_vat_class',
824
-					'orderby'  => 'meta_value',
825
-				)
826
-			);
827
-		}
828
-
829
-		// By vat rule.
830
-		if ( 'vat_rule' === $vars['orderby'] ) {
831
-			return array_merge(
832
-				$vars,
833
-				array(
834
-					'meta_key' => '_wpinv_vat_rule',
835
-					'orderby'  => 'meta_value',
836
-				)
837
-			);
838
-		}
839
-
840
-		// By price.
841
-		if ( 'price' === $vars['orderby'] ) {
842
-			return array_merge(
843
-				$vars,
844
-				array(
845
-					'meta_key' => '_wpinv_price',
846
-					'orderby'  => 'meta_value_num',
847
-				)
848
-			);
849
-		}
850
-
851
-		return $vars;
852
-
853
-	}
854
-
855
-	/**
856
-	 * Fired when deleting a post.
857
-	 */
858
-	public static function delete_post( $post_id ) {
859
-
860
-		switch ( get_post_type( $post_id ) ) {
861
-
862
-			case 'wpi_item':
863
-				do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) );
864
-				break;
865
-
866
-			case 'wpi_payment_form':
867
-				do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) );
868
-				break;
869
-
870
-			case 'wpi_discount':
871
-				do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) );
872
-				break;
873
-
874
-			case 'wpi_invoice':
875
-				$invoice = new WPInv_Invoice( $post_id );
876
-				do_action( 'getpaid_before_delete_invoice', $invoice );
877
-				$invoice->get_data_store()->delete_items( $invoice );
878
-				$invoice->get_data_store()->delete_special_fields( $invoice );
879
-				break;
880
-		}
881
-	}
882
-
883
-	/**
884
-	 * Add a post display state for special GetPaid pages in the page list table.
885
-	 *
886
-	 * @param array   $post_states An array of post display states.
887
-	 * @param WP_Post $post        The current post object.
888
-	 *
889
-	 * @return mixed
890
-	 */
891
-	public static function add_display_post_states( $post_states, $post ) {
892
-		if ( wpinv_get_option( 'success_page', 0 ) == $post->ID ) {
893
-			$post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
894
-		}
895
-
896
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
897
-			$_post_type = str_replace( "wpi_", "", $post_type );
898
-
899
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
900
-				$post_states[ "getpaid_{$post_type}_history_page" ] = wp_sprintf(
901
-					__( 'GetPaid %s History Page', 'invoicing' ),
902
-					$label
903
-				);
904
-			} else if ( wpinv_get_option( "{$_post_type}_history_page", 0 ) == $post->ID ) {
905
-				$post_states[ "getpaid_{$_post_type}_history_page" ] = wp_sprintf(
906
-					__( 'GetPaid %s History Page', 'invoicing' ),
907
-					$label
908
-				);
909
-			}
910
-		}
911
-
912
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
913
-			$post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscriptions Page', 'invoicing' );
914
-		}
915
-
916
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
917
-			$post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
918
-		}
919
-
920
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
921
-			$post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
922
-		}
923
-
924
-		if ( wpinv_get_option( 'failure_page', 0 ) == $post->ID ) {
925
-			$post_states['getpaid_failure_page'] = __( 'GetPaid Transaction Failed Page', 'invoicing' );
926
-		}
927
-
928
-		return $post_states;
789
+        }
790
+
791
+        $query->query_vars['meta_query'][] = array(
792
+            'key'     => '_wpinv_one_time',
793
+            'compare' => 'NOT EXISTS',
794
+        );
795
+    }
796
+
797
+    /**
798
+     * Reorders items.
799
+     */
800
+    public static function reorder_items( $vars ) {
801
+        global $typenow;
802
+
803
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
804
+            return $vars;
805
+        }
806
+
807
+        // By item type.
808
+        if ( 'type' === $vars['orderby'] ) {
809
+            return array_merge(
810
+                $vars,
811
+                array(
812
+                    'meta_key' => '_wpinv_type',
813
+                    'orderby'  => 'meta_value',
814
+                )
815
+            );
816
+        }
817
+
818
+        // By vat class.
819
+        if ( 'vat_class' === $vars['orderby'] ) {
820
+            return array_merge(
821
+                $vars,
822
+                array(
823
+                    'meta_key' => '_wpinv_vat_class',
824
+                    'orderby'  => 'meta_value',
825
+                )
826
+            );
827
+        }
828
+
829
+        // By vat rule.
830
+        if ( 'vat_rule' === $vars['orderby'] ) {
831
+            return array_merge(
832
+                $vars,
833
+                array(
834
+                    'meta_key' => '_wpinv_vat_rule',
835
+                    'orderby'  => 'meta_value',
836
+                )
837
+            );
838
+        }
839
+
840
+        // By price.
841
+        if ( 'price' === $vars['orderby'] ) {
842
+            return array_merge(
843
+                $vars,
844
+                array(
845
+                    'meta_key' => '_wpinv_price',
846
+                    'orderby'  => 'meta_value_num',
847
+                )
848
+            );
849
+        }
850
+
851
+        return $vars;
852
+
853
+    }
854
+
855
+    /**
856
+     * Fired when deleting a post.
857
+     */
858
+    public static function delete_post( $post_id ) {
859
+
860
+        switch ( get_post_type( $post_id ) ) {
861
+
862
+            case 'wpi_item':
863
+                do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) );
864
+                break;
865
+
866
+            case 'wpi_payment_form':
867
+                do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) );
868
+                break;
869
+
870
+            case 'wpi_discount':
871
+                do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) );
872
+                break;
873
+
874
+            case 'wpi_invoice':
875
+                $invoice = new WPInv_Invoice( $post_id );
876
+                do_action( 'getpaid_before_delete_invoice', $invoice );
877
+                $invoice->get_data_store()->delete_items( $invoice );
878
+                $invoice->get_data_store()->delete_special_fields( $invoice );
879
+                break;
880
+        }
881
+    }
882
+
883
+    /**
884
+     * Add a post display state for special GetPaid pages in the page list table.
885
+     *
886
+     * @param array   $post_states An array of post display states.
887
+     * @param WP_Post $post        The current post object.
888
+     *
889
+     * @return mixed
890
+     */
891
+    public static function add_display_post_states( $post_states, $post ) {
892
+        if ( wpinv_get_option( 'success_page', 0 ) == $post->ID ) {
893
+            $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
894
+        }
895
+
896
+        foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
897
+            $_post_type = str_replace( "wpi_", "", $post_type );
898
+
899
+            if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
900
+                $post_states[ "getpaid_{$post_type}_history_page" ] = wp_sprintf(
901
+                    __( 'GetPaid %s History Page', 'invoicing' ),
902
+                    $label
903
+                );
904
+            } else if ( wpinv_get_option( "{$_post_type}_history_page", 0 ) == $post->ID ) {
905
+                $post_states[ "getpaid_{$_post_type}_history_page" ] = wp_sprintf(
906
+                    __( 'GetPaid %s History Page', 'invoicing' ),
907
+                    $label
908
+                );
909
+            }
910
+        }
911
+
912
+        if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
913
+            $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscriptions Page', 'invoicing' );
914
+        }
915
+
916
+        if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
917
+            $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
918
+        }
919
+
920
+        if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
921
+            $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
922
+        }
923
+
924
+        if ( wpinv_get_option( 'failure_page', 0 ) == $post->ID ) {
925
+            $post_states['getpaid_failure_page'] = __( 'GetPaid Transaction Failed Page', 'invoicing' );
926
+        }
927
+
928
+        return $post_states;
929 929
     }
930 930
 
931 931
 }
Please login to merge, or discard this patch.
Spacing   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Post types Admin Class
@@ -21,74 +21,74 @@  discard block
 block discarded – undo
21 21
 		GetPaid_Metaboxes::init();
22 22
 
23 23
 		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
24
+		add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages');
25 25
 
26 26
 		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 );
27
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2);
28
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2);
29 29
 
30 30
 		// Invoice table columns.
31
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
32
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
33
-		add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) );
34
-		add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 );
31
+		add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100);
32
+		add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2);
33
+		add_filter('bulk_actions-edit-wpi_invoice', array(__CLASS__, 'invoice_bulk_actions'));
34
+		add_filter('handle_bulk_actions-edit-wpi_invoice', array(__CLASS__, 'handle_invoice_bulk_actions'), 10, 3);
35 35
 
36 36
 		// Items table columns.
37
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
38
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
39
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
40
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
41
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
42
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
37
+		add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100);
38
+		add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20);
39
+		add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2);
40
+		add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100);
41
+		add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100);
42
+		add_action('request', array(__CLASS__, 'reorder_items'), 100);
43 43
 
44 44
 		// Payment forms columns.
45
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
46
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
47
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
+		add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100);
46
+		add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2);
47
+		add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2);
48 48
 
49 49
 		// Discount table columns.
50
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
51
-		add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 );
50
+		add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100);
51
+		add_filter('bulk_actions-edit-wpi_discount', '__return_empty_array', 100);
52 52
 
53 53
 		// Deleting posts.
54
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
55
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
54
+		add_action('delete_post', array(__CLASS__, 'delete_post'));
55
+		add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2);
56 56
 
57
-		add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 );
57
+		add_filter('display_post_states', array(__CLASS__, 'add_display_post_states'), 10, 2);
58 58
 	}
59 59
 
60 60
 	/**
61 61
 	 * Post updated messages.
62 62
 	 */
63
-	public static function post_updated_messages( $messages ) {
63
+	public static function post_updated_messages($messages) {
64 64
 		global $post;
65 65
 
66 66
 		$messages['wpi_discount'] = array(
67 67
 			0  => '',
68
-			1  => __( 'Discount updated.', 'invoicing' ),
69
-			2  => __( 'Custom field updated.', 'invoicing' ),
70
-			3  => __( 'Custom field deleted.', 'invoicing' ),
71
-			4  => __( 'Discount updated.', 'invoicing' ),
72
-			5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
73
-			6  => __( 'Discount updated.', 'invoicing' ),
74
-			7  => __( 'Discount saved.', 'invoicing' ),
75
-			8  => __( 'Discount submitted.', 'invoicing' ),
76
-			9  => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
77
-			10 => __( 'Discount draft updated.', 'invoicing' ),
68
+			1  => __('Discount updated.', 'invoicing'),
69
+			2  => __('Custom field updated.', 'invoicing'),
70
+			3  => __('Custom field deleted.', 'invoicing'),
71
+			4  => __('Discount updated.', 'invoicing'),
72
+			5  => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
73
+			6  => __('Discount updated.', 'invoicing'),
74
+			7  => __('Discount saved.', 'invoicing'),
75
+			8  => __('Discount submitted.', 'invoicing'),
76
+			9  => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
77
+			10 => __('Discount draft updated.', 'invoicing'),
78 78
 		);
79 79
 
80 80
 		$messages['wpi_payment_form'] = array(
81 81
 			0  => '',
82
-			1  => __( 'Payment Form updated.', 'invoicing' ),
83
-			2  => __( 'Custom field updated.', 'invoicing' ),
84
-			3  => __( 'Custom field deleted.', 'invoicing' ),
85
-			4  => __( 'Payment Form updated.', 'invoicing' ),
86
-			5  => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
87
-			6  => __( 'Payment Form updated.', 'invoicing' ),
88
-			7  => __( 'Payment Form saved.', 'invoicing' ),
89
-			8  => __( 'Payment Form submitted.', 'invoicing' ),
90
-			9  => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
91
-			10 => __( 'Payment Form draft updated.', 'invoicing' ),
82
+			1  => __('Payment Form updated.', 'invoicing'),
83
+			2  => __('Custom field updated.', 'invoicing'),
84
+			3  => __('Custom field deleted.', 'invoicing'),
85
+			4  => __('Payment Form updated.', 'invoicing'),
86
+			5  => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
87
+			6  => __('Payment Form updated.', 'invoicing'),
88
+			7  => __('Payment Form saved.', 'invoicing'),
89
+			8  => __('Payment Form submitted.', 'invoicing'),
90
+			9  => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
91
+			10 => __('Payment Form draft updated.', 'invoicing'),
92 92
 		);
93 93
 
94 94
 		return $messages;
@@ -98,16 +98,16 @@  discard block
 block discarded – undo
98 98
 	/**
99 99
 	 * Post row actions.
100 100
 	 */
101
-	public static function post_row_actions( $actions, $post ) {
101
+	public static function post_row_actions($actions, $post) {
102 102
 
103
-		$post = get_post( $post );
103
+		$post = get_post($post);
104 104
 
105 105
 		// We do not want to edit the default payment form.
106
-		if ( 'wpi_payment_form' == $post->post_type ) {
106
+		if ('wpi_payment_form' == $post->post_type) {
107 107
 
108
-			if ( wpinv_get_default_payment_form() === $post->ID ) {
109
-				unset( $actions['trash'] );
110
-				unset( $actions['inline hide-if-no-js'] );
108
+			if (wpinv_get_default_payment_form() === $post->ID) {
109
+				unset($actions['trash']);
110
+				unset($actions['inline hide-if-no-js']);
111 111
 			}
112 112
 
113 113
 			$actions['duplicate'] = sprintf(
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 						'getpaid-nonce'
125 125
 					)
126 126
 				),
127
-				esc_html( __( 'Duplicate', 'invoicing' ) )
127
+				esc_html(__('Duplicate', 'invoicing'))
128 128
 			);
129 129
 
130 130
 			$actions['reset'] = sprintf(
@@ -141,17 +141,17 @@  discard block
 block discarded – undo
141 141
 						'getpaid-nonce'
142 142
 					)
143 143
 				),
144
-				esc_html( __( 'Reset Stats', 'invoicing' ) )
144
+				esc_html(__('Reset Stats', 'invoicing'))
145 145
 			);
146 146
 		}
147 147
 
148 148
 		// Link to item payment form.
149
-		if ( 'wpi_item' == $post->post_type ) {
150
-			if ( getpaid_item_type_supports( get_post_meta( $post->ID, '_wpinv_type', true ), 'buy_now' ) ) {
149
+		if ('wpi_item' == $post->post_type) {
150
+			if (getpaid_item_type_supports(get_post_meta($post->ID, '_wpinv_type', true), 'buy_now')) {
151 151
 				$actions['buy'] = sprintf(
152 152
 					'<a href="%1$s">%2$s</a>',
153
-					esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ),
154
-					esc_html( __( 'Buy', 'invoicing' ) )
153
+					esc_url(getpaid_embed_url(false, $post->ID . '|0')),
154
+					esc_html(__('Buy', 'invoicing'))
155 155
 				);
156 156
 			}
157 157
 		}
@@ -167,28 +167,28 @@  discard block
 block discarded – undo
167 167
 	 * @param WP_Post $post
168 168
      * @return array $actions actions without edit option
169 169
      */
170
-    public static function filter_invoice_row_actions( $actions, $post ) {
170
+    public static function filter_invoice_row_actions($actions, $post) {
171 171
 
172
-        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
172
+        if (getpaid_is_invoice_post_type($post->post_type)) {
173 173
 
174 174
 			$actions = array();
175
-			$invoice = new WPInv_Invoice( $post );
175
+			$invoice = new WPInv_Invoice($post);
176 176
 
177 177
 			$actions['edit'] = sprintf(
178 178
 				'<a href="%1$s">%2$s</a>',
179
-				esc_url( get_edit_post_link( $invoice->get_id() ) ),
180
-				esc_html( __( 'Edit', 'invoicing' ) )
179
+				esc_url(get_edit_post_link($invoice->get_id())),
180
+				esc_html(__('Edit', 'invoicing'))
181 181
 			);
182 182
 
183
-			if ( ! $invoice->is_draft() ) {
183
+			if (!$invoice->is_draft()) {
184 184
 
185 185
 				$actions['view'] = sprintf(
186 186
 					'<a href="%1$s">%2$s</a>',
187
-					esc_url( $invoice->get_view_url() ),
187
+					esc_url($invoice->get_view_url()),
188 188
 					sprintf(
189 189
 						// translators: %s is the invoice type
190
-						esc_html__( 'View %s', 'invoicing' ),
191
-						getpaid_get_post_type_label( $invoice->get_post_type(), false )
190
+						esc_html__('View %s', 'invoicing'),
191
+						getpaid_get_post_type_label($invoice->get_post_type(), false)
192 192
 					)
193 193
 				);
194 194
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 							'getpaid-nonce'
207 207
 						)
208 208
 					),
209
-					esc_html( __( 'Send to Customer', 'invoicing' ) )
209
+					esc_html(__('Send to Customer', 'invoicing'))
210 210
 				);
211 211
 
212 212
 			}
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 						'getpaid-nonce'
226 226
 					)
227 227
 				),
228
-				esc_html( __( 'Duplicate', 'invoicing' ) )
228
+				esc_html(__('Duplicate', 'invoicing'))
229 229
 			);
230 230
 
231 231
         }
@@ -236,59 +236,59 @@  discard block
 block discarded – undo
236 236
 	/**
237 237
 	 * Returns an array of invoice table columns.
238 238
 	 */
239
-	public static function invoice_columns( $columns ) {
239
+	public static function invoice_columns($columns) {
240 240
 
241 241
 		$columns = array(
242 242
 			'cb'           => $columns['cb'],
243
-			'number'       => __( 'Invoice', 'invoicing' ),
244
-			'customer'     => __( 'Customer', 'invoicing' ),
245
-			'invoice_date' => __( 'Created', 'invoicing' ),
246
-			'payment_date' => __( 'Completed', 'invoicing' ),
247
-			'amount'       => __( 'Amount', 'invoicing' ),
248
-			'recurring'    => __( 'Recurring', 'invoicing' ),
249
-			'status'       => __( 'Status', 'invoicing' ),
243
+			'number'       => __('Invoice', 'invoicing'),
244
+			'customer'     => __('Customer', 'invoicing'),
245
+			'invoice_date' => __('Created', 'invoicing'),
246
+			'payment_date' => __('Completed', 'invoicing'),
247
+			'amount'       => __('Amount', 'invoicing'),
248
+			'recurring'    => __('Recurring', 'invoicing'),
249
+			'status'       => __('Status', 'invoicing'),
250 250
 		);
251 251
 
252
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
252
+		return apply_filters('wpi_invoice_table_columns', $columns);
253 253
 	}
254 254
 
255 255
 	/**
256 256
 	 * Displays invoice table columns.
257 257
 	 */
258
-	public static function display_invoice_columns( $column_name, $post_id ) {
258
+	public static function display_invoice_columns($column_name, $post_id) {
259 259
 
260
-		$invoice = new WPInv_Invoice( $post_id );
260
+		$invoice = new WPInv_Invoice($post_id);
261 261
 
262
-		switch ( $column_name ) {
262
+		switch ($column_name) {
263 263
 
264 264
 			case 'invoice_date':
265
-				$date_time = esc_attr( $invoice->get_created_date() );
266
-				$date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
267
-				echo wp_kses_post( "<span title='$date_time'>$date</span>" );
265
+				$date_time = esc_attr($invoice->get_created_date());
266
+				$date      = esc_html(getpaid_format_date_value($date_time, '&mdash;', true));
267
+				echo wp_kses_post("<span title='$date_time'>$date</span>");
268 268
 				break;
269 269
 
270 270
 			case 'payment_date':
271
-				if ( $invoice->is_paid() || $invoice->is_refunded() ) {
272
-					$date_time = esc_attr( $invoice->get_completed_date() );
273
-					$date      = esc_html( getpaid_format_date_value( $date_time, '&mdash;', true ) );
274
-					echo wp_kses_post( "<span title='$date_time'>$date</span>" );
271
+				if ($invoice->is_paid() || $invoice->is_refunded()) {
272
+					$date_time = esc_attr($invoice->get_completed_date());
273
+					$date      = esc_html(getpaid_format_date_value($date_time, '&mdash;', true));
274
+					echo wp_kses_post("<span title='$date_time'>$date</span>");
275 275
 
276
-					if ( $_gateway = $invoice->get_gateway() ) {
277
-						$gateway_label = wpinv_get_gateway_admin_label( $_gateway );
276
+					if ($_gateway = $invoice->get_gateway()) {
277
+						$gateway_label = wpinv_get_gateway_admin_label($_gateway);
278 278
 
279
-						if ( $transaction_url = $invoice->get_transaction_url() ) {
280
-							$gateway_label = '<a href="' . esc_url( $transaction_url ) . '" target="_blank" title="' . esc_attr__( 'Open transaction link', 'invoicing' ) . '">' . $gateway_label . '</a>';
279
+						if ($transaction_url = $invoice->get_transaction_url()) {
280
+							$gateway_label = '<a href="' . esc_url($transaction_url) . '" target="_blank" title="' . esc_attr__('Open transaction link', 'invoicing') . '">' . $gateway_label . '</a>';
281 281
 						}
282 282
 
283
-						$gateway = '<small class="meta bsui"><span class="fs-xs text-muted fst-normal">' . wp_sprintf( _x( 'Via %s', 'Paid via gateway', 'invoicing' ), $gateway_label ) . '</span></small>';
283
+						$gateway = '<small class="meta bsui"><span class="fs-xs text-muted fst-normal">' . wp_sprintf(_x('Via %s', 'Paid via gateway', 'invoicing'), $gateway_label) . '</span></small>';
284 284
 					} else {
285 285
 						$gateway = '';
286 286
 					}
287 287
 
288
-					$gateway = apply_filters( 'getpaid_admin_invoices_list_table_gateway', $gateway, $invoice );
288
+					$gateway = apply_filters('getpaid_admin_invoices_list_table_gateway', $gateway, $invoice);
289 289
 
290
-					if ( $gateway ) {
291
-						echo wp_kses_post( $gateway ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
290
+					if ($gateway) {
291
+						echo wp_kses_post($gateway); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
292 292
 					}
293 293
 				} else {
294 294
 					echo '&mdash;';
@@ -298,60 +298,60 @@  discard block
 block discarded – undo
298 298
 
299 299
 			case 'amount':
300 300
 				$amount = $invoice->get_total();
301
-				$formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) );
301
+				$formated_amount = wp_kses_post(wpinv_price($amount, $invoice->get_currency()));
302 302
 
303
-				if ( $invoice->is_refunded() ) {
304
-					$refunded_amount = wpinv_price( 0, $invoice->get_currency() );
305
-					echo wp_kses_post( "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>" );
303
+				if ($invoice->is_refunded()) {
304
+					$refunded_amount = wpinv_price(0, $invoice->get_currency());
305
+					echo wp_kses_post("<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>");
306 306
 				} else {
307 307
 
308 308
 					$discount = $invoice->get_total_discount();
309 309
 
310
-					if ( ! empty( $discount ) ) {
311
-						$new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() );
312
-						echo wp_kses_post( "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>" );
310
+					if (!empty($discount)) {
311
+						$new_amount = wpinv_price($amount + $discount, $invoice->get_currency());
312
+						echo wp_kses_post("<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>");
313 313
 					} else {
314
-						echo wp_kses_post( $formated_amount );
314
+						echo wp_kses_post($formated_amount);
315 315
 					}
316 316
 				}
317 317
 
318 318
 				break;
319 319
 
320 320
 			case 'status':
321
-				$status = esc_html( $invoice->get_status() );
321
+				$status = esc_html($invoice->get_status());
322 322
 
323 323
 				// If it is paid, show the gateway title.
324
-				if ( $invoice->is_paid() ) {
325
-					$gateway = esc_html( $invoice->get_gateway_title() );
326
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
324
+				if ($invoice->is_paid()) {
325
+					$gateway = esc_html($invoice->get_gateway_title());
326
+					$gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), esc_html($gateway));
327 327
 
328
-					echo wp_kses_post( "<span class='bsui wpi-help-tip getpaid-invoice-statuss $status' title='$gateway'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" );
328
+					echo wp_kses_post("<span class='bsui wpi-help-tip getpaid-invoice-statuss $status' title='$gateway'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>");
329 329
 				} else {
330
-					echo wp_kses_post( "<span class='bsui getpaid-invoice-statuss $status'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>" );
330
+					echo wp_kses_post("<span class='bsui getpaid-invoice-statuss $status'><span class='fs-base'>" . $invoice->get_status_label_html() . "</span></span>");
331 331
 				}
332 332
 
333 333
 				// If it is not paid, display the overdue and view status.
334
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
334
+				if (!$invoice->is_paid() && !$invoice->is_refunded()) {
335 335
 
336 336
 					// Invoice view status.
337
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
338
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>';
337
+					if (wpinv_is_invoice_viewed($invoice->get_id())) {
338
+						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>';
339 339
 					} else {
340
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>';
340
+						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>';
341 341
 					}
342 342
 
343 343
 					// Display the overview status.
344
-					if ( wpinv_get_option( 'overdue_active' ) ) {
344
+					if (wpinv_get_option('overdue_active')) {
345 345
 						$due_date = $invoice->get_due_date();
346
-						$fomatted = getpaid_format_date( $due_date );
346
+						$fomatted = getpaid_format_date($due_date);
347 347
 
348
-						if ( ! empty( $fomatted ) ) {
348
+						if (!empty($fomatted)) {
349 349
 							$date = wp_sprintf(
350 350
 								// translators: %s is the due date.
351
-								__( 'Due %s', 'invoicing' ),
351
+								__('Due %s', 'invoicing'),
352 352
 								$fomatted
353 353
 							);
354
-							echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" );
354
+							echo wp_kses_post("<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>");
355 355
 						}
356 356
 					}
357 357
 				}
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 				break;
360 360
 
361 361
 			case 'recurring':
362
-				if ( $invoice->is_recurring() ) {
362
+				if ($invoice->is_recurring()) {
363 363
 					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
364 364
 				} else {
365 365
 					echo '<i class="fa fa-times" style="color:#616161;"></i>';
@@ -367,26 +367,26 @@  discard block
 block discarded – undo
367 367
 				break;
368 368
 
369 369
 			case 'number':
370
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
371
-				$invoice_number  = esc_html( $invoice->get_number() );
372
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
370
+				$edit_link       = esc_url(get_edit_post_link($invoice->get_id()));
371
+				$invoice_number  = esc_html($invoice->get_number());
372
+				$invoice_details = esc_attr__('View Invoice Details', 'invoicing');
373 373
 
374
-				echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" );
374
+				echo wp_kses_post("<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>");
375 375
 
376
-				do_action( 'getpaid_admin_table_invoice_number_column', $invoice );
376
+				do_action('getpaid_admin_table_invoice_number_column', $invoice);
377 377
 				break;
378 378
 
379 379
 			case 'customer':
380 380
 				$customer_name = $invoice->get_user_full_name();
381 381
 
382
-				if ( empty( $customer_name ) ) {
382
+				if (empty($customer_name)) {
383 383
 					$customer_name = $invoice->get_email();
384 384
 				}
385 385
 
386
-				if ( ! empty( $customer_name ) ) {
387
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
388
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
389
-					echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" );
386
+				if (!empty($customer_name)) {
387
+					$customer_details = esc_attr__('View Customer Details', 'invoicing');
388
+					$view_link        = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php')));
389
+					echo wp_kses_post("<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>");
390 390
 				} else {
391 391
 					echo '<div>&mdash;</div>';
392 392
 				}
@@ -400,19 +400,19 @@  discard block
 block discarded – undo
400 400
 	/**
401 401
 	 * Displays invoice bulk actions.
402 402
 	 */
403
-	public static function invoice_bulk_actions( $actions ) {
404
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
403
+	public static function invoice_bulk_actions($actions) {
404
+		$actions['resend-invoice'] = __('Send to Customer', 'invoicing');
405 405
 		return $actions;
406 406
 	}
407 407
 
408 408
 	/**
409 409
 	 * Processes invoice bulk actions.
410 410
 	 */
411
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
411
+	public static function handle_invoice_bulk_actions($redirect_url, $action, $post_ids) {
412 412
 
413
-		if ( 'resend-invoice' === $action ) {
414
-			foreach ( $post_ids as $post_id ) {
415
-				getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
413
+		if ('resend-invoice' === $action) {
414
+			foreach ($post_ids as $post_id) {
415
+				getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($post_id), true);
416 416
 			}
417 417
 		}
418 418
 
@@ -423,49 +423,49 @@  discard block
 block discarded – undo
423 423
 	/**
424 424
 	 * Returns an array of payment forms table columns.
425 425
 	 */
426
-	public static function payment_form_columns( $columns ) {
426
+	public static function payment_form_columns($columns) {
427 427
 
428 428
 		$columns = array(
429 429
 			'cb'        => $columns['cb'],
430
-			'title'     => __( 'Name', 'invoicing' ),
431
-			'shortcode' => __( 'Shortcode', 'invoicing' ),
432
-			'earnings'  => __( 'Revenue', 'invoicing' ),
433
-			'refunds'   => __( 'Refunded', 'invoicing' ),
434
-			'items'     => __( 'Items', 'invoicing' ),
435
-			'date'      => __( 'Date', 'invoicing' ),
430
+			'title'     => __('Name', 'invoicing'),
431
+			'shortcode' => __('Shortcode', 'invoicing'),
432
+			'earnings'  => __('Revenue', 'invoicing'),
433
+			'refunds'   => __('Refunded', 'invoicing'),
434
+			'items'     => __('Items', 'invoicing'),
435
+			'date'      => __('Date', 'invoicing'),
436 436
 		);
437 437
 
438
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
438
+		return apply_filters('wpi_payment_form_table_columns', $columns);
439 439
 
440 440
 	}
441 441
 
442 442
 	/**
443 443
 	 * Displays payment form table columns.
444 444
 	 */
445
-	public static function display_payment_form_columns( $column_name, $post_id ) {
445
+	public static function display_payment_form_columns($column_name, $post_id) {
446 446
 
447 447
 		// Retrieve the payment form.
448
-		$form = new GetPaid_Payment_Form( $post_id );
448
+		$form = new GetPaid_Payment_Form($post_id);
449 449
 
450
-		switch ( $column_name ) {
450
+		switch ($column_name) {
451 451
 
452 452
 			case 'earnings':
453
-				echo wp_kses_post( wpinv_price( $form->get_earned() ) );
453
+				echo wp_kses_post(wpinv_price($form->get_earned()));
454 454
 				break;
455 455
 
456 456
 			case 'refunds':
457
-				echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
457
+				echo wp_kses_post(wpinv_price($form->get_refunded()));
458 458
 				break;
459 459
 
460 460
 			case 'refunds':
461
-				echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
461
+				echo wp_kses_post(wpinv_price($form->get_refunded()));
462 462
 				break;
463 463
 
464 464
 			case 'shortcode':
465
-				if ( $form->is_default() ) {
465
+				if ($form->is_default()) {
466 466
 					echo '&mdash;';
467 467
 				} else {
468
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
468
+					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>';
469 469
 				}
470 470
 
471 471
 				break;
@@ -473,28 +473,28 @@  discard block
 block discarded – undo
473 473
 			case 'items':
474 474
 				$items = $form->get_items();
475 475
 
476
-				if ( $form->is_default() || empty( $items ) ) {
476
+				if ($form->is_default() || empty($items)) {
477 477
 					echo '&mdash;';
478 478
 					return;
479 479
 				}
480 480
 
481 481
 				$_items = array();
482 482
 
483
-				foreach ( $items as $item ) {
483
+				foreach ($items as $item) {
484 484
 					$url = $item->get_edit_url();
485 485
 
486
-					if ( empty( $url ) ) {
487
-						$_items[] = esc_html( $item->get_name() );
486
+					if (empty($url)) {
487
+						$_items[] = esc_html($item->get_name());
488 488
 					} else {
489 489
 						$_items[] = sprintf(
490 490
 							'<a href="%s">%s</a>',
491
-							esc_url( $url ),
492
-							esc_html( $item->get_name() )
491
+							esc_url($url),
492
+							esc_html($item->get_name())
493 493
 						);
494 494
 					}
495 495
 }
496 496
 
497
-				echo wp_kses_post( implode( '<br>', $_items ) );
497
+				echo wp_kses_post(implode('<br>', $_items));
498 498
 
499 499
 				break;
500 500
 
@@ -505,10 +505,10 @@  discard block
 block discarded – undo
505 505
 	/**
506 506
 	 * Filters post states.
507 507
 	 */
508
-	public static function filter_payment_form_state( $post_states, $post ) {
508
+	public static function filter_payment_form_state($post_states, $post) {
509 509
 
510
-		if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) {
511
-			$post_states['default_form'] = __( 'Default Payment Form', 'invoicing' );
510
+		if ('wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID) {
511
+			$post_states['default_form'] = __('Default Payment Form', 'invoicing');
512 512
 		}
513 513
 
514 514
 		return $post_states;
@@ -518,35 +518,35 @@  discard block
 block discarded – undo
518 518
 	/**
519 519
 	 * Returns an array of coupon table columns.
520 520
 	 */
521
-	public static function discount_columns( $columns ) {
521
+	public static function discount_columns($columns) {
522 522
 
523 523
 		$columns = array(
524 524
 			'cb'          => $columns['cb'],
525
-			'title'       => __( 'Name', 'invoicing' ),
526
-			'code'        => __( 'Code', 'invoicing' ),
527
-			'amount'      => __( 'Amount', 'invoicing' ),
528
-			'usage'       => __( 'Usage / Limit', 'invoicing' ),
529
-			'start_date'  => __( 'Start Date', 'invoicing' ),
530
-			'expiry_date' => __( 'Expiry Date', 'invoicing' ),
525
+			'title'       => __('Name', 'invoicing'),
526
+			'code'        => __('Code', 'invoicing'),
527
+			'amount'      => __('Amount', 'invoicing'),
528
+			'usage'       => __('Usage / Limit', 'invoicing'),
529
+			'start_date'  => __('Start Date', 'invoicing'),
530
+			'expiry_date' => __('Expiry Date', 'invoicing'),
531 531
 		);
532 532
 
533
-		return apply_filters( 'wpi_discount_table_columns', $columns );
533
+		return apply_filters('wpi_discount_table_columns', $columns);
534 534
 	}
535 535
 
536 536
 	/**
537 537
 	 * Filters post states.
538 538
 	 */
539
-	public static function filter_discount_state( $post_states, $post ) {
539
+	public static function filter_discount_state($post_states, $post) {
540 540
 
541
-		if ( 'wpi_discount' === $post->post_type ) {
541
+		if ('wpi_discount' === $post->post_type) {
542 542
 
543
-			$discount = new WPInv_Discount( $post );
543
+			$discount = new WPInv_Discount($post);
544 544
 
545 545
 			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
546 546
 
547
-			if ( 'publish' !== $status ) {
547
+			if ('publish' !== $status) {
548 548
 				return array(
549
-					'discount_status' => wpinv_discount_status( $status ),
549
+					'discount_status' => wpinv_discount_status($status),
550 550
 				);
551 551
 			}
552 552
 
@@ -561,30 +561,30 @@  discard block
 block discarded – undo
561 561
 	/**
562 562
 	 * Returns an array of items table columns.
563 563
 	 */
564
-	public static function item_columns( $columns ) {
564
+	public static function item_columns($columns) {
565 565
 
566 566
 		$columns = array(
567 567
 			'cb'        => $columns['cb'],
568
-			'title'     => __( 'Name', 'invoicing' ),
569
-			'price'     => __( 'Price', 'invoicing' ),
570
-			'vat_rule'  => __( 'Tax Rule', 'invoicing' ),
571
-			'vat_class' => __( 'Tax Class', 'invoicing' ),
572
-			'type'      => __( 'Type', 'invoicing' ),
573
-			'shortcode' => __( 'Shortcode', 'invoicing' ),
568
+			'title'     => __('Name', 'invoicing'),
569
+			'price'     => __('Price', 'invoicing'),
570
+			'vat_rule'  => __('Tax Rule', 'invoicing'),
571
+			'vat_class' => __('Tax Class', 'invoicing'),
572
+			'type'      => __('Type', 'invoicing'),
573
+			'shortcode' => __('Shortcode', 'invoicing'),
574 574
 		);
575 575
 
576
-		if ( ! wpinv_use_taxes() ) {
577
-			unset( $columns['vat_rule'] );
578
-			unset( $columns['vat_class'] );
576
+		if (!wpinv_use_taxes()) {
577
+			unset($columns['vat_rule']);
578
+			unset($columns['vat_class']);
579 579
 		}
580 580
 
581
-		return apply_filters( 'wpi_item_table_columns', $columns );
581
+		return apply_filters('wpi_item_table_columns', $columns);
582 582
 	}
583 583
 
584 584
 	/**
585 585
 	 * Returns an array of sortable items table columns.
586 586
 	 */
587
-	public static function sortable_item_columns( $columns ) {
587
+	public static function sortable_item_columns($columns) {
588 588
 
589 589
 		return array_merge(
590 590
 			$columns,
@@ -601,45 +601,45 @@  discard block
 block discarded – undo
601 601
 	/**
602 602
 	 * Displays items table columns.
603 603
 	 */
604
-	public static function display_item_columns( $column_name, $post_id ) {
604
+	public static function display_item_columns($column_name, $post_id) {
605 605
 
606
-		$item = new WPInv_Item( $post_id );
606
+		$item = new WPInv_Item($post_id);
607 607
 
608
-		switch ( $column_name ) {
608
+		switch ($column_name) {
609 609
 
610 610
 			case 'price':
611
-				if ( ! $item->is_recurring() ) {
612
-					echo wp_kses_post( $item->get_the_price() );
611
+				if (!$item->is_recurring()) {
612
+					echo wp_kses_post($item->get_the_price());
613 613
 					break;
614 614
 				}
615 615
 
616 616
 				$price = wp_sprintf(
617
-					__( '%1$s / %2$s', 'invoicing' ),
617
+					__('%1$s / %2$s', 'invoicing'),
618 618
 					$item->get_the_price(),
619
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
619
+					getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '')
620 620
 				);
621 621
 
622
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
623
-					echo wp_kses_post( $price );
622
+				if ($item->get_the_price() == $item->get_the_initial_price()) {
623
+					echo wp_kses_post($price);
624 624
 					break;
625 625
 				}
626 626
 
627
-				echo wp_kses_post( $item->get_the_initial_price() );
627
+				echo wp_kses_post($item->get_the_initial_price());
628 628
 
629
-				echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>';
629
+				echo '<span class="meta">' . wp_sprintf(esc_html__('then %s', 'invoicing'), wp_kses_post($price)) . '</span>';
630 630
 				break;
631 631
 
632 632
 			case 'vat_rule':
633
-				echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) );
633
+				echo wp_kses_post(getpaid_get_tax_rule_label($item->get_vat_rule()));
634 634
 				break;
635 635
 
636 636
 			case 'vat_class':
637
-				echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) );
637
+				echo wp_kses_post(getpaid_get_tax_class_label($item->get_vat_class()));
638 638
 				break;
639 639
 
640 640
 			case 'shortcode':
641
-				if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
642
-					echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
641
+				if ($item->is_type(array('', 'fee', 'custom'))) {
642
+					echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
643 643
 				} else {
644 644
 					echo '&mdash;';
645 645
 				}
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 				break;
648 648
 
649 649
 			case 'type':
650
-				echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' );
650
+				echo wp_kses_post(wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>');
651 651
 				break;
652 652
 
653 653
 		}
@@ -657,21 +657,21 @@  discard block
 block discarded – undo
657 657
 	/**
658 658
 	 * Lets users filter items using taxes.
659 659
 	 */
660
-	public static function add_item_filters( $post_type ) {
660
+	public static function add_item_filters($post_type) {
661 661
 
662 662
 		// Abort if we're not dealing with items.
663
-		if ( 'wpi_item' !== $post_type ) {
663
+		if ('wpi_item' !== $post_type) {
664 664
 			return;
665 665
 		}
666 666
 
667 667
 		// Filter by vat rules.
668
-		if ( wpinv_use_taxes() ) {
668
+		if (wpinv_use_taxes()) {
669 669
 
670 670
 			// Sanitize selected vat rule.
671 671
 			$vat_rule   = '';
672 672
 			$vat_rules  = getpaid_get_tax_rules();
673
-			if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
674
-				$vat_rule   = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
673
+			if (isset($_GET['vat_rule'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
674
+				$vat_rule = sanitize_text_field($_GET['vat_rule']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
675 675
 			}
676 676
 
677 677
 			// Filter by VAT rule.
@@ -679,13 +679,13 @@  discard block
 block discarded – undo
679 679
 				array(
680 680
 					'options'          => array_merge(
681 681
 						array(
682
-							'' => __( 'All Tax Rules', 'invoicing' ),
682
+							'' => __('All Tax Rules', 'invoicing'),
683 683
 						),
684 684
 						$vat_rules
685 685
 					),
686 686
 					'name'             => 'vat_rule',
687 687
 					'id'               => 'vat_rule',
688
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '',
688
+					'selected'         => in_array($vat_rule, array_keys($vat_rules), true) ? $vat_rule : '',
689 689
 					'show_option_all'  => false,
690 690
 					'show_option_none' => false,
691 691
 				)
@@ -696,21 +696,21 @@  discard block
 block discarded – undo
696 696
 			// Sanitize selected vat rule.
697 697
 			$vat_class   = '';
698 698
 			$vat_classes = getpaid_get_tax_classes();
699
-			if ( isset( $_GET['vat_class'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
700
-				$vat_class   = sanitize_text_field( $_GET['vat_class'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
699
+			if (isset($_GET['vat_class'])) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
700
+				$vat_class = sanitize_text_field($_GET['vat_class']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
701 701
 			}
702 702
 
703 703
 			wpinv_html_select(
704 704
 				array(
705 705
 					'options'          => array_merge(
706 706
 						array(
707
-							'' => __( 'All Tax Classes', 'invoicing' ),
707
+							'' => __('All Tax Classes', 'invoicing'),
708 708
 						),
709 709
 						$vat_classes
710 710
 					),
711 711
 					'name'             => 'vat_class',
712 712
 					'id'               => 'vat_class',
713
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '',
713
+					'selected'         => in_array($vat_class, array_keys($vat_classes), true) ? $vat_class : '',
714 714
 					'show_option_all'  => false,
715 715
 					'show_option_none' => false,
716 716
 				)
@@ -719,22 +719,22 @@  discard block
 block discarded – undo
719 719
 		}
720 720
 
721 721
 		// Filter by item type.
722
-		$type   = '';
723
-		if ( isset( $_GET['type'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
724
-			$type   = sanitize_text_field( $_GET['type'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
722
+		$type = '';
723
+		if (isset($_GET['type'])) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
724
+			$type = sanitize_text_field($_GET['type']); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
725 725
 		}
726 726
 
727 727
 		wpinv_html_select(
728 728
 			array(
729 729
 				'options'          => array_merge(
730 730
 					array(
731
-						'' => __( 'All item types', 'invoicing' ),
731
+						'' => __('All item types', 'invoicing'),
732 732
 					),
733 733
 					wpinv_get_item_types()
734 734
 				),
735 735
 				'name'             => 'type',
736 736
 				'id'               => 'type',
737
-				'selected'         => in_array( $type, wpinv_item_types(), true ) ? $type : '',
737
+				'selected'         => in_array($type, wpinv_item_types(), true) ? $type : '',
738 738
 				'show_option_all'  => false,
739 739
 				'show_option_none' => false,
740 740
 			)
@@ -745,45 +745,45 @@  discard block
 block discarded – undo
745 745
 	/**
746 746
 	 * Filters the item query.
747 747
 	 */
748
-	public static function filter_item_query( $query ) {
748
+	public static function filter_item_query($query) {
749 749
 
750 750
 		// modify the query only if it admin and main query.
751
-		if ( ! ( is_admin() && $query->is_main_query() ) ) {
751
+		if (!(is_admin() && $query->is_main_query())) {
752 752
 			return $query;
753 753
 		}
754 754
 
755 755
 		// we want to modify the query for our items.
756
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) {
756
+		if (empty($query->query['post_type']) || 'wpi_item' !== $query->query['post_type']) {
757 757
 			return $query;
758 758
 		}
759 759
 
760
-		if ( empty( $query->query_vars['meta_query'] ) ) {
760
+		if (empty($query->query_vars['meta_query'])) {
761 761
 			$query->query_vars['meta_query'] = array();
762 762
 		}
763 763
 
764 764
 		// Filter vat rule type
765
-        if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
765
+        if (!empty($_GET['vat_rule'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
766 766
             $query->query_vars['meta_query'][] = array(
767 767
                 'key'     => '_wpinv_vat_rule',
768
-                'value'   => sanitize_text_field( $_GET['vat_rule'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
768
+                'value'   => sanitize_text_field($_GET['vat_rule']), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
769 769
                 'compare' => '=',
770 770
             );
771 771
         }
772 772
 
773 773
         // Filter vat class
774
-        if ( ! empty( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
774
+        if (!empty($_GET['vat_class'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
775 775
             $query->query_vars['meta_query'][] = array(
776 776
                 'key'     => '_wpinv_vat_class',
777
-                'value'   => sanitize_text_field( $_GET['vat_class'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
777
+                'value'   => sanitize_text_field($_GET['vat_class']), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
778 778
                 'compare' => '=',
779 779
             );
780 780
         }
781 781
 
782 782
         // Filter item type
783
-        if ( ! empty( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
783
+        if (!empty($_GET['type'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
784 784
             $query->query_vars['meta_query'][] = array(
785 785
                 'key'     => '_wpinv_type',
786
-                'value'   => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
786
+                'value'   => sanitize_text_field($_GET['type']), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
787 787
                 'compare' => '=',
788 788
             );
789 789
 		}
@@ -797,15 +797,15 @@  discard block
 block discarded – undo
797 797
 	/**
798 798
 	 * Reorders items.
799 799
 	 */
800
-	public static function reorder_items( $vars ) {
800
+	public static function reorder_items($vars) {
801 801
 		global $typenow;
802 802
 
803
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
803
+		if ('wpi_item' !== $typenow || empty($vars['orderby'])) {
804 804
 			return $vars;
805 805
 		}
806 806
 
807 807
 		// By item type.
808
-		if ( 'type' === $vars['orderby'] ) {
808
+		if ('type' === $vars['orderby']) {
809 809
 			return array_merge(
810 810
 				$vars,
811 811
 				array(
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 		}
817 817
 
818 818
 		// By vat class.
819
-		if ( 'vat_class' === $vars['orderby'] ) {
819
+		if ('vat_class' === $vars['orderby']) {
820 820
 			return array_merge(
821 821
 				$vars,
822 822
 				array(
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
 		}
828 828
 
829 829
 		// By vat rule.
830
-		if ( 'vat_rule' === $vars['orderby'] ) {
830
+		if ('vat_rule' === $vars['orderby']) {
831 831
 			return array_merge(
832 832
 				$vars,
833 833
 				array(
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 		}
839 839
 
840 840
 		// By price.
841
-		if ( 'price' === $vars['orderby'] ) {
841
+		if ('price' === $vars['orderby']) {
842 842
 			return array_merge(
843 843
 				$vars,
844 844
 				array(
@@ -855,27 +855,27 @@  discard block
 block discarded – undo
855 855
 	/**
856 856
 	 * Fired when deleting a post.
857 857
 	 */
858
-	public static function delete_post( $post_id ) {
858
+	public static function delete_post($post_id) {
859 859
 
860
-		switch ( get_post_type( $post_id ) ) {
860
+		switch (get_post_type($post_id)) {
861 861
 
862 862
 			case 'wpi_item':
863
-				do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) );
863
+				do_action('getpaid_before_delete_item', new WPInv_Item($post_id));
864 864
 				break;
865 865
 
866 866
 			case 'wpi_payment_form':
867
-				do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) );
867
+				do_action('getpaid_before_delete_payment_form', new GetPaid_Payment_Form($post_id));
868 868
 				break;
869 869
 
870 870
 			case 'wpi_discount':
871
-				do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) );
871
+				do_action('getpaid_before_delete_discount', new WPInv_Discount($post_id));
872 872
 				break;
873 873
 
874 874
 			case 'wpi_invoice':
875
-				$invoice = new WPInv_Invoice( $post_id );
876
-				do_action( 'getpaid_before_delete_invoice', $invoice );
877
-				$invoice->get_data_store()->delete_items( $invoice );
878
-				$invoice->get_data_store()->delete_special_fields( $invoice );
875
+				$invoice = new WPInv_Invoice($post_id);
876
+				do_action('getpaid_before_delete_invoice', $invoice);
877
+				$invoice->get_data_store()->delete_items($invoice);
878
+				$invoice->get_data_store()->delete_special_fields($invoice);
879 879
 				break;
880 880
 		}
881 881
 	}
@@ -888,41 +888,41 @@  discard block
 block discarded – undo
888 888
 	 *
889 889
 	 * @return mixed
890 890
 	 */
891
-	public static function add_display_post_states( $post_states, $post ) {
892
-		if ( wpinv_get_option( 'success_page', 0 ) == $post->ID ) {
893
-			$post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
891
+	public static function add_display_post_states($post_states, $post) {
892
+		if (wpinv_get_option('success_page', 0) == $post->ID) {
893
+			$post_states['getpaid_success_page'] = __('GetPaid Receipt Page', 'invoicing');
894 894
 		}
895 895
 
896
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
897
-			$_post_type = str_replace( "wpi_", "", $post_type );
896
+		foreach (getpaid_get_invoice_post_types() as $post_type => $label) {
897
+			$_post_type = str_replace("wpi_", "", $post_type);
898 898
 
899
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
900
-				$post_states[ "getpaid_{$post_type}_history_page" ] = wp_sprintf(
901
-					__( 'GetPaid %s History Page', 'invoicing' ),
899
+			if (wpinv_get_option("{$post_type}_history_page", 0) == $post->ID) {
900
+				$post_states["getpaid_{$post_type}_history_page"] = wp_sprintf(
901
+					__('GetPaid %s History Page', 'invoicing'),
902 902
 					$label
903 903
 				);
904
-			} else if ( wpinv_get_option( "{$_post_type}_history_page", 0 ) == $post->ID ) {
905
-				$post_states[ "getpaid_{$_post_type}_history_page" ] = wp_sprintf(
906
-					__( 'GetPaid %s History Page', 'invoicing' ),
904
+			} else if (wpinv_get_option("{$_post_type}_history_page", 0) == $post->ID) {
905
+				$post_states["getpaid_{$_post_type}_history_page"] = wp_sprintf(
906
+					__('GetPaid %s History Page', 'invoicing'),
907 907
 					$label
908 908
 				);
909 909
 			}
910 910
 		}
911 911
 
912
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
913
-			$post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscriptions Page', 'invoicing' );
912
+		if (wpinv_get_option('invoice_subscription_page', 0) == $post->ID) {
913
+			$post_states['getpaid_invoice_subscription_page'] = __('GetPaid Subscriptions Page', 'invoicing');
914 914
 		}
915 915
 
916
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
917
-			$post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
916
+		if (wpinv_get_option('checkout_page', 0) == $post->ID) {
917
+			$post_states['getpaid_checkout_page'] = __('GetPaid Checkout Page', 'invoicing');
918 918
 		}
919 919
 
920
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
921
-			$post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
920
+		if (wpinv_get_option('checkout_page', 0) == $post->ID) {
921
+			$post_states['getpaid_checkout_page'] = __('GetPaid Checkout Page', 'invoicing');
922 922
 		}
923 923
 
924
-		if ( wpinv_get_option( 'failure_page', 0 ) == $post->ID ) {
925
-			$post_states['getpaid_failure_page'] = __( 'GetPaid Transaction Failed Page', 'invoicing' );
924
+		if (wpinv_get_option('failure_page', 0) == $post->ID) {
925
+			$post_states['getpaid_failure_page'] = __('GetPaid Transaction Failed Page', 'invoicing');
926 926
 		}
927 927
 
928 928
 		return $post_states;
Please login to merge, or discard this patch.
widgets/checkout.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -9,117 +9,117 @@
 block discarded – undo
9 9
  */
10 10
 class WPInv_Checkout_Widget extends WP_Super_Duper {
11 11
 
12
-	/**
13
-	 * Register the widget with WordPress.
14
-	 *
15
-	 */
16
-	public function __construct() {
12
+    /**
13
+     * Register the widget with WordPress.
14
+     *
15
+     */
16
+    public function __construct() {
17 17
 
18
-		$options = array(
19
-			'textdomain'     => 'invoicing',
20
-			'block-icon'     => 'admin-site',
21
-			'block-category' => 'widgets',
22
-			'block-keywords' => "['invoicing','checkout']",
23
-			'class_name'     => __CLASS__,
24
-			'base_id'        => 'wpinv_checkout',
25
-			'name'           => __( 'GetPaid > Checkout', 'invoicing' ),
26
-			'widget_ops'     => array(
27
-				'classname'   => 'getpaid-checkout bsui',
28
-				'description' => esc_html__( 'Displays a checkout form.', 'invoicing' ),
29
-			),
30
-			'arguments'      => array(
31
-				'title' => array(
32
-					'title'    => __( 'Widget title', 'invoicing' ),
33
-					'desc'     => __( 'Enter widget title.', 'invoicing' ),
34
-					'type'     => 'text',
35
-					'desc_tip' => true,
36
-					'default'  => '',
37
-					'advanced' => false,
38
-				),
39
-			),
18
+        $options = array(
19
+            'textdomain'     => 'invoicing',
20
+            'block-icon'     => 'admin-site',
21
+            'block-category' => 'widgets',
22
+            'block-keywords' => "['invoicing','checkout']",
23
+            'class_name'     => __CLASS__,
24
+            'base_id'        => 'wpinv_checkout',
25
+            'name'           => __( 'GetPaid > Checkout', 'invoicing' ),
26
+            'widget_ops'     => array(
27
+                'classname'   => 'getpaid-checkout bsui',
28
+                'description' => esc_html__( 'Displays a checkout form.', 'invoicing' ),
29
+            ),
30
+            'arguments'      => array(
31
+                'title' => array(
32
+                    'title'    => __( 'Widget title', 'invoicing' ),
33
+                    'desc'     => __( 'Enter widget title.', 'invoicing' ),
34
+                    'type'     => 'text',
35
+                    'desc_tip' => true,
36
+                    'default'  => '',
37
+                    'advanced' => false,
38
+                ),
39
+            ),
40 40
 
41
-		);
41
+        );
42 42
 
43
-		parent::__construct( $options );
44
-	}
43
+        parent::__construct( $options );
44
+    }
45 45
 
46
-	/**
47
-	 * The Super block output function.
48
-	 *
49
-	 * @param array $args
50
-	 * @param array $widget_args
51
-	 * @param string $content
52
-	 *
53
-	 * @return mixed|string|bool
54
-	 */
55
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
56
-		if ( $this->is_preview() ) {
57
-			return $this->get_dummy_preview( $args );
58
-		}
46
+    /**
47
+     * The Super block output function.
48
+     *
49
+     * @param array $args
50
+     * @param array $widget_args
51
+     * @param string $content
52
+     *
53
+     * @return mixed|string|bool
54
+     */
55
+    public function output( $args = array(), $widget_args = array(), $content = '' ) {
56
+        if ( $this->is_preview() ) {
57
+            return $this->get_dummy_preview( $args );
58
+        }
59 59
 
60
-		return wpinv_checkout_form();
61
-	}
60
+        return wpinv_checkout_form();
61
+    }
62 62
 
63
-	public function get_dummy_preview( $args ) {
64
-		$output = '<form><div class="col-12">';
63
+    public function get_dummy_preview( $args ) {
64
+        $output = '<form><div class="col-12">';
65 65
 
66
-		$output .= aui()->alert(
67
-			array(
68
-				'type'=> 'info',
69
-				'content' => __( 'This is a simple preview for a checkout form.', 'invoicing' )
70
-			)
71
-		);
66
+        $output .= aui()->alert(
67
+            array(
68
+                'type'=> 'info',
69
+                'content' => __( 'This is a simple preview for a checkout form.', 'invoicing' )
70
+            )
71
+        );
72 72
 
73
-		$output .= aui()->input(
74
-			array(
75
-				'name'        => 'mmdwqzpox',
76
-				'required'    => true,
77
-				'label'       => __( 'Billing Email', 'invoicing' ),
78
-				'label_type'  => 'vertical',
79
-				'type'        => 'text',
80
-				'placeholder' => '[email protected]',
81
-				'class'       => '',
82
-				'value'       => ''
83
-			)
84
-		);
73
+        $output .= aui()->input(
74
+            array(
75
+                'name'        => 'mmdwqzpox',
76
+                'required'    => true,
77
+                'label'       => __( 'Billing Email', 'invoicing' ),
78
+                'label_type'  => 'vertical',
79
+                'type'        => 'text',
80
+                'placeholder' => '[email protected]',
81
+                'class'       => '',
82
+                'value'       => ''
83
+            )
84
+        );
85 85
 
86
-		$output .= aui()->input(
87
-			array(
88
-				'name'        => 'mmdwqzpoy',
89
-				'required'    => true,
90
-				'label'       => __( 'First Name', 'invoicing' ),
91
-				'label_type'  => 'vertical',
92
-				'type'        => 'text',
93
-				'placeholder' => 'Jon',
94
-				'class'       => '',
95
-				'value'       => ''
96
-			)
97
-		);
86
+        $output .= aui()->input(
87
+            array(
88
+                'name'        => 'mmdwqzpoy',
89
+                'required'    => true,
90
+                'label'       => __( 'First Name', 'invoicing' ),
91
+                'label_type'  => 'vertical',
92
+                'type'        => 'text',
93
+                'placeholder' => 'Jon',
94
+                'class'       => '',
95
+                'value'       => ''
96
+            )
97
+        );
98 98
 
99
-		$output .= aui()->input(
100
-			array(
101
-				'name'        => 'mmdwqzpoz',
102
-				'required'    => true,
103
-				'label'       => __( 'Last Name', 'invoicing' ),
104
-				'label_type'  => 'vertical',
105
-				'type'        => 'text',
106
-				'placeholder' => 'Snow',
107
-				'class'       => '',
108
-				'value'       => ''
109
-			)
110
-		);
99
+        $output .= aui()->input(
100
+            array(
101
+                'name'        => 'mmdwqzpoz',
102
+                'required'    => true,
103
+                'label'       => __( 'Last Name', 'invoicing' ),
104
+                'label_type'  => 'vertical',
105
+                'type'        => 'text',
106
+                'placeholder' => 'Snow',
107
+                'class'       => '',
108
+                'value'       => ''
109
+            )
110
+        );
111 111
 
112
-		$output .= aui()->button(
113
-			array(
114
-				'type'        => 'button',
115
-				'class'       => 'btn btn-primary w-100',
116
-				'content'     => __( 'Pay Now »', 'invoicing' ),
117
-				'description' => __( 'By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' )
118
-			)
119
-		);
112
+        $output .= aui()->button(
113
+            array(
114
+                'type'        => 'button',
115
+                'class'       => 'btn btn-primary w-100',
116
+                'content'     => __( 'Pay Now »', 'invoicing' ),
117
+                'description' => __( 'By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' )
118
+            )
119
+        );
120 120
 
121
-		$output .= '</div></form>';
121
+        $output .= '</div></form>';
122 122
 
123
-		return $output;
124
-	}
123
+        return $output;
124
+    }
125 125
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit;
4 4
 }
5 5
 
@@ -22,15 +22,15 @@  discard block
 block discarded – undo
22 22
 			'block-keywords' => "['invoicing','checkout']",
23 23
 			'class_name'     => __CLASS__,
24 24
 			'base_id'        => 'wpinv_checkout',
25
-			'name'           => __( 'GetPaid > Checkout', 'invoicing' ),
25
+			'name'           => __('GetPaid > Checkout', 'invoicing'),
26 26
 			'widget_ops'     => array(
27 27
 				'classname'   => 'getpaid-checkout bsui',
28
-				'description' => esc_html__( 'Displays a checkout form.', 'invoicing' ),
28
+				'description' => esc_html__('Displays a checkout form.', 'invoicing'),
29 29
 			),
30 30
 			'arguments'      => array(
31 31
 				'title' => array(
32
-					'title'    => __( 'Widget title', 'invoicing' ),
33
-					'desc'     => __( 'Enter widget title.', 'invoicing' ),
32
+					'title'    => __('Widget title', 'invoicing'),
33
+					'desc'     => __('Enter widget title.', 'invoicing'),
34 34
 					'type'     => 'text',
35 35
 					'desc_tip' => true,
36 36
 					'default'  => '',
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
 		);
42 42
 
43
-		parent::__construct( $options );
43
+		parent::__construct($options);
44 44
 	}
45 45
 
46 46
 	/**
@@ -52,21 +52,21 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @return mixed|string|bool
54 54
 	 */
55
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
56
-		if ( $this->is_preview() ) {
57
-			return $this->get_dummy_preview( $args );
55
+	public function output($args = array(), $widget_args = array(), $content = '') {
56
+		if ($this->is_preview()) {
57
+			return $this->get_dummy_preview($args);
58 58
 		}
59 59
 
60 60
 		return wpinv_checkout_form();
61 61
 	}
62 62
 
63
-	public function get_dummy_preview( $args ) {
63
+	public function get_dummy_preview($args) {
64 64
 		$output = '<form><div class="col-12">';
65 65
 
66 66
 		$output .= aui()->alert(
67 67
 			array(
68 68
 				'type'=> 'info',
69
-				'content' => __( 'This is a simple preview for a checkout form.', 'invoicing' )
69
+				'content' => __('This is a simple preview for a checkout form.', 'invoicing')
70 70
 			)
71 71
 		);
72 72
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 			array(
75 75
 				'name'        => 'mmdwqzpox',
76 76
 				'required'    => true,
77
-				'label'       => __( 'Billing Email', 'invoicing' ),
77
+				'label'       => __('Billing Email', 'invoicing'),
78 78
 				'label_type'  => 'vertical',
79 79
 				'type'        => 'text',
80 80
 				'placeholder' => '[email protected]',
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 			array(
88 88
 				'name'        => 'mmdwqzpoy',
89 89
 				'required'    => true,
90
-				'label'       => __( 'First Name', 'invoicing' ),
90
+				'label'       => __('First Name', 'invoicing'),
91 91
 				'label_type'  => 'vertical',
92 92
 				'type'        => 'text',
93 93
 				'placeholder' => 'Jon',
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			array(
101 101
 				'name'        => 'mmdwqzpoz',
102 102
 				'required'    => true,
103
-				'label'       => __( 'Last Name', 'invoicing' ),
103
+				'label'       => __('Last Name', 'invoicing'),
104 104
 				'label_type'  => 'vertical',
105 105
 				'type'        => 'text',
106 106
 				'placeholder' => 'Snow',
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 			array(
114 114
 				'type'        => 'button',
115 115
 				'class'       => 'btn btn-primary w-100',
116
-				'content'     => __( 'Pay Now »', 'invoicing' ),
117
-				'description' => __( 'By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' )
116
+				'content'     => __('Pay Now »', 'invoicing'),
117
+				'description' => __('By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing')
118 118
 			)
119 119
 		);
120 120
 
Please login to merge, or discard this patch.