| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPCoder\Dashboard; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
use WPCoder\WPCoder; |
| 8 |
|
| 9 |
class Link { |
| 10 |
|
| 11 |
public static function create( $arg = [] ): string { |
| 12 |
return add_query_arg( $arg, self::link() ); |
| 13 |
} |
| 14 |
|
| 15 |
public static function activate_mode( $id = 0 ): string { |
| 16 |
return wp_nonce_url( add_query_arg( [ |
| 17 |
'id' => $id, |
| 18 |
], self::link() ), WPCoder::PREFIX . '_nonce', WPCoder::PREFIX . '_activate_mode' ); |
| 19 |
} |
| 20 |
|
| 21 |
public static function deactivate_mode( $id = 0 ) { |
| 22 |
return wp_nonce_url( add_query_arg( [ |
| 23 |
'id' => $id, |
| 24 |
], self::link() ), WPCoder::PREFIX . '_nonce', WPCoder::PREFIX . '_deactivate_mode' ); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
public static function activate_url( $id = 0 ) { |
| 29 |
return wp_nonce_url( add_query_arg( [ |
| 30 |
'id' => $id, |
| 31 |
'action' => 'activate', |
| 32 |
], self::link() ), WPCoder::PREFIX . '_nonce', WPCoder::PREFIX . '_activate_item' ); |
| 33 |
} |
| 34 |
|
| 35 |
public static function deactivate_url( $id = 0 ) { |
| 36 |
return wp_nonce_url( add_query_arg( [ |
| 37 |
'id' => $id, |
| 38 |
'action' => 'deactivate', |
| 39 |
], self::link() ), WPCoder::PREFIX . '_nonce', WPCoder::PREFIX . '_deactivate_item' ); |
| 40 |
} |
| 41 |
|
| 42 |
public static function remove_item() { |
| 43 |
return add_query_arg( [ |
| 44 |
'notice' => 'remove_item', |
| 45 |
], self::link() ); |
| 46 |
} |
| 47 |
|
| 48 |
public static function save_item( $id ) { |
| 49 |
|
| 50 |
$paged = $_GET['wpcoder-page'] ?? ''; |
| 51 |
|
| 52 |
$arg = [ |
| 53 |
'page' => WPCoder::SLUG . '-settings', |
| 54 |
'action' => 'update', |
| 55 |
'id' => $id, |
| 56 |
'notice' => 'save_item', |
| 57 |
]; |
| 58 |
|
| 59 |
if(!empty($paged)) { |
| 60 |
$arg['wpcoder-page'] = absint($paged); |
| 61 |
} |
| 62 |
|
| 63 |
return add_query_arg( $arg, admin_url( 'admin.php' ) ); |
| 64 |
} |
| 65 |
|
| 66 |
public static function menu( $page, $action, $id ): string { |
| 67 |
if ( ! empty( $id ) && $action === 'update' ) { |
| 68 |
return add_query_arg( [ |
| 69 |
'page' => WPCoder::SLUG . '-settings', |
| 70 |
'action' => 'update', |
| 71 |
'id' => $id, |
| 72 |
], admin_url( 'admin.php' ) ); |
| 73 |
} |
| 74 |
|
| 75 |
return add_query_arg( [ |
| 76 |
'tab' => $page, |
| 77 |
], self::link() ); |
| 78 |
} |
| 79 |
|
| 80 |
public static function edit( $id ) { |
| 81 |
if ( ! $id ) { |
| 82 |
return false; |
| 83 |
} |
| 84 |
$paged = $_GET['paged'] ?? ''; |
| 85 |
return add_query_arg( [ |
| 86 |
'page' => WPCoder::SLUG . '-settings', |
| 87 |
'action' => 'update', |
| 88 |
'id' => $id, |
| 89 |
'wpcoder-page' => absint( $paged ), |
| 90 |
], admin_url( 'admin.php' ) ); |
| 91 |
} |
| 92 |
|
| 93 |
public static function all_codes() { |
| 94 |
$paged = $_GET['wpcoder-page'] ?? ''; |
| 95 |
|
| 96 |
$arg = [ |
| 97 |
'page' => WPCoder::SLUG , |
| 98 |
]; |
| 99 |
|
| 100 |
if(!empty($paged)) { |
| 101 |
$arg['paged'] = absint($paged); |
| 102 |
} |
| 103 |
|
| 104 |
return add_query_arg( $arg, admin_url( 'admin.php' ) ); |
| 105 |
} |
| 106 |
|
| 107 |
public static function duplicate( $id ) { |
| 108 |
if ( ! $id ) { |
| 109 |
return false; |
| 110 |
} |
| 111 |
|
| 112 |
return add_query_arg( [ |
| 113 |
'page' => WPCoder::SLUG . '-settings', |
| 114 |
'action' => 'duplicate', |
| 115 |
'id' => $id |
| 116 |
], admin_url( 'admin.php' ) ); |
| 117 |
} |
| 118 |
|
| 119 |
public static function export( $id ) { |
| 120 |
if ( ! $id ) { |
| 121 |
return false; |
| 122 |
} |
| 123 |
|
| 124 |
return wp_nonce_url( add_query_arg( [ |
| 125 |
'action' => 'export', |
| 126 |
'id' => $id |
| 127 |
], self::link() ), WPCoder::PREFIX . '_nonce', WPCoder::PREFIX . '_export_item' ); |
| 128 |
} |
| 129 |
|
| 130 |
public static function remove( $id ) { |
| 131 |
if ( ! $id ) { |
| 132 |
return false; |
| 133 |
} |
| 134 |
|
| 135 |
return wp_nonce_url( add_query_arg( [ |
| 136 |
'action' => 'delete', |
| 137 |
'id' => $id |
| 138 |
], self::link() ), WPCoder::PREFIX . '_nonce', WPCoder::PREFIX . '_remove_item' ); |
| 139 |
} |
| 140 |
|
| 141 |
private static function link(): string { |
| 142 |
return add_query_arg( [ 'page' => WPCoder::SLUG ], admin_url( 'admin.php' ) ); |
| 143 |
} |
| 144 |
|
| 145 |
} |