Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions classes/class-db-driver-wpdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public function insert_record( $data ) {
// Insert record meta
foreach ( (array) $meta as $key => $vals ) {
foreach ( (array) $vals as $val ) {
$val = $this->normalize_meta_value( $val );
if ( null === $val ) {
continue;
}

$this->insert_meta( $record_id, $key, $val );
}
}
Expand Down Expand Up @@ -128,6 +133,37 @@ public function insert_meta( $record_id, $key, $val ) {
return $result;
}

/**
* Normalize meta values before inserting them into the DB.
*
* @param mixed $value Meta value.
*
* @return scalar|string|null
*/
private function normalize_meta_value( $value ) {
if ( null === $value || is_resource( $value ) ) {
return null;
}

if ( is_bool( $value ) ) {
return $value ? '1' : '0';
}

if ( is_scalar( $value ) ) {
if ( is_string( $value ) && is_email( $value ) ) {
return sanitize_email( $value );
}

return $value;
}

if ( is_array( $value ) || is_object( $value ) ) {
return maybe_serialize( $value );
}

return null;
}

/**
* Retrieve records
*
Expand Down
35 changes: 32 additions & 3 deletions connectors/class-connector-installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ public function get_context_labels() {
);
}

/**
* Normalize a theme reference into a stylesheet slug.
*
* @param mixed $theme Theme slug or WP_Theme instance.
*
* @return string|null
*/
private function normalize_theme_slug( $theme ) {
if ( $theme instanceof \WP_Theme ) {
$theme = $theme->get_stylesheet();
}

if ( is_scalar( $theme ) ) {
$theme = (string) $theme;
}

if ( ! is_string( $theme ) || '' === $theme ) {
return null;
}

return $theme;
}

/**
* Add action links to Stream drop row in admin list screen.
*
Expand Down Expand Up @@ -224,7 +247,7 @@ public function callback_upgrader_process_complete( $upgrader, $extra ) {
$name = $data['Name'];
$version = $data['Version'];
} else { // theme
$slug = $upgrader->theme_info();
$slug = $this->normalize_theme_slug( $upgrader->theme_info() );

if ( ! $slug ) {
return false;
Expand Down Expand Up @@ -339,10 +362,15 @@ public function callback_upgrader_process_complete( $upgrader, $extra ) {
$old_version = isset( $log['old_version'] ) ? $log['old_version'] : null;
$message = isset( $log['message'] ) ? $log['message'] : null;
$action = isset( $log['action'] ) ? $log['action'] : null;
$log_args = compact( 'type', 'name', 'version', 'slug', 'success', 'error', 'old_version' );

if ( null === $slug || '' === $slug ) {
unset( $log_args['slug'] );
}

$this->log(
$message,
compact( 'type', 'name', 'version', 'slug', 'success', 'error', 'old_version' ),
$log_args,
null,
$context,
$action
Expand Down Expand Up @@ -703,7 +731,8 @@ public function callback_mainwp_child_install_plugin_theme( $args ) {
$name = $args['Name'];
$version = $args['Version'];
} else { // theme
$slug = $args['slug'];
$raw_slug = ! empty( $args['slug'] ) ? $args['slug'] : null;
$slug = $this->normalize_theme_slug( $raw_slug );
if ( ! $slug ) {
return;
}
Expand Down