Cannot access site

  • Unknown's avatar

    I cannot access my site. When I try to, I am presented with this:

    /** * HTTP API: WP_Http_Cookie class * * @package WordPress * @subpackage HTTP * @since 4.4.0 */ /** * Core class used to encapsulate a single cookie object for internal use. * * Returned cookies are represented using this class, and when cookies are set, if they are not * already a WP_Http_Cookie() object, then they are turned into one. * * @todo The WordPress convention is to use underscores instead of camelCase for function and method * names. Need to switch to use underscores instead for the methods. * * @since 2.8.0 */ class WP_Http_Cookie { /** * Cookie name. * * @since 2.8.0 * @var string */ public $name; /** * Cookie value. * * @since 2.8.0 * @var string */ public $value; /** * When the cookie expires. * * @since 2.8.0 * @var string */ public $expires; /** * Cookie URL path. * * @since 2.8.0 * @var string */ public $path; /** * Cookie Domain. * * @since 2.8.0 * @var string */ public $domain; /** * Sets up this cookie object. * * The parameter $data should be either an associative array containing the indices names below * or a header string detailing it. * * @since 2.8.0 * * @param string|array $data { * Raw cookie data as header string or data array. * * @type string $name Cookie name. * @type mixed $value Value. Should NOT already be urlencoded. * @type string|int $expires Optional. Unix timestamp or formatted date. Default null. * @type string $path Optional. Path. Default ‘/’. * @type string $domain Optional. Domain. Default host of parsed $requested_url. * @type int $port Optional. Port. Default null. * } * @param string $requested_url The URL which the cookie was set on, used for default $domain * and $port values. */ public function __construct( $data, $requested_url = ” ) { if ( $requested_url ) $arrURL = @parse_url( $requested_url ); if ( isset( $arrURL[‘host’] ) ) $this->domain = $arrURL[‘host’]; $this->path = isset( $arrURL[‘path’] ) ? $arrURL[‘path’] : ‘/’; if ( ‘/’ != substr( $this->path, -1 ) ) $this->path = dirname( $this->path ) . ‘/’; if ( is_string( $data ) ) { // Assume it’s a header string direct from a previous request. $pairs = explode( ‘;’, $data ); // Special handling for first pair; name=value. Also be careful of ‘=’ in value. $name = trim( substr( $pairs[0], 0, strpos( $pairs[0], ‘=’ ) ) ); $value = substr( $pairs[0], strpos( $pairs[0], ‘=’ ) + 1 ); $this->name = $name; $this->value = urldecode( $value ); // Removes name=value from items. array_shift( $pairs ); // Set everything else as a property. foreach ( $pairs as $pair ) { $pair = rtrim($pair); // Handle the cookie ending in ; which results in a empty final pair. if ( empty($pair) ) continue; list( $key, $val ) = strpos( $pair, ‘=’ ) ? explode( ‘=’, $pair ) : array( $pair, ” ); $key = strtolower( trim( $key ) ); if ( ‘expires’ == $key ) $val = strtotime( $val ); $this->$key = $val; } } else { if ( !isset( $data[‘name’] ) ) return; // Set properties based directly on parameters. foreach ( array( ‘name’, ‘value’, ‘path’, ‘domain’, ‘port’ ) as $field ) { if ( isset( $data[ $field ] ) ) $this->$field = $data[ $field ]; } if ( isset( $data[‘expires’] ) ) $this->expires = is_int( $data[‘expires’] ) ? $data[‘expires’] : strtotime( $data[‘expires’] ); else $this->expires = null; } } /** * Confirms that it’s OK to send this cookie to the URL checked against. * * Decision is based on RFC 2109/2965, so look there for details on validity. * * @since 2.8.0 * * @param string $url URL you intend to send this cookie to * @return bool true if allowed, false otherwise. */ public function test( $url ) { if ( is_null( $this->name ) ) return false; // Expires – if expired then nothing else matters. if ( isset( $this->expires ) && time() > $this->expires ) return false; // Get details on the URL we’re thinking about sending to. $url = parse_url( $url ); $url[‘port’] = isset( $url[‘port’] ) ? $url[‘port’] : ( ‘https’ == $url[‘scheme’] ? 443 : 80 ); $url[‘path’] = isset( $url[‘path’] ) ? $url[‘path’] : ‘/’; // Values to use for comparison against the URL. $path = isset( $this->path ) ? $this->path : ‘/’; $port = isset( $this->port ) ? $this->port : null; $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url[‘host’] ); if ( false === stripos( $domain, ‘.’ ) ) $domain .= ‘.local’; // Host – very basic check that the request URL ends with the domain restriction (minus leading dot). $domain = substr( $domain, 0, 1 ) == ‘.’ ? substr( $domain, 1 ) : $domain; if ( substr( $url[‘host’], -strlen( $domain ) ) != $domain ) return false; // Port – supports ‘port-lists’ in the format: ‘80,8000,8080’. if ( !empty( $port ) && !in_array( $url[‘port’], explode( ‘,’, $port) ) ) return false; // Path – request path must start with path restriction. if ( substr( $url[‘path’], 0, strlen( $path ) ) != $path ) return false; return true; } /** * Convert cookie name and value back to header string. * * @since 2.8.0 * * @return string Header encoded cookie name and value. */ public function getHeaderValue() { if ( ! isset( $this->name ) || ! isset( $this->value ) ) return ”; /** * Filters the header-encoded cookie value. * * @since 3.4.0 * * @param string $value The cookie value. * @param string $name The cookie name. */ return $this->name . ‘=’ . apply_filters( ‘wp_http_cookie_value’, $this->value, $this->name ); } /** * Retrieve cookie header for usage in the rest of the WordPress HTTP API. * * @since 2.8.0 * * @return string */ public function getFullHeader() { return ‘Cookie: ‘ . $this->getHeaderValue(); } /** * Retrieves cookie attributes. * * @since 4.6.0 * * @return array { * List of attributes. * * @type string $expires When the cookie expires. * @type string $path Cookie URL path. * @type string $domain Cookie domain. * } */ public function get_attributes() { return array( ‘expires’ => $this->expires, ‘path’ => $this->path, ‘domain’ => $this->domain, ); } } /** * REST API: WP_REST_Meta_Fields class * * @package WordPress * @subpackage REST_API * @since 4.7.0 */ /** * Core class to manage meta values for an object via the REST API. * * @since 4.7.0 */ abstract class WP_REST_Meta_Fields { /** * Retrieves the object meta type. * * @since 4.7.0 * * @return string One of ‘post’, ‘comment’, ‘term’, ‘user’, or anything * else supported by `_get_meta_table()`. */ abstract protected function get_meta_type(); /** * Retrieves the object meta subtype. * * @since 4.9.8 * * @return string Subtype for the meta type, or empty string if no specific subtype. */ protected function get_meta_subtype() { return ”; } /** * Retrieves the object type for register_rest_field(). * * @since 4.7.0 * * @return string The REST field type, such as post type name, taxonomy name, ‘comment’, or `user`. */ abstract protected function get_rest_field_type(); /** * Registers the meta field. * * @since 4.7.0 * * @see register_rest_field() */ public function register_field() { register_rest_field( $this->get_rest_field_type(), ‘meta’, array( ‘get_callback’ => array( $this, ‘get_value’ ), ‘update_callback’ => array( $this, ‘update_value’ ), ‘schema’ => $this->get_field_schema(), )); } /** * Retrieves the meta field value. * * @since 4.7.0 * * @param int $object_id Object ID to fetch meta for. * @param WP_REST_Request $request Full details about the request. * @return WP_Error|object Object containing the meta values by name, otherwise WP_Error object. */ public function get_value( $object_id, $request ) { $fields = $this->get_registered_fields(); $response = array(); foreach ( $fields as $meta_key => $args ) { $name = $args[‘name’]; $all_values = get_metadata( $this->get_meta_type(), $object_id, $meta_key, false ); if ( $args[‘single’] ) { if ( empty( $all_values ) ) { $value = $args[‘schema’][‘default’]; } else { $value = $all_values[0]; } $value = $this->prepare_value_for_response( $value, $request, $args ); } else { $value = array(); foreach ( $all_values as $row ) { $value[] = $this->prepare_value_for_response( $row, $request, $args ); } } $response[ $name ] = $value; } return $response; } /** * Prepares a meta value for a response. * * This is required because some native types cannot be stored correctly * in the database, such as booleans. We need to cast back to the relevant * type before passing back to JSON. * * @since 4.7.0 * * @param mixed $value Meta value to prepare. * @param WP_REST_Request $request Current request object. * @param array $args Options for the field. * @return mixed Prepared value. */ protected function prepare_value_for_response( $value, $request, $args ) { if ( ! empty( $args[‘prepare_callback’] ) ) { $value = call_user_func( $args[‘prepare_callback’], $value, $request, $args ); } return $value; } /** * Updates meta values. * * @since 4.7.0 * * @param array $meta Array of meta parsed from the request. * @param int $object_id Object ID to fetch meta for. * @return WP_Error|null WP_Error if one occurs, null on success. */ public function update_value( $meta, $object_id ) { $fields = $this->get_registered_fields(); foreach ( $fields as $meta_key => $args ) { $name = $args[‘name’]; if ( ! array_key_exists( $name, $meta ) ) { continue; } /* * A null value means reset the field, which is essentially deleting it * from the database and then relying on the default value. */ if ( is_null( $meta[ $name ] ) ) { $result = $this->delete_meta_value( $object_id, $meta_key, $name ); if ( is_wp_error( $result ) ) { return $result; } continue; } $is_valid = rest_validate_value_from_schema( $meta[ $name ], $args[‘schema’], ‘meta.’ . $name ); if ( is_wp_error( $is_valid ) ) { $is_valid->add_data( array( ‘status’ => 400 ) ); return $is_valid; } $value = rest_sanitize_value_from_schema( $meta[ $name ], $args[‘schema’] ); if ( $args[‘single’] ) { $result = $this->update_meta_value( $object_id, $meta_key, $name, $value ); } else { $result = $this->update_multi_meta_value( $object_id, $meta_key, $name, $value ); } if ( is_wp_error( $result ) ) { return $result; } } return null; } /** * Deletes a meta value for an object. * * @since 4.7.0 * * @param int $object_id Object ID the field belongs to. * @param string $meta_key Key for the field. * @param string $name Name for the field that is exposed in the REST API. * @return bool|WP_Error True if meta field is deleted, WP_Error otherwise. */ protected function delete_meta_value( $object_id, $meta_key, $name ) { $meta_type = $this->get_meta_type(); if ( ! current_user_can( ‘delete_{$meta_type}_meta’, $object_id, $meta_key ) ) { return new WP_Error( ‘rest_cannot_delete’, /* translators: %s: custom field key */ sprintf( __( ‘Sorry, you are not allowed to edit the %s custom field.’ ), $name ), array( ‘key’ => $name, ‘status’ => rest_authorization_required_code() ) ); } if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ) ) ) { return new WP_Error( ‘rest_meta_database_error’, __( ‘Could not delete meta value from database.’ ), array( ‘key’ => $name, ‘status’ => WP_Http::INTERNAL_SERVER_ERROR ) ); } return true; } /** * Updates multiple meta values for an object. * * Alters the list of values in the database to match the list of provided values. * * @since 4.7.0 * * @param int $object_id Object ID to update. * @param string $meta_key Key for the custom field. * @param string $name Name for the field that is exposed in the REST API. * @param array $values List of values to update to. * @return bool|WP_Error True if meta fields are updated, WP_Error otherwise. */ protected function update_multi_meta_value( $object_id, $meta_key, $name, $values ) { $meta_type = $this->get_meta_type(); if ( ! current_user_can( ‘edit_{$meta_type}_meta’, $object_id, $meta_key ) ) { return new WP_Error( ‘rest_cannot_update’, /* translators: %s: custom field key */ sprintf( __( ‘Sorry, you are not allowed to edit the %s custom field.’ ), $name ), array( ‘key’ => $name, ‘status’ => rest_authorization_required_code() ) ); } $current = get_metadata( $meta_type, $object_id, $meta_key, false ); $to_remove = $current; $to_add = $values; foreach ( $to_add as $add_key => $value ) { $remove_keys = array_keys( $to_remove, $value, true ); if ( empty( $remove_keys ) ) { continue; } if ( count( $remove_keys ) > 1 ) { // To remove, we need to remove first, then add, so don’t touch. continue; } $remove_key = $remove_keys[0]; unset( $to_remove[ $remove_key ] ); unset( $to_add[ $add_key ] ); } // `delete_metadata` removes _all_ instances of the value, so only call once. $to_remove = array_unique( $to_remove ); foreach ( $to_remove as $value ) { if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { return new WP_Error( ‘rest_meta_database_error’, __( ‘Could not update meta value in database.’ ), array( ‘key’ => $name, ‘status’ => WP_Http::INTERNAL_SERVER_ERROR ) ); } } foreach ( $to_add as $value ) { if ( ! add_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { return new WP_Error( ‘rest_meta_database_error’, __( ‘Could not update meta value in database.’ ), array( ‘key’ => $name, ‘status’ => WP_Http::INTERNAL_SERVER_ERROR ) ); } } return true; } /** * Updates a meta value for an object. * * @since 4.7.0 * * @param int $object_id Object ID to update. * @param string $meta_key Key for the custom field. * @param string $name Name for the field that is exposed in the REST API. * @param mixed $value Updated value. * @return bool|WP_Error True if the meta field was updated, WP_Error otherwise. */ protected function update_meta_value( $object_id, $meta_key, $name, $value ) { $meta_type = $this->get_meta_type(); if ( ! current_user_can( ‘edit_{$meta_type}_meta’, $object_id, $meta_key ) ) { return new WP_Error( ‘rest_cannot_update’, /* translators: %s: custom field key */ sprintf( __( ‘Sorry, you are not allowed to edit the %s custom field.’ ), $name ), array( ‘key’ => $name, ‘status’ => rest_authorization_required_code() ) ); } $meta_key = wp_slash( $meta_key ); $meta_value = wp_slash( $value ); // Do the exact same check for a duplicate value as in update_metadata() to avoid update_metadata() returning false. $old_value = get_metadata( $meta_type, $object_id, $meta_key ); if ( 1 === count( $old_value ) ) { if ( $old_value[0] === $meta_value ) { return true; } } if ( ! update_metadata( $meta_type, $object_id, $meta_key, $meta_value ) ) { return new WP_Error( ‘rest_meta_database_error’, __( ‘Could not update meta value in database.’ ), array( ‘key’ => $name, ‘status’ => WP_Http::INTERNAL_SERVER_ERROR ) ); } return true; } /** * Retrieves all the registered meta fields. * * @since 4.7.0 * * @return array Registered fields. */ protected function get_registered_fields() { $registered = array(); $meta_type = $this->get_meta_type(); $meta_subtype = $this->get_meta_subtype(); $meta_keys = get_registered_meta_keys( $meta_type ); if ( ! empty( $meta_subtype ) ) { $meta_keys = array_merge( $meta_keys, get_registered_meta_keys( $meta_type, $meta_subtype ) ); } foreach ( $meta_keys as $name => $args ) { if ( empty( $args[‘show_in_rest’] ) ) { continue; } $rest_args = array(); if ( is_array( $args[‘show_in_rest’] ) ) { $rest_args = $args[‘show_in_rest’]; } $default_args = array( ‘name’ => $name, ‘single’ => $args[‘single’], ‘type’ => ! empty( $args[‘type’] ) ? $args[‘type’] : null, ‘schema’ => array(), ‘prepare_callback’ => array( $this, ‘prepare_value’ ), ); $default_schema = array( ‘type’ => $default_args[‘type’], ‘description’ => empty( $args[‘description’] ) ? ” : $args[‘description’], ‘default’ => isset( $args[‘default’] ) ? $args[‘default’] : null, ); $rest_args = array_merge( $default_args, $rest_args ); $rest_args[‘schema’] = array_merge( $default_schema, $rest_args[‘schema’] ); $type = ! empty( $rest_args[‘type’] ) ? $rest_args[‘type’] : null; $type = ! empty( $rest_args[‘schema’][‘type’] ) ? $rest_args[‘schema’][‘type’] : $type; if ( ! in_array( $type, array( ‘string’, ‘boolean’, ‘integer’, ‘number’ ) ) ) { continue; } if ( empty( $rest_args[‘single’] ) ) { $rest_args[‘schema’][‘items’] = array( ‘type’ => $rest_args[‘type’], ); $rest_args[‘schema’][‘type’] = ‘array’; } $registered[ $name ] = $rest_args; } return $registered; } /** * Retrieves the object’s meta schema, conforming to JSON Schema. * * @since 4.7.0 * * @return array Field schema data. */ public function get_field_schema() { $fields = $this->get_registered_fields(); $schema = array( ‘description’ => __( ‘Meta fields.’ ), ‘type’ => ‘object’, ‘context’ => array( ‘view’, ‘edit’ ), ‘properties’ => array(), ‘arg_options’ => array( ‘sanitize_callback’ => null, ‘validate_callback’ => array( $this, ‘check_meta_is_array’ ), ), ); foreach ( $fields as $args ) { $schema[‘properties’][ $args[‘name’] ] = $args[‘schema’]; } return $schema; } /** * Prepares a meta value for output. * * Default preparation for meta fields. Override by passing the * `prepare_callback` in your `show_in_rest` options. * * @since 4.7.0 * * @param mixed $value Meta value from the database. * @param WP_REST_Request $request Request object. * @param array $args REST-specific options for the meta key. * @return mixed Value prepared for output. If a non-JsonSerializable object, null. */ public static function prepare_value( $value, $request, $args ) { $type = $args[‘schema’][‘type’]; // For multi-value fields, check the item type instead. if ( ‘array’ === $type && ! empty( $args[‘schema’][‘items’][‘type’] ) ) { $type = $args[‘schema’][‘items’][‘type’]; } switch ( $type ) { case ‘string’: $value = (string) $value; break; case ‘integer’: $value = (int) $value; break; case ‘number’: $value = (float) $value; break; case ‘boolean’: $value = (bool) $value; break; } // Don’t allow objects to be output. if ( is_object( $value ) && ! ( $value instanceof JsonSerializable ) ) { return null; } return $value; } /** * Check the ‘meta’ value of a request is an associative array. * * @since 4.7.0 * * @param mixed $value The meta value submitted in the request. * @param WP_REST_Request $request Full details about the request. * @param string $param The parameter name. * @return WP_Error|string The meta array, if valid, otherwise an error. */ public function check_meta_is_array( $value, $request, $param ) { if ( ! is_array( $value ) ) { return false; } return $value; } }
    Fatal error: Class ‘WP_REST_Meta_Fields’ not found in /home/apgperso/public_html/wp-includes/rest-api/fields/class-wp-rest-comment-meta-fields.php on line 17

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar

    It is showing the wrong site as the one I need help with. It is actually: APGPersonalised.com

  • Unknown's avatar

    Hi There,

    APGPersonalised.com isn’t hosted here at WordPress.com – it’s a self-hosted WordPress.org site. This forum supports users with sites hosted at WordPress.com. This article explains the difference:

    WordPress.com vs. WordPress.org

    Pop over to the support forums for self-hosted WordPress at https://wordpress.org/support/ and you should find someone able to help.

    Have a think about whether you added/updated any plugins or made any other changes to the site just before this happened.

    Good luck!

  • The topic ‘Cannot access site’ is closed to new replies.