PluginProbe
Video Player for YouTube – Embed Videos Your Visitors Will Love to Watch / trunk
Video Player for YouTube – Embed Videos Your Visitors Will Love to Watch vtrunk
2.1.1 2.1.0 trunk 1.0 1.1 1.2 1.4.2 1.5.2 1.5.5 1.6.1 1.6.2 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
yt-player / inc / Database / Table.php

Table.php in Video Player for YouTube – Embed Videos Your Visitors Will Love to Watch trunk, at inc/Database/Table.php

76 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YTP\Database; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound
4
5 class Table
6 {
7 /**
8 * Create a database table
9 *
10 * @param string $name
11 * @param string $columns
12 * @param integer $version
13 * @param array $opts
14 * @return void
15 */
16 public function create($name, $columns, $version = 1, $opts = [])
17 {
18 $current_version = get_option("{$name}_database_version", 0);
19
20 if ($version == $current_version) {
21 return;
22 }
23
24 global $wpdb;
25
26 $full_table_name = $wpdb->prefix . sanitize_key($name); // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter
27
28 $opts = wp_parse_args($opts, [
29 'upgrade_method' => 'dbDelta',
30 'table_options' => '',
31 ]);
32
33 $charset_collate = '';
34 if ($wpdb->has_cap('collation')) {
35 if (!empty($wpdb->charset)) {
36 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
37 }
38 if (!empty($wpdb->collate)) {
39 $charset_collate .= " COLLATE $wpdb->collate";
40 }
41 }
42
43 $table_options = $charset_collate . ' ' . $opts['table_options'];
44
45 // use dbDelta by default
46 if ('dbDelta' == $opts['upgrade_method']) {
47 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
48 dbDelta("CREATE TABLE $full_table_name ( $columns ) $table_options"); // phpcs:ignore PluginCheck.Security.DirectDB.UnescapedDBParameter
49 update_option("{$name}_database_version", $version);
50 return;
51 }
52
53 if ('delete_first' == $opts['upgrade_method']) {
54 $wpdb->query("DROP TABLE IF EXISTS $full_table_name;"); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, PluginCheck.Security.DirectDB.UnescapedDBParameter
55 }
56
57 $wpdb->query("CREATE TABLE IF NOT EXISTS $full_table_name ( $columns ) $table_options;"); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, PluginCheck.Security.DirectDB.UnescapedDBParameter
58
59
60 update_option("{$name}_database_version", $version);
61 }
62
63 /**
64 * Drops the table and database option
65 *
66 * @param string $name
67 * @return void
68 */
69 public function drop($name)
70 {
71 global $wpdb;
72 $wpdb->query("DROP TABLE IF EXISTS " . $wpdb->prefix . sanitize_key($name)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, PluginCheck.Security.DirectDB.UnescapedDBParameter
73 delete_option("{$name}_database_version");
74 }
75 }
76