PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | php/Core/DB.php +13 -26 3.10.24.0.0-beta.2 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 namespace Code_Snippets\Core;
4 4
5 +use function Code_Snippets\Utils\validate_network_param;
5 6 use const Code_Snippets\CACHE_GROUP;
6 7
7 8 /**
8 9 * Functions used to manage the database tables.
@@ -61,30 +62,8 @@
61 62 $wpdb->ms_global_tables[] = self::MS_TABLE_NAME;
62 63 }
63 64
64 65 /**
65 - * Validate a provided 'network' or 'multisite' param, converting it to a boolean.
66 - *
67 - * @param bool|null $network Network argument value.
68 - *
69 - * @return bool Sanitized value.
70 - */
71 - public static function validate_network_param( ?bool $network = null ): bool {
72 -
73 - // If multisite is not active, then assume the value is false.
74 - if ( ! is_multisite() ) {
75 - return false;
76 - }
77 -
78 - // If $multisite is null, try to base it on the current admin page.
79 - if ( is_null( $network ) && function_exists( 'is_network_admin' ) ) {
80 - return is_network_admin();
81 - }
82 -
83 - return (bool) $network;
84 - }
85 -
86 - /**
87 66 * Return the appropriate snippet table name
88 67 *
89 68 * @param bool|null $is_network Whether retrieve the multisite table name (true) or the site table name (false).
90 69 *
@@ -91,9 +70,9 @@
91 70 * @return string The snippet table name
92 71 * @since 2.0
93 72 */
94 73 public function get_table_name( ?bool $is_network = null ): string {
95 - $is_network = is_bool( $is_network ) ? $is_network : self::validate_network_param( $is_network );
74 + $is_network = is_bool( $is_network ) ? $is_network : validate_network_param( $is_network );
96 75 return $is_network ? $this->ms_table : $this->table;
97 76 }
98 77
99 78 /**
@@ -165,11 +144,15 @@
165 144 active TINYINT(1) NOT NULL DEFAULT 0,
166 145 modified DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
167 146 revision BIGINT(20) NOT NULL DEFAULT 1,
168 147 cloud_id VARCHAR(255) NULL,
148 + created_by BIGINT(20) UNSIGNED NULL,
149 + updated_by BIGINT(20) UNSIGNED NULL,
169 150 PRIMARY KEY (id),
170 151 KEY scope (scope),
171 - KEY active (active)
152 + KEY active (active),
153 + KEY created_by (created_by),
154 + KEY updated_by (updated_by)
172 155 ) $charset_collate;";
173 156
174 157 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
175 158 dbDelta( $sql );
@@ -221,9 +204,11 @@
221 204 $ms_snippets = $this->fetch_snippets_from_table( $this->ms_table, $scopes, false );
222 205
223 206 if ( $ms_snippets ) {
224 207 $active_shared_ids = get_option( 'active_shared_network_snippets', [] );
225 - $active_shared_ids = is_array( $active_shared_ids ) ? array_map( 'intval', $active_shared_ids ) : [];
208 + $active_shared_ids = is_array( $active_shared_ids )
209 + ? array_map( 'intval', $active_shared_ids )
210 + : [];
226 211
227 212 foreach ( $ms_snippets as $snippet ) {
228 213 $id = intval( $snippet['id'] );
229 214 $active_value = intval( $snippet['active'] );
@@ -331,9 +316,11 @@
331 316 return false;
332 317 }
333 318
334 319 $scopes_format = implode( ',', array_fill( 0, count( $scopes ), '%s' ) );
335 - $extra_where = $active_only ? 'AND active=1' : '';
320 + $extra_where = $active_only
321 + ? 'AND active=1'
322 + : 'AND active <> -1';
336 323
337 324 $snippets = $wpdb->get_results(
338 325 // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
339 326 $wpdb->prepare(