'core', 'version' => $new_version, ]; break; case 'translation': if ( isset( $options['translations'] ) ) { if ( is_array( $options['translations'] ) ) { foreach ( $options['translations'] as $translation ) { $updates[] = static::add_translation( $translation ); } } else { $updates[] = static::add_translation( $options['translations'] ); } } if ( isset( $options['translation'] ) ) { $updates[] = static::add_translation( $options['translation'] ); } break; }//end switch }//end if if ( ! empty( $updates ) ) { self::run_tests( 'update', null, $updates ); } } /** * Prepare plugin for updates. * * @param string $plugin Plugin. * * @return array */ private static function add_plugin( $plugin ) { $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); $new_version = $plugin_data['Version']; $name = $plugin_data['Name']; $slug = dirname( plugin_basename( $plugin ) ); return [ 'type' => 'plugin', 'name' => $name, 'slug' => $slug, 'version' => $new_version, ]; } /** * Prepare theme for updates. * * @param string $theme Theme. * * @return array */ private static function add_theme( $theme ) { $theme_data = wp_get_theme( $theme ); $new_version = $theme_data->get( 'Version' ); $name = $theme_data->get( 'Name' ); $slug = $theme; return [ 'type' => 'theme', 'name' => $name, 'slug' => $slug, 'version' => $new_version, ]; } /** * Prepare translation for updates. * * @param array $translation Translation. * * @return array */ private static function add_translation( $translation ) { $type = $translation['type']; $slug = $translation['slug']; $language = $translation['language']; if ( 'plugin' === $type ) { $plugin_data = static::get_plugin_data( $slug ); $name = $plugin_data['Name']; } elseif ( 'theme' === $type ) { $theme_data = wp_get_theme( $slug ); $name = $theme_data->get( 'Name' ); } else { $name = 'WordPress'; } return [ 'type' => $type, 'name' => $name, 'slug' => $slug, 'language' => $language, ]; } /** * Get plugin data. * * @param string $plugin_slug_or_file Plugin slug or file. * * @return array */ private static function get_plugin_data( $plugin_slug_or_file ) { $plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug_or_file; $plugin_data = get_plugin_data( $plugin_file ); if ( empty( $plugin_data['Name'] ) ) { $plugins = get_plugins(); foreach ( $plugins as $file => $local_plugin_data ) { $slug = dirname( $file ); if ( $slug === $plugin_slug_or_file ) { $plugin_data = $local_plugin_data; break; } } } return $plugin_data; } /** * Run tests. * * @param string $trigger Trigger. * @param string $trigger_notes Trigger notes. * @param array $trigger_meta Trigger meta. */ private static function run_tests( $trigger, $trigger_notes, $trigger_meta = null ) { $has_subscription = Subscription::get_subscription_status(); if ( ! $has_subscription ) { return false; } $tests = Test::get_all_running(); $service_test_ids = wp_list_pluck( $tests, 'service_test_id' ); Service::run_manual_tests( $service_test_ids, [ 'trigger' => $trigger, 'trigger_notes' => $trigger_notes, 'trigger_meta' => $trigger_meta, ] ); } /** * Get WordPress version. * * @return string */ public static function get_wp_version() { return ( function () { require ABSPATH . WPINC . '/version.php'; return $wp_version; } )(); } }