PluginProbe
CatFolders – WordPress Media Library Folders & Categories / trunk
CatFolders – WordPress Media Library Folders & Categories vtrunk
2.5.6 2.5.5 trunk 1.6.1 1.8 1.9 2.0 2.2 2.3.1 2.3.2 2.4.4 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4
catfolders / includes / Install.php

Install.php in CatFolders – WordPress Media Library Folders & Categories trunk, at includes/Install.php

63 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace CatFolders;
3
4 class Install {
5 public function __construct() {
6 add_action( 'init', array( __CLASS__, 'checkVersion' ), 5 );
7 }
8
9 public static function install() {
10 self::createTables();
11 self::updatePluginVersion();
12 }
13
14 public static function createTables() {
15 global $wpdb;
16
17 $wpdb->hide_errors();
18
19 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
20
21 dbDelta( self::getSchema() );
22 }
23
24 public static function getSchema() {
25 global $wpdb;
26
27 $collate = '';
28
29 if ( $wpdb->has_cap( 'collation' ) ) {
30 $collate = $wpdb->get_charset_collate();
31 }
32
33 $tables = "
34 CREATE TABLE {$wpdb->prefix}catfolders (
35 id int(11) unsigned NOT NULL AUTO_INCREMENT,
36 title varchar(250) NOT NULL,
37 parent int(11) unsigned NOT NULL DEFAULT 0,
38 type varchar(20) NOT NULL DEFAULT 'attachment',
39 ord int(11) unsigned NULL DEFAULT 0,
40 created_by bigint(20) NOT NULL DEFAULT 0,
41 PRIMARY KEY (id)
42 ) $collate;
43 CREATE TABLE {$wpdb->prefix}catfolders_posts (
44 folder_id int(11) unsigned NOT NULL,
45 post_id bigint(20) unsigned NOT NULL,
46 UNIQUE KEY `folder_post` (`folder_id`,`post_id`)
47 ) $collate;
48 ";
49
50 return $tables;
51 }
52
53 public static function updatePluginVersion() {
54 update_option( 'catf_version', CATF_VERSION );
55 }
56
57 public static function checkVersion() {
58 if ( version_compare( get_option( 'catf_version' ), CATF_VERSION, '<' ) ) {
59 self::install();
60 }
61 }
62 }
63