| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 2 | +if ( ! defined( 'ABSPATH' ) ) | |
| 3 | + exit; | |
| 3 | 4 | function xyz_ihs_network_install($networkwide) { |
| 4 | 5 | global $wpdb; |
| 5 | 6 | |
| 6 | 7 | if (function_exists('is_multisite') && is_multisite()) { |
| @@ -21,11 +22,24 @@ | ||
| 21 | 22 | } |
| 22 | 23 | |
| 23 | 24 | |
| 24 | 25 | function xyz_ihs_install(){ |
| 25 | - | |
| 26 | + | |
| 26 | 27 | global $wpdb; |
| 27 | - //global $current_user; get_currentuserinfo(); | |
| 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 | +} | |
| 28 | 42 | if(get_option('xyz_ihs_sort_order')=='') |
| 29 | 43 | { |
| 30 | 44 | add_option('xyz_ihs_sort_order','desc'); |
| 31 | 45 | } |
| @@ -32,29 +46,70 @@ | ||
| 32 | 46 | if(get_option('xyz_ihs_sort_field_name')=='') |
| 33 | 47 | { |
| 34 | 48 | add_option('xyz_ihs_sort_field_name','id'); |
| 35 | 49 | } |
| 36 | - | |
| 37 | - | |
| 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 | + | |
| 38 | 57 | if(get_option('xyz_credit_link') == "") |
| 39 | 58 | { |
| 40 | 59 | add_option("xyz_credit_link",0); |
| 41 | 60 | } |
| 42 | 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 | + | |
| 43 | 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(); | |
| 44 | 76 | $queryInsertHtml = "CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."xyz_ihs_short_code ( |
| 45 | 77 | `id` int NOT NULL AUTO_INCREMENT, |
| 46 | - `title` varchar(1000) COLLATE utf8_unicode_ci NOT NULL, | |
| 47 | - `content` longtext COLLATE utf8_unicode_ci NOT NULL, | |
| 48 | - `short_code` varchar(2000) COLLATE utf8_unicode_ci NOT NULL, | |
| 78 | + `title` varchar(1000) NOT NULL, | |
| 79 | + `description` TEXT NULL , | |
| 80 | + `content` longtext NOT NULL, | |
| 81 | + `short_code` varchar(2000) NOT NULL, | |
| 49 | 82 | `status` int NOT NULL, |
| 50 | 83 | PRIMARY KEY (`id`) |
| 51 | - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"; | |
| 84 | + )ENGINE=InnoDB ".$charset_collate." AUTO_INCREMENT=1"; | |
| 52 | 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 | |
| 53 | 113 | } |
| 54 | 114 | |
| 55 | 115 | register_activation_hook( XYZ_INSERT_HTML_PLUGIN_FILE ,'xyz_ihs_network_install'); |
| 56 | - | |
| 57 | - | |
| 58 | - | |
| 59 | - | |
| 60 | - | |