Suspend
2 years ago
ActionScheduler.php
2 years ago
AdminPages.php
8 months ago
AdminUrl.php
8 months ago
DB.php
4 years ago
Post.php
5 years ago
Resources.php
5 years ago
SyncHash.php
8 months ago
WCTaxonomies.php
1 year ago
WcAdminPages.php
8 months ago
WpAdminPages.php
1 year ago
AdminUrl.php
231 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Utilities; |
| 4 | |
| 5 | use function WCML\functions\isStandAlone; |
| 6 | |
| 7 | class AdminUrl { |
| 8 | const PAGE_WPML_WCML = \WCML_Admin_Menus::SLUG; |
| 9 | |
| 10 | const PAGE_WOO_SETTINGS = 'wc-settings'; |
| 11 | |
| 12 | const TAB_PRODUCTS = 'products'; |
| 13 | const TAB_MULTILINGUAL = AdminPages::TAB_MULTILINGUAL; |
| 14 | const TAB_MULTILINGUAL_STANDALONE = AdminPages::TAB_MULTILINGUAL_STANDALONE; |
| 15 | const TAB_MULTICURRENCY = AdminPages::TAB_MULTICURRENCY; |
| 16 | const TAB_TROUBLESHOOTING = 'troubleshooting'; |
| 17 | const TAB_STORE_URL = 'slugs'; |
| 18 | const TAB_STATUS = 'status'; |
| 19 | |
| 20 | const TAB_SETTINGS = 'settings'; |
| 21 | const SRC_SETUP_LATER = 'setup_later'; |
| 22 | |
| 23 | const DASHBOARD_PARAM_SECTIONS = 'sections'; |
| 24 | const DASHBOARD_SECTION_PRODUCT = 'post/product'; |
| 25 | const DASHBOARD_SECTION_STRING = 'string'; |
| 26 | const DASHBOARD_PARAM_STRING_DOMAIN = 'predefinedStringDomain'; |
| 27 | |
| 28 | private static function getAdminUrl( array $getParams ) : string { |
| 29 | return add_query_arg( |
| 30 | $getParams, |
| 31 | admin_url( 'admin.php' ) |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | public static function getTab( $taxonomy ) : string { |
| 36 | return self::getAdminUrl( [ |
| 37 | 'page' => self::PAGE_WPML_WCML, |
| 38 | 'tab' => $taxonomy, |
| 39 | ] ); |
| 40 | } |
| 41 | |
| 42 | public static function getMultilingualTab() : string { |
| 43 | return self::getAdminUrl( [ |
| 44 | 'page' => self::PAGE_WPML_WCML, |
| 45 | 'tab' => isStandAlone() ? self::TAB_MULTILINGUAL_STANDALONE : self::TAB_MULTILINGUAL, |
| 46 | ] ); |
| 47 | } |
| 48 | |
| 49 | public static function getMultiCurrencyTab( string $anchor = '' ) : string { |
| 50 | $url = self::getAdminUrl( [ |
| 51 | 'page' => self::PAGE_WPML_WCML, |
| 52 | 'tab' => self::TAB_MULTICURRENCY, |
| 53 | ] ); |
| 54 | |
| 55 | if ( ! empty( $anchor ) ) { |
| 56 | $url .= '#' . $anchor; |
| 57 | } |
| 58 | |
| 59 | return $url; |
| 60 | } |
| 61 | |
| 62 | public static function getStoreURLTab() : string { |
| 63 | return self::getAdminUrl( [ |
| 64 | 'page' => self::PAGE_WPML_WCML, |
| 65 | 'tab' => self::TAB_STORE_URL, |
| 66 | ] ); |
| 67 | } |
| 68 | |
| 69 | public static function getStatusTab() : string { |
| 70 | return self::getAdminUrl( [ |
| 71 | 'page' => self::PAGE_WPML_WCML, |
| 72 | 'tab' => self::TAB_STATUS, |
| 73 | ] ); |
| 74 | } |
| 75 | |
| 76 | public static function getSettingsTab() : string { |
| 77 | return self::getAdminUrl( [ |
| 78 | 'page' => self::PAGE_WPML_WCML, |
| 79 | 'tab' => self::TAB_SETTINGS, |
| 80 | ] ); |
| 81 | } |
| 82 | |
| 83 | public static function getTroubleshootingTab() : string { |
| 84 | return self::getAdminUrl( [ |
| 85 | 'page' => self::PAGE_WPML_WCML, |
| 86 | 'tab' => self::TAB_TROUBLESHOOTING, |
| 87 | ] ); |
| 88 | } |
| 89 | |
| 90 | public static function getSetupLater() : string { |
| 91 | return self::getAdminUrl( [ |
| 92 | 'page' => self::PAGE_WPML_WCML, |
| 93 | 'src' => self::SRC_SETUP_LATER, |
| 94 | ] ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @param ?string $step |
| 99 | */ |
| 100 | public static function getSetup( $step = null ) : string { |
| 101 | $args = []; |
| 102 | $args['page'] = \WCML_Setup_UI::SLUG; |
| 103 | if ( ! is_null( $step ) ) { |
| 104 | $args['step'] = $step; |
| 105 | } |
| 106 | |
| 107 | return self::getAdminUrl( $args ); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @param string[] $sections |
| 112 | * @param string $stringDomain |
| 113 | * |
| 114 | * @return string |
| 115 | * |
| 116 | * @throws \Error if WPML is not active, since \WPML\UIPage depends on it. |
| 117 | */ |
| 118 | public static function getWPMLTMDashboard( array $sections = [], string $stringDomain = '' ) : string { |
| 119 | $dashboardUrl = admin_url( \WPML\UIPage::getTMDashboard() ); |
| 120 | if ( empty( $sections ) ) { |
| 121 | return $dashboardUrl; |
| 122 | } |
| 123 | |
| 124 | $dashboardUrl = add_query_arg( |
| 125 | [ self::DASHBOARD_PARAM_SECTIONS => implode( ',', $sections ) ], |
| 126 | $dashboardUrl |
| 127 | ); |
| 128 | |
| 129 | if ( in_array( self::DASHBOARD_SECTION_STRING, $sections, true ) && $stringDomain ) { |
| 130 | $dashboardUrl = add_query_arg( |
| 131 | [ self::DASHBOARD_PARAM_STRING_DOMAIN => $stringDomain ], |
| 132 | $dashboardUrl |
| 133 | ); |
| 134 | } |
| 135 | |
| 136 | return $dashboardUrl; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * @param string $domain |
| 141 | * |
| 142 | * @return string |
| 143 | * |
| 144 | * @throws \Error if WPML is not active, since \WPML\UIPage depends on it. |
| 145 | */ |
| 146 | public static function getWPMLTMDashboardStringDomain( string $domain ) : string { |
| 147 | return self::getWPMLTMDashboard( |
| 148 | [ self::DASHBOARD_SECTION_STRING ], |
| 149 | $domain |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @return string |
| 155 | * |
| 156 | * @throws \Error if WPML is not active, since \WPML\UIPage depends on it. |
| 157 | */ |
| 158 | public static function getWPMLTMDashboardProducts() : string { |
| 159 | return self::getWPMLTMDashboard( [ self::DASHBOARD_SECTION_PRODUCT ] ); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * @param ?string $taxonomy |
| 164 | * |
| 165 | * @return string |
| 166 | * |
| 167 | * @throws \Error if WPML is not active, since WPML_PLUGIN_FOLDER depends on it. |
| 168 | */ |
| 169 | public static function getWPMLTaxonomyTranslation( $taxonomy = null ) : string { |
| 170 | $args = [ |
| 171 | 'page' => WPML_PLUGIN_FOLDER . '/menu/taxonomy-translation.php', |
| 172 | 'taxonomy' => $taxonomy, |
| 173 | ]; |
| 174 | |
| 175 | return self::getAdminUrl( $args ); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @param array $args |
| 180 | * |
| 181 | * @return string |
| 182 | * |
| 183 | * @throws \Error if WPML is not active, since WPML_ST_FOLDER depends on it. |
| 184 | */ |
| 185 | public static function getWPMLStringTranslation( array $args = [] ) : string { |
| 186 | $args = array_merge( |
| 187 | [ |
| 188 | 'page' => WPML_ST_FOLDER . '/menu/string-translation.php', |
| 189 | ], |
| 190 | $args |
| 191 | ); |
| 192 | |
| 193 | return self::getAdminUrl( $args ); |
| 194 | } |
| 195 | |
| 196 | public static function getWooProductAll() : string { |
| 197 | $args = [ |
| 198 | 'post_type' => 'product', |
| 199 | ]; |
| 200 | |
| 201 | return add_query_arg( |
| 202 | $args, |
| 203 | admin_url( 'edit.php' ) |
| 204 | ); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * @param ?string $tab |
| 209 | */ |
| 210 | public static function getWooSettings( $tab = null ) : string { |
| 211 | $args = [ |
| 212 | 'page' => self::PAGE_WOO_SETTINGS, |
| 213 | 'tab' => $tab, |
| 214 | ]; |
| 215 | |
| 216 | return self::getAdminUrl( $args ); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * @param ?string $tab |
| 221 | */ |
| 222 | public static function getWooStatus( $tab = null ) : string { |
| 223 | $args = [ |
| 224 | 'page' => 'wc-status', |
| 225 | 'tab' => $tab, |
| 226 | ]; |
| 227 | |
| 228 | return self::getAdminUrl( $args ); |
| 229 | } |
| 230 | } |
| 231 |