Apple_Exporter\Workspace::log_error PHP Метод

log_error() публичный Метод

Logs errors encountered during publishing.
С версии: 1.0.6
public log_error ( string $key, string $value )
$key string
$value string
    public function log_error($key, $value)
    {
        // Get current errors
        $errors = get_post_meta($this->content_id, self::ERRORS_META_KEY, true);
        // Initialize if needed
        if (empty($errors)) {
            $errors = array();
        }
        // Initialize the key if needed
        if (empty($errors[$key])) {
            $errors[$key] = array();
        }
        // Log the error
        $errors[$key][] = $value;
        // Save the errors
        update_post_meta($this->content_id, self::ERRORS_META_KEY, $errors);
    }

Usage Example

 /**
  * Builds an array with all the components of this WordPress content.
  *
  * @return array
  * @access protected
  */
 protected function build()
 {
     $components = array();
     $workspace = new Workspace($this->content_id());
     // Handle body components first
     foreach ($this->split_into_components() as $component) {
         // Check if the component is valid
         $component_array = $component->to_array();
         if (is_wp_error($component_array)) {
             $workspace->log_error('component_errors', $component_array->get_error_message());
         } else {
             $components[] = $component_array;
         }
     }
     // Meta components are handled after and then prepended since
     // they could change depending on the above body processing,
     // such as if a thumbnail was used from the body.
     $components = array_merge($this->meta_components(), $components);
     // Group body components to improve text flow at all orientations
     return $this->group_body_components($components);
 }