| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace ImageOptimizer\Classes; | |
| 3 | +namespace ImageOptimization\Classes; | |
| 4 | 4 | |
| 5 | -use ImageOptimizer\Plugin; | |
| 5 | +use ImageOptimization\Classes\Client\Client; | |
| 6 | +use ImageOptimization\Plugin; | |
| 6 | 7 | |
| 7 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 9 | exit; // Exit if accessed directly. |
| 9 | 10 | } |
| @@ -75,14 +76,68 @@ | ||
| 75 | 76 | |
| 76 | 77 | return 'upload' === $current_screen->id && 'attachment' === $current_screen->post_type; |
| 77 | 78 | } |
| 78 | 79 | |
| 80 | + public static function is_media_upload_page(): bool { | |
| 81 | + $current_screen = get_current_screen(); | |
| 82 | + | |
| 83 | + if ( ! $current_screen ) { | |
| 84 | + return false; | |
| 85 | + } | |
| 86 | + | |
| 87 | + return 'media' === $current_screen->id && 'add' === $current_screen->action; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public static function is_single_attachment_page(): bool { | |
| 91 | + $current_screen = get_current_screen(); | |
| 92 | + | |
| 93 | + if ( ! $current_screen ) { | |
| 94 | + return false; | |
| 95 | + } | |
| 96 | + | |
| 97 | + return 'attachment' === $current_screen->id && 'post' === $current_screen->base; | |
| 98 | + } | |
| 99 | + | |
| 79 | 100 | public static function is_plugin_page(): bool { |
| 80 | 101 | $current_screen = get_current_screen(); |
| 81 | 102 | |
| 82 | - return str_contains( $current_screen->id, 'image-optimizer-' ); | |
| 103 | + return str_contains( $current_screen->id, 'image-optimization-' ); | |
| 83 | 104 | } |
| 84 | 105 | |
| 106 | + public static function is_plugin_settings_page(): bool { | |
| 107 | + $current_screen = get_current_screen(); | |
| 108 | + | |
| 109 | + return str_contains( $current_screen->id, 'image-optimization-settings' ); | |
| 110 | + } | |
| 111 | + | |
| 112 | + public static function is_bulk_optimization_page(): bool { | |
| 113 | + $current_screen = get_current_screen(); | |
| 114 | + | |
| 115 | + return str_contains( $current_screen->id, 'image-optimization-bulk-optimization' ); | |
| 116 | + } | |
| 117 | + | |
| 85 | 118 | public static function user_is_admin(): bool { |
| 86 | 119 | return current_user_can( 'manage_options' ); |
| 120 | + } | |
| 121 | + | |
| 122 | + public static function is_wp_dashboard_page(): bool { | |
| 123 | + $current_screen = get_current_screen(); | |
| 124 | + | |
| 125 | + return str_contains( $current_screen->id, 'dashboard' ); | |
| 126 | + } | |
| 127 | + | |
| 128 | + public static function is_wp_updates_page(): bool { | |
| 129 | + $current_screen = get_current_screen(); | |
| 130 | + | |
| 131 | + return str_contains( $current_screen->id, 'update' ); | |
| 132 | + } | |
| 133 | + | |
| 134 | + public static function get_upgrade_link( $link ): string { | |
| 135 | + $subscription_id = get_option( 'image_optimizer_subscription_id' ); | |
| 136 | + | |
| 137 | + if ( ! $subscription_id ) { | |
| 138 | + return $link; | |
| 139 | + } | |
| 140 | + | |
| 141 | + return add_query_arg( 'subscription_id', $subscription_id, $link ); | |
| 87 | 142 | } |
| 88 | 143 | } |