| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Fired during plugin activation |
| 5 |
* |
| 6 |
* @link https://wpdeveloper.com |
| 7 |
* @since 1.0.0 |
| 8 |
* |
| 9 |
* @package BetterDocs |
| 10 |
* @subpackage BetterDocs/includes |
| 11 |
*/ |
| 12 |
|
| 13 |
/** |
| 14 |
* Fired during plugin activation. |
| 15 |
* |
| 16 |
* This class defines all code necessary to run during the plugin's activation. |
| 17 |
* |
| 18 |
* @since 1.0.0 |
| 19 |
* @package BetterDocs |
| 20 |
* @subpackage BetterDocs/includes |
| 21 |
* @author WPDeveloper <support@wpdeveloper.com> |
| 22 |
*/ |
| 23 |
class BetterDocs_Activator { |
| 24 |
|
| 25 |
/** |
| 26 |
* Detect plugin activation |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
*/ |
| 30 |
public static function activate() { |
| 31 |
if( current_user_can( 'delete_users' ) ) { |
| 32 |
set_transient( '_betterdocs_meta_activation_notice', true, 30 ); |
| 33 |
} |
| 34 |
BetterDocs_Settings::save_default_settings(); |
| 35 |
} |
| 36 |
|
| 37 |
public static function search_migration() { |
| 38 |
global $wpdb; |
| 39 |
$search_data = get_option( 'betterdocs_search_data' ); |
| 40 |
if (!empty($search_data)) { |
| 41 |
$search_data_arr = unserialize($search_data); |
| 42 |
foreach ($search_data_arr as $key=>$value) { |
| 43 |
$args = array( |
| 44 |
'post_type' => 'docs', |
| 45 |
'post_status' => 'publish', |
| 46 |
'posts_per_page' => -1, |
| 47 |
'suppress_filters' => true, |
| 48 |
's' => $key |
| 49 |
); |
| 50 |
|
| 51 |
$loop = new WP_Query($args); |
| 52 |
if ($loop->have_posts()) { |
| 53 |
$count = $value; |
| 54 |
$not_found_count = 0; |
| 55 |
} else { |
| 56 |
$count = 0; |
| 57 |
$not_found_count = $value; |
| 58 |
} |
| 59 |
$insert = $wpdb->query( |
| 60 |
$wpdb->prepare( |
| 61 |
"INSERT INTO {$wpdb->prefix}betterdocs_search_keyword |
| 62 |
( keyword ) |
| 63 |
VALUES ( %s )", |
| 64 |
array( |
| 65 |
$key |
| 66 |
) |
| 67 |
) |
| 68 |
); |
| 69 |
|
| 70 |
if ($insert) { |
| 71 |
$wpdb->query( |
| 72 |
$wpdb->prepare( |
| 73 |
"INSERT INTO {$wpdb->prefix}betterdocs_search_log |
| 74 |
(keyword_id, count, not_found_count, created_at) |
| 75 |
VALUES (%d, %d, %d, %s)", |
| 76 |
array( |
| 77 |
$wpdb->insert_id, |
| 78 |
$count, |
| 79 |
$not_found_count, |
| 80 |
date('Y-m-d') |
| 81 |
) |
| 82 |
) |
| 83 |
); |
| 84 |
} |
| 85 |
} |
| 86 |
update_option( "betterdocs_search_data_migration", '1.0' ); |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|