| @@ -9,23 +9,26 @@ | ||
| 9 | 9 | * |
| 10 | 10 | * @since 3.4.0 |
| 11 | 11 | * @package Code_Snippets |
| 12 | 12 | * |
| 13 | - * @property int $id The remote ID. | |
| 14 | - * @property string $name The snippet title. | |
| 15 | - * @property string $description The formatted description. | |
| 16 | - * @property string $code The executable code. | |
| 17 | - * @property array<string> $tags An array of the tags. | |
| 18 | - * @property string $scope The scope name. | |
| 19 | - * @property string $codevault Name of user codevault. | |
| 20 | - * @property string $total_votes The total number of votes. | |
| 21 | - * @property string $vote_count The number of actual votes. | |
| 22 | - * @property string $wp_tested Tested with WP version. | |
| 23 | - * @property string $status Snippet Status ID. | |
| 24 | - * @property string $created The date and time when the snippet data was first created, in ISO format. | |
| 25 | - * @property string $updated When the snippet was last updated, in ISO format. | |
| 26 | - * @property int $revision The update revision number. | |
| 27 | - * @property bool $is_owner If user is owner or author of snippet. | |
| 13 | + * @property int $id The remote ID. | |
| 14 | + * @property string $slug The snippet slug. | |
| 15 | + * @property string $name The snippet title. | |
| 16 | + * @property string $description The formatted description. | |
| 17 | + * @property string $code The executable code. | |
| 18 | + * @property string[] $tags An array of the tags. | |
| 19 | + * @property string $scope The scope name. | |
| 20 | + * @property string $codevault Name of user codevault. | |
| 21 | + * @property string $total_votes The total number of votes. | |
| 22 | + * @property string $vote_count The number of actual votes. | |
| 23 | + * @property string $wp_tested Tested with WP version. | |
| 24 | + * @property string $status Snippet Status ID. | |
| 25 | + * @property string $created The date and time when the snippet data was first created, in ISO format. | |
| 26 | + * @property string $updated When the snippet was last updated, in ISO format. | |
| 27 | + * @property int $revision The update revision number. | |
| 28 | + * @property bool $is_owner If user is owner or author of snippet. | |
| 29 | + * @property int|null $local_id The local snippet ID when this cloud snippet has been downloaded. | |
| 30 | + * @property bool|null $update_available If synchronised, whether there is an update available on the cloud platform. | |
| 28 | 31 | */ |
| 29 | 32 | class Cloud_Snippet extends Model { |
| 30 | 33 | |
| 31 | 34 | /** |
| @@ -33,26 +36,27 @@ | ||
| 33 | 36 | * |
| 34 | 37 | * @var array<string, mixed> |
| 35 | 38 | */ |
| 36 | 39 | protected static array $default_values = [ |
| 37 | - 'id' => '', | |
| 38 | - 'cloud_id' => '', | |
| 39 | - 'name' => '', | |
| 40 | - 'description' => '', | |
| 41 | - 'code' => '', | |
| 42 | - 'tags' => [], | |
| 43 | - 'scope' => '', | |
| 44 | - 'language' => '', | |
| 45 | - 'status' => '', | |
| 46 | - 'codevault' => '', | |
| 47 | - 'total_votes' => '', | |
| 48 | - 'vote_count' => '', | |
| 49 | - 'wp_tested' => '', | |
| 50 | - 'created' => '', | |
| 51 | - 'updated' => '', | |
| 52 | - 'revision' => 0, | |
| 53 | - 'is_owner' => false, | |
| 54 | - 'shared_network' => false, | |
| 40 | + 'id' => '', | |
| 41 | + 'cloud_id' => '', | |
| 42 | + 'name' => '', | |
| 43 | + 'description' => '', | |
| 44 | + 'code' => '', | |
| 45 | + 'tags' => [], | |
| 46 | + 'scope' => '', | |
| 47 | + 'language' => '', | |
| 48 | + 'status' => '', | |
| 49 | + 'codevault' => '', | |
| 50 | + 'total_votes' => '', | |
| 51 | + 'vote_count' => '', | |
| 52 | + 'wp_tested' => '', | |
| 53 | + 'created' => '', | |
| 54 | + 'updated' => '', | |
| 55 | + 'revision' => 0, | |
| 56 | + 'is_owner' => false, | |
| 57 | + 'local_id' => null, | |
| 58 | + 'update_available' => null, | |
| 55 | 59 | ]; |
| 56 | 60 | |
| 57 | 61 | /** |
| 58 | 62 | * Prepare a value before it is stored. |
| @@ -67,17 +71,31 @@ | ||
| 67 | 71 | case 'id': |
| 68 | 72 | case 'revision': |
| 69 | 73 | return absint( $value ); |
| 70 | 74 | |
| 75 | + case 'local_id': | |
| 76 | + return is_null( $value ) ? null : absint( $value ); | |
| 77 | + | |
| 71 | 78 | case 'is_owner': |
| 72 | 79 | return (bool) $value; |
| 80 | + | |
| 73 | 81 | case 'description': |
| 74 | - return ( null === $value ) ? '' : $value; | |
| 82 | + return is_scalar( $value ) ? wp_kses_post( (string) $value ) : ''; | |
| 83 | + | |
| 75 | 84 | case 'tags': |
| 76 | 85 | return code_snippets_build_tags_array( $value ); |
| 77 | 86 | |
| 78 | 87 | case 'language': |
| 79 | 88 | return is_array( $value ) ? ( $value['name'] ?? '' ) : (string) $value; |
| 89 | + | |
| 90 | + case 'name': | |
| 91 | + case 'code': | |
| 92 | + case 'scope': | |
| 93 | + case 'codevault': | |
| 94 | + case 'wp_tested': | |
| 95 | + case 'created': | |
| 96 | + case 'updated': | |
| 97 | + return is_scalar( $value ) ? (string) $value : ''; | |
| 80 | 98 | |
| 81 | 99 | default: |
| 82 | 100 | return $value; |
| 83 | 101 | } |