PluginProbe
Insert Html Snippet / trunk
Insert Html Snippet vtrunk
1.4.6 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 All 27 releases
insert-html-snippet / admin / install.php

install.php in Insert Html Snippet trunk, at admin/install.php

116 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4 function xyz_ihs_network_install($networkwide) {
5 global $wpdb;
6
7 if (function_exists('is_multisite') && is_multisite()) {
8 // check if it is a network activation - if so, run the activation function for each blog id
9 if ($networkwide) {
10 $old_blog = $wpdb->blogid;
11 // Get all blog ids
12 $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
13 foreach ($blogids as $blog_id) {
14 switch_to_blog($blog_id);
15 xyz_ihs_install();
16 }
17 switch_to_blog($old_blog);
18 return;
19 }
20 }
21 xyz_ihs_install();
22 }
23
24
25 function xyz_ihs_install(){
26
27 global $wpdb;
28
29 $pluginName = 'xyz-wp-insert-code-snippet/xyz-wp-insert-code-snippet.php';
30 if (is_plugin_active($pluginName)) {
31 wp_die( "The plugin Insert HTML Snippet cannot be activated unless the premium version of this plugin is deactivated. Back to <a href='".esc_url(admin_url())."plugins.php'>Plugin Installation</a>." );
32 }
33 if ( version_compare( PHP_VERSION, '7.0.0', '<' ) ) {
34 wp_die(
35 sprintf(
36 'This plugin requires PHP version 7.0 or higher. You are using PHP %s. <a href="%s">Go back to Plugins page</a>.',
37 PHP_VERSION,
38 esc_url( admin_url( 'plugins.php' ) )
39 )
40 );
41 }
42 if(get_option('xyz_ihs_sort_order')=='')
43 {
44 add_option('xyz_ihs_sort_order','desc');
45 }
46 if(get_option('xyz_ihs_sort_field_name')=='')
47 {
48 add_option('xyz_ihs_sort_field_name','id');
49 }
50
51 $xyz_ihs_installed_date = get_option('xyz_ihs_installed_date');
52 if ($xyz_ihs_installed_date=="") {
53 $xyz_ihs_installed_date = time();
54 update_option('xyz_ihs_installed_date', $xyz_ihs_installed_date);
55 }
56
57 if(get_option('xyz_credit_link') == "")
58 {
59 add_option("xyz_credit_link",0);
60 }
61
62 if(get_option('xyz_ihs_dismiss')=='')
63 {
64 add_option('xyz_ihs_dismiss',0);
65 }
66
67 if(get_option('xyz_ihs_premium_version_ads')==""){
68 add_option('xyz_ihs_premium_version_ads',1);
69 }
70
71 add_option('xyz_ihs_limit',20);
72 add_option('xyz_ihs_exec_in_editor','0');
73
74
75 $charset_collate = $wpdb->get_charset_collate();
76 $queryInsertHtml = "CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."xyz_ihs_short_code (
77 `id` int NOT NULL AUTO_INCREMENT,
78 `title` varchar(1000) NOT NULL,
79 `description` TEXT NULL ,
80 `content` longtext NOT NULL,
81 `short_code` varchar(2000) NOT NULL,
82 `status` int NOT NULL,
83 PRIMARY KEY (`id`)
84 )ENGINE=InnoDB ".$charset_collate." AUTO_INCREMENT=1";
85 $wpdb->query($queryInsertHtml);
86 $tblcolums = $wpdb->get_col("SHOW COLUMNS FROM ".$wpdb->prefix."xyz_ihs_short_code");
87 if(!(in_array("insertionMethod", $tblcolums)))
88 $wpdb->query("ALTER TABLE ".$wpdb->prefix."xyz_ihs_short_code ADD insertionMethod int NOT NULL default 2");
89 if(!(in_array("insertionLocation", $tblcolums)))
90 $wpdb->query("ALTER TABLE ".$wpdb->prefix."xyz_ihs_short_code ADD insertionLocation int NOT NULL default 0");
91 if(!(in_array("insertionLocationType", $tblcolums)))
92 $wpdb->query("ALTER TABLE ".$wpdb->prefix."xyz_ihs_short_code ADD insertionLocationType int NOT NULL default 0");
93 if(!(in_array("description", $tblcolums)))
94 $wpdb->query("ALTER TABLE ".$wpdb->prefix."xyz_ihs_short_code ADD description TEXT NULL ");
95 $table_name = $wpdb->prefix . 'xyz_ihs_usage';
96 $charset_collate = $wpdb->get_charset_collate();
97 $sql = "CREATE TABLE {$table_name} (
98 post_id BIGINT(20) UNSIGNED NOT NULL,
99 snippet_id BIGINT(20) UNSIGNED NOT NULL,
100 post_type VARCHAR(20) NOT NULL,
101 PRIMARY KEY (post_id, snippet_id),
102 KEY post_id (post_id),
103 KEY snippet_id (snippet_id)
104 ) {$charset_collate};";
105 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
106 dbDelta($sql);
107 // Set sync flag only if not already set
108 if (get_option('xyz_ihs_sync_needed') === false) {
109 add_option('xyz_ihs_sync_needed', 1);
110 }
111 //Show Snippet Usage Details
112 add_option('xyz_ihs_show_snippet_usage',1);//default enable
113 }
114
115 register_activation_hook( XYZ_INSERT_HTML_PLUGIN_FILE ,'xyz_ihs_network_install');
116