helpers
3 months ago
routes
1 month ago
src
3 hours ago
CLAUDE.md
4 months ago
config.php
1 month ago
helpers.php
4 months ago
hooks.php
2 months ago
hooks.php
65 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Declare any actions and filters here. USE THIS SPARINGLY. |
| 4 | * |
| 5 | * In most cases you should use a service provider, but in cases where you |
| 6 | * just need to add an action/filter and forget about it you can add it here. |
| 7 | * |
| 8 | * @package SureCart |
| 9 | */ |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Don't let WordPress redirect guess our web routes. |
| 17 | * |
| 18 | * This prevents WordPress from finding a close match |
| 19 | * to one of our web routes in the database and redirecting. |
| 20 | */ |
| 21 | add_filter( |
| 22 | 'do_redirect_guess_404_permalink', |
| 23 | function ( $guess ) { |
| 24 | if ( ( strpos( $_SERVER['REQUEST_URI'], '/' . untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'buy_page' ) ) . '/' ) !== false ) ) { |
| 25 | return false; |
| 26 | } |
| 27 | if ( ( strpos( $_SERVER['REQUEST_URI'], 'surecart/webhooks' ) !== false ) ) { |
| 28 | return false; |
| 29 | } |
| 30 | if ( ( strpos( $_SERVER['REQUEST_URI'], 'surecart/redirect' ) !== false ) ) { |
| 31 | return false; |
| 32 | } |
| 33 | if ( ( strpos( $_SERVER['REQUEST_URI'], '/' . untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'product_page' ) ) . '/' ) !== false ) ) { |
| 34 | return false; |
| 35 | } |
| 36 | return $guess; |
| 37 | }, |
| 38 | 9999999999 |
| 39 | ); |
| 40 | |
| 41 | register_uninstall_hook( SURECART_PLUGIN_FILE, 'surecart_uninstall' ); |
| 42 | |
| 43 | /** |
| 44 | * Uninstall. |
| 45 | * |
| 46 | * @return void |
| 47 | */ |
| 48 | function surecart_uninstall() { |
| 49 | if ( (bool) get_option( 'sc_uninstall', false ) ) { |
| 50 | \SureCart::activation()->uninstall(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // redirect to an admin page that they can't access instead of homepage. |
| 55 | // Otherwise the homepage if they cannot access admin. |
| 56 | add_filter( |
| 57 | 'surecart.middleware.user.can.redirect_url', |
| 58 | function ( $url ) { |
| 59 | if ( current_user_can( 'read' ) ) { |
| 60 | return get_admin_url() . 'admin.php?page=sc-denied'; |
| 61 | } |
| 62 | return $url; |
| 63 | } |
| 64 | ); |
| 65 |