| 1 |
<?php |
| 2 |
/** |
| 3 |
* The class that is responsible for registering the Upgrades page. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Upgrade_Page |
| 6 |
* @version 1.3.0 |
| 7 |
* @author David Bisset |
| 8 |
* @copyright Copyright (c) 2022, WP Charitable LLC |
| 9 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Upgrade_Page' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Upgrade_Page |
| 21 |
* |
| 22 |
* @since 1.3.0 |
| 23 |
*/ |
| 24 |
class Charitable_Upgrade_Page { |
| 25 |
|
| 26 |
/** |
| 27 |
* The one and only class instance. |
| 28 |
* |
| 29 |
* @since 1.3.0 |
| 30 |
* |
| 31 |
* @var Charitable_Upgrade_Page |
| 32 |
*/ |
| 33 |
private static $instance = null; |
| 34 |
|
| 35 |
/** |
| 36 |
* Create class object. Private constructor. |
| 37 |
* |
| 38 |
* @since 1.3.0 |
| 39 |
*/ |
| 40 |
private function __construct() { |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Create and return the class object. |
| 45 |
* |
| 46 |
* @since 1.3.0 |
| 47 |
*/ |
| 48 |
public static function get_instance() { |
| 49 |
if ( is_null( self::$instance ) ) { |
| 50 |
self::$instance = new self(); |
| 51 |
} |
| 52 |
|
| 53 |
return self::$instance; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Register the page. |
| 58 |
* |
| 59 |
* @since 1.3.0 |
| 60 |
* |
| 61 |
* @return void |
| 62 |
*/ |
| 63 |
public function register_page() { |
| 64 |
add_dashboard_page( |
| 65 |
__( 'Upgrade Charitable', 'charitable' ), |
| 66 |
__( 'Upgrade Charitable', 'charitable' ), |
| 67 |
'manage_charitable_settings', |
| 68 |
'charitable-upgrades', |
| 69 |
array( $this, 'render_page' ) |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Remove the page from the dashboard menu. |
| 75 |
* |
| 76 |
* @since 1.3.0 |
| 77 |
* |
| 78 |
* @return void |
| 79 |
*/ |
| 80 |
public function remove_page_from_menu() { |
| 81 |
remove_submenu_page( 'index.php', 'charitable-upgrades' ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Render the page. |
| 86 |
* |
| 87 |
* @since 1.3.0 |
| 88 |
* |
| 89 |
* @return void |
| 90 |
*/ |
| 91 |
public function render_page() { |
| 92 |
charitable_admin_view( 'upgrades-page/page', array( 'page' => $this ) ); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Return the current upgrade action. |
| 97 |
* |
| 98 |
* @since 1.3.0 |
| 99 |
* |
| 100 |
* @return false|string False if no action was specified. |
| 101 |
*/ |
| 102 |
public function get_action() { |
| 103 |
if ( ! isset( $_GET['charitable-upgrade'] ) ) { |
| 104 |
return false; |
| 105 |
} |
| 106 |
|
| 107 |
return sanitize_text_field( $_GET['charitable-upgrade'] ); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Return the current upgrade step. |
| 112 |
* |
| 113 |
* @since 1.3.0 |
| 114 |
* |
| 115 |
* @return int |
| 116 |
*/ |
| 117 |
public function get_step() { |
| 118 |
if ( ! isset( $_GET['step'] ) ) { |
| 119 |
return 1; |
| 120 |
} |
| 121 |
|
| 122 |
return absint( $_GET['step'] ); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Return the total number of records to be updated. |
| 127 |
* |
| 128 |
* @since 1.3.0 |
| 129 |
* |
| 130 |
* @return false|int |
| 131 |
*/ |
| 132 |
public function get_total() { |
| 133 |
if ( ! isset( $_GET['total'] ) ) { |
| 134 |
return false; |
| 135 |
} |
| 136 |
|
| 137 |
return absint( $_GET['total'] ); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Return the |
| 142 |
* |
| 143 |
* @since 1.3.0 |
| 144 |
* |
| 145 |
* @return int |
| 146 |
*/ |
| 147 |
public function get_number() { |
| 148 |
if ( ! isset( $_GET['number'] ) ) { |
| 149 |
return 100; |
| 150 |
} |
| 151 |
|
| 152 |
return absint( $_GET['number'] ); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Return the total number of steps. |
| 157 |
* |
| 158 |
* @since 1.3.0 |
| 159 |
* |
| 160 |
* @param int $total The total number of records to update. |
| 161 |
* @param int $number The number to update in a single step. |
| 162 |
* @return int |
| 163 |
*/ |
| 164 |
public function get_steps( $total, $number ) { |
| 165 |
return round( ( $total / $number ), 0 ); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
endif; |
| 170 |
|