@@ -1,7 +1,7 @@ discard block |
||
| 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,249 +11,249 @@ discard block |
||
| 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 | - * |
|
| 19 | - * @return string |
|
| 20 | - */ |
|
| 21 | - public static function name($text,$multiple = false){ |
|
| 22 | - $output = ''; |
|
| 23 | - |
|
| 24 | - if($text){ |
|
| 25 | - $is_multiple = strpos($text, '[]') !== false || (strpos($text, '[]') === false && $multiple ) ? '[]' : ''; |
|
| 26 | - $output = ' name="'.sanitize_html_class($text).$is_multiple.'" '; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return $output; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * A component helper for generating a item id. |
|
| 34 | - * |
|
| 35 | - * @param $text string The text to be used as the value. |
|
| 36 | - * |
|
| 37 | - * @return string The sanitized item. |
|
| 38 | - */ |
|
| 39 | - public static function id($text){ |
|
| 40 | - $output = ''; |
|
| 41 | - |
|
| 42 | - if($text){ |
|
| 43 | - $output = ' id="'.sanitize_html_class($text).'" '; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return $output; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * A component helper for generating a item title. |
|
| 51 | - * |
|
| 52 | - * @param $text string The text to be used as the value. |
|
| 53 | - * |
|
| 54 | - * @return string The sanitized item. |
|
| 55 | - */ |
|
| 56 | - public static function title($text){ |
|
| 57 | - $output = ''; |
|
| 58 | - |
|
| 59 | - if($text){ |
|
| 60 | - $output = ' title="'.esc_attr($text).'" '; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $output; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * A component helper for generating a item value. |
|
| 68 | - * |
|
| 69 | - * @param $text string The text to be used as the value. |
|
| 70 | - * |
|
| 71 | - * @return string The sanitized item. |
|
| 72 | - */ |
|
| 73 | - public static function value($text){ |
|
| 74 | - $output = ''; |
|
| 75 | - |
|
| 76 | - if($text){ |
|
| 77 | - $output = ' value="'.sanitize_text_field($text).'" '; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return $output; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * A component helper for generating a item class attribute. |
|
| 85 | - * |
|
| 86 | - * @param $text string The text to be used as the value. |
|
| 87 | - * |
|
| 88 | - * @return string The sanitized item. |
|
| 89 | - */ |
|
| 90 | - public static function class_attr($text){ |
|
| 91 | - $output = ''; |
|
| 92 | - |
|
| 93 | - if($text){ |
|
| 94 | - $classes = self::esc_classes($text); |
|
| 95 | - if(!empty($classes)){ |
|
| 96 | - $output = ' class="'.$classes.'" '; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return $output; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Escape a string of classes. |
|
| 105 | - * |
|
| 106 | - * @param $text |
|
| 107 | - * |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public static function esc_classes($text){ |
|
| 111 | - $output = ''; |
|
| 112 | - |
|
| 113 | - if($text){ |
|
| 114 | - $classes = explode(" ",$text); |
|
| 115 | - $classes = array_map("trim",$classes); |
|
| 116 | - $classes = array_map("sanitize_html_class",$classes); |
|
| 117 | - if(!empty($classes)){ |
|
| 118 | - $output = implode(" ",$classes); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return $output; |
|
| 123 | - |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param $args |
|
| 128 | - * |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public static function data_attributes($args){ |
|
| 132 | - $output = ''; |
|
| 133 | - |
|
| 134 | - if(!empty($args)){ |
|
| 135 | - |
|
| 136 | - foreach($args as $key => $val){ |
|
| 137 | - if(substr( $key, 0, 5 ) === "data-"){ |
|
| 138 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $output; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param $args |
|
| 148 | - * |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 151 | - public static function aria_attributes($args){ |
|
| 152 | - $output = ''; |
|
| 153 | - |
|
| 154 | - if(!empty($args)){ |
|
| 155 | - |
|
| 156 | - foreach($args as $key => $val){ |
|
| 157 | - if(substr( $key, 0, 5 ) === "aria-"){ |
|
| 158 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return $output; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Build a font awesome icon from a class. |
|
| 168 | - * |
|
| 169 | - * @param $class |
|
| 170 | - * @param bool $space_after |
|
| 171 | - * @param array $extra_attributes An array of extra attributes. |
|
| 172 | - * |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
| 176 | - $output = ''; |
|
| 177 | - |
|
| 178 | - if($class){ |
|
| 179 | - $classes = self::esc_classes($class); |
|
| 180 | - if(!empty($classes)){ |
|
| 181 | - $output = '<i class="'.$classes.'" '; |
|
| 182 | - // extra attributes |
|
| 183 | - if(!empty($extra_attributes)){ |
|
| 184 | - $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
| 185 | - } |
|
| 186 | - $output .= '></i>'; |
|
| 187 | - if($space_after){ |
|
| 188 | - $output .= " "; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - return $output; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * @param $args |
|
| 198 | - * |
|
| 199 | - * @return string |
|
| 200 | - */ |
|
| 201 | - public static function extra_attributes($args){ |
|
| 202 | - $output = ''; |
|
| 203 | - |
|
| 204 | - if(!empty($args)){ |
|
| 205 | - |
|
| 206 | - if( is_array($args) ){ |
|
| 207 | - foreach($args as $key => $val){ |
|
| 208 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 209 | - } |
|
| 210 | - }else{ |
|
| 211 | - $output .= ' '.$args.' '; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return $output; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param $args |
|
| 221 | - * |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - public static function help_text($text){ |
|
| 225 | - $output = ''; |
|
| 226 | - |
|
| 227 | - if($text){ |
|
| 228 | - $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - return $output; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Replace element require context with JS. |
|
| 237 | - * |
|
| 238 | - * @param $input |
|
| 239 | - * |
|
| 240 | - * @return string|void |
|
| 241 | - */ |
|
| 242 | - public static function element_require( $input ) { |
|
| 243 | - |
|
| 244 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 245 | - |
|
| 246 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
| 247 | - "jQuery(form).find('[data-argument=\"", |
|
| 248 | - "\"]').find('input,select,textarea').val()", |
|
| 249 | - "\"]').find('input:checked').val()", |
|
| 250 | - ), $input ) ); |
|
| 251 | - |
|
| 252 | - if($output){ |
|
| 253 | - $output = ' data-element-require="'.$output.'" '; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - return $output; |
|
| 257 | - } |
|
| 14 | + /** |
|
| 15 | + * A component helper for generating a input name. |
|
| 16 | + * |
|
| 17 | + * @param $text |
|
| 18 | + * |
|
| 19 | + * @return string |
|
| 20 | + */ |
|
| 21 | + public static function name($text,$multiple = false){ |
|
| 22 | + $output = ''; |
|
| 23 | + |
|
| 24 | + if($text){ |
|
| 25 | + $is_multiple = strpos($text, '[]') !== false || (strpos($text, '[]') === false && $multiple ) ? '[]' : ''; |
|
| 26 | + $output = ' name="'.sanitize_html_class($text).$is_multiple.'" '; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return $output; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * A component helper for generating a item id. |
|
| 34 | + * |
|
| 35 | + * @param $text string The text to be used as the value. |
|
| 36 | + * |
|
| 37 | + * @return string The sanitized item. |
|
| 38 | + */ |
|
| 39 | + public static function id($text){ |
|
| 40 | + $output = ''; |
|
| 41 | + |
|
| 42 | + if($text){ |
|
| 43 | + $output = ' id="'.sanitize_html_class($text).'" '; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return $output; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * A component helper for generating a item title. |
|
| 51 | + * |
|
| 52 | + * @param $text string The text to be used as the value. |
|
| 53 | + * |
|
| 54 | + * @return string The sanitized item. |
|
| 55 | + */ |
|
| 56 | + public static function title($text){ |
|
| 57 | + $output = ''; |
|
| 58 | + |
|
| 59 | + if($text){ |
|
| 60 | + $output = ' title="'.esc_attr($text).'" '; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $output; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * A component helper for generating a item value. |
|
| 68 | + * |
|
| 69 | + * @param $text string The text to be used as the value. |
|
| 70 | + * |
|
| 71 | + * @return string The sanitized item. |
|
| 72 | + */ |
|
| 73 | + public static function value($text){ |
|
| 74 | + $output = ''; |
|
| 75 | + |
|
| 76 | + if($text){ |
|
| 77 | + $output = ' value="'.sanitize_text_field($text).'" '; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return $output; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * A component helper for generating a item class attribute. |
|
| 85 | + * |
|
| 86 | + * @param $text string The text to be used as the value. |
|
| 87 | + * |
|
| 88 | + * @return string The sanitized item. |
|
| 89 | + */ |
|
| 90 | + public static function class_attr($text){ |
|
| 91 | + $output = ''; |
|
| 92 | + |
|
| 93 | + if($text){ |
|
| 94 | + $classes = self::esc_classes($text); |
|
| 95 | + if(!empty($classes)){ |
|
| 96 | + $output = ' class="'.$classes.'" '; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return $output; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Escape a string of classes. |
|
| 105 | + * |
|
| 106 | + * @param $text |
|
| 107 | + * |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public static function esc_classes($text){ |
|
| 111 | + $output = ''; |
|
| 112 | + |
|
| 113 | + if($text){ |
|
| 114 | + $classes = explode(" ",$text); |
|
| 115 | + $classes = array_map("trim",$classes); |
|
| 116 | + $classes = array_map("sanitize_html_class",$classes); |
|
| 117 | + if(!empty($classes)){ |
|
| 118 | + $output = implode(" ",$classes); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return $output; |
|
| 123 | + |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param $args |
|
| 128 | + * |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public static function data_attributes($args){ |
|
| 132 | + $output = ''; |
|
| 133 | + |
|
| 134 | + if(!empty($args)){ |
|
| 135 | + |
|
| 136 | + foreach($args as $key => $val){ |
|
| 137 | + if(substr( $key, 0, 5 ) === "data-"){ |
|
| 138 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $output; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param $args |
|
| 148 | + * |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | + public static function aria_attributes($args){ |
|
| 152 | + $output = ''; |
|
| 153 | + |
|
| 154 | + if(!empty($args)){ |
|
| 155 | + |
|
| 156 | + foreach($args as $key => $val){ |
|
| 157 | + if(substr( $key, 0, 5 ) === "aria-"){ |
|
| 158 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return $output; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Build a font awesome icon from a class. |
|
| 168 | + * |
|
| 169 | + * @param $class |
|
| 170 | + * @param bool $space_after |
|
| 171 | + * @param array $extra_attributes An array of extra attributes. |
|
| 172 | + * |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
| 176 | + $output = ''; |
|
| 177 | + |
|
| 178 | + if($class){ |
|
| 179 | + $classes = self::esc_classes($class); |
|
| 180 | + if(!empty($classes)){ |
|
| 181 | + $output = '<i class="'.$classes.'" '; |
|
| 182 | + // extra attributes |
|
| 183 | + if(!empty($extra_attributes)){ |
|
| 184 | + $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
| 185 | + } |
|
| 186 | + $output .= '></i>'; |
|
| 187 | + if($space_after){ |
|
| 188 | + $output .= " "; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + return $output; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * @param $args |
|
| 198 | + * |
|
| 199 | + * @return string |
|
| 200 | + */ |
|
| 201 | + public static function extra_attributes($args){ |
|
| 202 | + $output = ''; |
|
| 203 | + |
|
| 204 | + if(!empty($args)){ |
|
| 205 | + |
|
| 206 | + if( is_array($args) ){ |
|
| 207 | + foreach($args as $key => $val){ |
|
| 208 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
| 209 | + } |
|
| 210 | + }else{ |
|
| 211 | + $output .= ' '.$args.' '; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return $output; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param $args |
|
| 221 | + * |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + public static function help_text($text){ |
|
| 225 | + $output = ''; |
|
| 226 | + |
|
| 227 | + if($text){ |
|
| 228 | + $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + return $output; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Replace element require context with JS. |
|
| 237 | + * |
|
| 238 | + * @param $input |
|
| 239 | + * |
|
| 240 | + * @return string|void |
|
| 241 | + */ |
|
| 242 | + public static function element_require( $input ) { |
|
| 243 | + |
|
| 244 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 245 | + |
|
| 246 | + $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
| 247 | + "jQuery(form).find('[data-argument=\"", |
|
| 248 | + "\"]').find('input,select,textarea').val()", |
|
| 249 | + "\"]').find('input:checked').val()", |
|
| 250 | + ), $input ) ); |
|
| 251 | + |
|
| 252 | + if($output){ |
|
| 253 | + $output = ' data-element-require="'.$output.'" '; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + return $output; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | 259 | } |
| 260 | 260 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * Bail if we are not in WP. |
| 14 | 14 | */ |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -21,199 +21,199 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | if ( ! class_exists( 'AyeCode_UI_Settings' ) ) { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * A Class to be able to change settings for Font Awesome. |
|
| 26 | - * |
|
| 27 | - * Class AyeCode_UI_Settings |
|
| 28 | - * @ver 1.0.0 |
|
| 29 | - * @todo decide how to implement textdomain |
|
| 30 | - */ |
|
| 31 | - class AyeCode_UI_Settings { |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Class version version. |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - public $version = '1.0.1'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Class textdomain. |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - public $textdomain = 'aui'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Latest version of Bootstrap at time of publish published. |
|
| 49 | - * |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - public $latest = "4.3.1"; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Current version of select2 being used. |
|
| 56 | - * |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - public $select2_version = "4.0.11"; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * The title. |
|
| 63 | - * |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - public $name = 'AyeCode UI'; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The relative url to the assets. |
|
| 70 | - * |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - public $url = ''; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Holds the settings values. |
|
| 77 | - * |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - private $settings; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * AyeCode_UI_Settings instance. |
|
| 84 | - * |
|
| 85 | - * @access private |
|
| 86 | - * @since 1.0.0 |
|
| 87 | - * @var AyeCode_UI_Settings There can be only one! |
|
| 88 | - */ |
|
| 89 | - private static $instance = null; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Main AyeCode_UI_Settings Instance. |
|
| 93 | - * |
|
| 94 | - * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
| 95 | - * |
|
| 96 | - * @since 1.0.0 |
|
| 97 | - * @static |
|
| 98 | - * @return AyeCode_UI_Settings - Main instance. |
|
| 99 | - */ |
|
| 100 | - public static function instance() { |
|
| 101 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
| 102 | - |
|
| 103 | - self::$instance = new AyeCode_UI_Settings; |
|
| 104 | - |
|
| 105 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 106 | - |
|
| 107 | - if ( is_admin() ) { |
|
| 108 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 109 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 110 | - |
|
| 111 | - // Maybe show example page |
|
| 112 | - add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
| 113 | - } |
|
| 24 | + /** |
|
| 25 | + * A Class to be able to change settings for Font Awesome. |
|
| 26 | + * |
|
| 27 | + * Class AyeCode_UI_Settings |
|
| 28 | + * @ver 1.0.0 |
|
| 29 | + * @todo decide how to implement textdomain |
|
| 30 | + */ |
|
| 31 | + class AyeCode_UI_Settings { |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Class version version. |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + public $version = '1.0.1'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Class textdomain. |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + public $textdomain = 'aui'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Latest version of Bootstrap at time of publish published. |
|
| 49 | + * |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + public $latest = "4.3.1"; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Current version of select2 being used. |
|
| 56 | + * |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + public $select2_version = "4.0.11"; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * The title. |
|
| 63 | + * |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + public $name = 'AyeCode UI'; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The relative url to the assets. |
|
| 70 | + * |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + public $url = ''; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Holds the settings values. |
|
| 77 | + * |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + private $settings; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * AyeCode_UI_Settings instance. |
|
| 84 | + * |
|
| 85 | + * @access private |
|
| 86 | + * @since 1.0.0 |
|
| 87 | + * @var AyeCode_UI_Settings There can be only one! |
|
| 88 | + */ |
|
| 89 | + private static $instance = null; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Main AyeCode_UI_Settings Instance. |
|
| 93 | + * |
|
| 94 | + * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
| 95 | + * |
|
| 96 | + * @since 1.0.0 |
|
| 97 | + * @static |
|
| 98 | + * @return AyeCode_UI_Settings - Main instance. |
|
| 99 | + */ |
|
| 100 | + public static function instance() { |
|
| 101 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
| 102 | + |
|
| 103 | + self::$instance = new AyeCode_UI_Settings; |
|
| 104 | + |
|
| 105 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 106 | + |
|
| 107 | + if ( is_admin() ) { |
|
| 108 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 109 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 110 | + |
|
| 111 | + // Maybe show example page |
|
| 112 | + add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
| 116 | - |
|
| 117 | - do_action( 'ayecode_ui_settings_loaded' ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return self::$instance; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Setup some constants. |
|
| 125 | - */ |
|
| 126 | - public function constants(){ |
|
| 127 | - define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
| 128 | - define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
| 129 | - if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
| 130 | - if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Initiate the settings and add the required action hooks. |
|
| 135 | - */ |
|
| 136 | - public function init() { |
|
| 137 | - $this->constants(); |
|
| 138 | - $this->settings = $this->get_settings(); |
|
| 139 | - $this->url = $this->get_url(); |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Maybe load CSS |
|
| 143 | - * |
|
| 144 | - * We load super early in case there is a theme version that might change the colors |
|
| 145 | - */ |
|
| 146 | - if ( $this->settings['css'] ) { |
|
| 147 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
| 148 | - } |
|
| 149 | - if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
| 150 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // maybe load JS |
|
| 154 | - if ( $this->settings['js'] ) { |
|
| 155 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
| 156 | - } |
|
| 157 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
| 158 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // Maybe set the HTML font size |
|
| 162 | - if ( $this->settings['html_font_size'] ) { |
|
| 163 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Check if we should load the admin scripts or not. |
|
| 171 | - * |
|
| 172 | - * @return bool |
|
| 173 | - */ |
|
| 174 | - public function load_admin_scripts(){ |
|
| 175 | - $result = true; |
|
| 176 | - |
|
| 177 | - if(!empty($this->settings['disable_admin'])){ |
|
| 178 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
| 179 | - foreach($url_parts as $part){ |
|
| 180 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
| 181 | - return false; // return early, no point checking further |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 115 | + add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
| 116 | + |
|
| 117 | + do_action( 'ayecode_ui_settings_loaded' ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return self::$instance; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Setup some constants. |
|
| 125 | + */ |
|
| 126 | + public function constants(){ |
|
| 127 | + define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
| 128 | + define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
| 129 | + if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
| 130 | + if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Initiate the settings and add the required action hooks. |
|
| 135 | + */ |
|
| 136 | + public function init() { |
|
| 137 | + $this->constants(); |
|
| 138 | + $this->settings = $this->get_settings(); |
|
| 139 | + $this->url = $this->get_url(); |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Maybe load CSS |
|
| 143 | + * |
|
| 144 | + * We load super early in case there is a theme version that might change the colors |
|
| 145 | + */ |
|
| 146 | + if ( $this->settings['css'] ) { |
|
| 147 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
| 148 | + } |
|
| 149 | + if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
| 150 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // maybe load JS |
|
| 154 | + if ( $this->settings['js'] ) { |
|
| 155 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
| 156 | + } |
|
| 157 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
| 158 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // Maybe set the HTML font size |
|
| 162 | + if ( $this->settings['html_font_size'] ) { |
|
| 163 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Check if we should load the admin scripts or not. |
|
| 171 | + * |
|
| 172 | + * @return bool |
|
| 173 | + */ |
|
| 174 | + public function load_admin_scripts(){ |
|
| 175 | + $result = true; |
|
| 176 | + |
|
| 177 | + if(!empty($this->settings['disable_admin'])){ |
|
| 178 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
| 179 | + foreach($url_parts as $part){ |
|
| 180 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
| 181 | + return false; // return early, no point checking further |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - return $result; |
|
| 187 | - } |
|
| 186 | + return $result; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Add a html font size to the footer. |
|
| 191 | - */ |
|
| 192 | - public function html_font_size(){ |
|
| 193 | - $this->settings = $this->get_settings(); |
|
| 194 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
| 195 | - } |
|
| 189 | + /** |
|
| 190 | + * Add a html font size to the footer. |
|
| 191 | + */ |
|
| 192 | + public function html_font_size(){ |
|
| 193 | + $this->settings = $this->get_settings(); |
|
| 194 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Adds the Font Awesome styles. |
|
| 199 | - */ |
|
| 200 | - public function enqueue_style() { |
|
| 197 | + /** |
|
| 198 | + * Adds the Font Awesome styles. |
|
| 199 | + */ |
|
| 200 | + public function enqueue_style() { |
|
| 201 | 201 | |
| 202 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
| 202 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
| 203 | 203 | |
| 204 | - if($this->settings[$css_setting]){ |
|
| 205 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
| 206 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css'; |
|
| 207 | - wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
| 208 | - wp_enqueue_style( 'ayecode-ui' ); |
|
| 204 | + if($this->settings[$css_setting]){ |
|
| 205 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
| 206 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css'; |
|
| 207 | + wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
| 208 | + wp_enqueue_style( 'ayecode-ui' ); |
|
| 209 | 209 | |
| 210 | - // flatpickr |
|
| 211 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
| 210 | + // flatpickr |
|
| 211 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
| 212 | 212 | |
| 213 | 213 | |
| 214 | - // fix some wp-admin issues |
|
| 215 | - if(is_admin()){ |
|
| 216 | - $custom_css = " |
|
| 214 | + // fix some wp-admin issues |
|
| 215 | + if(is_admin()){ |
|
| 216 | + $custom_css = " |
|
| 217 | 217 | body{ |
| 218 | 218 | background-color: #f1f1f1; |
| 219 | 219 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -249,29 +249,29 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | "; |
| 251 | 251 | |
| 252 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
| 253 | - $custom_css .= " |
|
| 252 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
| 253 | + $custom_css .= " |
|
| 254 | 254 | .edit-post-sidebar input[type=color].components-text-control__input{ |
| 255 | 255 | padding: 0; |
| 256 | 256 | } |
| 257 | 257 | "; |
| 258 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
| 259 | - } |
|
| 258 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - // custom changes |
|
| 262 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
| 261 | + // custom changes |
|
| 262 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
| 263 | 263 | |
| 264 | - } |
|
| 265 | - } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Get inline script used if bootstrap enqueued |
|
| 269 | - * |
|
| 270 | - * If this remains small then its best to use this than to add another JS file. |
|
| 271 | - */ |
|
| 272 | - public function inline_script(){ |
|
| 273 | - ob_start(); |
|
| 274 | - ?> |
|
| 267 | + /** |
|
| 268 | + * Get inline script used if bootstrap enqueued |
|
| 269 | + * |
|
| 270 | + * If this remains small then its best to use this than to add another JS file. |
|
| 271 | + */ |
|
| 272 | + public function inline_script(){ |
|
| 273 | + ob_start(); |
|
| 274 | + ?> |
|
| 275 | 275 | <script> |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -758,25 +758,25 @@ discard block |
||
| 758 | 758 | |
| 759 | 759 | </script> |
| 760 | 760 | <?php |
| 761 | - $output = ob_get_clean(); |
|
| 761 | + $output = ob_get_clean(); |
|
| 762 | 762 | |
| 763 | - /* |
|
| 763 | + /* |
|
| 764 | 764 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 765 | 765 | */ |
| 766 | - return str_replace( array( |
|
| 767 | - '<script>', |
|
| 768 | - '</script>' |
|
| 769 | - ), '', $output ); |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * Get inline script used if bootstrap file browser enqueued. |
|
| 774 | - * |
|
| 775 | - * If this remains small then its best to use this than to add another JS file. |
|
| 776 | - */ |
|
| 777 | - public function inline_script_file_browser(){ |
|
| 778 | - ob_start(); |
|
| 779 | - ?> |
|
| 766 | + return str_replace( array( |
|
| 767 | + '<script>', |
|
| 768 | + '</script>' |
|
| 769 | + ), '', $output ); |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * Get inline script used if bootstrap file browser enqueued. |
|
| 774 | + * |
|
| 775 | + * If this remains small then its best to use this than to add another JS file. |
|
| 776 | + */ |
|
| 777 | + public function inline_script_file_browser(){ |
|
| 778 | + ob_start(); |
|
| 779 | + ?> |
|
| 780 | 780 | <script> |
| 781 | 781 | // run on doc ready |
| 782 | 782 | jQuery(document).ready(function () { |
@@ -784,184 +784,184 @@ discard block |
||
| 784 | 784 | }); |
| 785 | 785 | </script> |
| 786 | 786 | <?php |
| 787 | - $output = ob_get_clean(); |
|
| 787 | + $output = ob_get_clean(); |
|
| 788 | 788 | |
| 789 | - /* |
|
| 789 | + /* |
|
| 790 | 790 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 791 | 791 | */ |
| 792 | - return str_replace( array( |
|
| 793 | - '<script>', |
|
| 794 | - '</script>' |
|
| 795 | - ), '', $output ); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * Adds the Font Awesome JS. |
|
| 800 | - */ |
|
| 801 | - public function enqueue_scripts() { |
|
| 802 | - |
|
| 803 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
| 804 | - |
|
| 805 | - // select2 |
|
| 806 | - wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version ); |
|
| 807 | - |
|
| 808 | - // flatpickr |
|
| 809 | - wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
| 810 | - |
|
| 811 | - // Bootstrap file browser |
|
| 812 | - wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version ); |
|
| 813 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
| 814 | - |
|
| 815 | - $load_inline = false; |
|
| 816 | - |
|
| 817 | - if($this->settings[$js_setting]=='core-popper'){ |
|
| 818 | - // Bootstrap bundle |
|
| 819 | - $url = $this->url.'assets/js/bootstrap.bundle.min.js'; |
|
| 820 | - wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest ); |
|
| 821 | - // if in admin then add to footer for compatibility. |
|
| 822 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle'); |
|
| 823 | - $script = $this->inline_script(); |
|
| 824 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
| 825 | - }elseif($this->settings[$js_setting]=='popper'){ |
|
| 826 | - $url = $this->url.'assets/js/popper.min.js'; |
|
| 827 | - wp_register_script( 'bootstrap-js-popper', $url, array('jquery'), $this->latest ); |
|
| 828 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
| 829 | - $load_inline = true; |
|
| 830 | - }else{ |
|
| 831 | - $load_inline = true; |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
| 835 | - if($load_inline){ |
|
| 836 | - wp_register_script( 'bootstrap-dummy', '',array('jquery') ); |
|
| 837 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
| 838 | - $script = $this->inline_script(); |
|
| 839 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - /** |
|
| 845 | - * Enqueue flatpickr if called. |
|
| 846 | - */ |
|
| 847 | - public function enqueue_flatpickr(){ |
|
| 848 | - wp_enqueue_style( 'flatpickr' ); |
|
| 849 | - wp_enqueue_script( 'flatpickr' ); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - /** |
|
| 853 | - * Get the url path to the current folder. |
|
| 854 | - * |
|
| 855 | - * @return string |
|
| 856 | - */ |
|
| 857 | - public function get_url() { |
|
| 858 | - |
|
| 859 | - $url = ''; |
|
| 860 | - // check if we are inside a plugin |
|
| 861 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
| 862 | - |
|
| 863 | - // add check in-case user has changed wp-content dir name. |
|
| 864 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
| 865 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
| 866 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
| 867 | - |
|
| 868 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
| 869 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - return $url; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * Register the database settings with WordPress. |
|
| 877 | - */ |
|
| 878 | - public function register_settings() { |
|
| 879 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Add the WordPress settings menu item. |
|
| 884 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 885 | - */ |
|
| 886 | - public function menu_item() { |
|
| 887 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 888 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
| 889 | - $this, |
|
| 890 | - 'settings_page' |
|
| 891 | - ) ); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /** |
|
| 895 | - * Get a list of themes and their default JS settings. |
|
| 896 | - * |
|
| 897 | - * @return array |
|
| 898 | - */ |
|
| 899 | - public function theme_js_settings(){ |
|
| 900 | - return array( |
|
| 901 | - 'ayetheme' => 'popper', |
|
| 902 | - 'listimia' => 'required', |
|
| 903 | - 'listimia_backend' => 'core-popper', |
|
| 904 | - 'avada' => 'required', |
|
| 905 | - ); |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Get the current Font Awesome output settings. |
|
| 910 | - * |
|
| 911 | - * @return array The array of settings. |
|
| 912 | - */ |
|
| 913 | - public function get_settings() { |
|
| 914 | - |
|
| 915 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
| 916 | - $js_default = 'core-popper'; |
|
| 917 | - $js_default_backend = $js_default; |
|
| 918 | - |
|
| 919 | - // maybe set defaults (if no settings set) |
|
| 920 | - if(empty($db_settings)){ |
|
| 921 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
| 922 | - $theme_js_settings = self::theme_js_settings(); |
|
| 923 | - if(isset($theme_js_settings[$active_theme])){ |
|
| 924 | - $js_default = $theme_js_settings[$active_theme]; |
|
| 925 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - $defaults = array( |
|
| 930 | - 'css' => 'compatibility', // core, compatibility |
|
| 931 | - 'js' => $js_default, // js to load, core-popper, popper |
|
| 932 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
| 933 | - 'css_backend' => 'compatibility', // core, compatibility |
|
| 934 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
| 935 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
| 936 | - ); |
|
| 937 | - |
|
| 938 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 939 | - |
|
| 940 | - /** |
|
| 941 | - * Filter the Bootstrap settings. |
|
| 942 | - * |
|
| 943 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 944 | - */ |
|
| 945 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - /** |
|
| 950 | - * The settings page html output. |
|
| 951 | - */ |
|
| 952 | - public function settings_page() { |
|
| 953 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 954 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
| 955 | - } |
|
| 956 | - ?> |
|
| 792 | + return str_replace( array( |
|
| 793 | + '<script>', |
|
| 794 | + '</script>' |
|
| 795 | + ), '', $output ); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * Adds the Font Awesome JS. |
|
| 800 | + */ |
|
| 801 | + public function enqueue_scripts() { |
|
| 802 | + |
|
| 803 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
| 804 | + |
|
| 805 | + // select2 |
|
| 806 | + wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version ); |
|
| 807 | + |
|
| 808 | + // flatpickr |
|
| 809 | + wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
| 810 | + |
|
| 811 | + // Bootstrap file browser |
|
| 812 | + wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version ); |
|
| 813 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
| 814 | + |
|
| 815 | + $load_inline = false; |
|
| 816 | + |
|
| 817 | + if($this->settings[$js_setting]=='core-popper'){ |
|
| 818 | + // Bootstrap bundle |
|
| 819 | + $url = $this->url.'assets/js/bootstrap.bundle.min.js'; |
|
| 820 | + wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest ); |
|
| 821 | + // if in admin then add to footer for compatibility. |
|
| 822 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle'); |
|
| 823 | + $script = $this->inline_script(); |
|
| 824 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
| 825 | + }elseif($this->settings[$js_setting]=='popper'){ |
|
| 826 | + $url = $this->url.'assets/js/popper.min.js'; |
|
| 827 | + wp_register_script( 'bootstrap-js-popper', $url, array('jquery'), $this->latest ); |
|
| 828 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
| 829 | + $load_inline = true; |
|
| 830 | + }else{ |
|
| 831 | + $load_inline = true; |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
| 835 | + if($load_inline){ |
|
| 836 | + wp_register_script( 'bootstrap-dummy', '',array('jquery') ); |
|
| 837 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
| 838 | + $script = $this->inline_script(); |
|
| 839 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + /** |
|
| 845 | + * Enqueue flatpickr if called. |
|
| 846 | + */ |
|
| 847 | + public function enqueue_flatpickr(){ |
|
| 848 | + wp_enqueue_style( 'flatpickr' ); |
|
| 849 | + wp_enqueue_script( 'flatpickr' ); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + /** |
|
| 853 | + * Get the url path to the current folder. |
|
| 854 | + * |
|
| 855 | + * @return string |
|
| 856 | + */ |
|
| 857 | + public function get_url() { |
|
| 858 | + |
|
| 859 | + $url = ''; |
|
| 860 | + // check if we are inside a plugin |
|
| 861 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
| 862 | + |
|
| 863 | + // add check in-case user has changed wp-content dir name. |
|
| 864 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
| 865 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
| 866 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
| 867 | + |
|
| 868 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
| 869 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + return $url; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * Register the database settings with WordPress. |
|
| 877 | + */ |
|
| 878 | + public function register_settings() { |
|
| 879 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Add the WordPress settings menu item. |
|
| 884 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 885 | + */ |
|
| 886 | + public function menu_item() { |
|
| 887 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 888 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
| 889 | + $this, |
|
| 890 | + 'settings_page' |
|
| 891 | + ) ); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /** |
|
| 895 | + * Get a list of themes and their default JS settings. |
|
| 896 | + * |
|
| 897 | + * @return array |
|
| 898 | + */ |
|
| 899 | + public function theme_js_settings(){ |
|
| 900 | + return array( |
|
| 901 | + 'ayetheme' => 'popper', |
|
| 902 | + 'listimia' => 'required', |
|
| 903 | + 'listimia_backend' => 'core-popper', |
|
| 904 | + 'avada' => 'required', |
|
| 905 | + ); |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Get the current Font Awesome output settings. |
|
| 910 | + * |
|
| 911 | + * @return array The array of settings. |
|
| 912 | + */ |
|
| 913 | + public function get_settings() { |
|
| 914 | + |
|
| 915 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
| 916 | + $js_default = 'core-popper'; |
|
| 917 | + $js_default_backend = $js_default; |
|
| 918 | + |
|
| 919 | + // maybe set defaults (if no settings set) |
|
| 920 | + if(empty($db_settings)){ |
|
| 921 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
| 922 | + $theme_js_settings = self::theme_js_settings(); |
|
| 923 | + if(isset($theme_js_settings[$active_theme])){ |
|
| 924 | + $js_default = $theme_js_settings[$active_theme]; |
|
| 925 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + $defaults = array( |
|
| 930 | + 'css' => 'compatibility', // core, compatibility |
|
| 931 | + 'js' => $js_default, // js to load, core-popper, popper |
|
| 932 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
| 933 | + 'css_backend' => 'compatibility', // core, compatibility |
|
| 934 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
| 935 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
| 936 | + ); |
|
| 937 | + |
|
| 938 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 939 | + |
|
| 940 | + /** |
|
| 941 | + * Filter the Bootstrap settings. |
|
| 942 | + * |
|
| 943 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 944 | + */ |
|
| 945 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + /** |
|
| 950 | + * The settings page html output. |
|
| 951 | + */ |
|
| 952 | + public function settings_page() { |
|
| 953 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 954 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
| 955 | + } |
|
| 956 | + ?> |
|
| 957 | 957 | <div class="wrap"> |
| 958 | 958 | <h1><?php echo $this->name; ?></h1> |
| 959 | 959 | <p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p> |
| 960 | 960 | <form method="post" action="options.php"> |
| 961 | 961 | <?php |
| 962 | - settings_fields( 'ayecode-ui-settings' ); |
|
| 963 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
| 964 | - ?> |
|
| 962 | + settings_fields( 'ayecode-ui-settings' ); |
|
| 963 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
| 964 | + ?> |
|
| 965 | 965 | |
| 966 | 966 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
| 967 | 967 | <table class="form-table wpbs-table-settings"> |
@@ -1041,489 +1041,489 @@ discard block |
||
| 1041 | 1041 | </table> |
| 1042 | 1042 | |
| 1043 | 1043 | <?php |
| 1044 | - submit_button(); |
|
| 1045 | - ?> |
|
| 1044 | + submit_button(); |
|
| 1045 | + ?> |
|
| 1046 | 1046 | </form> |
| 1047 | 1047 | |
| 1048 | 1048 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
| 1049 | 1049 | </div> |
| 1050 | 1050 | |
| 1051 | 1051 | <?php |
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - public function customizer_settings($wp_customize){ |
|
| 1055 | - $wp_customize->add_section('aui_settings', array( |
|
| 1056 | - 'title' => __('AyeCode UI','aui'), |
|
| 1057 | - 'priority' => 120, |
|
| 1058 | - )); |
|
| 1059 | - |
|
| 1060 | - // ============================= |
|
| 1061 | - // = Color Picker = |
|
| 1062 | - // ============================= |
|
| 1063 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
| 1064 | - 'default' => AUI_PRIMARY_COLOR, |
|
| 1065 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
| 1066 | - 'capability' => 'edit_theme_options', |
|
| 1067 | - 'type' => 'option', |
|
| 1068 | - 'transport' => 'refresh', |
|
| 1069 | - )); |
|
| 1070 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
| 1071 | - 'label' => __('Primary Color','aui'), |
|
| 1072 | - 'section' => 'aui_settings', |
|
| 1073 | - 'settings' => 'aui_options[color_primary]', |
|
| 1074 | - ))); |
|
| 1075 | - |
|
| 1076 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
| 1077 | - 'default' => '#6c757d', |
|
| 1078 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
| 1079 | - 'capability' => 'edit_theme_options', |
|
| 1080 | - 'type' => 'option', |
|
| 1081 | - 'transport' => 'refresh', |
|
| 1082 | - )); |
|
| 1083 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
| 1084 | - 'label' => __('Secondary Color','aui'), |
|
| 1085 | - 'section' => 'aui_settings', |
|
| 1086 | - 'settings' => 'aui_options[color_secondary]', |
|
| 1087 | - ))); |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - |
|
| 1091 | - public static function custom_css($compatibility = true) { |
|
| 1092 | - $settings = get_option('aui_options'); |
|
| 1093 | - |
|
| 1094 | - ob_start(); |
|
| 1095 | - |
|
| 1096 | - $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
| 1097 | - $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
| 1098 | - //AUI_PRIMARY_COLOR_ORIGINAL |
|
| 1099 | - ?> |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + public function customizer_settings($wp_customize){ |
|
| 1055 | + $wp_customize->add_section('aui_settings', array( |
|
| 1056 | + 'title' => __('AyeCode UI','aui'), |
|
| 1057 | + 'priority' => 120, |
|
| 1058 | + )); |
|
| 1059 | + |
|
| 1060 | + // ============================= |
|
| 1061 | + // = Color Picker = |
|
| 1062 | + // ============================= |
|
| 1063 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
| 1064 | + 'default' => AUI_PRIMARY_COLOR, |
|
| 1065 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
| 1066 | + 'capability' => 'edit_theme_options', |
|
| 1067 | + 'type' => 'option', |
|
| 1068 | + 'transport' => 'refresh', |
|
| 1069 | + )); |
|
| 1070 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
| 1071 | + 'label' => __('Primary Color','aui'), |
|
| 1072 | + 'section' => 'aui_settings', |
|
| 1073 | + 'settings' => 'aui_options[color_primary]', |
|
| 1074 | + ))); |
|
| 1075 | + |
|
| 1076 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
| 1077 | + 'default' => '#6c757d', |
|
| 1078 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
| 1079 | + 'capability' => 'edit_theme_options', |
|
| 1080 | + 'type' => 'option', |
|
| 1081 | + 'transport' => 'refresh', |
|
| 1082 | + )); |
|
| 1083 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
| 1084 | + 'label' => __('Secondary Color','aui'), |
|
| 1085 | + 'section' => 'aui_settings', |
|
| 1086 | + 'settings' => 'aui_options[color_secondary]', |
|
| 1087 | + ))); |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + |
|
| 1091 | + public static function custom_css($compatibility = true) { |
|
| 1092 | + $settings = get_option('aui_options'); |
|
| 1093 | + |
|
| 1094 | + ob_start(); |
|
| 1095 | + |
|
| 1096 | + $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
| 1097 | + $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
| 1098 | + //AUI_PRIMARY_COLOR_ORIGINAL |
|
| 1099 | + ?> |
|
| 1100 | 1100 | <style> |
| 1101 | 1101 | <?php |
| 1102 | - if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
| 1103 | - echo self::css_primary($primary_color,$compatibility); |
|
| 1104 | - } |
|
| 1102 | + if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
| 1103 | + echo self::css_primary($primary_color,$compatibility); |
|
| 1104 | + } |
|
| 1105 | 1105 | |
| 1106 | - if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
| 1107 | - echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
| 1108 | - } |
|
| 1106 | + if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
| 1107 | + echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
| 1108 | + } |
|
| 1109 | 1109 | ?> |
| 1110 | 1110 | </style> |
| 1111 | 1111 | <?php |
| 1112 | 1112 | |
| 1113 | 1113 | |
| 1114 | - /* |
|
| 1114 | + /* |
|
| 1115 | 1115 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1116 | 1116 | */ |
| 1117 | - return str_replace( array( |
|
| 1118 | - '<style>', |
|
| 1119 | - '</style>' |
|
| 1120 | - ), '', ob_get_clean()); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - public static function css_primary($color_code,$compatibility){; |
|
| 1124 | - $color_code = sanitize_hex_color($color_code); |
|
| 1125 | - if(!$color_code){return '';} |
|
| 1126 | - /** |
|
| 1127 | - * c = color, b = background color, o = border-color, f = fill |
|
| 1128 | - */ |
|
| 1129 | - $selectors = array( |
|
| 1130 | - 'a' => array('c'), |
|
| 1131 | - '.btn-primary' => array('b','o'), |
|
| 1132 | - '.btn-primary.disabled' => array('b','o'), |
|
| 1133 | - '.btn-primary:disabled' => array('b','o'), |
|
| 1134 | - '.btn-outline-primary' => array('c','o'), |
|
| 1135 | - '.btn-outline-primary:hover' => array('b','o'), |
|
| 1136 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
| 1137 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
| 1138 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
| 1139 | - '.btn-link' => array('c'), |
|
| 1140 | - '.dropdown-item.active' => array('b'), |
|
| 1141 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
| 1142 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
| 1117 | + return str_replace( array( |
|
| 1118 | + '<style>', |
|
| 1119 | + '</style>' |
|
| 1120 | + ), '', ob_get_clean()); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + public static function css_primary($color_code,$compatibility){; |
|
| 1124 | + $color_code = sanitize_hex_color($color_code); |
|
| 1125 | + if(!$color_code){return '';} |
|
| 1126 | + /** |
|
| 1127 | + * c = color, b = background color, o = border-color, f = fill |
|
| 1128 | + */ |
|
| 1129 | + $selectors = array( |
|
| 1130 | + 'a' => array('c'), |
|
| 1131 | + '.btn-primary' => array('b','o'), |
|
| 1132 | + '.btn-primary.disabled' => array('b','o'), |
|
| 1133 | + '.btn-primary:disabled' => array('b','o'), |
|
| 1134 | + '.btn-outline-primary' => array('c','o'), |
|
| 1135 | + '.btn-outline-primary:hover' => array('b','o'), |
|
| 1136 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
| 1137 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
| 1138 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
| 1139 | + '.btn-link' => array('c'), |
|
| 1140 | + '.dropdown-item.active' => array('b'), |
|
| 1141 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
| 1142 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
| 1143 | 1143 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
| 1144 | 1144 | // '.custom-range::-moz-range-thumb' => array('b'), |
| 1145 | 1145 | // '.custom-range::-ms-thumb' => array('b'), |
| 1146 | - '.nav-pills .nav-link.active' => array('b'), |
|
| 1147 | - '.nav-pills .show>.nav-link' => array('b'), |
|
| 1148 | - '.page-link' => array('c'), |
|
| 1149 | - '.page-item.active .page-link' => array('b','o'), |
|
| 1150 | - '.badge-primary' => array('b'), |
|
| 1151 | - '.alert-primary' => array('b','o'), |
|
| 1152 | - '.progress-bar' => array('b'), |
|
| 1153 | - '.list-group-item.active' => array('b','o'), |
|
| 1154 | - '.bg-primary' => array('b','f'), |
|
| 1155 | - '.btn-link.btn-primary' => array('c'), |
|
| 1156 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
| 1157 | - ); |
|
| 1158 | - |
|
| 1159 | - $important_selectors = array( |
|
| 1160 | - '.bg-primary' => array('b','f'), |
|
| 1161 | - '.border-primary' => array('o'), |
|
| 1162 | - '.text-primary' => array('c'), |
|
| 1163 | - ); |
|
| 1164 | - |
|
| 1165 | - $color = array(); |
|
| 1166 | - $color_i = array(); |
|
| 1167 | - $background = array(); |
|
| 1168 | - $background_i = array(); |
|
| 1169 | - $border = array(); |
|
| 1170 | - $border_i = array(); |
|
| 1171 | - $fill = array(); |
|
| 1172 | - $fill_i = array(); |
|
| 1173 | - |
|
| 1174 | - $output = ''; |
|
| 1175 | - |
|
| 1176 | - // build rules into each type |
|
| 1177 | - foreach($selectors as $selector => $types){ |
|
| 1178 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1179 | - $types = array_combine($types,$types); |
|
| 1180 | - if(isset($types['c'])){$color[] = $selector;} |
|
| 1181 | - if(isset($types['b'])){$background[] = $selector;} |
|
| 1182 | - if(isset($types['o'])){$border[] = $selector;} |
|
| 1183 | - if(isset($types['f'])){$fill[] = $selector;} |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - // build rules into each type |
|
| 1187 | - foreach($important_selectors as $selector => $types){ |
|
| 1188 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1189 | - $types = array_combine($types,$types); |
|
| 1190 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
| 1191 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
| 1192 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
| 1193 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - // add any color rules |
|
| 1197 | - if(!empty($color)){ |
|
| 1198 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
| 1199 | - } |
|
| 1200 | - if(!empty($color_i)){ |
|
| 1201 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - // add any background color rules |
|
| 1205 | - if(!empty($background)){ |
|
| 1206 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
| 1207 | - } |
|
| 1208 | - if(!empty($background_i)){ |
|
| 1209 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - // add any border color rules |
|
| 1213 | - if(!empty($border)){ |
|
| 1214 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
| 1215 | - } |
|
| 1216 | - if(!empty($border_i)){ |
|
| 1217 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - // add any fill color rules |
|
| 1221 | - if(!empty($fill)){ |
|
| 1222 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
| 1223 | - } |
|
| 1224 | - if(!empty($fill_i)){ |
|
| 1225 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - $prefix = $compatibility ? ".bsui " : ""; |
|
| 1230 | - |
|
| 1231 | - // darken |
|
| 1232 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
| 1233 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
| 1234 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
| 1235 | - |
|
| 1236 | - // lighten |
|
| 1237 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
| 1238 | - |
|
| 1239 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
| 1240 | - $op_25 = $color_code."40"; // 25% opacity |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - // button states |
|
| 1244 | - $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
| 1245 | - $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1246 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
| 1247 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1248 | - |
|
| 1249 | - |
|
| 1250 | - // dropdown's |
|
| 1251 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
| 1252 | - |
|
| 1253 | - |
|
| 1254 | - // input states |
|
| 1255 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1256 | - |
|
| 1257 | - // page link |
|
| 1258 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1259 | - |
|
| 1260 | - return $output; |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - public static function css_secondary($color_code,$compatibility){; |
|
| 1264 | - $color_code = sanitize_hex_color($color_code); |
|
| 1265 | - if(!$color_code){return '';} |
|
| 1266 | - /** |
|
| 1267 | - * c = color, b = background color, o = border-color, f = fill |
|
| 1268 | - */ |
|
| 1269 | - $selectors = array( |
|
| 1270 | - '.btn-secondary' => array('b','o'), |
|
| 1271 | - '.btn-secondary.disabled' => array('b','o'), |
|
| 1272 | - '.btn-secondary:disabled' => array('b','o'), |
|
| 1273 | - '.btn-outline-secondary' => array('c','o'), |
|
| 1274 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
| 1275 | - '.btn-outline-secondary.disabled' => array('c'), |
|
| 1276 | - '.btn-outline-secondary:disabled' => array('c'), |
|
| 1277 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
| 1278 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
| 1279 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
| 1280 | - '.badge-secondary' => array('b'), |
|
| 1281 | - '.alert-secondary' => array('b','o'), |
|
| 1282 | - '.btn-link.btn-secondary' => array('c'), |
|
| 1283 | - ); |
|
| 1284 | - |
|
| 1285 | - $important_selectors = array( |
|
| 1286 | - '.bg-secondary' => array('b','f'), |
|
| 1287 | - '.border-secondary' => array('o'), |
|
| 1288 | - '.text-secondary' => array('c'), |
|
| 1289 | - ); |
|
| 1290 | - |
|
| 1291 | - $color = array(); |
|
| 1292 | - $color_i = array(); |
|
| 1293 | - $background = array(); |
|
| 1294 | - $background_i = array(); |
|
| 1295 | - $border = array(); |
|
| 1296 | - $border_i = array(); |
|
| 1297 | - $fill = array(); |
|
| 1298 | - $fill_i = array(); |
|
| 1299 | - |
|
| 1300 | - $output = ''; |
|
| 1301 | - |
|
| 1302 | - // build rules into each type |
|
| 1303 | - foreach($selectors as $selector => $types){ |
|
| 1304 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1305 | - $types = array_combine($types,$types); |
|
| 1306 | - if(isset($types['c'])){$color[] = $selector;} |
|
| 1307 | - if(isset($types['b'])){$background[] = $selector;} |
|
| 1308 | - if(isset($types['o'])){$border[] = $selector;} |
|
| 1309 | - if(isset($types['f'])){$fill[] = $selector;} |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - // build rules into each type |
|
| 1313 | - foreach($important_selectors as $selector => $types){ |
|
| 1314 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1315 | - $types = array_combine($types,$types); |
|
| 1316 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
| 1317 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
| 1318 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
| 1319 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - // add any color rules |
|
| 1323 | - if(!empty($color)){ |
|
| 1324 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
| 1325 | - } |
|
| 1326 | - if(!empty($color_i)){ |
|
| 1327 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - // add any background color rules |
|
| 1331 | - if(!empty($background)){ |
|
| 1332 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
| 1333 | - } |
|
| 1334 | - if(!empty($background_i)){ |
|
| 1335 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - // add any border color rules |
|
| 1339 | - if(!empty($border)){ |
|
| 1340 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
| 1341 | - } |
|
| 1342 | - if(!empty($border_i)){ |
|
| 1343 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - // add any fill color rules |
|
| 1347 | - if(!empty($fill)){ |
|
| 1348 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
| 1349 | - } |
|
| 1350 | - if(!empty($fill_i)){ |
|
| 1351 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - |
|
| 1355 | - $prefix = $compatibility ? ".bsui " : ""; |
|
| 1356 | - |
|
| 1357 | - // darken |
|
| 1358 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
| 1359 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
| 1360 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
| 1361 | - |
|
| 1362 | - // lighten |
|
| 1363 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
| 1364 | - |
|
| 1365 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
| 1366 | - $op_25 = $color_code."40"; // 25% opacity |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - // button states |
|
| 1370 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
| 1371 | - $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1372 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
| 1373 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - return $output; |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - /** |
|
| 1380 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
| 1381 | - * |
|
| 1382 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
| 1383 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
| 1384 | - * |
|
| 1385 | - * @return string |
|
| 1386 | - */ |
|
| 1387 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
| 1388 | - $hexCode = ltrim($hexCode, '#'); |
|
| 1389 | - |
|
| 1390 | - if (strlen($hexCode) == 3) { |
|
| 1391 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
| 1395 | - |
|
| 1396 | - foreach ($hexCode as & $color) { |
|
| 1397 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
| 1398 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
| 1399 | - |
|
| 1400 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - return '#' . implode($hexCode); |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * Check if we should display examples. |
|
| 1408 | - */ |
|
| 1409 | - public function maybe_show_examples(){ |
|
| 1410 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
| 1411 | - echo "<head>"; |
|
| 1412 | - wp_head(); |
|
| 1413 | - echo "</head>"; |
|
| 1414 | - echo "<body>"; |
|
| 1415 | - echo $this->get_examples(); |
|
| 1416 | - echo "</body>"; |
|
| 1417 | - exit; |
|
| 1418 | - } |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * Get developer examples. |
|
| 1423 | - * |
|
| 1424 | - * @return string |
|
| 1425 | - */ |
|
| 1426 | - public function get_examples(){ |
|
| 1427 | - $output = ''; |
|
| 1428 | - |
|
| 1429 | - |
|
| 1430 | - // open form |
|
| 1431 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
| 1432 | - |
|
| 1433 | - // input example |
|
| 1434 | - $output .= aui()->input(array( |
|
| 1435 | - 'type' => 'text', |
|
| 1436 | - 'id' => 'text-example', |
|
| 1437 | - 'name' => 'text-example', |
|
| 1438 | - 'placeholder' => 'text placeholder', |
|
| 1439 | - 'title' => 'Text input example', |
|
| 1440 | - 'value' => '', |
|
| 1441 | - 'required' => false, |
|
| 1442 | - 'help_text' => 'help text', |
|
| 1443 | - 'label' => 'Text input example label' |
|
| 1444 | - )); |
|
| 1445 | - |
|
| 1446 | - // input example |
|
| 1447 | - $output .= aui()->input(array( |
|
| 1448 | - 'type' => 'url', |
|
| 1449 | - 'id' => 'text-example2', |
|
| 1450 | - 'name' => 'text-example', |
|
| 1451 | - 'placeholder' => 'url placeholder', |
|
| 1452 | - 'title' => 'Text input example', |
|
| 1453 | - 'value' => '', |
|
| 1454 | - 'required' => false, |
|
| 1455 | - 'help_text' => 'help text', |
|
| 1456 | - 'label' => 'Text input example label' |
|
| 1457 | - )); |
|
| 1458 | - |
|
| 1459 | - // checkbox example |
|
| 1460 | - $output .= aui()->input(array( |
|
| 1461 | - 'type' => 'checkbox', |
|
| 1462 | - 'id' => 'checkbox-example', |
|
| 1463 | - 'name' => 'checkbox-example', |
|
| 1464 | - 'placeholder' => 'checkbox-example', |
|
| 1465 | - 'title' => 'Checkbox example', |
|
| 1466 | - 'value' => '1', |
|
| 1467 | - 'checked' => true, |
|
| 1468 | - 'required' => false, |
|
| 1469 | - 'help_text' => 'help text', |
|
| 1470 | - 'label' => 'Checkbox checked' |
|
| 1471 | - )); |
|
| 1472 | - |
|
| 1473 | - // checkbox example |
|
| 1474 | - $output .= aui()->input(array( |
|
| 1475 | - 'type' => 'checkbox', |
|
| 1476 | - 'id' => 'checkbox-example2', |
|
| 1477 | - 'name' => 'checkbox-example2', |
|
| 1478 | - 'placeholder' => 'checkbox-example', |
|
| 1479 | - 'title' => 'Checkbox example', |
|
| 1480 | - 'value' => '1', |
|
| 1481 | - 'checked' => false, |
|
| 1482 | - 'required' => false, |
|
| 1483 | - 'help_text' => 'help text', |
|
| 1484 | - 'label' => 'Checkbox un-checked' |
|
| 1485 | - )); |
|
| 1486 | - |
|
| 1487 | - // switch example |
|
| 1488 | - $output .= aui()->input(array( |
|
| 1489 | - 'type' => 'checkbox', |
|
| 1490 | - 'id' => 'switch-example', |
|
| 1491 | - 'name' => 'switch-example', |
|
| 1492 | - 'placeholder' => 'checkbox-example', |
|
| 1493 | - 'title' => 'Switch example', |
|
| 1494 | - 'value' => '1', |
|
| 1495 | - 'checked' => true, |
|
| 1496 | - 'switch' => true, |
|
| 1497 | - 'required' => false, |
|
| 1498 | - 'help_text' => 'help text', |
|
| 1499 | - 'label' => 'Switch on' |
|
| 1500 | - )); |
|
| 1501 | - |
|
| 1502 | - // switch example |
|
| 1503 | - $output .= aui()->input(array( |
|
| 1504 | - 'type' => 'checkbox', |
|
| 1505 | - 'id' => 'switch-example2', |
|
| 1506 | - 'name' => 'switch-example2', |
|
| 1507 | - 'placeholder' => 'checkbox-example', |
|
| 1508 | - 'title' => 'Switch example', |
|
| 1509 | - 'value' => '1', |
|
| 1510 | - 'checked' => false, |
|
| 1511 | - 'switch' => true, |
|
| 1512 | - 'required' => false, |
|
| 1513 | - 'help_text' => 'help text', |
|
| 1514 | - 'label' => 'Switch off' |
|
| 1515 | - )); |
|
| 1516 | - |
|
| 1517 | - // close form |
|
| 1518 | - $output .= "</form>"; |
|
| 1519 | - |
|
| 1520 | - return $output; |
|
| 1521 | - } |
|
| 1522 | - |
|
| 1523 | - } |
|
| 1524 | - |
|
| 1525 | - /** |
|
| 1526 | - * Run the class if found. |
|
| 1527 | - */ |
|
| 1528 | - AyeCode_UI_Settings::instance(); |
|
| 1146 | + '.nav-pills .nav-link.active' => array('b'), |
|
| 1147 | + '.nav-pills .show>.nav-link' => array('b'), |
|
| 1148 | + '.page-link' => array('c'), |
|
| 1149 | + '.page-item.active .page-link' => array('b','o'), |
|
| 1150 | + '.badge-primary' => array('b'), |
|
| 1151 | + '.alert-primary' => array('b','o'), |
|
| 1152 | + '.progress-bar' => array('b'), |
|
| 1153 | + '.list-group-item.active' => array('b','o'), |
|
| 1154 | + '.bg-primary' => array('b','f'), |
|
| 1155 | + '.btn-link.btn-primary' => array('c'), |
|
| 1156 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
| 1157 | + ); |
|
| 1158 | + |
|
| 1159 | + $important_selectors = array( |
|
| 1160 | + '.bg-primary' => array('b','f'), |
|
| 1161 | + '.border-primary' => array('o'), |
|
| 1162 | + '.text-primary' => array('c'), |
|
| 1163 | + ); |
|
| 1164 | + |
|
| 1165 | + $color = array(); |
|
| 1166 | + $color_i = array(); |
|
| 1167 | + $background = array(); |
|
| 1168 | + $background_i = array(); |
|
| 1169 | + $border = array(); |
|
| 1170 | + $border_i = array(); |
|
| 1171 | + $fill = array(); |
|
| 1172 | + $fill_i = array(); |
|
| 1173 | + |
|
| 1174 | + $output = ''; |
|
| 1175 | + |
|
| 1176 | + // build rules into each type |
|
| 1177 | + foreach($selectors as $selector => $types){ |
|
| 1178 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1179 | + $types = array_combine($types,$types); |
|
| 1180 | + if(isset($types['c'])){$color[] = $selector;} |
|
| 1181 | + if(isset($types['b'])){$background[] = $selector;} |
|
| 1182 | + if(isset($types['o'])){$border[] = $selector;} |
|
| 1183 | + if(isset($types['f'])){$fill[] = $selector;} |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + // build rules into each type |
|
| 1187 | + foreach($important_selectors as $selector => $types){ |
|
| 1188 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1189 | + $types = array_combine($types,$types); |
|
| 1190 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
| 1191 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
| 1192 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
| 1193 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + // add any color rules |
|
| 1197 | + if(!empty($color)){ |
|
| 1198 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
| 1199 | + } |
|
| 1200 | + if(!empty($color_i)){ |
|
| 1201 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + // add any background color rules |
|
| 1205 | + if(!empty($background)){ |
|
| 1206 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
| 1207 | + } |
|
| 1208 | + if(!empty($background_i)){ |
|
| 1209 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + // add any border color rules |
|
| 1213 | + if(!empty($border)){ |
|
| 1214 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
| 1215 | + } |
|
| 1216 | + if(!empty($border_i)){ |
|
| 1217 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + // add any fill color rules |
|
| 1221 | + if(!empty($fill)){ |
|
| 1222 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
| 1223 | + } |
|
| 1224 | + if(!empty($fill_i)){ |
|
| 1225 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + $prefix = $compatibility ? ".bsui " : ""; |
|
| 1230 | + |
|
| 1231 | + // darken |
|
| 1232 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
| 1233 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
| 1234 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
| 1235 | + |
|
| 1236 | + // lighten |
|
| 1237 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
| 1238 | + |
|
| 1239 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
| 1240 | + $op_25 = $color_code."40"; // 25% opacity |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + // button states |
|
| 1244 | + $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
| 1245 | + $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1246 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
| 1247 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1248 | + |
|
| 1249 | + |
|
| 1250 | + // dropdown's |
|
| 1251 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
| 1252 | + |
|
| 1253 | + |
|
| 1254 | + // input states |
|
| 1255 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1256 | + |
|
| 1257 | + // page link |
|
| 1258 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1259 | + |
|
| 1260 | + return $output; |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + public static function css_secondary($color_code,$compatibility){; |
|
| 1264 | + $color_code = sanitize_hex_color($color_code); |
|
| 1265 | + if(!$color_code){return '';} |
|
| 1266 | + /** |
|
| 1267 | + * c = color, b = background color, o = border-color, f = fill |
|
| 1268 | + */ |
|
| 1269 | + $selectors = array( |
|
| 1270 | + '.btn-secondary' => array('b','o'), |
|
| 1271 | + '.btn-secondary.disabled' => array('b','o'), |
|
| 1272 | + '.btn-secondary:disabled' => array('b','o'), |
|
| 1273 | + '.btn-outline-secondary' => array('c','o'), |
|
| 1274 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
| 1275 | + '.btn-outline-secondary.disabled' => array('c'), |
|
| 1276 | + '.btn-outline-secondary:disabled' => array('c'), |
|
| 1277 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
| 1278 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
| 1279 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
| 1280 | + '.badge-secondary' => array('b'), |
|
| 1281 | + '.alert-secondary' => array('b','o'), |
|
| 1282 | + '.btn-link.btn-secondary' => array('c'), |
|
| 1283 | + ); |
|
| 1284 | + |
|
| 1285 | + $important_selectors = array( |
|
| 1286 | + '.bg-secondary' => array('b','f'), |
|
| 1287 | + '.border-secondary' => array('o'), |
|
| 1288 | + '.text-secondary' => array('c'), |
|
| 1289 | + ); |
|
| 1290 | + |
|
| 1291 | + $color = array(); |
|
| 1292 | + $color_i = array(); |
|
| 1293 | + $background = array(); |
|
| 1294 | + $background_i = array(); |
|
| 1295 | + $border = array(); |
|
| 1296 | + $border_i = array(); |
|
| 1297 | + $fill = array(); |
|
| 1298 | + $fill_i = array(); |
|
| 1299 | + |
|
| 1300 | + $output = ''; |
|
| 1301 | + |
|
| 1302 | + // build rules into each type |
|
| 1303 | + foreach($selectors as $selector => $types){ |
|
| 1304 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1305 | + $types = array_combine($types,$types); |
|
| 1306 | + if(isset($types['c'])){$color[] = $selector;} |
|
| 1307 | + if(isset($types['b'])){$background[] = $selector;} |
|
| 1308 | + if(isset($types['o'])){$border[] = $selector;} |
|
| 1309 | + if(isset($types['f'])){$fill[] = $selector;} |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + // build rules into each type |
|
| 1313 | + foreach($important_selectors as $selector => $types){ |
|
| 1314 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
| 1315 | + $types = array_combine($types,$types); |
|
| 1316 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
| 1317 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
| 1318 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
| 1319 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + // add any color rules |
|
| 1323 | + if(!empty($color)){ |
|
| 1324 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
| 1325 | + } |
|
| 1326 | + if(!empty($color_i)){ |
|
| 1327 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + // add any background color rules |
|
| 1331 | + if(!empty($background)){ |
|
| 1332 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
| 1333 | + } |
|
| 1334 | + if(!empty($background_i)){ |
|
| 1335 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + // add any border color rules |
|
| 1339 | + if(!empty($border)){ |
|
| 1340 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
| 1341 | + } |
|
| 1342 | + if(!empty($border_i)){ |
|
| 1343 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + // add any fill color rules |
|
| 1347 | + if(!empty($fill)){ |
|
| 1348 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
| 1349 | + } |
|
| 1350 | + if(!empty($fill_i)){ |
|
| 1351 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + |
|
| 1355 | + $prefix = $compatibility ? ".bsui " : ""; |
|
| 1356 | + |
|
| 1357 | + // darken |
|
| 1358 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
| 1359 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
| 1360 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
| 1361 | + |
|
| 1362 | + // lighten |
|
| 1363 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
| 1364 | + |
|
| 1365 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
| 1366 | + $op_25 = $color_code."40"; // 25% opacity |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + // button states |
|
| 1370 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
| 1371 | + $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1372 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
| 1373 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + return $output; |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + /** |
|
| 1380 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
| 1381 | + * |
|
| 1382 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
| 1383 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
| 1384 | + * |
|
| 1385 | + * @return string |
|
| 1386 | + */ |
|
| 1387 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
| 1388 | + $hexCode = ltrim($hexCode, '#'); |
|
| 1389 | + |
|
| 1390 | + if (strlen($hexCode) == 3) { |
|
| 1391 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
| 1395 | + |
|
| 1396 | + foreach ($hexCode as & $color) { |
|
| 1397 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
| 1398 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
| 1399 | + |
|
| 1400 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + return '#' . implode($hexCode); |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * Check if we should display examples. |
|
| 1408 | + */ |
|
| 1409 | + public function maybe_show_examples(){ |
|
| 1410 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
| 1411 | + echo "<head>"; |
|
| 1412 | + wp_head(); |
|
| 1413 | + echo "</head>"; |
|
| 1414 | + echo "<body>"; |
|
| 1415 | + echo $this->get_examples(); |
|
| 1416 | + echo "</body>"; |
|
| 1417 | + exit; |
|
| 1418 | + } |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * Get developer examples. |
|
| 1423 | + * |
|
| 1424 | + * @return string |
|
| 1425 | + */ |
|
| 1426 | + public function get_examples(){ |
|
| 1427 | + $output = ''; |
|
| 1428 | + |
|
| 1429 | + |
|
| 1430 | + // open form |
|
| 1431 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
| 1432 | + |
|
| 1433 | + // input example |
|
| 1434 | + $output .= aui()->input(array( |
|
| 1435 | + 'type' => 'text', |
|
| 1436 | + 'id' => 'text-example', |
|
| 1437 | + 'name' => 'text-example', |
|
| 1438 | + 'placeholder' => 'text placeholder', |
|
| 1439 | + 'title' => 'Text input example', |
|
| 1440 | + 'value' => '', |
|
| 1441 | + 'required' => false, |
|
| 1442 | + 'help_text' => 'help text', |
|
| 1443 | + 'label' => 'Text input example label' |
|
| 1444 | + )); |
|
| 1445 | + |
|
| 1446 | + // input example |
|
| 1447 | + $output .= aui()->input(array( |
|
| 1448 | + 'type' => 'url', |
|
| 1449 | + 'id' => 'text-example2', |
|
| 1450 | + 'name' => 'text-example', |
|
| 1451 | + 'placeholder' => 'url placeholder', |
|
| 1452 | + 'title' => 'Text input example', |
|
| 1453 | + 'value' => '', |
|
| 1454 | + 'required' => false, |
|
| 1455 | + 'help_text' => 'help text', |
|
| 1456 | + 'label' => 'Text input example label' |
|
| 1457 | + )); |
|
| 1458 | + |
|
| 1459 | + // checkbox example |
|
| 1460 | + $output .= aui()->input(array( |
|
| 1461 | + 'type' => 'checkbox', |
|
| 1462 | + 'id' => 'checkbox-example', |
|
| 1463 | + 'name' => 'checkbox-example', |
|
| 1464 | + 'placeholder' => 'checkbox-example', |
|
| 1465 | + 'title' => 'Checkbox example', |
|
| 1466 | + 'value' => '1', |
|
| 1467 | + 'checked' => true, |
|
| 1468 | + 'required' => false, |
|
| 1469 | + 'help_text' => 'help text', |
|
| 1470 | + 'label' => 'Checkbox checked' |
|
| 1471 | + )); |
|
| 1472 | + |
|
| 1473 | + // checkbox example |
|
| 1474 | + $output .= aui()->input(array( |
|
| 1475 | + 'type' => 'checkbox', |
|
| 1476 | + 'id' => 'checkbox-example2', |
|
| 1477 | + 'name' => 'checkbox-example2', |
|
| 1478 | + 'placeholder' => 'checkbox-example', |
|
| 1479 | + 'title' => 'Checkbox example', |
|
| 1480 | + 'value' => '1', |
|
| 1481 | + 'checked' => false, |
|
| 1482 | + 'required' => false, |
|
| 1483 | + 'help_text' => 'help text', |
|
| 1484 | + 'label' => 'Checkbox un-checked' |
|
| 1485 | + )); |
|
| 1486 | + |
|
| 1487 | + // switch example |
|
| 1488 | + $output .= aui()->input(array( |
|
| 1489 | + 'type' => 'checkbox', |
|
| 1490 | + 'id' => 'switch-example', |
|
| 1491 | + 'name' => 'switch-example', |
|
| 1492 | + 'placeholder' => 'checkbox-example', |
|
| 1493 | + 'title' => 'Switch example', |
|
| 1494 | + 'value' => '1', |
|
| 1495 | + 'checked' => true, |
|
| 1496 | + 'switch' => true, |
|
| 1497 | + 'required' => false, |
|
| 1498 | + 'help_text' => 'help text', |
|
| 1499 | + 'label' => 'Switch on' |
|
| 1500 | + )); |
|
| 1501 | + |
|
| 1502 | + // switch example |
|
| 1503 | + $output .= aui()->input(array( |
|
| 1504 | + 'type' => 'checkbox', |
|
| 1505 | + 'id' => 'switch-example2', |
|
| 1506 | + 'name' => 'switch-example2', |
|
| 1507 | + 'placeholder' => 'checkbox-example', |
|
| 1508 | + 'title' => 'Switch example', |
|
| 1509 | + 'value' => '1', |
|
| 1510 | + 'checked' => false, |
|
| 1511 | + 'switch' => true, |
|
| 1512 | + 'required' => false, |
|
| 1513 | + 'help_text' => 'help text', |
|
| 1514 | + 'label' => 'Switch off' |
|
| 1515 | + )); |
|
| 1516 | + |
|
| 1517 | + // close form |
|
| 1518 | + $output .= "</form>"; |
|
| 1519 | + |
|
| 1520 | + return $output; |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + } |
|
| 1524 | + |
|
| 1525 | + /** |
|
| 1526 | + * Run the class if found. |
|
| 1527 | + */ |
|
| 1528 | + AyeCode_UI_Settings::instance(); |
|
| 1529 | 1529 | } |
| 1530 | 1530 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 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,231 +11,231 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Holds the class instance. |
|
| 16 | - * |
|
| 17 | - * @since 1.0.0 |
|
| 18 | - * @var null |
|
| 19 | - */ |
|
| 20 | - private static $instance = null; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Holds the current AUI version number. |
|
| 24 | - * |
|
| 25 | - * @var string $ver The current version number. |
|
| 26 | - */ |
|
| 27 | - public static $ver = '0.1.32'; |
|
| 28 | - |
|
| 29 | - public static $options = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * There can be only one. |
|
| 33 | - * |
|
| 34 | - * @since 1.0.0 |
|
| 35 | - * @return AUI|null |
|
| 36 | - */ |
|
| 37 | - public static function instance() { |
|
| 38 | - if ( self::$instance == null ) { |
|
| 39 | - self::$instance = new AUI(); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - return self::$instance; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * AUI constructor. |
|
| 47 | - * |
|
| 48 | - * @since 1.0.0 |
|
| 49 | - */ |
|
| 50 | - private function __construct() { |
|
| 51 | - if ( function_exists( "__autoload" ) ) { |
|
| 52 | - spl_autoload_register( "__autoload" ); |
|
| 53 | - } |
|
| 54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 55 | - |
|
| 56 | - // load options |
|
| 57 | - self::$options = get_option('aui_options'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Autoload any components on the fly. |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * |
|
| 65 | - * @param $classname |
|
| 66 | - */ |
|
| 67 | - private function autoload( $classname ) { |
|
| 68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
| 69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
| 70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
| 71 | - include_once( $file_path ); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Get the AUI options. |
|
| 77 | - * |
|
| 78 | - * @param $option |
|
| 79 | - * |
|
| 80 | - * @return string|void |
|
| 81 | - */ |
|
| 82 | - public function get_option( $option ){ |
|
| 83 | - $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
| 84 | - |
|
| 85 | - if ( ! $result && $option) { |
|
| 86 | - if( $option == 'color_primary' ){ |
|
| 87 | - $result = AUI_PRIMARY_COLOR; |
|
| 88 | - }elseif( $option == 'color_secondary' ){ |
|
| 89 | - $result = AUI_SECONDARY_COLOR; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - return $result; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function render( $items = array() ) { |
|
| 96 | - $output = ''; |
|
| 97 | - |
|
| 98 | - if ( ! empty( $items ) ) { |
|
| 99 | - foreach ( $items as $args ) { |
|
| 100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
| 101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
| 102 | - $output .= $this->$render( $args ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $output; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Render and return a bootstrap alert component. |
|
| 112 | - * |
|
| 113 | - * @since 1.0.0 |
|
| 114 | - * |
|
| 115 | - * @param array $args |
|
| 116 | - * |
|
| 117 | - * @return string The rendered component. |
|
| 118 | - */ |
|
| 119 | - public function alert( $args = array() ) { |
|
| 120 | - return AUI_Component_Alert::get( $args ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Render and return a bootstrap input component. |
|
| 125 | - * |
|
| 126 | - * @since 1.0.0 |
|
| 127 | - * |
|
| 128 | - * @param array $args |
|
| 129 | - * |
|
| 130 | - * @return string The rendered component. |
|
| 131 | - */ |
|
| 132 | - public function input( $args = array() ) { |
|
| 133 | - return AUI_Component_Input::input( $args ); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Render and return a bootstrap textarea component. |
|
| 138 | - * |
|
| 139 | - * @since 1.0.0 |
|
| 140 | - * |
|
| 141 | - * @param array $args |
|
| 142 | - * |
|
| 143 | - * @return string The rendered component. |
|
| 144 | - */ |
|
| 145 | - public function textarea( $args = array() ) { |
|
| 146 | - return AUI_Component_Input::textarea( $args ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Render and return a bootstrap button component. |
|
| 151 | - * |
|
| 152 | - * @since 1.0.0 |
|
| 153 | - * |
|
| 154 | - * @param array $args |
|
| 155 | - * |
|
| 156 | - * @return string The rendered component. |
|
| 157 | - */ |
|
| 158 | - public function button( $args = array() ) { |
|
| 159 | - return AUI_Component_Button::get( $args ); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Render and return a bootstrap button component. |
|
| 164 | - * |
|
| 165 | - * @since 1.0.0 |
|
| 166 | - * |
|
| 167 | - * @param array $args |
|
| 168 | - * |
|
| 169 | - * @return string The rendered component. |
|
| 170 | - */ |
|
| 171 | - public function badge( $args = array() ) { |
|
| 172 | - $defaults = array( |
|
| 173 | - 'class' => 'badge badge-primary align-middle', |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - // maybe set type |
|
| 177 | - if ( empty( $args['href'] ) ) { |
|
| 178 | - $defaults['type'] = 'badge'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 183 | - */ |
|
| 184 | - $args = wp_parse_args( $args, $defaults ); |
|
| 185 | - |
|
| 186 | - return AUI_Component_Button::get( $args ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Render and return a bootstrap dropdown component. |
|
| 191 | - * |
|
| 192 | - * @since 1.0.0 |
|
| 193 | - * |
|
| 194 | - * @param array $args |
|
| 195 | - * |
|
| 196 | - * @return string The rendered component. |
|
| 197 | - */ |
|
| 198 | - public function dropdown( $args = array() ) { |
|
| 199 | - return AUI_Component_Dropdown::get( $args ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Render and return a bootstrap select component. |
|
| 204 | - * |
|
| 205 | - * @since 1.0.0 |
|
| 206 | - * |
|
| 207 | - * @param array $args |
|
| 208 | - * |
|
| 209 | - * @return string The rendered component. |
|
| 210 | - */ |
|
| 211 | - public function select( $args = array() ) { |
|
| 212 | - return AUI_Component_Input::select( $args ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Render and return a bootstrap radio component. |
|
| 217 | - * |
|
| 218 | - * @since 1.0.0 |
|
| 219 | - * |
|
| 220 | - * @param array $args |
|
| 221 | - * |
|
| 222 | - * @return string The rendered component. |
|
| 223 | - */ |
|
| 224 | - public function radio( $args = array() ) { |
|
| 225 | - return AUI_Component_Input::radio( $args ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Render and return a bootstrap pagination component. |
|
| 230 | - * |
|
| 231 | - * @since 1.0.0 |
|
| 232 | - * |
|
| 233 | - * @param array $args |
|
| 234 | - * |
|
| 235 | - * @return string The rendered component. |
|
| 236 | - */ |
|
| 237 | - public function pagination( $args = array() ) { |
|
| 238 | - return AUI_Component_Pagination::get( $args ); |
|
| 239 | - } |
|
| 14 | + /** |
|
| 15 | + * Holds the class instance. |
|
| 16 | + * |
|
| 17 | + * @since 1.0.0 |
|
| 18 | + * @var null |
|
| 19 | + */ |
|
| 20 | + private static $instance = null; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Holds the current AUI version number. |
|
| 24 | + * |
|
| 25 | + * @var string $ver The current version number. |
|
| 26 | + */ |
|
| 27 | + public static $ver = '0.1.32'; |
|
| 28 | + |
|
| 29 | + public static $options = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * There can be only one. |
|
| 33 | + * |
|
| 34 | + * @since 1.0.0 |
|
| 35 | + * @return AUI|null |
|
| 36 | + */ |
|
| 37 | + public static function instance() { |
|
| 38 | + if ( self::$instance == null ) { |
|
| 39 | + self::$instance = new AUI(); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + return self::$instance; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * AUI constructor. |
|
| 47 | + * |
|
| 48 | + * @since 1.0.0 |
|
| 49 | + */ |
|
| 50 | + private function __construct() { |
|
| 51 | + if ( function_exists( "__autoload" ) ) { |
|
| 52 | + spl_autoload_register( "__autoload" ); |
|
| 53 | + } |
|
| 54 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 55 | + |
|
| 56 | + // load options |
|
| 57 | + self::$options = get_option('aui_options'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Autoload any components on the fly. |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * |
|
| 65 | + * @param $classname |
|
| 66 | + */ |
|
| 67 | + private function autoload( $classname ) { |
|
| 68 | + $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
| 69 | + $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
| 70 | + if ( $file_path && is_readable( $file_path ) ) { |
|
| 71 | + include_once( $file_path ); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Get the AUI options. |
|
| 77 | + * |
|
| 78 | + * @param $option |
|
| 79 | + * |
|
| 80 | + * @return string|void |
|
| 81 | + */ |
|
| 82 | + public function get_option( $option ){ |
|
| 83 | + $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
| 84 | + |
|
| 85 | + if ( ! $result && $option) { |
|
| 86 | + if( $option == 'color_primary' ){ |
|
| 87 | + $result = AUI_PRIMARY_COLOR; |
|
| 88 | + }elseif( $option == 'color_secondary' ){ |
|
| 89 | + $result = AUI_SECONDARY_COLOR; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + return $result; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function render( $items = array() ) { |
|
| 96 | + $output = ''; |
|
| 97 | + |
|
| 98 | + if ( ! empty( $items ) ) { |
|
| 99 | + foreach ( $items as $args ) { |
|
| 100 | + $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
| 101 | + if ( $render && method_exists( __CLASS__, $render ) ) { |
|
| 102 | + $output .= $this->$render( $args ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $output; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Render and return a bootstrap alert component. |
|
| 112 | + * |
|
| 113 | + * @since 1.0.0 |
|
| 114 | + * |
|
| 115 | + * @param array $args |
|
| 116 | + * |
|
| 117 | + * @return string The rendered component. |
|
| 118 | + */ |
|
| 119 | + public function alert( $args = array() ) { |
|
| 120 | + return AUI_Component_Alert::get( $args ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Render and return a bootstrap input component. |
|
| 125 | + * |
|
| 126 | + * @since 1.0.0 |
|
| 127 | + * |
|
| 128 | + * @param array $args |
|
| 129 | + * |
|
| 130 | + * @return string The rendered component. |
|
| 131 | + */ |
|
| 132 | + public function input( $args = array() ) { |
|
| 133 | + return AUI_Component_Input::input( $args ); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Render and return a bootstrap textarea component. |
|
| 138 | + * |
|
| 139 | + * @since 1.0.0 |
|
| 140 | + * |
|
| 141 | + * @param array $args |
|
| 142 | + * |
|
| 143 | + * @return string The rendered component. |
|
| 144 | + */ |
|
| 145 | + public function textarea( $args = array() ) { |
|
| 146 | + return AUI_Component_Input::textarea( $args ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Render and return a bootstrap button component. |
|
| 151 | + * |
|
| 152 | + * @since 1.0.0 |
|
| 153 | + * |
|
| 154 | + * @param array $args |
|
| 155 | + * |
|
| 156 | + * @return string The rendered component. |
|
| 157 | + */ |
|
| 158 | + public function button( $args = array() ) { |
|
| 159 | + return AUI_Component_Button::get( $args ); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Render and return a bootstrap button component. |
|
| 164 | + * |
|
| 165 | + * @since 1.0.0 |
|
| 166 | + * |
|
| 167 | + * @param array $args |
|
| 168 | + * |
|
| 169 | + * @return string The rendered component. |
|
| 170 | + */ |
|
| 171 | + public function badge( $args = array() ) { |
|
| 172 | + $defaults = array( |
|
| 173 | + 'class' => 'badge badge-primary align-middle', |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + // maybe set type |
|
| 177 | + if ( empty( $args['href'] ) ) { |
|
| 178 | + $defaults['type'] = 'badge'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 183 | + */ |
|
| 184 | + $args = wp_parse_args( $args, $defaults ); |
|
| 185 | + |
|
| 186 | + return AUI_Component_Button::get( $args ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Render and return a bootstrap dropdown component. |
|
| 191 | + * |
|
| 192 | + * @since 1.0.0 |
|
| 193 | + * |
|
| 194 | + * @param array $args |
|
| 195 | + * |
|
| 196 | + * @return string The rendered component. |
|
| 197 | + */ |
|
| 198 | + public function dropdown( $args = array() ) { |
|
| 199 | + return AUI_Component_Dropdown::get( $args ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Render and return a bootstrap select component. |
|
| 204 | + * |
|
| 205 | + * @since 1.0.0 |
|
| 206 | + * |
|
| 207 | + * @param array $args |
|
| 208 | + * |
|
| 209 | + * @return string The rendered component. |
|
| 210 | + */ |
|
| 211 | + public function select( $args = array() ) { |
|
| 212 | + return AUI_Component_Input::select( $args ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Render and return a bootstrap radio component. |
|
| 217 | + * |
|
| 218 | + * @since 1.0.0 |
|
| 219 | + * |
|
| 220 | + * @param array $args |
|
| 221 | + * |
|
| 222 | + * @return string The rendered component. |
|
| 223 | + */ |
|
| 224 | + public function radio( $args = array() ) { |
|
| 225 | + return AUI_Component_Input::radio( $args ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Render and return a bootstrap pagination component. |
|
| 230 | + * |
|
| 231 | + * @since 1.0.0 |
|
| 232 | + * |
|
| 233 | + * @param array $args |
|
| 234 | + * |
|
| 235 | + * @return string The rendered component. |
|
| 236 | + */ |
|
| 237 | + public function pagination( $args = array() ) { |
|
| 238 | + return AUI_Component_Pagination::get( $args ); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | 241 | } |
| 242 | 242 | \ No newline at end of file |
@@ -7,40 +7,40 @@ |
||
| 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.1.32"; |
|
| 19 | - if(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.1.32"; |
|
| 19 | + if(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 | } |
| 47 | 47 | \ No newline at end of file |
@@ -15,125 +15,125 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Which data store to load. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $data_store_name = 'subscription'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * This is the name of this object type. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $object_type = 'subscription'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array( |
|
| 39 | - 'customer_id' => 0, |
|
| 40 | - 'frequency' => 1, |
|
| 41 | - 'period' => 'D', |
|
| 42 | - 'initial_amount' => null, |
|
| 43 | - 'recurring_amount' => null, |
|
| 44 | - 'bill_times' => 0, |
|
| 45 | - 'transaction_id' => '', |
|
| 46 | - 'parent_payment_id' => null, |
|
| 47 | - 'product_id' => 0, |
|
| 48 | - 'created' => '0000-00-00 00:00:00', |
|
| 49 | - 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | - 'trial_period' => '', |
|
| 51 | - 'status' => 'pending', |
|
| 52 | - 'profile_id' => '', |
|
| 53 | - 'gateway' => '', |
|
| 54 | - 'customer' => '', |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Stores the status transition information. |
|
| 59 | - * |
|
| 60 | - * @since 1.0.19 |
|
| 61 | - * @var bool |
|
| 62 | - */ |
|
| 63 | - protected $status_transition = false; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | - * |
|
| 68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | - * @param bool $deprecated |
|
| 70 | - */ |
|
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | - |
|
| 73 | - parent::__construct( $subscription ); |
|
| 74 | - |
|
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 80 | - $this->set_id( $subscription->id ); |
|
| 81 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 82 | - $this->set_id( $subscription_id ); |
|
| 83 | - } else { |
|
| 84 | - $this->set_object_read( true ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Load the datastore. |
|
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | - |
|
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | - * |
|
| 99 | - * |
|
| 100 | - * @static |
|
| 101 | - * @param string $value |
|
| 102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | - * @since 1.0.19 |
|
| 104 | - * @return int |
|
| 105 | - */ |
|
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 18 | + /** |
|
| 19 | + * Which data store to load. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $data_store_name = 'subscription'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * This is the name of this object type. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $object_type = 'subscription'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array( |
|
| 39 | + 'customer_id' => 0, |
|
| 40 | + 'frequency' => 1, |
|
| 41 | + 'period' => 'D', |
|
| 42 | + 'initial_amount' => null, |
|
| 43 | + 'recurring_amount' => null, |
|
| 44 | + 'bill_times' => 0, |
|
| 45 | + 'transaction_id' => '', |
|
| 46 | + 'parent_payment_id' => null, |
|
| 47 | + 'product_id' => 0, |
|
| 48 | + 'created' => '0000-00-00 00:00:00', |
|
| 49 | + 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | + 'trial_period' => '', |
|
| 51 | + 'status' => 'pending', |
|
| 52 | + 'profile_id' => '', |
|
| 53 | + 'gateway' => '', |
|
| 54 | + 'customer' => '', |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Stores the status transition information. |
|
| 59 | + * |
|
| 60 | + * @since 1.0.19 |
|
| 61 | + * @var bool |
|
| 62 | + */ |
|
| 63 | + protected $status_transition = false; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | + * |
|
| 68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | + * @param bool $deprecated |
|
| 70 | + */ |
|
| 71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | + |
|
| 73 | + parent::__construct( $subscription ); |
|
| 74 | + |
|
| 75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | + $this->set_id( $subscription ); |
|
| 77 | + } elseif ( $subscription instanceof self ) { |
|
| 78 | + $this->set_id( $subscription->get_id() ); |
|
| 79 | + } elseif ( ! empty( $subscription->id ) ) { |
|
| 80 | + $this->set_id( $subscription->id ); |
|
| 81 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 82 | + $this->set_id( $subscription_id ); |
|
| 83 | + } else { |
|
| 84 | + $this->set_object_read( true ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Load the datastore. |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | + |
|
| 90 | + if ( $this->get_id() > 0 ) { |
|
| 91 | + $this->data_store->read( $this ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | + * |
|
| 99 | + * |
|
| 100 | + * @static |
|
| 101 | + * @param string $value |
|
| 102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | + * @since 1.0.19 |
|
| 104 | + * @return int |
|
| 105 | + */ |
|
| 106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - // Trim the value. |
|
| 110 | - $value = trim( $value ); |
|
| 109 | + // Trim the value. |
|
| 110 | + $value = trim( $value ); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 113 | - return 0; |
|
| 114 | - } |
|
| 112 | + if ( empty( $value ) ) { |
|
| 113 | + return 0; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 117 | - $field = 'parent_payment_id'; |
|
| 118 | - } |
|
| 116 | + if ( 'invoice_id' == $field ) { |
|
| 117 | + $field = 'parent_payment_id'; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | // Valid fields. |
| 121 | 121 | $fields = array( |
| 122 | - 'parent_payment_id', |
|
| 123 | - 'transaction_id', |
|
| 124 | - 'profile_id' |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Ensure a field has been passed. |
|
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Maybe retrieve from the cache. |
|
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 135 | - return $subscription_id; |
|
| 136 | - } |
|
| 122 | + 'parent_payment_id', |
|
| 123 | + 'transaction_id', |
|
| 124 | + 'profile_id' |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Ensure a field has been passed. |
|
| 128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Maybe retrieve from the cache. |
|
| 133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | + if ( ! empty( $subscription_id ) ) { |
|
| 135 | + return $subscription_id; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,34 +141,34 @@ discard block |
||
| 141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 145 | - return 0; |
|
| 146 | - } |
|
| 144 | + if ( empty( $subscription_id ) ) { |
|
| 145 | + return 0; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - // Update the cache with our data. |
|
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 148 | + // Update the cache with our data. |
|
| 149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 150 | 150 | |
| 151 | - return $subscription_id; |
|
| 152 | - } |
|
| 151 | + return $subscription_id; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 154 | + /** |
|
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | - } |
|
| 158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 164 | + /** |
|
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | 167 | public function _isset( $key ) { |
| 168 | 168 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /* |
|
| 171 | + /* |
|
| 172 | 172 | |-------------------------------------------------------------------------- |
| 173 | 173 | | CRUD methods |
| 174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,545 +177,545 @@ discard block |
||
| 177 | 177 | | |
| 178 | 178 | */ |
| 179 | 179 | |
| 180 | - /* |
|
| 180 | + /* |
|
| 181 | 181 | |-------------------------------------------------------------------------- |
| 182 | 182 | | Getters |
| 183 | 183 | |-------------------------------------------------------------------------- |
| 184 | 184 | */ |
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Get customer id. |
|
| 188 | - * |
|
| 189 | - * @since 1.0.19 |
|
| 190 | - * @param string $context View or edit context. |
|
| 191 | - * @return int |
|
| 192 | - */ |
|
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Get customer information. |
|
| 199 | - * |
|
| 200 | - * @since 1.0.19 |
|
| 201 | - * @param string $context View or edit context. |
|
| 202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | - */ |
|
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Get parent invoice id. |
|
| 210 | - * |
|
| 211 | - * @since 1.0.19 |
|
| 212 | - * @param string $context View or edit context. |
|
| 213 | - * @return int |
|
| 214 | - */ |
|
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Alias for self::get_parent_invoice_id(). |
|
| 221 | - * |
|
| 222 | - * @since 1.0.19 |
|
| 223 | - * @param string $context View or edit context. |
|
| 224 | - * @return int |
|
| 225 | - */ |
|
| 186 | + /** |
|
| 187 | + * Get customer id. |
|
| 188 | + * |
|
| 189 | + * @since 1.0.19 |
|
| 190 | + * @param string $context View or edit context. |
|
| 191 | + * @return int |
|
| 192 | + */ |
|
| 193 | + public function get_customer_id( $context = 'view' ) { |
|
| 194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Get customer information. |
|
| 199 | + * |
|
| 200 | + * @since 1.0.19 |
|
| 201 | + * @param string $context View or edit context. |
|
| 202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | + */ |
|
| 204 | + public function get_customer( $context = 'view' ) { |
|
| 205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Get parent invoice id. |
|
| 210 | + * |
|
| 211 | + * @since 1.0.19 |
|
| 212 | + * @param string $context View or edit context. |
|
| 213 | + * @return int |
|
| 214 | + */ |
|
| 215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Alias for self::get_parent_invoice_id(). |
|
| 221 | + * |
|
| 222 | + * @since 1.0.19 |
|
| 223 | + * @param string $context View or edit context. |
|
| 224 | + * @return int |
|
| 225 | + */ |
|
| 226 | 226 | public function get_parent_payment_id( $context = 'view' ) { |
| 227 | 227 | return $this->get_parent_invoice_id( $context ); |
| 228 | - } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Alias for self::get_parent_invoice_id(). |
|
| 232 | + * |
|
| 233 | + * @since 1.0.0 |
|
| 234 | + * @return int |
|
| 235 | + */ |
|
| 236 | + public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | + return $this->get_parent_invoice_id( $context ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Get parent invoice. |
|
| 242 | + * |
|
| 243 | + * @since 1.0.19 |
|
| 244 | + * @param string $context View or edit context. |
|
| 245 | + * @return WPInv_Invoice |
|
| 246 | + */ |
|
| 247 | + public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Alias for self::get_parent_invoice(). |
|
| 253 | + * |
|
| 254 | + * @since 1.0.19 |
|
| 255 | + * @param string $context View or edit context. |
|
| 256 | + * @return WPInv_Invoice |
|
| 257 | + */ |
|
| 258 | + public function get_parent_payment( $context = 'view' ) { |
|
| 259 | + return $this->get_parent_invoice( $context ); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Get subscription's product id. |
|
| 264 | + * |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @param string $context View or edit context. |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function get_product_id( $context = 'view' ) { |
|
| 270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Get the subscription product. |
|
| 275 | + * |
|
| 276 | + * @since 1.0.19 |
|
| 277 | + * @param string $context View or edit context. |
|
| 278 | + * @return WPInv_Item |
|
| 279 | + */ |
|
| 280 | + public function get_product( $context = 'view' ) { |
|
| 281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Get parent invoice's gateway. |
|
| 286 | + * |
|
| 287 | + * Here for backwards compatibility. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @param string $context View or edit context. |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function get_gateway( $context = 'view' ) { |
|
| 294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Get the period of a renewal. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.19 |
|
| 301 | + * @param string $context View or edit context. |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function get_period( $context = 'view' ) { |
|
| 305 | + return $this->get_prop( 'period', $context ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Get number of periods each renewal is valid for. |
|
| 310 | + * |
|
| 311 | + * @since 1.0.19 |
|
| 312 | + * @param string $context View or edit context. |
|
| 313 | + * @return int |
|
| 314 | + */ |
|
| 315 | + public function get_frequency( $context = 'view' ) { |
|
| 316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get the initial amount for the subscription. |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @param string $context View or edit context. |
|
| 324 | + * @return float |
|
| 325 | + */ |
|
| 326 | + public function get_initial_amount( $context = 'view' ) { |
|
| 327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get the recurring amount for the subscription. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param string $context View or edit context. |
|
| 335 | + * @return float |
|
| 336 | + */ |
|
| 337 | + public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Get number of times that this subscription can be renewed. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + * @param string $context View or edit context. |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function get_bill_times( $context = 'view' ) { |
|
| 349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Get transaction id of this subscription's parent invoice. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param string $context View or edit context. |
|
| 357 | + * @return string |
|
| 358 | + */ |
|
| 359 | + public function get_transaction_id( $context = 'view' ) { |
|
| 360 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Get the date that the subscription was created. |
|
| 365 | + * |
|
| 366 | + * @since 1.0.19 |
|
| 367 | + * @param string $context View or edit context. |
|
| 368 | + * @return string |
|
| 369 | + */ |
|
| 370 | + public function get_created( $context = 'view' ) { |
|
| 371 | + return $this->get_prop( 'created', $context ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Alias for self::get_created(). |
|
| 376 | + * |
|
| 377 | + * @since 1.0.19 |
|
| 378 | + * @param string $context View or edit context. |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public function get_date_created( $context = 'view' ) { |
|
| 382 | + return $this->get_created( $context ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Retrieves the creation date in a timestamp |
|
| 387 | + * |
|
| 388 | + * @since 1.0.0 |
|
| 389 | + * @return int |
|
| 390 | + */ |
|
| 391 | + public function get_time_created() { |
|
| 392 | + $created = $this->get_date_created(); |
|
| 393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Get GMT date when the subscription was created. |
|
| 398 | + * |
|
| 399 | + * @since 1.0.19 |
|
| 400 | + * @param string $context View or edit context. |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | + $date = $this->get_date_created( $context ); |
|
| 405 | + |
|
| 406 | + if ( $date ) { |
|
| 407 | + $date = get_gmt_from_date( $date ); |
|
| 408 | + } |
|
| 409 | + return $date; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Get the date that the subscription will renew. |
|
| 414 | + * |
|
| 415 | + * @since 1.0.19 |
|
| 416 | + * @param string $context View or edit context. |
|
| 417 | + * @return string |
|
| 418 | + */ |
|
| 419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | + return $this->get_prop( 'expiration', $context ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Alias for self::get_next_renewal_date(). |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + * @param string $context View or edit context. |
|
| 428 | + * @return string |
|
| 429 | + */ |
|
| 430 | + public function get_expiration( $context = 'view' ) { |
|
| 431 | + return $this->get_next_renewal_date( $context ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Retrieves the expiration date in a timestamp |
|
| 436 | + * |
|
| 437 | + * @since 1.0.0 |
|
| 438 | + * @return int |
|
| 439 | + */ |
|
| 440 | + public function get_expiration_time() { |
|
| 441 | + $expiration = $this->get_expiration(); |
|
| 442 | + |
|
| 443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | + return current_time( 'timestamp' ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Get GMT date when the subscription will renew. |
|
| 453 | + * |
|
| 454 | + * @since 1.0.19 |
|
| 455 | + * @param string $context View or edit context. |
|
| 456 | + * @return string |
|
| 457 | + */ |
|
| 458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | + $date = $this->get_next_renewal_date( $context ); |
|
| 460 | + |
|
| 461 | + if ( $date ) { |
|
| 462 | + $date = get_gmt_from_date( $date ); |
|
| 463 | + } |
|
| 464 | + return $date; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Get the subscription's trial period. |
|
| 469 | + * |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + * @param string $context View or edit context. |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public function get_trial_period( $context = 'view' ) { |
|
| 475 | + return $this->get_prop( 'trial_period', $context ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Get the subscription's status. |
|
| 480 | + * |
|
| 481 | + * @since 1.0.19 |
|
| 482 | + * @param string $context View or edit context. |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + public function get_status( $context = 'view' ) { |
|
| 486 | + return $this->get_prop( 'status', $context ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Get the subscription's profile id. |
|
| 491 | + * |
|
| 492 | + * @since 1.0.19 |
|
| 493 | + * @param string $context View or edit context. |
|
| 494 | + * @return string |
|
| 495 | + */ |
|
| 496 | + public function get_profile_id( $context = 'view' ) { |
|
| 497 | + return $this->get_prop( 'profile_id', $context ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /* |
|
| 501 | + |-------------------------------------------------------------------------- |
|
| 502 | + | Setters |
|
| 503 | + |-------------------------------------------------------------------------- |
|
| 504 | + */ |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Set customer id. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.19 |
|
| 510 | + * @param int $value The customer's id. |
|
| 511 | + */ |
|
| 512 | + public function set_customer_id( $value ) { |
|
| 513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Set parent invoice id. |
|
| 518 | + * |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + * @param int $value The parent invoice id. |
|
| 521 | + */ |
|
| 522 | + public function set_parent_invoice_id( $value ) { |
|
| 523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Alias for self::set_parent_invoice_id(). |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + * @param int $value The parent invoice id. |
|
| 531 | + */ |
|
| 532 | + public function set_parent_payment_id( $value ) { |
|
| 533 | + $this->set_parent_invoice_id( $value ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Alias for self::set_parent_invoice_id(). |
|
| 538 | + * |
|
| 539 | + * @since 1.0.19 |
|
| 540 | + * @param int $value The parent invoice id. |
|
| 541 | + */ |
|
| 542 | + public function set_original_payment_id( $value ) { |
|
| 543 | + $this->set_parent_invoice_id( $value ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Set subscription's product id. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param int $value The subscription product id. |
|
| 551 | + */ |
|
| 552 | + public function set_product_id( $value ) { |
|
| 553 | + $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Set the period of a renewal. |
|
| 558 | + * |
|
| 559 | + * @since 1.0.19 |
|
| 560 | + * @param string $value The renewal period. |
|
| 561 | + */ |
|
| 562 | + public function set_period( $value ) { |
|
| 563 | + $this->set_prop( 'period', $value ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Set number of periods each renewal is valid for. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + * @param int $value The subscription frequency. |
|
| 571 | + */ |
|
| 572 | + public function set_frequency( $value ) { |
|
| 573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Set the initial amount for the subscription. |
|
| 579 | + * |
|
| 580 | + * @since 1.0.19 |
|
| 581 | + * @param float $value The initial subcription amount. |
|
| 582 | + */ |
|
| 583 | + public function set_initial_amount( $value ) { |
|
| 584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Set the recurring amount for the subscription. |
|
| 589 | + * |
|
| 590 | + * @since 1.0.19 |
|
| 591 | + * @param float $value The recurring subcription amount. |
|
| 592 | + */ |
|
| 593 | + public function set_recurring_amount( $value ) { |
|
| 594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Set number of times that this subscription can be renewed. |
|
| 599 | + * |
|
| 600 | + * @since 1.0.19 |
|
| 601 | + * @param int $value Bill times. |
|
| 602 | + */ |
|
| 603 | + public function set_bill_times( $value ) { |
|
| 604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | + } |
|
| 229 | 606 | |
| 230 | - /** |
|
| 231 | - * Alias for self::get_parent_invoice_id(). |
|
| 607 | + /** |
|
| 608 | + * Get transaction id of this subscription's parent invoice. |
|
| 232 | 609 | * |
| 233 | - * @since 1.0.0 |
|
| 234 | - * @return int |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @param string $value Bill times. |
|
| 235 | 612 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 613 | + public function set_transaction_id( $value ) { |
|
| 614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 238 | 615 | } |
| 239 | 616 | |
| 240 | - /** |
|
| 241 | - * Get parent invoice. |
|
| 242 | - * |
|
| 243 | - * @since 1.0.19 |
|
| 244 | - * @param string $context View or edit context. |
|
| 245 | - * @return WPInv_Invoice |
|
| 246 | - */ |
|
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Alias for self::get_parent_invoice(). |
|
| 253 | - * |
|
| 254 | - * @since 1.0.19 |
|
| 255 | - * @param string $context View or edit context. |
|
| 256 | - * @return WPInv_Invoice |
|
| 257 | - */ |
|
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Get subscription's product id. |
|
| 264 | - * |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @param string $context View or edit context. |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Get the subscription product. |
|
| 275 | - * |
|
| 276 | - * @since 1.0.19 |
|
| 277 | - * @param string $context View or edit context. |
|
| 278 | - * @return WPInv_Item |
|
| 279 | - */ |
|
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Get parent invoice's gateway. |
|
| 286 | - * |
|
| 287 | - * Here for backwards compatibility. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @param string $context View or edit context. |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Get the period of a renewal. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.19 |
|
| 301 | - * @param string $context View or edit context. |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Get number of periods each renewal is valid for. |
|
| 310 | - * |
|
| 311 | - * @since 1.0.19 |
|
| 312 | - * @param string $context View or edit context. |
|
| 313 | - * @return int |
|
| 314 | - */ |
|
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get the initial amount for the subscription. |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @param string $context View or edit context. |
|
| 324 | - * @return float |
|
| 325 | - */ |
|
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get the recurring amount for the subscription. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param string $context View or edit context. |
|
| 335 | - * @return float |
|
| 336 | - */ |
|
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Get number of times that this subscription can be renewed. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - * @param string $context View or edit context. |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Get transaction id of this subscription's parent invoice. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param string $context View or edit context. |
|
| 357 | - * @return string |
|
| 358 | - */ |
|
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Get the date that the subscription was created. |
|
| 365 | - * |
|
| 366 | - * @since 1.0.19 |
|
| 367 | - * @param string $context View or edit context. |
|
| 368 | - * @return string |
|
| 369 | - */ |
|
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Alias for self::get_created(). |
|
| 376 | - * |
|
| 377 | - * @since 1.0.19 |
|
| 378 | - * @param string $context View or edit context. |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Retrieves the creation date in a timestamp |
|
| 387 | - * |
|
| 388 | - * @since 1.0.0 |
|
| 389 | - * @return int |
|
| 390 | - */ |
|
| 391 | - public function get_time_created() { |
|
| 392 | - $created = $this->get_date_created(); |
|
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Get GMT date when the subscription was created. |
|
| 398 | - * |
|
| 399 | - * @since 1.0.19 |
|
| 400 | - * @param string $context View or edit context. |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 617 | + /** |
|
| 618 | + * Set date when this subscription started. |
|
| 619 | + * |
|
| 620 | + * @since 1.0.19 |
|
| 621 | + * @param string $value strtotime compliant date. |
|
| 622 | + */ |
|
| 623 | + public function set_created( $value ) { |
|
| 624 | + $date = strtotime( $value ); |
|
| 405 | 625 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 626 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | + $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | + return; |
|
| 408 | 629 | } |
| 409 | - return $date; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Get the date that the subscription will renew. |
|
| 414 | - * |
|
| 415 | - * @since 1.0.19 |
|
| 416 | - * @param string $context View or edit context. |
|
| 417 | - * @return string |
|
| 418 | - */ |
|
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Alias for self::get_next_renewal_date(). |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - * @param string $context View or edit context. |
|
| 428 | - * @return string |
|
| 429 | - */ |
|
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Retrieves the expiration date in a timestamp |
|
| 436 | - * |
|
| 437 | - * @since 1.0.0 |
|
| 438 | - * @return int |
|
| 439 | - */ |
|
| 440 | - public function get_expiration_time() { |
|
| 441 | - $expiration = $this->get_expiration(); |
|
| 442 | - |
|
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Get GMT date when the subscription will renew. |
|
| 453 | - * |
|
| 454 | - * @since 1.0.19 |
|
| 455 | - * @param string $context View or edit context. |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 460 | 630 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 463 | - } |
|
| 464 | - return $date; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Get the subscription's trial period. |
|
| 469 | - * |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - * @param string $context View or edit context. |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Get the subscription's status. |
|
| 480 | - * |
|
| 481 | - * @since 1.0.19 |
|
| 482 | - * @param string $context View or edit context. |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Get the subscription's profile id. |
|
| 491 | - * |
|
| 492 | - * @since 1.0.19 |
|
| 493 | - * @param string $context View or edit context. |
|
| 494 | - * @return string |
|
| 495 | - */ |
|
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /* |
|
| 501 | - |-------------------------------------------------------------------------- |
|
| 502 | - | Setters |
|
| 503 | - |-------------------------------------------------------------------------- |
|
| 504 | - */ |
|
| 631 | + $this->set_prop( 'created', '' ); |
|
| 505 | 632 | |
| 506 | - /** |
|
| 507 | - * Set customer id. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.19 |
|
| 510 | - * @param int $value The customer's id. |
|
| 511 | - */ |
|
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Set parent invoice id. |
|
| 518 | - * |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - * @param int $value The parent invoice id. |
|
| 521 | - */ |
|
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Alias for self::set_parent_invoice_id(). |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - * @param int $value The parent invoice id. |
|
| 531 | - */ |
|
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 534 | - } |
|
| 633 | + } |
|
| 535 | 634 | |
| 536 | - /** |
|
| 537 | - * Alias for self::set_parent_invoice_id(). |
|
| 635 | + /** |
|
| 636 | + * Alias for self::set_created(). |
|
| 538 | 637 | * |
| 539 | 638 | * @since 1.0.19 |
| 540 | - * @param int $value The parent invoice id. |
|
| 639 | + * @param string $value strtotime compliant date. |
|
| 541 | 640 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Set subscription's product id. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param int $value The subscription product id. |
|
| 551 | - */ |
|
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Set the period of a renewal. |
|
| 558 | - * |
|
| 559 | - * @since 1.0.19 |
|
| 560 | - * @param string $value The renewal period. |
|
| 561 | - */ |
|
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Set number of periods each renewal is valid for. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - * @param int $value The subscription frequency. |
|
| 571 | - */ |
|
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Set the initial amount for the subscription. |
|
| 579 | - * |
|
| 580 | - * @since 1.0.19 |
|
| 581 | - * @param float $value The initial subcription amount. |
|
| 582 | - */ |
|
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Set the recurring amount for the subscription. |
|
| 589 | - * |
|
| 590 | - * @since 1.0.19 |
|
| 591 | - * @param float $value The recurring subcription amount. |
|
| 592 | - */ |
|
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Set number of times that this subscription can be renewed. |
|
| 599 | - * |
|
| 600 | - * @since 1.0.19 |
|
| 601 | - * @param int $value Bill times. |
|
| 602 | - */ |
|
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get transaction id of this subscription's parent invoice. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @param string $value Bill times. |
|
| 612 | - */ |
|
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Set date when this subscription started. |
|
| 619 | - * |
|
| 620 | - * @since 1.0.19 |
|
| 621 | - * @param string $value strtotime compliant date. |
|
| 622 | - */ |
|
| 623 | - public function set_created( $value ) { |
|
| 641 | + public function set_date_created( $value ) { |
|
| 642 | + $this->set_created( $value ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Set the date that the subscription will renew. |
|
| 647 | + * |
|
| 648 | + * @since 1.0.19 |
|
| 649 | + * @param string $value strtotime compliant date. |
|
| 650 | + */ |
|
| 651 | + public function set_next_renewal_date( $value ) { |
|
| 624 | 652 | $date = strtotime( $value ); |
| 625 | 653 | |
| 626 | 654 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | 656 | return; |
| 629 | 657 | } |
| 630 | 658 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 659 | + $this->set_prop( 'expiration', '' ); |
|
| 660 | + |
|
| 661 | + } |
|
| 632 | 662 | |
| 633 | - } |
|
| 663 | + /** |
|
| 664 | + * Alias for self::set_next_renewal_date(). |
|
| 665 | + * |
|
| 666 | + * @since 1.0.19 |
|
| 667 | + * @param string $value strtotime compliant date. |
|
| 668 | + */ |
|
| 669 | + public function set_expiration( $value ) { |
|
| 670 | + $this->set_next_renewal_date( $value ); |
|
| 671 | + } |
|
| 634 | 672 | |
| 635 | - /** |
|
| 636 | - * Alias for self::set_created(). |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @param string $value strtotime compliant date. |
|
| 640 | - */ |
|
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 673 | + /** |
|
| 674 | + * Set the subscription's trial period. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @param string $value trial period e.g 1 year. |
|
| 678 | + */ |
|
| 679 | + public function set_trial_period( $value ) { |
|
| 680 | + $this->set_prop( 'trial_period', $value ); |
|
| 643 | 681 | } |
| 644 | 682 | |
| 645 | - /** |
|
| 646 | - * Set the date that the subscription will renew. |
|
| 647 | - * |
|
| 648 | - * @since 1.0.19 |
|
| 649 | - * @param string $value strtotime compliant date. |
|
| 650 | - */ |
|
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 683 | + /** |
|
| 684 | + * Set the subscription's status. |
|
| 685 | + * |
|
| 686 | + * @since 1.0.19 |
|
| 687 | + * @param string $new_status New subscription status. |
|
| 688 | + */ |
|
| 689 | + public function set_status( $new_status ) { |
|
| 653 | 690 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 691 | + // Abort if this is not a valid status; |
|
| 692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 656 | 693 | return; |
| 657 | - } |
|
| 658 | - |
|
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 660 | - |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Alias for self::set_next_renewal_date(). |
|
| 665 | - * |
|
| 666 | - * @since 1.0.19 |
|
| 667 | - * @param string $value strtotime compliant date. |
|
| 668 | - */ |
|
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Set the subscription's trial period. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @param string $value trial period e.g 1 year. |
|
| 678 | - */ |
|
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Set the subscription's status. |
|
| 685 | - * |
|
| 686 | - * @since 1.0.19 |
|
| 687 | - * @param string $new_status New subscription status. |
|
| 688 | - */ |
|
| 689 | - public function set_status( $new_status ) { |
|
| 690 | - |
|
| 691 | - // Abort if this is not a valid status; |
|
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $old_status = $this->get_status(); |
|
| 697 | - $this->set_prop( 'status', $new_status ); |
|
| 698 | - |
|
| 699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | - $this->status_transition = array( |
|
| 701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | - 'to' => $new_status, |
|
| 703 | - ); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Set the subscription's (remote) profile id. |
|
| 710 | - * |
|
| 711 | - * @since 1.0.19 |
|
| 712 | - * @param string $value the remote profile id. |
|
| 713 | - */ |
|
| 714 | - public function set_profile_id( $value ) { |
|
| 715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /* |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + $old_status = $this->get_status(); |
|
| 697 | + $this->set_prop( 'status', $new_status ); |
|
| 698 | + |
|
| 699 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | + $this->status_transition = array( |
|
| 701 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | + 'to' => $new_status, |
|
| 703 | + ); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * Set the subscription's (remote) profile id. |
|
| 710 | + * |
|
| 711 | + * @since 1.0.19 |
|
| 712 | + * @param string $value the remote profile id. |
|
| 713 | + */ |
|
| 714 | + public function set_profile_id( $value ) { |
|
| 715 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /* |
|
| 719 | 719 | |-------------------------------------------------------------------------- |
| 720 | 720 | | Boolean methods |
| 721 | 721 | |-------------------------------------------------------------------------- |
@@ -724,55 +724,55 @@ discard block |
||
| 724 | 724 | | |
| 725 | 725 | */ |
| 726 | 726 | |
| 727 | - /** |
|
| 727 | + /** |
|
| 728 | 728 | * Checks if the subscription has a given status. |
| 729 | - * |
|
| 730 | - * @param string|array String or array of strings to check for. |
|
| 731 | - * @return bool |
|
| 729 | + * |
|
| 730 | + * @param string|array String or array of strings to check for. |
|
| 731 | + * @return bool |
|
| 732 | 732 | */ |
| 733 | 733 | public function has_status( $status ) { |
| 734 | 734 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
| 735 | - } |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | - /** |
|
| 737 | + /** |
|
| 738 | 738 | * Checks if the subscription has a trial period. |
| 739 | - * |
|
| 740 | - * @return bool |
|
| 739 | + * |
|
| 740 | + * @return bool |
|
| 741 | 741 | */ |
| 742 | 742 | public function has_trial_period() { |
| 743 | - $period = $this->get_trial_period(); |
|
| 743 | + $period = $this->get_trial_period(); |
|
| 744 | 744 | return ! empty( $period ); |
| 745 | - } |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Is the subscription active? |
|
| 749 | - * |
|
| 750 | - * @return bool |
|
| 751 | - */ |
|
| 752 | - public function is_active() { |
|
| 753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * Is the subscription expired? |
|
| 758 | - * |
|
| 759 | - * @return bool |
|
| 760 | - */ |
|
| 761 | - public function is_expired() { |
|
| 762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Is this the last renewals? |
|
| 767 | - * |
|
| 768 | - * @return bool |
|
| 769 | - */ |
|
| 770 | - public function is_last_renewal() { |
|
| 771 | - $max_bills = $this->get_bill_times(); |
|
| 772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /* |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Is the subscription active? |
|
| 749 | + * |
|
| 750 | + * @return bool |
|
| 751 | + */ |
|
| 752 | + public function is_active() { |
|
| 753 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * Is the subscription expired? |
|
| 758 | + * |
|
| 759 | + * @return bool |
|
| 760 | + */ |
|
| 761 | + public function is_expired() { |
|
| 762 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Is this the last renewals? |
|
| 767 | + * |
|
| 768 | + * @return bool |
|
| 769 | + */ |
|
| 770 | + public function is_last_renewal() { |
|
| 771 | + $max_bills = $this->get_bill_times(); |
|
| 772 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /* |
|
| 776 | 776 | |-------------------------------------------------------------------------- |
| 777 | 777 | | Additional methods |
| 778 | 778 | |-------------------------------------------------------------------------- |
@@ -781,27 +781,27 @@ discard block |
||
| 781 | 781 | | |
| 782 | 782 | */ |
| 783 | 783 | |
| 784 | - /** |
|
| 785 | - * Backwards compatibilty. |
|
| 786 | - */ |
|
| 787 | - public function create( $data = array() ) { |
|
| 784 | + /** |
|
| 785 | + * Backwards compatibilty. |
|
| 786 | + */ |
|
| 787 | + public function create( $data = array() ) { |
|
| 788 | 788 | |
| 789 | - // Set the properties. |
|
| 790 | - if ( is_array( $data ) ) { |
|
| 791 | - $this->set_props( $data ); |
|
| 792 | - } |
|
| 789 | + // Set the properties. |
|
| 790 | + if ( is_array( $data ) ) { |
|
| 791 | + $this->set_props( $data ); |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | - // Save the item. |
|
| 795 | - return $this->save(); |
|
| 794 | + // Save the item. |
|
| 795 | + return $this->save(); |
|
| 796 | 796 | |
| 797 | - } |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | - /** |
|
| 800 | - * Backwards compatibilty. |
|
| 801 | - */ |
|
| 802 | - public function update( $args = array() ) { |
|
| 803 | - return $this->create( $args ); |
|
| 804 | - } |
|
| 799 | + /** |
|
| 800 | + * Backwards compatibilty. |
|
| 801 | + */ |
|
| 802 | + public function update( $args = array() ) { |
|
| 803 | + return $this->create( $args ); |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | 806 | /** |
| 807 | 807 | * Retrieve renewal payments for a subscription |
@@ -811,22 +811,22 @@ discard block |
||
| 811 | 811 | */ |
| 812 | 812 | public function get_child_payments( $hide_pending = true ) { |
| 813 | 813 | |
| 814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 815 | 815 | |
| 816 | - if ( ! $hide_pending ) { |
|
| 817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | - } |
|
| 816 | + if ( ! $hide_pending ) { |
|
| 817 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | return get_posts( |
| 821 | - array( |
|
| 822 | - 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | - 'numberposts' => -1, |
|
| 824 | - 'post_status' => $statuses, |
|
| 825 | - 'orderby' => 'ID', |
|
| 826 | - 'order' => 'DESC', |
|
| 827 | - 'post_type' => 'wpi_invoice' |
|
| 828 | - ) |
|
| 829 | - ); |
|
| 821 | + array( |
|
| 822 | + 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | + 'numberposts' => -1, |
|
| 824 | + 'post_status' => $statuses, |
|
| 825 | + 'orderby' => 'ID', |
|
| 826 | + 'order' => 'DESC', |
|
| 827 | + 'post_type' => 'wpi_invoice' |
|
| 828 | + ) |
|
| 829 | + ); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
@@ -836,16 +836,16 @@ discard block |
||
| 836 | 836 | * @return int |
| 837 | 837 | */ |
| 838 | 838 | public function get_total_payments() { |
| 839 | - global $wpdb; |
|
| 839 | + global $wpdb; |
|
| 840 | 840 | |
| 841 | - $count = (int) $wpdb->get_var( |
|
| 842 | - $wpdb->prepare( |
|
| 843 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 844 | - $this->get_parent_invoice_id() |
|
| 845 | - ) |
|
| 846 | - ); |
|
| 841 | + $count = (int) $wpdb->get_var( |
|
| 842 | + $wpdb->prepare( |
|
| 843 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 844 | + $this->get_parent_invoice_id() |
|
| 845 | + ) |
|
| 846 | + ); |
|
| 847 | 847 | |
| 848 | - // Maybe include parent invoice. |
|
| 848 | + // Maybe include parent invoice. |
|
| 849 | 849 | if ( $this->get_parent_payment()->is_paid() ) { |
| 850 | 850 | $count++; |
| 851 | 851 | } |
@@ -874,57 +874,57 @@ discard block |
||
| 874 | 874 | * |
| 875 | 875 | * @since 2.4 |
| 876 | 876 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 877 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 877 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 878 | 878 | * @return bool |
| 879 | 879 | */ |
| 880 | 880 | public function add_payment( $args = array(), $invoice = false ) { |
| 881 | 881 | |
| 882 | - // Process each payment once. |
|
| 882 | + // Process each payment once. |
|
| 883 | 883 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
| 884 | 884 | return false; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - // Are we creating a new invoice? |
|
| 888 | - if ( empty( $invoice ) ) { |
|
| 889 | - $invoice = $this->create_payment(); |
|
| 887 | + // Are we creating a new invoice? |
|
| 888 | + if ( empty( $invoice ) ) { |
|
| 889 | + $invoice = $this->create_payment(); |
|
| 890 | 890 | |
| 891 | - if ( empty( $invoice ) ) { |
|
| 892 | - return false; |
|
| 893 | - } |
|
| 891 | + if ( empty( $invoice ) ) { |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - } |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 897 | + $invoice->set_status( 'wpi-renewal' ); |
|
| 898 | 898 | |
| 899 | - // Maybe set a transaction id. |
|
| 900 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 901 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 902 | - } |
|
| 899 | + // Maybe set a transaction id. |
|
| 900 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
| 901 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - // Set the completed date. |
|
| 905 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 904 | + // Set the completed date. |
|
| 905 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 906 | 906 | |
| 907 | - // And the gateway. |
|
| 908 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 909 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 910 | - } |
|
| 907 | + // And the gateway. |
|
| 908 | + if ( ! empty( $args['gateway'] ) ) { |
|
| 909 | + $invoice->set_gateway( $args['gateway'] ); |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | - $invoice->save(); |
|
| 912 | + $invoice->save(); |
|
| 913 | 913 | |
| 914 | - if ( ! $invoice->get_id() ) { |
|
| 915 | - return 0; |
|
| 916 | - } |
|
| 914 | + if ( ! $invoice->get_id() ) { |
|
| 915 | + return 0; |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 919 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 918 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 919 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 920 | 920 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 921 | 921 | |
| 922 | 922 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 923 | 923 | |
| 924 | 924 | return $invoice->get_id(); |
| 925 | - } |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | - /** |
|
| 927 | + /** |
|
| 928 | 928 | * Creates a new invoice and returns it. |
| 929 | 929 | * |
| 930 | 930 | * @since 1.0.19 |
@@ -932,97 +932,97 @@ discard block |
||
| 932 | 932 | */ |
| 933 | 933 | public function create_payment() { |
| 934 | 934 | |
| 935 | - $parent_invoice = $this->get_parent_payment(); |
|
| 936 | - |
|
| 937 | - if ( ! $parent_invoice->exists() ) { |
|
| 938 | - return false; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - // Duplicate the parent invoice. |
|
| 942 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 943 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 944 | - $invoice->recalculate_total(); |
|
| 945 | - $invoice->set_status( 'wpi-pending' ); |
|
| 946 | - $invoice->save(); |
|
| 947 | - |
|
| 948 | - return $invoice->exists() ? $invoice : false; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - /** |
|
| 952 | - * Renews or completes a subscription |
|
| 953 | - * |
|
| 954 | - * @since 1.0.0 |
|
| 955 | - * @return int The subscription's id |
|
| 956 | - */ |
|
| 957 | - public function renew() { |
|
| 958 | - |
|
| 959 | - // Complete subscription if applicable |
|
| 960 | - if ( $this->is_last_renewal() ) { |
|
| 961 | - return $this->complete(); |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - // Calculate new expiration |
|
| 965 | - $frequency = $this->get_frequency(); |
|
| 966 | - $period = $this->get_period(); |
|
| 967 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 968 | - |
|
| 969 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 970 | - $this->set_status( 'active' ); |
|
| 971 | - return $this->save(); |
|
| 972 | - |
|
| 973 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 974 | - |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * Marks a subscription as completed |
|
| 979 | - * |
|
| 980 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 981 | - * |
|
| 982 | - * @since 1.0.0 |
|
| 983 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 984 | - */ |
|
| 985 | - public function complete() { |
|
| 986 | - |
|
| 987 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 988 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 989 | - return false; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - $this->set_status( 'completed' ); |
|
| 993 | - return $this->save(); |
|
| 994 | - |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - /** |
|
| 998 | - * Marks a subscription as expired |
|
| 999 | - * |
|
| 1000 | - * @since 1.0.0 |
|
| 1001 | - * @param bool $check_expiration |
|
| 1002 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1003 | - */ |
|
| 1004 | - public function expire( $check_expiration = false ) { |
|
| 1005 | - |
|
| 1006 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1007 | - // Do not mark as expired since real expiration date is in the future |
|
| 1008 | - return false; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - $this->set_status( 'expired' ); |
|
| 1012 | - return $this->save(); |
|
| 1013 | - |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - /** |
|
| 1017 | - * Marks a subscription as failing |
|
| 1018 | - * |
|
| 1019 | - * @since 2.4.2 |
|
| 1020 | - * @return int Subscription id. |
|
| 1021 | - */ |
|
| 1022 | - public function failing() { |
|
| 1023 | - $this->set_status( 'failing' ); |
|
| 1024 | - return $this->save(); |
|
| 1025 | - } |
|
| 935 | + $parent_invoice = $this->get_parent_payment(); |
|
| 936 | + |
|
| 937 | + if ( ! $parent_invoice->exists() ) { |
|
| 938 | + return false; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // Duplicate the parent invoice. |
|
| 942 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 943 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 944 | + $invoice->recalculate_total(); |
|
| 945 | + $invoice->set_status( 'wpi-pending' ); |
|
| 946 | + $invoice->save(); |
|
| 947 | + |
|
| 948 | + return $invoice->exists() ? $invoice : false; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + /** |
|
| 952 | + * Renews or completes a subscription |
|
| 953 | + * |
|
| 954 | + * @since 1.0.0 |
|
| 955 | + * @return int The subscription's id |
|
| 956 | + */ |
|
| 957 | + public function renew() { |
|
| 958 | + |
|
| 959 | + // Complete subscription if applicable |
|
| 960 | + if ( $this->is_last_renewal() ) { |
|
| 961 | + return $this->complete(); |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + // Calculate new expiration |
|
| 965 | + $frequency = $this->get_frequency(); |
|
| 966 | + $period = $this->get_period(); |
|
| 967 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 968 | + |
|
| 969 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 970 | + $this->set_status( 'active' ); |
|
| 971 | + return $this->save(); |
|
| 972 | + |
|
| 973 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
| 974 | + |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * Marks a subscription as completed |
|
| 979 | + * |
|
| 980 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 981 | + * |
|
| 982 | + * @since 1.0.0 |
|
| 983 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 984 | + */ |
|
| 985 | + public function complete() { |
|
| 986 | + |
|
| 987 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 988 | + if ( $this->has_status( 'cancelled' ) ) { |
|
| 989 | + return false; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + $this->set_status( 'completed' ); |
|
| 993 | + return $this->save(); |
|
| 994 | + |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + /** |
|
| 998 | + * Marks a subscription as expired |
|
| 999 | + * |
|
| 1000 | + * @since 1.0.0 |
|
| 1001 | + * @param bool $check_expiration |
|
| 1002 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1003 | + */ |
|
| 1004 | + public function expire( $check_expiration = false ) { |
|
| 1005 | + |
|
| 1006 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1007 | + // Do not mark as expired since real expiration date is in the future |
|
| 1008 | + return false; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + $this->set_status( 'expired' ); |
|
| 1012 | + return $this->save(); |
|
| 1013 | + |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + /** |
|
| 1017 | + * Marks a subscription as failing |
|
| 1018 | + * |
|
| 1019 | + * @since 2.4.2 |
|
| 1020 | + * @return int Subscription id. |
|
| 1021 | + */ |
|
| 1022 | + public function failing() { |
|
| 1023 | + $this->set_status( 'failing' ); |
|
| 1024 | + return $this->save(); |
|
| 1025 | + } |
|
| 1026 | 1026 | |
| 1027 | 1027 | /** |
| 1028 | 1028 | * Marks a subscription as cancelled |
@@ -1031,19 +1031,19 @@ discard block |
||
| 1031 | 1031 | * @return int Subscription id. |
| 1032 | 1032 | */ |
| 1033 | 1033 | public function cancel() { |
| 1034 | - $this->set_status( 'cancelled' ); |
|
| 1035 | - return $this->save(); |
|
| 1034 | + $this->set_status( 'cancelled' ); |
|
| 1035 | + return $this->save(); |
|
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | - /** |
|
| 1039 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1040 | - * |
|
| 1041 | - * @since 1.0.0 |
|
| 1042 | - * @return bool |
|
| 1043 | - */ |
|
| 1044 | - public function can_cancel() { |
|
| 1045 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1046 | - } |
|
| 1038 | + /** |
|
| 1039 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1040 | + * |
|
| 1041 | + * @since 1.0.0 |
|
| 1042 | + * @return bool |
|
| 1043 | + */ |
|
| 1044 | + public function can_cancel() { |
|
| 1045 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1046 | + } |
|
| 1047 | 1047 | |
| 1048 | 1048 | /** |
| 1049 | 1049 | * Returns an array of subscription statuses that can be cancelled |
@@ -1056,93 +1056,93 @@ discard block |
||
| 1056 | 1056 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - /** |
|
| 1060 | - * Retrieves the URL to cancel subscription |
|
| 1061 | - * |
|
| 1062 | - * @since 1.0.0 |
|
| 1063 | - * @return string |
|
| 1064 | - */ |
|
| 1065 | - public function get_cancel_url() { |
|
| 1066 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1067 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - /** |
|
| 1071 | - * Retrieves the URL to view a subscription |
|
| 1072 | - * |
|
| 1073 | - * @since 1.0.19 |
|
| 1074 | - * @return string |
|
| 1075 | - */ |
|
| 1076 | - public function get_view_url() { |
|
| 1077 | - $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1078 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * Determines if subscription can be manually renewed |
|
| 1083 | - * |
|
| 1084 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1085 | - * that can be renewed manually |
|
| 1086 | - * |
|
| 1087 | - * @since 2.5 |
|
| 1088 | - * @return bool |
|
| 1089 | - */ |
|
| 1090 | - public function can_renew() { |
|
| 1091 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * Retrieves the URL to renew a subscription |
|
| 1096 | - * |
|
| 1097 | - * @since 2.5 |
|
| 1098 | - * @return string |
|
| 1099 | - */ |
|
| 1100 | - public function get_renew_url() { |
|
| 1101 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1102 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * Determines if subscription can have their payment method updated |
|
| 1107 | - * |
|
| 1108 | - * @since 1.0.0 |
|
| 1109 | - * @return bool |
|
| 1110 | - */ |
|
| 1111 | - public function can_update() { |
|
| 1112 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * Retrieves the URL to update subscription |
|
| 1117 | - * |
|
| 1118 | - * @since 1.0.0 |
|
| 1119 | - * @return string |
|
| 1120 | - */ |
|
| 1121 | - public function get_update_url() { |
|
| 1122 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1123 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - /** |
|
| 1127 | - * Retrieves the subscription status label |
|
| 1128 | - * |
|
| 1129 | - * @since 1.0.0 |
|
| 1130 | - * @return string |
|
| 1131 | - */ |
|
| 1132 | - public function get_status_label() { |
|
| 1133 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - /** |
|
| 1137 | - * Retrieves the subscription status class |
|
| 1138 | - * |
|
| 1139 | - * @since 1.0.19 |
|
| 1140 | - * @return string |
|
| 1141 | - */ |
|
| 1142 | - public function get_status_class() { |
|
| 1143 | - $statuses = getpaid_get_subscription_status_classes(); |
|
| 1144 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
| 1145 | - } |
|
| 1059 | + /** |
|
| 1060 | + * Retrieves the URL to cancel subscription |
|
| 1061 | + * |
|
| 1062 | + * @since 1.0.0 |
|
| 1063 | + * @return string |
|
| 1064 | + */ |
|
| 1065 | + public function get_cancel_url() { |
|
| 1066 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1067 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + /** |
|
| 1071 | + * Retrieves the URL to view a subscription |
|
| 1072 | + * |
|
| 1073 | + * @since 1.0.19 |
|
| 1074 | + * @return string |
|
| 1075 | + */ |
|
| 1076 | + public function get_view_url() { |
|
| 1077 | + $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1078 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * Determines if subscription can be manually renewed |
|
| 1083 | + * |
|
| 1084 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1085 | + * that can be renewed manually |
|
| 1086 | + * |
|
| 1087 | + * @since 2.5 |
|
| 1088 | + * @return bool |
|
| 1089 | + */ |
|
| 1090 | + public function can_renew() { |
|
| 1091 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * Retrieves the URL to renew a subscription |
|
| 1096 | + * |
|
| 1097 | + * @since 2.5 |
|
| 1098 | + * @return string |
|
| 1099 | + */ |
|
| 1100 | + public function get_renew_url() { |
|
| 1101 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1102 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * Determines if subscription can have their payment method updated |
|
| 1107 | + * |
|
| 1108 | + * @since 1.0.0 |
|
| 1109 | + * @return bool |
|
| 1110 | + */ |
|
| 1111 | + public function can_update() { |
|
| 1112 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * Retrieves the URL to update subscription |
|
| 1117 | + * |
|
| 1118 | + * @since 1.0.0 |
|
| 1119 | + * @return string |
|
| 1120 | + */ |
|
| 1121 | + public function get_update_url() { |
|
| 1122 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1123 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + /** |
|
| 1127 | + * Retrieves the subscription status label |
|
| 1128 | + * |
|
| 1129 | + * @since 1.0.0 |
|
| 1130 | + * @return string |
|
| 1131 | + */ |
|
| 1132 | + public function get_status_label() { |
|
| 1133 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + /** |
|
| 1137 | + * Retrieves the subscription status class |
|
| 1138 | + * |
|
| 1139 | + * @since 1.0.19 |
|
| 1140 | + * @return string |
|
| 1141 | + */ |
|
| 1142 | + public function get_status_class() { |
|
| 1143 | + $statuses = getpaid_get_subscription_status_classes(); |
|
| 1144 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
| 1145 | + } |
|
| 1146 | 1146 | |
| 1147 | 1147 | /** |
| 1148 | 1148 | * Retrieves the subscription status label |
@@ -1152,11 +1152,11 @@ discard block |
||
| 1152 | 1152 | */ |
| 1153 | 1153 | public function get_status_label_html() { |
| 1154 | 1154 | |
| 1155 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1156 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1157 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
| 1155 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1156 | + $class = esc_attr( $this->get_status_class() ); |
|
| 1157 | + $status = sanitize_html_class( $this->get_status_label() ); |
|
| 1158 | 1158 | |
| 1159 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
| 1159 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | /** |
@@ -1167,75 +1167,75 @@ discard block |
||
| 1167 | 1167 | * @return bool |
| 1168 | 1168 | */ |
| 1169 | 1169 | public function payment_exists( $txn_id = '' ) { |
| 1170 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1170 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1171 | 1171 | return ! empty( $invoice_id ); |
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - /** |
|
| 1175 | - * Handle the status transition. |
|
| 1176 | - */ |
|
| 1177 | - protected function status_transition() { |
|
| 1178 | - $status_transition = $this->status_transition; |
|
| 1179 | - |
|
| 1180 | - // Reset status transition variable. |
|
| 1181 | - $this->status_transition = false; |
|
| 1182 | - |
|
| 1183 | - if ( $status_transition ) { |
|
| 1184 | - try { |
|
| 1185 | - |
|
| 1186 | - // Fire a hook for the status change. |
|
| 1187 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1188 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1189 | - |
|
| 1190 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1191 | - |
|
| 1192 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1193 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1194 | - |
|
| 1195 | - // Note the transition occurred. |
|
| 1196 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1197 | - |
|
| 1198 | - // Fire another hook. |
|
| 1199 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1200 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1201 | - |
|
| 1202 | - } else { |
|
| 1203 | - /* translators: %s: new invoice status */ |
|
| 1204 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1205 | - |
|
| 1206 | - // Note the transition occurred. |
|
| 1207 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1208 | - |
|
| 1209 | - } |
|
| 1210 | - } catch ( Exception $e ) { |
|
| 1211 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - /** |
|
| 1218 | - * Save data to the database. |
|
| 1219 | - * |
|
| 1220 | - * @since 1.0.19 |
|
| 1221 | - * @return int subscription ID |
|
| 1222 | - */ |
|
| 1223 | - public function save() { |
|
| 1224 | - parent::save(); |
|
| 1225 | - $this->status_transition(); |
|
| 1226 | - return $this->get_id(); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * Activates a subscription. |
|
| 1231 | - * |
|
| 1232 | - * @since 1.0.19 |
|
| 1233 | - * @return int subscription ID |
|
| 1234 | - */ |
|
| 1235 | - public function activate() { |
|
| 1236 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1237 | - $this->set_status( $status ); |
|
| 1238 | - return $this->save(); |
|
| 1239 | - } |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * Handle the status transition. |
|
| 1176 | + */ |
|
| 1177 | + protected function status_transition() { |
|
| 1178 | + $status_transition = $this->status_transition; |
|
| 1179 | + |
|
| 1180 | + // Reset status transition variable. |
|
| 1181 | + $this->status_transition = false; |
|
| 1182 | + |
|
| 1183 | + if ( $status_transition ) { |
|
| 1184 | + try { |
|
| 1185 | + |
|
| 1186 | + // Fire a hook for the status change. |
|
| 1187 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1188 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1189 | + |
|
| 1190 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 1191 | + |
|
| 1192 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1193 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1194 | + |
|
| 1195 | + // Note the transition occurred. |
|
| 1196 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1197 | + |
|
| 1198 | + // Fire another hook. |
|
| 1199 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1200 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1201 | + |
|
| 1202 | + } else { |
|
| 1203 | + /* translators: %s: new invoice status */ |
|
| 1204 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1205 | + |
|
| 1206 | + // Note the transition occurred. |
|
| 1207 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1208 | + |
|
| 1209 | + } |
|
| 1210 | + } catch ( Exception $e ) { |
|
| 1211 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + /** |
|
| 1218 | + * Save data to the database. |
|
| 1219 | + * |
|
| 1220 | + * @since 1.0.19 |
|
| 1221 | + * @return int subscription ID |
|
| 1222 | + */ |
|
| 1223 | + public function save() { |
|
| 1224 | + parent::save(); |
|
| 1225 | + $this->status_transition(); |
|
| 1226 | + return $this->get_id(); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * Activates a subscription. |
|
| 1231 | + * |
|
| 1232 | + * @since 1.0.19 |
|
| 1233 | + * @return int subscription ID |
|
| 1234 | + */ |
|
| 1235 | + public function activate() { |
|
| 1236 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1237 | + $this->set_status( $status ); |
|
| 1238 | + return $this->save(); |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | 1241 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wpinv_subscriptions_page() { |
| 16 | 16 | |
| 17 | - ?> |
|
| 17 | + ?> |
|
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | - // Verify user permissions. |
|
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 25 | + // Verify user permissions. |
|
| 26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 27 | 27 | |
| 28 | - echo aui()->alert( |
|
| 29 | - array( |
|
| 30 | - 'type' => 'danger', |
|
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 28 | + echo aui()->alert( |
|
| 29 | + array( |
|
| 30 | + 'type' => 'danger', |
|
| 31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 36 | 36 | |
| 37 | - // Display a single subscription. |
|
| 38 | - wpinv_recurring_subscription_details(); |
|
| 39 | - } else { |
|
| 37 | + // Display a single subscription. |
|
| 38 | + wpinv_recurring_subscription_details(); |
|
| 39 | + } else { |
|
| 40 | 40 | |
| 41 | - // Display a list of available subscriptions. |
|
| 42 | - getpaid_print_subscriptions_list(); |
|
| 43 | - } |
|
| 41 | + // Display a list of available subscriptions. |
|
| 42 | + getpaid_print_subscriptions_list(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - ?> |
|
| 45 | + ?> |
|
| 46 | 46 | |
| 47 | 47 | </div> |
| 48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function getpaid_print_subscriptions_list() { |
| 61 | 61 | |
| 62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | - $subscribers_table->prepare_items(); |
|
| 62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | + $subscribers_table->prepare_items(); |
|
| 64 | 64 | |
| 65 | - ?> |
|
| 65 | + ?> |
|
| 66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
| 67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,27 +80,27 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function wpinv_recurring_subscription_details() { |
| 82 | 82 | |
| 83 | - // Fetch the subscription. |
|
| 84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | - if ( ! $sub->get_id() ) { |
|
| 83 | + // Fetch the subscription. |
|
| 84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | + if ( ! $sub->get_id() ) { |
|
| 86 | 86 | |
| 87 | - echo aui()->alert( |
|
| 88 | - array( |
|
| 89 | - 'type' => 'danger', |
|
| 90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 87 | + echo aui()->alert( |
|
| 88 | + array( |
|
| 89 | + 'type' => 'danger', |
|
| 90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - return; |
|
| 95 | - } |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // Use metaboxes to display the subscription details. |
|
| 98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 97 | + // Use metaboxes to display the subscription details. |
|
| 98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 102 | 102 | |
| 103 | - ?> |
|
| 103 | + ?> |
|
| 104 | 104 | |
| 105 | 105 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
| 106 | 106 | |
@@ -140,41 +140,41 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function getpaid_admin_subscription_details_metabox( $sub ) { |
| 142 | 142 | |
| 143 | - // Prepare subscription detail columns. |
|
| 144 | - $fields = apply_filters( |
|
| 145 | - 'getpaid_subscription_admin_page_fields', |
|
| 146 | - array( |
|
| 147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 153 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - |
|
| 160 | - if ( ! $sub->is_active() ) { |
|
| 161 | - |
|
| 162 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 163 | - unset( $fields['renews_on'] ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ( isset( $fields['gateway'] ) ) { |
|
| 167 | - unset( $fields['gateway'] ); |
|
| 168 | - } |
|
| 143 | + // Prepare subscription detail columns. |
|
| 144 | + $fields = apply_filters( |
|
| 145 | + 'getpaid_subscription_admin_page_fields', |
|
| 146 | + array( |
|
| 147 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 153 | + 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + |
|
| 160 | + if ( ! $sub->is_active() ) { |
|
| 161 | + |
|
| 162 | + if ( isset( $fields['renews_on'] ) ) { |
|
| 163 | + unset( $fields['renews_on'] ); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ( isset( $fields['gateway'] ) ) { |
|
| 167 | + unset( $fields['gateway'] ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - $profile_id = $sub->get_profile_id(); |
|
| 173 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 174 | - unset( $fields['profile_id'] ); |
|
| 175 | - } |
|
| 172 | + $profile_id = $sub->get_profile_id(); |
|
| 173 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 174 | + unset( $fields['profile_id'] ); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - ?> |
|
| 177 | + ?> |
|
| 178 | 178 | |
| 179 | 179 | <table class="table table-borderless" style="font-size: 14px;"> |
| 180 | 180 | <tbody> |
@@ -208,20 +208,20 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 210 | 210 | |
| 211 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 211 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 212 | 212 | |
| 213 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 214 | - if ( $user ) { |
|
| 213 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 214 | + if ( $user ) { |
|
| 215 | 215 | |
| 216 | - $username = sprintf( |
|
| 217 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 218 | - absint( $user->ID ), |
|
| 219 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 220 | - ); |
|
| 216 | + $username = sprintf( |
|
| 217 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 218 | + absint( $user->ID ), |
|
| 219 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 220 | + ); |
|
| 221 | 221 | |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - echo $username; |
|
| 224 | + echo $username; |
|
| 225 | 225 | } |
| 226 | 226 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 227 | 227 | |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * @param WPInv_Subscription $subscription |
| 232 | 232 | */ |
| 233 | 233 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 234 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 235 | - echo "<span>$amount</span>"; |
|
| 234 | + $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 235 | + echo "<span>$amount</span>"; |
|
| 236 | 236 | } |
| 237 | 237 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 238 | 238 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @param WPInv_Subscription $subscription |
| 243 | 243 | */ |
| 244 | 244 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 245 | - echo '#' . absint( $subscription->get_id() ); |
|
| 245 | + echo '#' . absint( $subscription->get_id() ); |
|
| 246 | 246 | } |
| 247 | 247 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
| 248 | 248 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param WPInv_Subscription $subscription |
| 253 | 253 | */ |
| 254 | 254 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 255 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 255 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 256 | 256 | } |
| 257 | 257 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
| 258 | 258 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * @param WPInv_Subscription $subscription |
| 263 | 263 | */ |
| 264 | 264 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 265 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 265 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 266 | 266 | } |
| 267 | 267 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
| 268 | 268 | |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | * @param WPInv_Subscription $subscription |
| 273 | 273 | */ |
| 274 | 274 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 275 | - $max_bills = $subscription->get_bill_times(); |
|
| 276 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 275 | + $max_bills = $subscription->get_bill_times(); |
|
| 276 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 277 | 277 | } |
| 278 | 278 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 279 | 279 | /** |
@@ -283,16 +283,16 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
| 285 | 285 | |
| 286 | - $item = get_post( $subscription->get_product_id() ); |
|
| 286 | + $item = get_post( $subscription->get_product_id() ); |
|
| 287 | 287 | |
| 288 | - if ( ! empty( $item ) ) { |
|
| 289 | - $link = get_edit_post_link( $item ); |
|
| 290 | - $link = esc_url( $link ); |
|
| 291 | - $name = esc_html( get_the_title( $item ) ); |
|
| 292 | - echo "<a href='$link'>$name</a>"; |
|
| 293 | - } else { |
|
| 294 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 295 | - } |
|
| 288 | + if ( ! empty( $item ) ) { |
|
| 289 | + $link = get_edit_post_link( $item ); |
|
| 290 | + $link = esc_url( $link ); |
|
| 291 | + $name = esc_html( get_the_title( $item ) ); |
|
| 292 | + echo "<a href='$link'>$name</a>"; |
|
| 293 | + } else { |
|
| 294 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | 297 | } |
| 298 | 298 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | */ |
| 305 | 305 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 306 | 306 | |
| 307 | - $gateway = $subscription->get_gateway(); |
|
| 307 | + $gateway = $subscription->get_gateway(); |
|
| 308 | 308 | |
| 309 | - if ( ! empty( $gateway ) ) { |
|
| 310 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 311 | - } else { |
|
| 312 | - echo "—"; |
|
| 313 | - } |
|
| 309 | + if ( ! empty( $gateway ) ) { |
|
| 310 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 311 | + } else { |
|
| 312 | + echo "—"; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | } |
| 316 | 316 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @param WPInv_Subscription $subscription |
| 322 | 322 | */ |
| 323 | 323 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 324 | - echo $subscription->get_status_label_html(); |
|
| 324 | + echo $subscription->get_status_label_html(); |
|
| 325 | 325 | } |
| 326 | 326 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 327 | 327 | |
@@ -332,14 +332,14 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 334 | 334 | |
| 335 | - $profile_id = $subscription->get_profile_id(); |
|
| 335 | + $profile_id = $subscription->get_profile_id(); |
|
| 336 | 336 | |
| 337 | - if ( ! empty( $profile_id ) ) { |
|
| 338 | - $profile_id = sanitize_text_field( $profile_id ); |
|
| 339 | - echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
| 340 | - } else { |
|
| 341 | - echo "—"; |
|
| 342 | - } |
|
| 337 | + if ( ! empty( $profile_id ) ) { |
|
| 338 | + $profile_id = sanitize_text_field( $profile_id ); |
|
| 339 | + echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
| 340 | + } else { |
|
| 341 | + echo "—"; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | 344 | } |
| 345 | 345 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -351,39 +351,39 @@ discard block |
||
| 351 | 351 | */ |
| 352 | 352 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 353 | 353 | |
| 354 | - ?> |
|
| 354 | + ?> |
|
| 355 | 355 | <div class="mt-3"> |
| 356 | 356 | |
| 357 | 357 | <?php |
| 358 | - echo aui()->select( |
|
| 359 | - array( |
|
| 360 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 361 | - 'name' => 'subscription_status', |
|
| 362 | - 'id' => 'subscription_status_update_select', |
|
| 363 | - 'required' => true, |
|
| 364 | - 'no_wrap' => false, |
|
| 365 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 366 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 367 | - 'select2' => true, |
|
| 368 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 369 | - ) |
|
| 370 | - ); |
|
| 371 | - ?> |
|
| 358 | + echo aui()->select( |
|
| 359 | + array( |
|
| 360 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 361 | + 'name' => 'subscription_status', |
|
| 362 | + 'id' => 'subscription_status_update_select', |
|
| 363 | + 'required' => true, |
|
| 364 | + 'no_wrap' => false, |
|
| 365 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 366 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 367 | + 'select2' => true, |
|
| 368 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 369 | + ) |
|
| 370 | + ); |
|
| 371 | + ?> |
|
| 372 | 372 | |
| 373 | 373 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 374 | 374 | |
| 375 | 375 | <?php |
| 376 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 376 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 377 | 377 | |
| 378 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 379 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 380 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 378 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 379 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 380 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 381 | 381 | |
| 382 | - if ( $subscription->is_active() ) { |
|
| 383 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 384 | - } |
|
| 382 | + if ( $subscription->is_active() ) { |
|
| 383 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - echo '</div></div>'; |
|
| 386 | + echo '</div></div>'; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -393,33 +393,33 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
| 395 | 395 | |
| 396 | - $columns = apply_filters( |
|
| 397 | - 'getpaid_subscription_related_invoices_columns', |
|
| 398 | - array( |
|
| 399 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 400 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 401 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 402 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 403 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 404 | - ), |
|
| 405 | - $subscription |
|
| 406 | - ); |
|
| 407 | - |
|
| 408 | - // Prepare the invoices. |
|
| 409 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 410 | - $parent = $subscription->get_parent_invoice(); |
|
| 411 | - |
|
| 412 | - if ( $parent->get_id() ) { |
|
| 413 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 414 | - } |
|
| 396 | + $columns = apply_filters( |
|
| 397 | + 'getpaid_subscription_related_invoices_columns', |
|
| 398 | + array( |
|
| 399 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 400 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 401 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 402 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 403 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 404 | + ), |
|
| 405 | + $subscription |
|
| 406 | + ); |
|
| 407 | + |
|
| 408 | + // Prepare the invoices. |
|
| 409 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 410 | + $parent = $subscription->get_parent_invoice(); |
|
| 411 | + |
|
| 412 | + if ( $parent->get_id() ) { |
|
| 413 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - $table_class = 'w-100 bg-white'; |
|
| 416 | + $table_class = 'w-100 bg-white'; |
|
| 417 | 417 | |
| 418 | - if ( ! is_admin() ) { |
|
| 419 | - $table_class = 'table table-bordered table-striped'; |
|
| 420 | - } |
|
| 418 | + if ( ! is_admin() ) { |
|
| 419 | + $table_class = 'table table-bordered table-striped'; |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - ?> |
|
| 422 | + ?> |
|
| 423 | 423 | <div class="m-0" style="overflow: auto;"> |
| 424 | 424 | |
| 425 | 425 | <table class="<?php echo $table_class; ?>"> |
@@ -427,13 +427,13 @@ discard block |
||
| 427 | 427 | <thead> |
| 428 | 428 | <tr> |
| 429 | 429 | <?php |
| 430 | - foreach ( $columns as $key => $label ) { |
|
| 431 | - $key = esc_attr( $key ); |
|
| 432 | - $label = sanitize_text_field( $label ); |
|
| 430 | + foreach ( $columns as $key => $label ) { |
|
| 431 | + $key = esc_attr( $key ); |
|
| 432 | + $label = sanitize_text_field( $label ); |
|
| 433 | 433 | |
| 434 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
| 435 | - } |
|
| 436 | - ?> |
|
| 434 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
| 435 | + } |
|
| 436 | + ?> |
|
| 437 | 437 | </tr> |
| 438 | 438 | </thead> |
| 439 | 439 | |
@@ -449,66 +449,66 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | <?php |
| 451 | 451 | |
| 452 | - foreach( $payments as $payment ) : |
|
| 452 | + foreach( $payments as $payment ) : |
|
| 453 | 453 | |
| 454 | - // Ensure that we have an invoice. |
|
| 455 | - $payment = new WPInv_Invoice( $payment ); |
|
| 454 | + // Ensure that we have an invoice. |
|
| 455 | + $payment = new WPInv_Invoice( $payment ); |
|
| 456 | 456 | |
| 457 | - // Abort if the invoice is invalid. |
|
| 458 | - if ( ! $payment->get_id() ) { |
|
| 459 | - continue; |
|
| 460 | - } |
|
| 457 | + // Abort if the invoice is invalid. |
|
| 458 | + if ( ! $payment->get_id() ) { |
|
| 459 | + continue; |
|
| 460 | + } |
|
| 461 | 461 | |
| 462 | - echo '<tr>'; |
|
| 462 | + echo '<tr>'; |
|
| 463 | 463 | |
| 464 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 464 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 465 | 465 | |
| 466 | - echo '<td class="p-2 text-left">'; |
|
| 466 | + echo '<td class="p-2 text-left">'; |
|
| 467 | 467 | |
| 468 | - switch( $key ) { |
|
| 468 | + switch( $key ) { |
|
| 469 | 469 | |
| 470 | - case 'total': |
|
| 471 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total() ) ), $payment->get_currency() ) . '</strong>'; |
|
| 472 | - break; |
|
| 470 | + case 'total': |
|
| 471 | + echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total() ) ), $payment->get_currency() ) . '</strong>'; |
|
| 472 | + break; |
|
| 473 | 473 | |
| 474 | - case 'relationship': |
|
| 475 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 476 | - break; |
|
| 474 | + case 'relationship': |
|
| 475 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 476 | + break; |
|
| 477 | 477 | |
| 478 | - case 'date': |
|
| 479 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 480 | - break; |
|
| 478 | + case 'date': |
|
| 479 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 480 | + break; |
|
| 481 | 481 | |
| 482 | - case 'status': |
|
| 482 | + case 'status': |
|
| 483 | 483 | |
| 484 | - $status = $payment->get_status_nicename(); |
|
| 485 | - if ( is_admin() ) { |
|
| 486 | - $status = $payment->get_status_label_html(); |
|
| 487 | - } |
|
| 484 | + $status = $payment->get_status_nicename(); |
|
| 485 | + if ( is_admin() ) { |
|
| 486 | + $status = $payment->get_status_label_html(); |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - echo $status; |
|
| 490 | - break; |
|
| 489 | + echo $status; |
|
| 490 | + break; |
|
| 491 | 491 | |
| 492 | - case 'invoice': |
|
| 493 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 492 | + case 'invoice': |
|
| 493 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 494 | 494 | |
| 495 | - if ( ! is_admin() ) { |
|
| 496 | - $link = esc_url( $payment->get_view_url() ); |
|
| 497 | - } |
|
| 495 | + if ( ! is_admin() ) { |
|
| 496 | + $link = esc_url( $payment->get_view_url() ); |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 500 | - echo "<a href='$link'>$invoice</a>"; |
|
| 501 | - break; |
|
| 502 | - } |
|
| 499 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 500 | + echo "<a href='$link'>$invoice</a>"; |
|
| 501 | + break; |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - echo '</td>'; |
|
| 504 | + echo '</td>'; |
|
| 505 | 505 | |
| 506 | - } |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | - echo '</tr>'; |
|
| 508 | + echo '</tr>'; |
|
| 509 | 509 | |
| 510 | - endforeach; |
|
| 511 | - ?> |
|
| 510 | + endforeach; |
|
| 511 | + ?> |
|
| 512 | 512 | |
| 513 | 513 | </tbody> |
| 514 | 514 | |
@@ -13,72 +13,72 @@ discard block |
||
| 13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'paypal'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 1; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Stores line items to send to PayPal. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 37 | + * Stores line items to send to PayPal. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | 41 | protected $line_items = array(); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Endpoint for requests from PayPal. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $notify_url; |
|
| 44 | + * Endpoint for requests from PayPal. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $notify_url; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Endpoint for requests to PayPal. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 50 | + /** |
|
| 51 | + * Endpoint for requests to PayPal. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | 55 | protected $endpoint; |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Currencies this gateway is allowed for. |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 58 | + * Currencies this gateway is allowed for. |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a transaction. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 65 | + * URL to view a transaction. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * URL to view a subscription. |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 72 | + * URL to view a subscription. |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Class constructor. |
|
| 80 | - */ |
|
| 81 | - public function __construct() { |
|
| 79 | + * Class constructor. |
|
| 80 | + */ |
|
| 81 | + public function __construct() { |
|
| 82 | 82 | |
| 83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
| 84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
@@ -92,15 +92,15 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * Process Payment. |
|
| 96 | - * |
|
| 97 | - * |
|
| 98 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 99 | - * @param array $submission_data Posted checkout fields. |
|
| 100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 101 | - * @return array |
|
| 102 | - */ |
|
| 103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 95 | + * Process Payment. |
|
| 96 | + * |
|
| 97 | + * |
|
| 98 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 99 | + * @param array $submission_data Posted checkout fields. |
|
| 100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 101 | + * @return array |
|
| 102 | + */ |
|
| 103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 104 | 104 | |
| 105 | 105 | // Get redirect url. |
| 106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | - * Get the PayPal request URL for an invoice. |
|
| 127 | - * |
|
| 128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public function get_request_url( $invoice ) { |
|
| 126 | + * Get the PayPal request URL for an invoice. |
|
| 127 | + * |
|
| 128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public function get_request_url( $invoice ) { |
|
| 132 | 132 | |
| 133 | 133 | // Endpoint for this request |
| 134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 135 | 135 | |
| 136 | 136 | // Retrieve paypal args. |
| 137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
| 146 | 146 | |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | - * Get PayPal Args for passing to PP. |
|
| 151 | - * |
|
| 152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - protected function get_paypal_args( $invoice ) { |
|
| 150 | + * Get PayPal Args for passing to PP. |
|
| 151 | + * |
|
| 152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + protected function get_paypal_args( $invoice ) { |
|
| 156 | 156 | |
| 157 | 157 | // Whether or not to send the line items as one item. |
| 158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
| 159 | - |
|
| 160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 161 | - $force_one_line_item = true; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $paypal_args = apply_filters( |
|
| 165 | - 'getpaid_paypal_args', |
|
| 166 | - array_merge( |
|
| 167 | - $this->get_transaction_args( $invoice ), |
|
| 168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 169 | - ), |
|
| 170 | - $invoice |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
| 159 | + |
|
| 160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 161 | + $force_one_line_item = true; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $paypal_args = apply_filters( |
|
| 165 | + 'getpaid_paypal_args', |
|
| 166 | + array_merge( |
|
| 167 | + $this->get_transaction_args( $invoice ), |
|
| 168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 169 | + ), |
|
| 170 | + $invoice |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
| 177 | - * Get transaction args for paypal request. |
|
| 178 | - * |
|
| 179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 180 | - * @return array |
|
| 181 | - */ |
|
| 182 | - protected function get_transaction_args( $invoice ) { |
|
| 177 | + * Get transaction args for paypal request. |
|
| 178 | + * |
|
| 179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 180 | + * @return array |
|
| 181 | + */ |
|
| 182 | + protected function get_transaction_args( $invoice ) { |
|
| 183 | 183 | |
| 184 | - return array( |
|
| 184 | + return array( |
|
| 185 | 185 | 'cmd' => '_cart', |
| 186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
| 187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | - * Get line item args for paypal request. |
|
| 210 | - * |
|
| 211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 213 | - * @return array |
|
| 214 | - */ |
|
| 215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 209 | + * Get line item args for paypal request. |
|
| 210 | + * |
|
| 211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 213 | + * @return array |
|
| 214 | + */ |
|
| 215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 216 | 216 | |
| 217 | 217 | // Maybe send invoice as a single item. |
| 218 | - if ( $force_one_line_item ) { |
|
| 218 | + if ( $force_one_line_item ) { |
|
| 219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
| 235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
| 243 | - * Get line item args for paypal request as a single line item. |
|
| 244 | - * |
|
| 245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 246 | - * @return array |
|
| 247 | - */ |
|
| 248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 249 | - $this->delete_line_items(); |
|
| 243 | + * Get line item args for paypal request as a single line item. |
|
| 244 | + * |
|
| 245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 246 | + * @return array |
|
| 247 | + */ |
|
| 248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
| 249 | + $this->delete_line_items(); |
|
| 250 | 250 | |
| 251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
| 252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
| 252 | + $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
| 253 | 253 | |
| 254 | - return $this->get_line_items(); |
|
| 254 | + return $this->get_line_items(); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
| 258 | - * Return all line items. |
|
| 259 | - */ |
|
| 260 | - protected function get_line_items() { |
|
| 261 | - return $this->line_items; |
|
| 262 | - } |
|
| 258 | + * Return all line items. |
|
| 259 | + */ |
|
| 260 | + protected function get_line_items() { |
|
| 261 | + return $this->line_items; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | 264 | /** |
| 265 | - * Remove all line items. |
|
| 266 | - */ |
|
| 267 | - protected function delete_line_items() { |
|
| 268 | - $this->line_items = array(); |
|
| 265 | + * Remove all line items. |
|
| 266 | + */ |
|
| 267 | + protected function delete_line_items() { |
|
| 268 | + $this->line_items = array(); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
| 272 | - * Prepare line items to send to paypal. |
|
| 273 | - * |
|
| 274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 275 | - */ |
|
| 276 | - protected function prepare_line_items( $invoice ) { |
|
| 277 | - $this->delete_line_items(); |
|
| 278 | - |
|
| 279 | - // Items. |
|
| 280 | - foreach ( $invoice->get_items() as $item ) { |
|
| 281 | - $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
| 282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 272 | + * Prepare line items to send to paypal. |
|
| 273 | + * |
|
| 274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 275 | + */ |
|
| 276 | + protected function prepare_line_items( $invoice ) { |
|
| 277 | + $this->delete_line_items(); |
|
| 278 | + |
|
| 279 | + // Items. |
|
| 280 | + foreach ( $invoice->get_items() as $item ) { |
|
| 281 | + $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
| 282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Fees. |
| 287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 288 | 288 | $this->add_line_item( $fee, 1, $data['amount'] ); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
| 294 | - * Add PayPal Line Item. |
|
| 295 | - * |
|
| 296 | - * @param string $item_name Item name. |
|
| 297 | - * @param int $quantity Item quantity. |
|
| 298 | - * @param float $amount Amount. |
|
| 299 | - * @param string $item_number Item number. |
|
| 300 | - */ |
|
| 301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 303 | - |
|
| 304 | - $item = apply_filters( |
|
| 305 | - 'getpaid_paypal_line_item', |
|
| 306 | - array( |
|
| 307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 308 | - 'quantity' => (int) $quantity, |
|
| 309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 310 | - 'item_number' => $item_number, |
|
| 311 | - ), |
|
| 312 | - $item_name, |
|
| 313 | - $quantity, |
|
| 314 | - $amount, |
|
| 315 | - $item_number |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 294 | + * Add PayPal Line Item. |
|
| 295 | + * |
|
| 296 | + * @param string $item_name Item name. |
|
| 297 | + * @param int $quantity Item quantity. |
|
| 298 | + * @param float $amount Amount. |
|
| 299 | + * @param string $item_number Item number. |
|
| 300 | + */ |
|
| 301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 303 | + |
|
| 304 | + $item = apply_filters( |
|
| 305 | + 'getpaid_paypal_line_item', |
|
| 306 | + array( |
|
| 307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 308 | + 'quantity' => (int) $quantity, |
|
| 309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 310 | + 'item_number' => $item_number, |
|
| 311 | + ), |
|
| 312 | + $item_name, |
|
| 313 | + $quantity, |
|
| 314 | + $amount, |
|
| 315 | + $item_number |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
| 320 | 320 | |
| 321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
| 323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 322 | + $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
| 323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
| 327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
| 328 | - * |
|
| 329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 330 | - * |
|
| 331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 333 | - * @return array |
|
| 334 | - */ |
|
| 335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 336 | - $max_paypal_length = 2083; |
|
| 337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 338 | - |
|
| 339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 340 | - return $paypal_args; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return apply_filters( |
|
| 344 | - 'getpaid_paypal_args', |
|
| 345 | - array_merge( |
|
| 346 | - $this->get_transaction_args( $invoice ), |
|
| 347 | - $this->get_line_item_args( $invoice, true ) |
|
| 348 | - ), |
|
| 349 | - $invoice |
|
| 350 | - ); |
|
| 327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
| 328 | + * |
|
| 329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 330 | + * |
|
| 331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 333 | + * @return array |
|
| 334 | + */ |
|
| 335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 336 | + $max_paypal_length = 2083; |
|
| 337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 338 | + |
|
| 339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 340 | + return $paypal_args; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return apply_filters( |
|
| 344 | + 'getpaid_paypal_args', |
|
| 345 | + array_merge( |
|
| 346 | + $this->get_transaction_args( $invoice ), |
|
| 347 | + $this->get_line_item_args( $invoice, true ) |
|
| 348 | + ), |
|
| 349 | + $invoice |
|
| 350 | + ); |
|
| 351 | 351 | |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
| 355 | - * Processes recurring invoices. |
|
| 356 | - * |
|
| 357 | - * @param array $paypal_args PayPal args. |
|
| 358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 359 | - */ |
|
| 360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 355 | + * Processes recurring invoices. |
|
| 356 | + * |
|
| 357 | + * @param array $paypal_args PayPal args. |
|
| 358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 359 | + */ |
|
| 360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
| 361 | 361 | |
| 362 | 362 | // Make sure this is a subscription. |
| 363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
| 382 | 382 | |
| 383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 384 | 384 | |
| 385 | - // Trial period length. |
|
| 386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 385 | + // Trial period length. |
|
| 386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 387 | 387 | |
| 388 | - // Trial period. |
|
| 389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 388 | + // Trial period. |
|
| 389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 390 | 390 | |
| 391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
| 392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // We have a recurring payment |
| 412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 413 | 413 | |
| 414 | - // Subscription price |
|
| 415 | - $paypal_args['a3'] = $recurring_amount; |
|
| 414 | + // Subscription price |
|
| 415 | + $paypal_args['a3'] = $recurring_amount; |
|
| 416 | 416 | |
| 417 | - // Subscription duration |
|
| 418 | - $paypal_args['p3'] = $interval; |
|
| 417 | + // Subscription duration |
|
| 418 | + $paypal_args['p3'] = $interval; |
|
| 419 | 419 | |
| 420 | - // Subscription period |
|
| 421 | - $paypal_args['t3'] = $period; |
|
| 420 | + // Subscription period |
|
| 421 | + $paypal_args['t3'] = $period; |
|
| 422 | 422 | |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // Recurring payments |
| 426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 427 | 427 | |
| 428 | - // Non-recurring payments |
|
| 429 | - $paypal_args['src'] = 0; |
|
| 428 | + // Non-recurring payments |
|
| 429 | + $paypal_args['src'] = 0; |
|
| 430 | 430 | |
| 431 | - } else { |
|
| 431 | + } else { |
|
| 432 | 432 | |
| 433 | - $paypal_args['src'] = 1; |
|
| 433 | + $paypal_args['src'] = 1; |
|
| 434 | 434 | |
| 435 | - if ( $bill_times > 0 ) { |
|
| 435 | + if ( $bill_times > 0 ) { |
|
| 436 | 436 | |
| 437 | - // An initial period is being used to charge a sign-up fee |
|
| 438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 439 | - $bill_times--; |
|
| 440 | - } |
|
| 437 | + // An initial period is being used to charge a sign-up fee |
|
| 438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 439 | + $bill_times--; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | 442 | // Make sure it's not over the max of 52 |
| 443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,24 +458,24 @@ discard block |
||
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | return apply_filters( |
| 461 | - 'getpaid_paypal_subscription_args', |
|
| 462 | - $paypal_args, |
|
| 463 | - $invoice |
|
| 461 | + 'getpaid_paypal_subscription_args', |
|
| 462 | + $paypal_args, |
|
| 463 | + $invoice |
|
| 464 | 464 | ); |
| 465 | 465 | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
| 469 | - * Processes ipns and marks payments as complete. |
|
| 470 | - * |
|
| 471 | - * @return void |
|
| 472 | - */ |
|
| 473 | - public function verify_ipn() { |
|
| 469 | + * Processes ipns and marks payments as complete. |
|
| 470 | + * |
|
| 471 | + * @return void |
|
| 472 | + */ |
|
| 473 | + public function verify_ipn() { |
|
| 474 | 474 | |
| 475 | 475 | // Validate the IPN. |
| 476 | 476 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 477 | - wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) ); |
|
| 478 | - } |
|
| 477 | + wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) ); |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | 480 | // Process the IPN. |
| 481 | 481 | $posted = wp_unslash( $_POST ); |
@@ -489,8 +489,8 @@ discard block |
||
| 489 | 489 | wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
| 490 | 490 | wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
| 491 | 491 | |
| 492 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 493 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 492 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 493 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 494 | 494 | } else { |
| 495 | 495 | wpinv_error_log( 'Aborting, Invalid type:' . $posted['txn_type'] ); |
| 496 | 496 | } |
@@ -502,33 +502,33 @@ discard block |
||
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
| 505 | - * Check PayPal IPN validity. |
|
| 506 | - */ |
|
| 507 | - public function validate_ipn() { |
|
| 508 | - |
|
| 509 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
| 510 | - |
|
| 511 | - // Get received values from post data. |
|
| 512 | - $validate_ipn = wp_unslash( $_POST ); |
|
| 513 | - $validate_ipn['cmd'] = '_notify-validate'; |
|
| 514 | - |
|
| 515 | - // Send back post vars to paypal. |
|
| 516 | - $params = array( |
|
| 517 | - 'body' => $validate_ipn, |
|
| 518 | - 'timeout' => 60, |
|
| 519 | - 'httpversion' => '1.1', |
|
| 520 | - 'compress' => false, |
|
| 521 | - 'decompress' => false, |
|
| 522 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 523 | - ); |
|
| 505 | + * Check PayPal IPN validity. |
|
| 506 | + */ |
|
| 507 | + public function validate_ipn() { |
|
| 508 | + |
|
| 509 | + wpinv_error_log( 'Validating PayPal IPN response' ); |
|
| 510 | + |
|
| 511 | + // Get received values from post data. |
|
| 512 | + $validate_ipn = wp_unslash( $_POST ); |
|
| 513 | + $validate_ipn['cmd'] = '_notify-validate'; |
|
| 514 | + |
|
| 515 | + // Send back post vars to paypal. |
|
| 516 | + $params = array( |
|
| 517 | + 'body' => $validate_ipn, |
|
| 518 | + 'timeout' => 60, |
|
| 519 | + 'httpversion' => '1.1', |
|
| 520 | + 'compress' => false, |
|
| 521 | + 'decompress' => false, |
|
| 522 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 523 | + ); |
|
| 524 | 524 | |
| 525 | - // Post back to get a response. |
|
| 526 | - $response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 525 | + // Post back to get a response. |
|
| 526 | + $response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 527 | 527 | |
| 528 | 528 | // Check to see if the request was valid. |
| 529 | - if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 529 | + if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 530 | 530 | wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
| 531 | - return true; |
|
| 531 | + return true; |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | if ( is_wp_error( $response ) ) { |
@@ -542,63 +542,63 @@ discard block |
||
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
| 545 | - * Check currency from IPN matches the invoice. |
|
| 546 | - * |
|
| 547 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 548 | - * @param string $currency currency to validate. |
|
| 549 | - */ |
|
| 550 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 551 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 545 | + * Check currency from IPN matches the invoice. |
|
| 546 | + * |
|
| 547 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 548 | + * @param string $currency currency to validate. |
|
| 549 | + */ |
|
| 550 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 551 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 552 | 552 | wpinv_record_gateway_error( 'IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}" ); |
| 553 | 553 | |
| 554 | - /* translators: %s: currency code. */ |
|
| 555 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 556 | - exit; |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Check payment amount from IPN matches the invoice. |
|
| 562 | - * |
|
| 563 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 564 | - * @param float $amount amount to validate. |
|
| 565 | - */ |
|
| 566 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 567 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 554 | + /* translators: %s: currency code. */ |
|
| 555 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 556 | + exit; |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Check payment amount from IPN matches the invoice. |
|
| 562 | + * |
|
| 563 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 564 | + * @param float $amount amount to validate. |
|
| 565 | + */ |
|
| 566 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 567 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 568 | 568 | wpinv_record_gateway_error( 'IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}" ); |
| 569 | 569 | |
| 570 | - /* translators: %s: Amount. */ |
|
| 571 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 572 | - exit; |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * Verify receiver email from PayPal. |
|
| 578 | - * |
|
| 579 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 580 | - * @param string $receiver_email Email to validate. |
|
| 581 | - */ |
|
| 582 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 570 | + /* translators: %s: Amount. */ |
|
| 571 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 572 | + exit; |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * Verify receiver email from PayPal. |
|
| 578 | + * |
|
| 579 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 580 | + * @param string $receiver_email Email to validate. |
|
| 581 | + */ |
|
| 582 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 583 | 583 | $paypal_email = wpinv_get_option( 'paypal_email' ); |
| 584 | 584 | |
| 585 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 585 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 586 | 586 | wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
| 587 | 587 | |
| 588 | - /* translators: %s: email address . */ |
|
| 589 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 590 | - exit; |
|
| 588 | + /* translators: %s: email address . */ |
|
| 589 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 590 | + exit; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - } |
|
| 593 | + } |
|
| 594 | 594 | |
| 595 | 595 | /** |
| 596 | - * Handles one time payments. |
|
| 597 | - * |
|
| 598 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 599 | - * @param array $posted Posted data. |
|
| 600 | - */ |
|
| 601 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 596 | + * Handles one time payments. |
|
| 597 | + * |
|
| 598 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 599 | + * @param array $posted Posted data. |
|
| 600 | + */ |
|
| 601 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 602 | 602 | |
| 603 | 603 | // Collect payment details |
| 604 | 604 | $payment_status = strtolower( $posted['payment_status'] ); |
@@ -659,27 +659,27 @@ discard block |
||
| 659 | 659 | // Process failures. |
| 660 | 660 | |
| 661 | 661 | /* translators: %s: payment status. */ |
| 662 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) ); |
|
| 663 | - |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Handles one time payments. |
|
| 668 | - * |
|
| 669 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 670 | - * @param array $posted Posted data. |
|
| 671 | - */ |
|
| 672 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 673 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 662 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) ); |
|
| 663 | + |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Handles one time payments. |
|
| 668 | + * |
|
| 669 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 670 | + * @param array $posted Posted data. |
|
| 671 | + */ |
|
| 672 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 673 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /** |
| 677 | - * Handles subscription sign ups. |
|
| 678 | - * |
|
| 679 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 680 | - * @param array $posted Posted data. |
|
| 681 | - */ |
|
| 682 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 677 | + * Handles subscription sign ups. |
|
| 678 | + * |
|
| 679 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 680 | + * @param array $posted Posted data. |
|
| 681 | + */ |
|
| 682 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 683 | 683 | |
| 684 | 684 | // Make sure the invoice has a subscription. |
| 685 | 685 | $subscription = wpinv_get_subscription( $invoice ); |
@@ -718,12 +718,12 @@ discard block |
||
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
| 721 | - * Handles subscription renewals. |
|
| 722 | - * |
|
| 723 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 724 | - * @param array $posted Posted data. |
|
| 725 | - */ |
|
| 726 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 721 | + * Handles subscription renewals. |
|
| 722 | + * |
|
| 723 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 724 | + * @param array $posted Posted data. |
|
| 725 | + */ |
|
| 726 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 727 | 727 | |
| 728 | 728 | // Make sure the invoice has a subscription. |
| 729 | 729 | $subscription = wpinv_get_subscription( $invoice ); |
@@ -766,12 +766,12 @@ discard block |
||
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | /** |
| 769 | - * Handles subscription cancelations. |
|
| 770 | - * |
|
| 771 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 772 | - * @param array $posted Posted data. |
|
| 773 | - */ |
|
| 774 | - protected function ipn_txn_subscr_cancel( $invoice, $posted ) { |
|
| 769 | + * Handles subscription cancelations. |
|
| 770 | + * |
|
| 771 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 772 | + * @param array $posted Posted data. |
|
| 773 | + */ |
|
| 774 | + protected function ipn_txn_subscr_cancel( $invoice, $posted ) { |
|
| 775 | 775 | |
| 776 | 776 | if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
| 777 | 777 | $subscription->cancel(); |
@@ -780,12 +780,12 @@ discard block |
||
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
| 783 | - * Handles subscription completions. |
|
| 784 | - * |
|
| 785 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 786 | - * @param array $posted Posted data. |
|
| 787 | - */ |
|
| 788 | - protected function ipn_txn_subscr_eot( $invoice, $posted ) { |
|
| 783 | + * Handles subscription completions. |
|
| 784 | + * |
|
| 785 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 786 | + * @param array $posted Posted data. |
|
| 787 | + */ |
|
| 788 | + protected function ipn_txn_subscr_eot( $invoice, $posted ) { |
|
| 789 | 789 | |
| 790 | 790 | if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
| 791 | 791 | $subscription->complete(); |
@@ -794,12 +794,12 @@ discard block |
||
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | /** |
| 797 | - * Handles subscription fails. |
|
| 798 | - * |
|
| 799 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 800 | - * @param array $posted Posted data. |
|
| 801 | - */ |
|
| 802 | - protected function ipn_txn_subscr_failed( $invoice, $posted ) { |
|
| 797 | + * Handles subscription fails. |
|
| 798 | + * |
|
| 799 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 800 | + * @param array $posted Posted data. |
|
| 801 | + */ |
|
| 802 | + protected function ipn_txn_subscr_failed( $invoice, $posted ) { |
|
| 803 | 803 | |
| 804 | 804 | if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
| 805 | 805 | $subscription->failing(); |
@@ -13,58 +13,58 @@ discard block |
||
| 13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'authorizenet'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 4; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Endpoint for requests from Authorize.net. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $notify_url; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Endpoint for requests to Authorize.net. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 37 | + * Endpoint for requests from Authorize.net. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $notify_url; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Endpoint for requests to Authorize.net. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | 48 | protected $endpoint; |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Class constructor. |
|
| 66 | - */ |
|
| 67 | - public function __construct() { |
|
| 65 | + * Class constructor. |
|
| 66 | + */ |
|
| 67 | + public function __construct() { |
|
| 68 | 68 | |
| 69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
| 70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Displays the payment method select field. |
|
| 80 | - * |
|
| 81 | - * @param int $invoice_id 0 or invoice id. |
|
| 82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 83 | - */ |
|
| 79 | + * Displays the payment method select field. |
|
| 80 | + * |
|
| 81 | + * @param int $invoice_id 0 or invoice id. |
|
| 82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 83 | + */ |
|
| 84 | 84 | public function payment_fields( $invoice_id, $form ) { |
| 85 | 85 | |
| 86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * Creates a customer profile. |
|
| 95 | - * |
|
| 96 | - * |
|
| 97 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 94 | + * Creates a customer profile. |
|
| 95 | + * |
|
| 96 | + * |
|
| 97 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 98 | 98 | * @param array $submission_data Posted checkout fields. |
| 99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
| 100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 101 | - * @return string|WP_Error Payment profile id. |
|
| 102 | - */ |
|
| 103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 101 | + * @return string|WP_Error Payment profile id. |
|
| 102 | + */ |
|
| 103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 104 | 104 | |
| 105 | 105 | // Remove non-digits from the number |
| 106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | - * Retrieves a customer profile. |
|
| 171 | - * |
|
| 172 | - * |
|
| 173 | - * @param string $profile_id profile id. |
|
| 174 | - * @return string|WP_Error Profile id. |
|
| 170 | + * Retrieves a customer profile. |
|
| 171 | + * |
|
| 172 | + * |
|
| 173 | + * @param string $profile_id profile id. |
|
| 174 | + * @return string|WP_Error Profile id. |
|
| 175 | 175 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
| 176 | - */ |
|
| 177 | - public function get_customer_profile( $profile_id ) { |
|
| 176 | + */ |
|
| 177 | + public function get_customer_profile( $profile_id ) { |
|
| 178 | 178 | |
| 179 | 179 | // Generate args. |
| 180 | 180 | $args = array( |
@@ -189,17 +189,17 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | - * Creates a customer profile. |
|
| 193 | - * |
|
| 194 | - * |
|
| 192 | + * Creates a customer profile. |
|
| 193 | + * |
|
| 194 | + * |
|
| 195 | 195 | * @param string $profile_id profile id. |
| 196 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 196 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 197 | 197 | * @param array $submission_data Posted checkout fields. |
| 198 | 198 | * @param bool $save Whether or not to save the payment as a token. |
| 199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 200 | - * @return string|WP_Error Profile id. |
|
| 201 | - */ |
|
| 202 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 200 | + * @return string|WP_Error Profile id. |
|
| 201 | + */ |
|
| 202 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 203 | 203 | |
| 204 | 204 | // Remove non-digits from the number |
| 205 | 205 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -259,15 +259,15 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | - * Retrieves a customer payment profile. |
|
| 263 | - * |
|
| 264 | - * |
|
| 265 | - * @param string $customer_profile_id customer profile id. |
|
| 262 | + * Retrieves a customer payment profile. |
|
| 263 | + * |
|
| 264 | + * |
|
| 265 | + * @param string $customer_profile_id customer profile id. |
|
| 266 | 266 | * @param string $payment_profile_id payment profile id. |
| 267 | - * @return string|WP_Error Profile id. |
|
| 267 | + * @return string|WP_Error Profile id. |
|
| 268 | 268 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
| 269 | - */ |
|
| 270 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 269 | + */ |
|
| 270 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 271 | 271 | |
| 272 | 272 | // Generate args. |
| 273 | 273 | $args = array( |
@@ -283,15 +283,15 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
| 286 | - * Charges a customer payment profile. |
|
| 287 | - * |
|
| 286 | + * Charges a customer payment profile. |
|
| 287 | + * |
|
| 288 | 288 | * @param string $customer_profile_id customer profile id. |
| 289 | 289 | * @param string $payment_profile_id payment profile id. |
| 290 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 290 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 291 | 291 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
| 292 | - * @return WP_Error|object |
|
| 293 | - */ |
|
| 294 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 292 | + * @return WP_Error|object |
|
| 293 | + */ |
|
| 294 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 295 | 295 | |
| 296 | 296 | // Generate args. |
| 297 | 297 | $args = array( |
@@ -333,41 +333,41 @@ discard block |
||
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | - * Processes a customer charge. |
|
| 337 | - * |
|
| 336 | + * Processes a customer charge. |
|
| 337 | + * |
|
| 338 | 338 | * @param stdClass $result Api response. |
| 339 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 340 | - */ |
|
| 341 | - public function process_charge_response( $result, $invoice ) { |
|
| 339 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 340 | + */ |
|
| 341 | + public function process_charge_response( $result, $invoice ) { |
|
| 342 | 342 | |
| 343 | 343 | wpinv_clear_errors(); |
| 344 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
| 344 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
| 345 | 345 | |
| 346 | - // Succeeded. |
|
| 347 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
| 346 | + // Succeeded. |
|
| 347 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
| 348 | 348 | |
| 349 | - // Maybe set a transaction id. |
|
| 350 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 351 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 352 | - } |
|
| 349 | + // Maybe set a transaction id. |
|
| 350 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 351 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 354 | + $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 355 | 355 | |
| 356 | - if ( 1 == $response_code ) { |
|
| 357 | - return $invoice->mark_paid(); |
|
| 358 | - } |
|
| 356 | + if ( 1 == $response_code ) { |
|
| 357 | + return $invoice->mark_paid(); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - $invoice->set_status( 'wpi-onhold' ); |
|
| 361 | - $invoice->add_note( |
|
| 360 | + $invoice->set_status( 'wpi-onhold' ); |
|
| 361 | + $invoice->add_note( |
|
| 362 | 362 | sprintf( |
| 363 | 363 | __( 'Held for review: %s', 'invoicing' ), |
| 364 | 364 | $result->transactionResponse->messages->message[0]->description |
| 365 | 365 | ) |
| 366 | - ); |
|
| 366 | + ); |
|
| 367 | 367 | |
| 368 | - return $invoice->save(); |
|
| 368 | + return $invoice->save(); |
|
| 369 | 369 | |
| 370 | - } |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | 372 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
| 373 | 373 | |
@@ -379,13 +379,13 @@ discard block |
||
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
| 382 | - * Returns payment information. |
|
| 383 | - * |
|
| 384 | - * |
|
| 385 | - * @param array $card Card details. |
|
| 386 | - * @return array |
|
| 387 | - */ |
|
| 388 | - public function get_payment_information( $card ) { |
|
| 382 | + * Returns payment information. |
|
| 383 | + * |
|
| 384 | + * |
|
| 385 | + * @param array $card Card details. |
|
| 386 | + * @return array |
|
| 387 | + */ |
|
| 388 | + public function get_payment_information( $card ) { |
|
| 389 | 389 | return array( |
| 390 | 390 | |
| 391 | 391 | 'creditCard' => array ( |
@@ -398,25 +398,25 @@ discard block |
||
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | - * Returns the customer profile meta name. |
|
| 402 | - * |
|
| 403 | - * |
|
| 404 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 405 | - * @return string |
|
| 406 | - */ |
|
| 407 | - public function get_customer_profile_meta_name( $invoice ) { |
|
| 401 | + * Returns the customer profile meta name. |
|
| 402 | + * |
|
| 403 | + * |
|
| 404 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 405 | + * @return string |
|
| 406 | + */ |
|
| 407 | + public function get_customer_profile_meta_name( $invoice ) { |
|
| 408 | 408 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
| 412 | - * Validates the submitted data. |
|
| 413 | - * |
|
| 414 | - * |
|
| 415 | - * @param array $submission_data Posted checkout fields. |
|
| 412 | + * Validates the submitted data. |
|
| 413 | + * |
|
| 414 | + * |
|
| 415 | + * @param array $submission_data Posted checkout fields. |
|
| 416 | 416 | * @param WPInv_Invoice $invoice |
| 417 | - * @return WP_Error|string The payment profile id |
|
| 418 | - */ |
|
| 419 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
| 417 | + * @return WP_Error|string The payment profile id |
|
| 418 | + */ |
|
| 419 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
| 420 | 420 | |
| 421 | 421 | // Validate authentication details. |
| 422 | 422 | $auth = $this->get_auth_params(); |
@@ -448,13 +448,13 @@ discard block |
||
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | /** |
| 451 | - * Returns invoice line items. |
|
| 452 | - * |
|
| 453 | - * |
|
| 454 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 455 | - * @return array |
|
| 456 | - */ |
|
| 457 | - public function get_line_items( $invoice ) { |
|
| 451 | + * Returns invoice line items. |
|
| 452 | + * |
|
| 453 | + * |
|
| 454 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 455 | + * @return array |
|
| 456 | + */ |
|
| 457 | + public function get_line_items( $invoice ) { |
|
| 458 | 458 | $items = array(); |
| 459 | 459 | |
| 460 | 460 | foreach ( $invoice->get_items() as $item ) { |
@@ -474,15 +474,15 @@ discard block |
||
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
| 477 | - * Process Payment. |
|
| 478 | - * |
|
| 479 | - * |
|
| 480 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 481 | - * @param array $submission_data Posted checkout fields. |
|
| 482 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 483 | - * @return array |
|
| 484 | - */ |
|
| 485 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 477 | + * Process Payment. |
|
| 478 | + * |
|
| 479 | + * |
|
| 480 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 481 | + * @param array $submission_data Posted checkout fields. |
|
| 482 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 483 | + * @return array |
|
| 484 | + */ |
|
| 485 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 486 | 486 | |
| 487 | 487 | // Validate the submitted data. |
| 488 | 488 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -515,69 +515,69 @@ discard block |
||
| 515 | 515 | |
| 516 | 516 | exit; |
| 517 | 517 | |
| 518 | - } |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | - /** |
|
| 521 | - * Processes the initial payment. |
|
| 522 | - * |
|
| 520 | + /** |
|
| 521 | + * Processes the initial payment. |
|
| 522 | + * |
|
| 523 | 523 | * @param WPInv_Invoice $invoice Invoice. |
| 524 | - */ |
|
| 525 | - protected function process_initial_payment( $invoice ) { |
|
| 524 | + */ |
|
| 525 | + protected function process_initial_payment( $invoice ) { |
|
| 526 | 526 | |
| 527 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 527 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 528 | 528 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
| 529 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 529 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 530 | 530 | |
| 531 | - // Do we have an error? |
|
| 532 | - if ( is_wp_error( $result ) ) { |
|
| 533 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 534 | - wpinv_send_back_to_checkout(); |
|
| 535 | - } |
|
| 531 | + // Do we have an error? |
|
| 532 | + if ( is_wp_error( $result ) ) { |
|
| 533 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 534 | + wpinv_send_back_to_checkout(); |
|
| 535 | + } |
|
| 536 | 536 | |
| 537 | - // Process the response. |
|
| 538 | - $this->process_charge_response( $result, $invoice ); |
|
| 537 | + // Process the response. |
|
| 538 | + $this->process_charge_response( $result, $invoice ); |
|
| 539 | 539 | |
| 540 | - if ( wpinv_get_errors() ) { |
|
| 541 | - wpinv_send_back_to_checkout(); |
|
| 542 | - } |
|
| 540 | + if ( wpinv_get_errors() ) { |
|
| 541 | + wpinv_send_back_to_checkout(); |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - } |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | 546 | /** |
| 547 | - * Processes recurring payments. |
|
| 548 | - * |
|
| 547 | + * Processes recurring payments. |
|
| 548 | + * |
|
| 549 | 549 | * @param WPInv_Invoice $invoice Invoice. |
| 550 | 550 | * @param WPInv_Subscription $subscription Subscription. |
| 551 | - */ |
|
| 552 | - public function process_subscription( $invoice, $subscription ) { |
|
| 551 | + */ |
|
| 552 | + public function process_subscription( $invoice, $subscription ) { |
|
| 553 | 553 | |
| 554 | 554 | // Check if there is an initial amount to charge. |
| 555 | 555 | if ( (float) $invoice->get_total() > 0 ) { |
| 556 | - $this->process_initial_payment( $invoice ); |
|
| 556 | + $this->process_initial_payment( $invoice ); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | // Activate the subscription. |
| 560 | 560 | $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
| 561 | 561 | $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
| 562 | 562 | |
| 563 | - $subscription->set_next_renewal_date( $expiry ); |
|
| 564 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 565 | - $subscription->set_profile_id( $invoice->generate_key() ); |
|
| 566 | - $subscription->activate(); |
|
| 563 | + $subscription->set_next_renewal_date( $expiry ); |
|
| 564 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 565 | + $subscription->set_profile_id( $invoice->generate_key() ); |
|
| 566 | + $subscription->activate(); |
|
| 567 | 567 | |
| 568 | - // Redirect to the success page. |
|
| 568 | + // Redirect to the success page. |
|
| 569 | 569 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
| 570 | 570 | |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - /** |
|
| 574 | - * (Maybe) renews an authorize.net subscription profile. |
|
| 575 | - * |
|
| 576 | - * |
|
| 577 | - * @param bool $should_expire |
|
| 573 | + /** |
|
| 574 | + * (Maybe) renews an authorize.net subscription profile. |
|
| 575 | + * |
|
| 576 | + * |
|
| 577 | + * @param bool $should_expire |
|
| 578 | 578 | * @param WPInv_Subscription $subscription |
| 579 | - */ |
|
| 580 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 579 | + */ |
|
| 580 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 581 | 581 | |
| 582 | 582 | // Ensure its our subscription && it's active. |
| 583 | 583 | if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -594,18 +594,18 @@ discard block |
||
| 594 | 594 | |
| 595 | 595 | return false; |
| 596 | 596 | |
| 597 | - } |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | 599 | /** |
| 600 | - * Renews a subscription. |
|
| 601 | - * |
|
| 600 | + * Renews a subscription. |
|
| 601 | + * |
|
| 602 | 602 | * @param WPInv_Subscription $subscription |
| 603 | - */ |
|
| 604 | - public function renew_subscription( $subscription ) { |
|
| 603 | + */ |
|
| 604 | + public function renew_subscription( $subscription ) { |
|
| 605 | 605 | |
| 606 | - // Generate the renewal invoice. |
|
| 607 | - $new_invoice = $subscription->create_payment(); |
|
| 608 | - $old_invoice = $subscription->get_parent_payment(); |
|
| 606 | + // Generate the renewal invoice. |
|
| 607 | + $new_invoice = $subscription->create_payment(); |
|
| 608 | + $old_invoice = $subscription->get_parent_payment(); |
|
| 609 | 609 | |
| 610 | 610 | if ( empty( $new_invoice ) ) { |
| 611 | 611 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -613,38 +613,38 @@ discard block |
||
| 613 | 613 | return; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | - // Charge the payment method. |
|
| 617 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 618 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 619 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 616 | + // Charge the payment method. |
|
| 617 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 618 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 619 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 620 | 620 | |
| 621 | - // Do we have an error? |
|
| 622 | - if ( is_wp_error( $result ) ) { |
|
| 621 | + // Do we have an error? |
|
| 622 | + if ( is_wp_error( $result ) ) { |
|
| 623 | 623 | |
| 624 | - $old_invoice->add_note( |
|
| 625 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 626 | - true, |
|
| 627 | - false, |
|
| 628 | - true |
|
| 629 | - ); |
|
| 630 | - $subscription->failing(); |
|
| 631 | - return; |
|
| 624 | + $old_invoice->add_note( |
|
| 625 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 626 | + true, |
|
| 627 | + false, |
|
| 628 | + true |
|
| 629 | + ); |
|
| 630 | + $subscription->failing(); |
|
| 631 | + return; |
|
| 632 | 632 | |
| 633 | - } |
|
| 633 | + } |
|
| 634 | 634 | |
| 635 | - // Process the response. |
|
| 636 | - $this->process_charge_response( $result, $new_invoice ); |
|
| 635 | + // Process the response. |
|
| 636 | + $this->process_charge_response( $result, $new_invoice ); |
|
| 637 | 637 | |
| 638 | - if ( wpinv_get_errors() ) { |
|
| 638 | + if ( wpinv_get_errors() ) { |
|
| 639 | 639 | |
| 640 | - $old_invoice->add_note( |
|
| 641 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 642 | - true, |
|
| 643 | - false, |
|
| 644 | - true |
|
| 645 | - ); |
|
| 646 | - $subscription->failing(); |
|
| 647 | - return; |
|
| 640 | + $old_invoice->add_note( |
|
| 641 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 642 | + true, |
|
| 643 | + false, |
|
| 644 | + true |
|
| 645 | + ); |
|
| 646 | + $subscription->failing(); |
|
| 647 | + return; |
|
| 648 | 648 | |
| 649 | 649 | } |
| 650 | 650 | |
@@ -670,11 +670,11 @@ discard block |
||
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /** |
| 673 | - * Filters the gateway settings. |
|
| 674 | - * |
|
| 675 | - * @param array $admin_settings |
|
| 676 | - */ |
|
| 677 | - public function admin_settings( $admin_settings ) { |
|
| 673 | + * Filters the gateway settings. |
|
| 674 | + * |
|
| 675 | + * @param array $admin_settings |
|
| 676 | + */ |
|
| 677 | + public function admin_settings( $admin_settings ) { |
|
| 678 | 678 | |
| 679 | 679 | $currencies = sprintf( |
| 680 | 680 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | 'readonly' => true, |
| 715 | 715 | ); |
| 716 | 716 | |
| 717 | - return $admin_settings; |
|
| 718 | - } |
|
| 717 | + return $admin_settings; |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | 720 | } |