Language_Pack_Upgrader example

check_admin_referer( 'upgrade-translations' );

    require_once ABSPATH . 'wp-admin/admin-header.php';
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';

    $url     = 'update-core.php?action=do-translation-upgrade';
    $nonce   = 'upgrade-translations';
    $title   = __( 'Update Translations' );
    $context = WP_LANG_DIR;

    $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
    $result   = $upgrader->bulk_upgrade();

    wp_localize_script(
        'updates',
        '_wpUpdatesItemCounts',
        array(
            'totals' => wp_get_update_data(),
        )
    );

    require_once ABSPATH . 'wp-admin/admin-footer.php';

}
$context  = ABSPATH;
                break;
            case 'plugin':
                $upgrader = new Plugin_Upgrader( $skin );
                $context  = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR.                 break;
            case 'theme':
                $upgrader = new Theme_Upgrader( $skin );
                $context  = get_theme_root( $item->theme );
                break;
            case 'translation':
                $upgrader = new Language_Pack_Upgrader( $skin );
                $context  = WP_CONTENT_DIR; // WP_LANG_DIR;                 break;
        }

        // Determine whether we can and should perform this update.         if ( ! $this->should_update( $type$item$context ) ) {
            return false;
        }

        /** * Fires immediately prior to an auto-update. * * @since 4.4.0 * * @param string $type The type of update being checked: 'core', 'theme', 'plugin', or 'translation'. * @param object $item The update offer. * @param string $context The filesystem context (a path) against which filesystem access and status * should be checked. */
// Re-use the automatic upgrader skin if the parent upgrader is using it.         if ( $upgrader && $upgrader->skin instanceof Automatic_Upgrader_Skin ) {
            $skin = $upgrader->skin;
        } else {
            $skin = new Language_Pack_Upgrader_Skin(
                array(
                    'skip_header_footer' => true,
                )
            );
        }

        $lp_upgrader = new Language_Pack_Upgrader( $skin );
        $lp_upgrader->bulk_upgrade( $language_updates );
    }

    /** * Initializes the upgrade strings. * * @since 3.7.0 */
    public function upgrade_strings() {
        $this->strings['starting_upgrade'] = __( 'Some of your translations need updating. Sit tight for a few more seconds while they are updated as well.' );
        $this->strings['up_to_date']       = __( 'Your translations are all up to date.' );
        
break;
        }
    }

    if ( empty( $translation_to_load ) ) {
        return false;
    }
    $translation = (object) $translation;

    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $skin              = new Automatic_Upgrader_Skin();
    $upgrader          = new Language_Pack_Upgrader( $skin );
    $translation->type = 'core';
    $result            = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );

    if ( ! $result || is_wp_error( $result ) ) {
        return false;
    }

    return $translation->language;
}

/** * Check if WordPress has access to the filesystem without asking for * credentials. * * @since 4.0.0 * * @return bool Returns true on success, false on failure. */
$api->language_packs
        );

        $language_packs = array_filter(
            $language_packs,
            static function( $pack ) use ( $installed_locales ) {
                return in_array( $pack->language, $installed_locales, true );
            }
        );

        if ( $language_packs ) {
            $lp_upgrader = new Language_Pack_Upgrader( $skin );

            // Install all applicable language packs for the plugin.             $lp_upgrader->bulk_upgrade( $language_packs );
        }

        $path          = WP_PLUGIN_DIR . '/' . $file;
        $data          = get_plugin_data( $path, false, false );
        $data['_file'] = $file;

        $response = $this->prepare_item_for_response( $data$request );
        $response->set_status( 201 );
        
Home | Imprint | This part of the site doesn't use cookies.