| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The Link class provides methods for generating URLs with query arguments. |
| 5 |
* |
| 6 |
* @package WowPlugin |
| 7 |
* @subpackage Admin |
| 8 |
* @author Dmytro Lobov <dev@wow-company.com>, Wow-Company |
| 9 |
* @copyright 2024 Dmytro Lobov |
| 10 |
* @license GPL-2.0+ |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace ButtonGenerator\Admin; |
| 14 |
|
| 15 |
defined( 'ABSPATH' ) || exit; |
| 16 |
|
| 17 |
use ButtonGenerator\WOWP_Plugin; |
| 18 |
|
| 19 |
class Link { |
| 20 |
|
| 21 |
public static function add_new_item(): string { |
| 22 |
|
| 23 |
return add_query_arg( [ |
| 24 |
'page' => WOWP_Plugin::SLUG, |
| 25 |
'tab' => 'settings', |
| 26 |
'action' => 'new' |
| 27 |
], admin_url( 'admin.php' ) ); |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
public static function create( $arg = [] ): string { |
| 32 |
return add_query_arg( $arg, self::link() ); |
| 33 |
} |
| 34 |
|
| 35 |
public static function activate_mode( $id = 0 ): string { |
| 36 |
return wp_nonce_url( add_query_arg( [ |
| 37 |
'id' => $id, |
| 38 |
], self::link() ), WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_activate_mode' ); |
| 39 |
} |
| 40 |
|
| 41 |
public static function deactivate_mode( $id = 0 ): string { |
| 42 |
return wp_nonce_url( add_query_arg( [ |
| 43 |
'id' => $id, |
| 44 |
], self::link() ), WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_deactivate_mode' ); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
public static function activate_url( $id = 0 ): string { |
| 49 |
return wp_nonce_url( add_query_arg( [ |
| 50 |
'id' => $id, |
| 51 |
'action' => 'activate', |
| 52 |
], self::link() ), WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_activate_item' ); |
| 53 |
} |
| 54 |
|
| 55 |
public static function deactivate_url( $id = 0 ): string { |
| 56 |
return wp_nonce_url( add_query_arg( [ |
| 57 |
'id' => $id, |
| 58 |
'action' => 'deactivate', |
| 59 |
], self::link() ), WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_deactivate_item' ); |
| 60 |
} |
| 61 |
|
| 62 |
public static function remove_item(): string { |
| 63 |
return add_query_arg( [ |
| 64 |
'notice' => 'remove_item', |
| 65 |
], self::link() ); |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
public static function save_item( $id ): string { |
| 70 |
return add_query_arg( [ |
| 71 |
'tab' => 'settings', |
| 72 |
'action' => 'update', |
| 73 |
'id' => $id, |
| 74 |
'notice' => 'save_item', |
| 75 |
'nonce' => wp_create_nonce( 'save-item' ) |
| 76 |
], self::link() ); |
| 77 |
} |
| 78 |
|
| 79 |
public static function menu( $page, $action, $id ): string { |
| 80 |
if ( ! empty( $id ) && $action === 'update' ) { |
| 81 |
return add_query_arg( [ |
| 82 |
'tab' => $page, |
| 83 |
'action' => 'update', |
| 84 |
'id' => $id, |
| 85 |
], self::link() ); |
| 86 |
} |
| 87 |
|
| 88 |
return add_query_arg( [ |
| 89 |
'tab' => $page, |
| 90 |
], self::link() ); |
| 91 |
} |
| 92 |
|
| 93 |
public static function edit( $id ) { |
| 94 |
if ( ! $id ) { |
| 95 |
return false; |
| 96 |
} |
| 97 |
|
| 98 |
return add_query_arg( [ |
| 99 |
'action' => 'update', |
| 100 |
'tab' => 'settings', |
| 101 |
'id' => $id |
| 102 |
], self::link() ); |
| 103 |
} |
| 104 |
|
| 105 |
public static function duplicate( $id ) { |
| 106 |
if ( ! $id ) { |
| 107 |
return false; |
| 108 |
} |
| 109 |
|
| 110 |
return add_query_arg( [ |
| 111 |
'action' => 'duplicate', |
| 112 |
'tab' => 'settings', |
| 113 |
'id' => $id |
| 114 |
], self::link() ); |
| 115 |
} |
| 116 |
|
| 117 |
public static function export( $id ) { |
| 118 |
if ( ! $id ) { |
| 119 |
return false; |
| 120 |
} |
| 121 |
|
| 122 |
return wp_nonce_url( add_query_arg( [ |
| 123 |
'action' => 'export', |
| 124 |
'id' => $id |
| 125 |
], self::link() ), WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_export_item' ); |
| 126 |
} |
| 127 |
|
| 128 |
public static function remove( $id ) { |
| 129 |
if ( ! $id ) { |
| 130 |
return false; |
| 131 |
} |
| 132 |
|
| 133 |
return wp_nonce_url( add_query_arg( [ |
| 134 |
'action' => 'delete', |
| 135 |
'id' => $id |
| 136 |
], self::link() ), WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_remove_item' ); |
| 137 |
} |
| 138 |
|
| 139 |
public static function reset_count( $id ) { |
| 140 |
if ( ! $id ) { |
| 141 |
return false; |
| 142 |
} |
| 143 |
|
| 144 |
return wp_nonce_url( add_query_arg( [ |
| 145 |
'action' => 'reset_statistic', |
| 146 |
'id' => $id |
| 147 |
], self::link() ), WOWP_Plugin::PREFIX . '_nonce', WOWP_Plugin::PREFIX . '_reset_count' ); |
| 148 |
} |
| 149 |
|
| 150 |
private static function link(): string { |
| 151 |
return add_query_arg( [ 'page' => WOWP_Plugin::SLUG ], admin_url( 'admin.php' ) ); |
| 152 |
} |
| 153 |
|
| 154 |
} |