@@ -53,25 +53,20 @@ private function get_github_plugins() {
5353 $ cache_key = 'wp_addon_github_plugins ' ;
5454 $ cached_plugins = get_transient ($ cache_key );
5555 if ($ cached_plugins !== false ) {
56- error_log ('GitHub plugins loaded from cache: ' . count ($ cached_plugins ));
5756 return $ cached_plugins ;
5857 }
5958
6059 $ token = defined ('GITHUB_TOKEN ' ) ? GITHUB_TOKEN : null ;
6160 $ headers = $ token ? ['Authorization ' => 'token ' . $ token ] : [];
62- error_log ('Using GitHub token: ' . ($ token ? 'yes ' : 'no ' ));
6361
6462 $ response = wp_remote_get ('https://api.github.com/users/rwsite/repos?page=1&per_page=100 ' , ['headers ' => $ headers ]);
6563 if (is_wp_error ($ response )) {
66- error_log ('GitHub API error (repos): ' . $ response ->get_error_message ());
6764 return [];
6865 }
6966 $ repos = json_decode (wp_remote_retrieve_body ($ response ), true );
7067 if (!is_array ($ repos )) {
71- error_log ('Invalid repos response: ' . wp_remote_retrieve_body ($ response ));
7268 return [];
7369 }
74- error_log ('Repos loaded: ' . count ($ repos ));
7570 $ plugins = [];
7671 foreach ($ repos as $ repo ) {
7772 $ name = $ repo ['name ' ] ?? '' ;
@@ -86,23 +81,19 @@ private function get_github_plugins() {
8681 // Проверяем наличие тегов (стабильных версий)
8782 $ tags_response = wp_remote_get ('https://api.github.com/repos/rwsite/ ' . $ name . '/tags?per_page=1 ' , ['headers ' => $ headers ]);
8883 if (is_wp_error ($ tags_response )) {
89- error_log ('Tags error for ' . $ name . ': ' . $ tags_response ->get_error_message ());
9084 continue ;
9185 }
9286 $ tags = json_decode (wp_remote_retrieve_body ($ tags_response ), true );
9387 if (!is_array ($ tags ) || empty ($ tags )) {
94- error_log ('No tags for ' . $ name );
9588 continue ;
9689 }
9790 // Проверяем, что это WordPress плагин (наличие plugin.php или readme.txt)
9891 $ contents_response = wp_remote_get ('https://api.github.com/repos/rwsite/ ' . $ name . '/contents?ref= ' . ($ repo ['default_branch ' ] ?? 'main ' ), ['headers ' => $ headers ]);
9992 if (is_wp_error ($ contents_response )) {
100- error_log ('Contents error for ' . $ name . ': ' . $ contents_response ->get_error_message ());
10193 continue ;
10294 }
10395 $ contents = json_decode (wp_remote_retrieve_body ($ contents_response ), true );
10496 if (!is_array ($ contents )) {
105- error_log ('Invalid contents for ' . $ name );
10697 continue ;
10798 }
10899 $ has_plugin_file = false ;
@@ -113,7 +104,6 @@ private function get_github_plugins() {
113104 }
114105 }
115106 if (!$ has_plugin_file ) {
116- error_log ('No plugin file for ' . $ name );
117107 continue ;
118108 }
119109 $ plugins [] = [
@@ -123,7 +113,6 @@ private function get_github_plugins() {
123113 'zip_url ' => 'https://github.com/rwsite/ ' . $ name . '/archive/ ' . ($ repo ['default_branch ' ] ?? 'main ' ) . '.zip ' ,
124114 ];
125115 }
126- error_log ('Filtered plugins: ' . count ($ plugins ));
127116
128117 // Кешируем на сутки
129118 set_transient ($ cache_key , $ plugins , DAY_IN_SECONDS );
@@ -303,8 +292,7 @@ public function uninstall_plugin_ajax() {
303292 require_once ABSPATH . 'wp-admin/includes/plugin.php ' ;
304293 require_once ABSPATH . 'wp-admin/includes/file.php ' ;
305294 if (!WP_Filesystem ()) {
306- error_log ('WP_Filesystem failed ' );
307- wp_send_json_error ('Ошибка файловой системы. ' );
295+ wp_send_json_error ('Ошибка файловой системы. ' );
308296 return ;
309297 }
310298 global $ wp_filesystem ;
@@ -320,14 +308,9 @@ public function uninstall_plugin_ajax() {
320308 wp_send_json_error ('Плагин не найден. ' );
321309 return ;
322310 }
323- // Деактивировать плагин
324- deactivate_plugins ($ plugin_file );
325- error_log ('Deactivated plugin: ' . $ plugin_file );
326- // Удалить папку
327311 $ plugin_dir = WP_PLUGIN_DIR . '/ ' . $ repo ;
328312 if ($ wp_filesystem ->exists ($ plugin_dir )) {
329313 $ wp_filesystem ->delete ($ plugin_dir , true );
330- error_log ('Deleted plugin dir: ' . $ plugin_dir );
331314 }
332315 wp_send_json_success ();
333316 }
@@ -346,14 +329,12 @@ public function toggle_plugin_ajax() {
346329 if (in_array ($ plugin_file , $ active_plugins )) {
347330 // Деактивировать
348331 deactivate_plugins ($ plugin_file );
349- error_log ('Deactivated plugin: ' . $ plugin_file );
350- wp_send_json_success (['action ' => 'deactivated ' ]);
332+ wp_send_json_success (['action ' => 'deactivated ' ]);
351333 } else {
352334 // Активировать
353335 $ activate_result = activate_plugin ($ plugin_file );
354336 if ($ activate_result === true || is_null ($ activate_result )) {
355- error_log ('Activated plugin: ' . $ plugin_file );
356- wp_send_json_success (['action ' => 'activated ' ]);
337+ wp_send_json_success (['action ' => 'activated ' ]);
357338 } else {
358339 wp_send_json_error ('Не удалось активировать плагин: ' . (is_wp_error ($ activate_result ) ? $ activate_result ->get_error_message () : 'Неизвестная ошибка ' ));
359340 }
@@ -375,32 +356,25 @@ public function install_plugin_ajax() {
375356 require_once ABSPATH . 'wp-admin/includes/plugin-install.php ' ;
376357 require_once ABSPATH . 'wp-admin/includes/file.php ' ;
377358 if (!WP_Filesystem ()) {
378- error_log ('WP_Filesystem failed ' );
379- wp_send_json_error ('Ошибка файловой системы. ' );
359+ wp_send_json_error ('Ошибка файловой системы. ' );
380360 return ;
381361 }
382- error_log ('Installing plugin from: ' . $ zip_url );
383362 $ upgrader = new Plugin_Upgrader ( new Automatic_Upgrader_Skin () );
384363 $ result = $ upgrader ->install ($ zip_url );
385364 if ($ result ) {
386365 // Найти установленную папку (GitHub ZIP создает папку с -main)
387366 $ possible_dirs = glob (WP_PLUGIN_DIR . '/ ' . $ repo . '-* ' );
388367 if (empty ($ possible_dirs )) {
389- error_log ('No installed dir found for ' . $ repo );
390368 wp_send_json_error ('Не найдена установленная папка. ' );
391369 return ;
392370 }
393371 $ installed_dir = $ possible_dirs [0 ]; // берем первую
394372 $ expected_dir = WP_PLUGIN_DIR . '/ ' . $ repo ;
395- error_log ('Found installed dir: ' . $ installed_dir );
396- error_log ('Expected dir: ' . $ expected_dir );
397373 if (is_dir ($ expected_dir )) {
398- error_log ('Expected dir already exists: ' . $ expected_dir );
399374 wp_send_json_error ('Папка плагина уже существует. ' );
400375 return ;
401376 }
402377 if (rename ($ installed_dir , $ expected_dir )) {
403- error_log ('Renamed to: ' . $ expected_dir );
404378 // Найти основной файл плагина
405379 $ plugin_files = glob ($ expected_dir . '/*.php ' );
406380 $ plugin_file = null ;
@@ -413,23 +387,17 @@ public function install_plugin_ajax() {
413387 }
414388 if ($ plugin_file ) {
415389 $ activate_result = activate_plugin ($ plugin_file );
416- error_log ('Activate result: ' . print_r ($ activate_result , true ));
417390 if ($ activate_result === true || is_null ($ activate_result )) {
418391 wp_send_json_success ();
419392 } else {
420393 wp_send_json_error ('Плагин установлен, но не удалось активировать: ' . (is_wp_error ($ activate_result ) ? $ activate_result ->get_error_message () : 'Неизвестная ошибка ' ));
421394 }
422395 } else {
423- error_log ('No plugin file found in ' . $ expected_dir );
424396 wp_send_json_error ('Не найден файл плагина для активации. ' );
425397 }
426398 } else {
427- error_log ('Rename failed from ' . $ installed_dir . ' to ' . $ expected_dir );
428399 wp_send_json_error ('Не удалось переименовать папку плагина. ' );
429400 }
430- } else {
431- error_log ('Install failed ' );
432- wp_send_json_error ('Ошибка установки плагина. ' );
433401 }
434402 }
435403
0 commit comments