Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/cli.tar
Назад
cli_media.php 0000644 00000006525 14720522663 0007202 0 ustar 00 <?php /** * CLI commands responsible for the Optimole media. */ if ( ! class_exists( 'WP_CLI' ) ) { return; } /** * Class Optml_Cli_Media */ class Optml_Cli_Media extends WP_CLI_Command { /** * Move all existing images to our servers. */ public function move_to_optimole() { $this->update_images_template( 'offload' ); } /** * Move all existing images from our servers to your media library. */ public function rollback_images() { $this->update_images_template( 'rollback' ); } /** * Template for bulk image processing to avoid duplicate code. * * @param string $action The action to perform rollback/offload. * @return mixed WP_CLI::error If it fails. */ private function update_images_template( $action ) { $strings = [ 'offload' => [ 'info' => __( 'Moving all images to Optimole Cloud', 'optimole-wp' ), 'success' => __( 'All images have been uploaded to Optimole Cloud', 'optimole-wp' ), ], 'rollback' => [ 'info' => __( 'Moving all images back to your media library', 'optimole-wp' ), 'success' => __( 'All images have been uploaded to your media library', 'optimole-wp' ), ], 'limit_exceeded' => __( 'You have reached the maximum offloading limit of images. To increase the offload limit and for more information, contact our support.', 'optimole-wp' ), ]; $settings = new Optml_Settings(); if ( $settings->get( 'offload_media' ) === 'disabled' ) { return \WP_CLI::error( __( 'You need to have the offload_media option enabled in order to use this command', 'optimole-wp' ) ); } WP_CLI::line( $strings[ $action ]['info'] ); $number_of_images_for = 'offload_images'; if ( $action === 'rollback' ) { $number_of_images_for = 'rollback_images'; } $number_of_images = Optml_Media_Offload::number_of_images_and_pages( $number_of_images_for ); Optml_Media_Offload::record_process_meta( $number_of_images ); $batch = 5; $possible_batch = ceil( $number_of_images / 10 ); if ( $possible_batch < $batch ) { $batch = $possible_batch; } $total_progress = ceil( $number_of_images / $batch ); $progress = \WP_CLI\Utils\make_progress_bar( __( 'Progress bar', 'optimole-wp' ), (int) $total_progress ); $tick = 0; $page = 1; while ( $tick < $total_progress ) { $posts_to_update = $action === 'offload' ? [] : Optml_Media_Offload::instance()->update_content( $page, $number_of_images_for, $batch ); // Kept for backward compatibility with old offloading mechanism where pages were modified. if ( $action === 'rollback' && isset( $posts_to_update['page'] ) && $posts_to_update['page'] > $page ) { $page = $posts_to_update['page']; if ( isset( $posts_to_update['imagesToUpdate'] ) && count( $posts_to_update['imagesToUpdate'] ) ) { foreach ( $posts_to_update['imagesToUpdate'] as $post_id => $images ) { Optml_Media_Offload::instance()->rollback_and_update_images( $images ); Optml_Media_Offload::instance()->update_page( $post_id ); } } } else { $action === 'rollback' ? Optml_Media_Offload::instance()->rollback_images( $batch ) : Optml_Media_Offload::instance()->upload_images( $batch ); } if ( Optml_Media_Offload::instance()->settings->is_offload_limit_reached() ) { WP_CLI::error( $strings['limit_exceeded'], true ); } $progress->tick(); ++$tick; } $progress->finish(); WP_CLI::line( $strings[ $action ]['success'] ); } } cli_setting.php 0000644 00000010134 14720522663 0007567 0 ustar 00 <?php /** * CLI commands responsible for the Optimole settings. */ if ( ! class_exists( 'WP_CLI' ) ) { return; } /** * Class Optml_Cli_Setting */ class Optml_Cli_Setting extends WP_CLI_Command { /** * Connect to service * <apikey> * : The api key to use. */ public function connect( $args ) { if ( empty( $args ) || ! isset( $args[0] ) || $args[0] === '' ) { return \WP_CLI::error( 'No argument passed. Required one argument ( api key )' ); } if ( sizeof( $args ) > 1 ) { return \WP_CLI::error( 'To many arguments passed' ); } $api_key = $args[0]; $request = new Optml_Api(); $data = $request->get_user_data( $api_key ); if ( $data === false || is_wp_error( $data ) ) { $extra = ''; if ( is_wp_error( $data ) ) { /** * Error from api. * * @var WP_Error $data Error object. */ $extra = sprintf( /* translators: errors details */ __( '. ERROR details: %s', 'optimole-wp' ), $data->get_error_message() ); } return \WP_CLI::error( __( 'Can not connect to Optimole service', 'optimole-wp' ) . $extra ); } $settings = new Optml_Settings(); $settings->update( 'service_data', $data ); $settings->update( 'api_key', $api_key ); \WP_CLI::success( sprintf( 'Connected API key %s to Optimole Service', $args[0] ) ); } /** * Disconnect from service. */ public function disconnect() { $settings = new Optml_Settings(); $settings->reset(); \WP_CLI::success( 'Disconnected from Optimole Service' ); } /** * Update settings. * * <setting_name> * : The setting name to update. * * <setting_value> * : The setting value to update. */ public function update( $args ) { if ( empty( $args ) || ! isset( Optml_Settings::$whitelisted_settings[ $args[0] ] ) ) { return \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( Optml_Settings::$whitelisted_settings ) ) ) ); } if ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'bool' && ( ! isset( $args[1] ) || $args[1] === '' || ! in_array( $args[1], [ 'on', 'off', ], true ) ) ) { return \WP_CLI::error( 'No argument passed. Required one argument ( on/off )' ); } if ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'int' && ( ! isset( $args[1] ) || $args[1] === '' || (int) $args[1] > 100 || (int) $args[1] < 0 ) ) { return \WP_CLI::error( 'Invalid argument, must be between 0 and 100.' ); } $value = ( Optml_Settings::$whitelisted_settings[ $args[0] ] === 'bool' ) ? ( $args[1] === 'on' ? 'enabled' : 'disabled' ) : (int) $args[1]; $new_value = $this->update_setting( [ $args[0] => $value ] ); \WP_CLI::success( sprintf( 'Setting %s updated to: %s', $args[0], $new_value[ $args[0] ] ) ); } /** * Check settings. * * <setting_name> * : The setting name to check. */ public function get( $args ) { if ( empty( $args ) || ! isset( Optml_Settings::$whitelisted_settings[ $args[0] ] ) ) { return \WP_CLI::error( sprintf( 'Setting must be one of: %s', implode( ',', array_keys( Optml_Settings::$whitelisted_settings ) ) ) ); } $value = ( new Optml_Settings() )->get( $args[0] ); \WP_CLI::success( sprintf( 'Setting %s is set to: %s', $args[0], $value ) ); } /** * Utility method to update setting * * @param mixed $new_setting The setting to parse. * * @return array */ private function update_setting( $new_setting ) { if ( empty( $new_setting ) ) { \WP_CLI::error( __( 'No setting to update', 'optimole-wp' ) ); } $settings = new Optml_Settings(); return $settings->parse_settings( $new_setting ); } /** * Clear cache. * * --type=<type> * : The type of cache to clear. Default is images. */ public function clear_cache( $args, $assoc_args ) { $type = ''; // If assoc_args has a type key, use that. if ( isset( $assoc_args['type'] ) && $assoc_args['type'] === 'assets' ) { $type = $assoc_args['type']; } $settings = new Optml_Settings(); $token = $settings->clear_cache( $type ); if ( is_wp_error( $token ) ) { \WP_CLI::error( $token->get_error_message() ); } \WP_CLI::success( sprintf( 'Cache type %s cleared', $assoc_args['type'] ) ); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка