| @@ -43,12 +43,15 @@ | ||
| 43 | 43 | /** |
| 44 | 44 | * Handle addon action: install, update, activate, deactivate, update-purchase. |
| 45 | 45 | * |
| 46 | 46 | * @return void |
| 47 | + * @since 4.4.9 | |
| 48 | + * @version 1.0.2 | |
| 47 | 49 | */ |
| 48 | 50 | public function addon_action() { |
| 49 | 51 | $response = new Response(); |
| 50 | 52 | $lp_file_system = LP_WP_Filesystem::instance(); |
| 53 | + $message = ''; | |
| 51 | 54 | |
| 52 | 55 | try { |
| 53 | 56 | if ( is_multisite() && ! is_super_admin() ) { |
| 54 | 57 | throw new Exception( __( 'You do not have permission.', 'learnpress' ) ); |
| @@ -90,17 +93,20 @@ | ||
| 90 | 93 | $purchase_codes = LP_Settings::get_option( $this->addon_service->key_purchase_addons, array() ); |
| 91 | 94 | $purchase_code = $purchase_codes[ $addon['slug'] ] ?? ''; |
| 92 | 95 | } |
| 93 | 96 | |
| 94 | - if ( $is_paid_addon && 'install' === $action ) { | |
| 95 | - $purchase_info = $this->addon_service->validate_and_save_purchase_code( $addon['slug'], (string) $purchase_code ); | |
| 96 | - } | |
| 97 | - | |
| 98 | 97 | if ( ! empty( $addon['is_org'] ) ) { |
| 99 | 98 | $link_download = "{$this->addon_service->link_org}{$addon['slug']}.{$addon['version']}.zip"; |
| 100 | 99 | } else { |
| 101 | - // Allow active key for site if site active on DB "updates" is empty. | |
| 102 | - $this->addon_service->active_site( $addon['slug'], $purchase_code ); | |
| 100 | + if ( 'install' === $action ) { | |
| 101 | + // Allow active key for site if site active on DB "updates" is empty. | |
| 102 | + $this->addon_service->active_site( $addon['slug'], $purchase_code ); | |
| 103 | + } | |
| 104 | + | |
| 105 | + $purchase_info = $this->addon_service->get_addon_purchase_info( | |
| 106 | + $addon['slug'], | |
| 107 | + $purchase_code | |
| 108 | + ); | |
| 103 | 109 | // Download addon from ThimPress server. |
| 104 | 110 | $path_file = $this->addon_service->download_from_thimpress( $addon, $purchase_code ); |
| 105 | 111 | } |
| 106 | 112 | |
| @@ -119,8 +125,21 @@ | ||
| 119 | 125 | if ( ! empty( $path_file ) ) { |
| 120 | 126 | $lp_file_system->lp_filesystem->delete( $path_file ); |
| 121 | 127 | } |
| 122 | 128 | |
| 129 | + $message = sprintf( | |
| 130 | + /* translators: %s: addon name */ | |
| 131 | + __( 'Installed successfully %s', 'learnpress' ), | |
| 132 | + $addon['name'] ?? '' | |
| 133 | + ); | |
| 134 | + if ( 'update' === $action ) { | |
| 135 | + $message = sprintf( | |
| 136 | + /* translators: %s: addon name */ | |
| 137 | + __( 'Updated successfully %s', 'learnpress' ), | |
| 138 | + $addon['name'] ?? '' | |
| 139 | + ); | |
| 140 | + } | |
| 141 | + | |
| 123 | 142 | break; |
| 124 | 143 | case 'activate': |
| 125 | 144 | if ( ! current_user_can( 'activate_plugins' ) ) { |
| 126 | 145 | throw new Exception( __( 'You do not have permission to activate plugins.', 'learnpress' ) ); |
| @@ -126,17 +145,33 @@ | ||
| 126 | 145 | throw new Exception( __( 'You do not have permission to activate plugins.', 'learnpress' ) ); |
| 127 | 146 | } |
| 128 | 147 | |
| 129 | 148 | $this->addon_service->activate( $addon ); |
| 149 | + $message = sprintf( | |
| 150 | + /* translators: %s: addon name */ | |
| 151 | + __( 'Activated successfully %s', 'learnpress' ), | |
| 152 | + $addon['name'] ?? '' | |
| 153 | + ); | |
| 130 | 154 | break; |
| 131 | 155 | case 'deactivate': |
| 132 | 156 | $this->addon_service->deactivate( $addon ); |
| 157 | + $message = sprintf( | |
| 158 | + /* translators: %s: addon name */ | |
| 159 | + __( 'Deactivated successfully %s', 'learnpress' ), | |
| 160 | + $addon['name'] ?? '' | |
| 161 | + ); | |
| 133 | 162 | break; |
| 134 | 163 | case 'update-purchase': |
| 135 | - $purchase_info = $this->addon_service->validate_and_save_purchase_code( | |
| 164 | + $this->addon_service->active_site( | |
| 136 | 165 | $addon['slug'], |
| 137 | - (string) $purchase_code | |
| 166 | + $purchase_code | |
| 138 | 167 | ); |
| 168 | + $purchase_info = $this->addon_service->get_addon_purchase_info( $addon['slug'], $purchase_code ); | |
| 169 | + $message = sprintf( | |
| 170 | + /* translators: %s: addon name */ | |
| 171 | + __( 'Updated purchase code successfully for %s', 'learnpress' ), | |
| 172 | + $addon['name'] ?? '' | |
| 173 | + ); | |
| 139 | 174 | break; |
| 140 | 175 | default: |
| 141 | 176 | break; |
| 142 | 177 | } |
| @@ -141,9 +176,9 @@ | ||
| 141 | 176 | break; |
| 142 | 177 | } |
| 143 | 178 | |
| 144 | 179 | $response->status = Response::STATUS_SUCCESS; |
| 145 | - $response->message = sprintf( | |
| 180 | + $response->message = ! empty( $message ) ? $message : sprintf( | |
| 146 | 181 | '"%s" %s %s', |
| 147 | 182 | $addon['name'] ?? '', |
| 148 | 183 | $action, |
| 149 | 184 | __( 'successfully', 'learnpress' ) |