文件操作 - functions.php
返回文件管理
返回主菜单
删除本文件
文件: /home/www/public/wp-content/plugins/ionos-loop/inc/functions.php
编辑文件内容
<?php namespace Ionos\Loop; const SURVEYS_URL = 'https://s3-de-central.profitbricks.com/web-hosting/loop-surveys/ionos-standard.json'; const SURVEYS_TRANSIENT_NAME = 'ionos_loop_survey_collection'; const SURVEYS_TRANSIENT_EXPIRATION_TIME = 10800; // 3h /** * Gets the plugin slug from a plugin filename. * * @param string $plugin_file Path to the plugin File. * * @return string */ function get_plugin_slug( $plugin_file ) { $file = basename( $plugin_file, '.php' ); $dir = dirname( $plugin_file ); return ( $dir === $file ) ? $file : \trailingslashit( $dir ) . $file; } /** * Normalizes version strings to the format x.y, dropping all patch versions and possible other comments. * Will return an empty string if it does not match x.y format. * * @param string $version_string The version string to normalize. * @param bool $long If true, will return x.y.z format. * * @return string|null The normalized version string or null if it does not match the format. */ function normalize_version_string( $version_string, $long = false ) { if ( $long === true ) { $pattern = '/^(\d+\.\d+(?:\.\d+)?).*/'; } else { $pattern = '/^(\d+\.\d+).*/'; } $version_string = trim( $version_string ); if ( ! preg_match( $pattern, $version_string ) ) { return null; } return preg_replace( $pattern, '$1', $version_string ); } /** * Gets the URL of the Rest API. * * @return string The URL of the REST API. */ function get_loop_rest_api() { $api = get_rest_url( null, 'ionos/v1' ); $find = 'wp-json'; $position = strpos( $api, $find ); if ( $position === false ) { return $api; } return substr( $api, $position + strlen( $find ) ); } /** * Gets the surveys from the remote server or locally, if the environment is local or development. * * @return array|false The surveys or false if the surveys could not be retrieved. */ function get_surveys() { switch ( wp_get_environment_type() ) { case 'local': case 'development': $result = json_decode( file_get_contents( IONOS_LOOP_PATH . 'config/config.json' ), true ); break; default: // Get the surveys from the transients. If the transient does not exist or has expired, the surveys are pulled from the S3 and stored as transient. $result = get_transient( SURVEYS_TRANSIENT_NAME ); if ( $result === false ) { // Any result of wp_remote_get is allowed as a value, because if the result is not valid, json_decode would return NULL at the latest. // NULL is a valid value. $result = json_decode( wp_remote_retrieve_body( wp_remote_get( SURVEYS_URL ) ), true ); set_transient( SURVEYS_TRANSIENT_NAME, $result, SURVEYS_TRANSIENT_EXPIRATION_TIME ); } break; } if ( ! is_array( $result ) || ! isset( $result['surveys'] ) ) { return false; } return $result['surveys']; }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件