ninja_forms_activation

The Ninja Forms ninja forms activation function.

Description

ninja_forms_activation( $network_wide ); 

Parameters (1)

0. $network_wide
The network wide.

Usage

  1. if ( !function_exists( 'ninja_forms_activation' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/activation.php'; 
  3.  
  4. // The network wide. 
  5. $network_wide = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = ninja_forms_activation($network_wide); 
  9.  

Defined (1)

The function is defined in the following location(s).

/deprecated/includes/activation.php  
  1. function ninja_forms_activation( $network_wide ) { 
  2. global $wpdb; 
  3.  
  4. if ( ! $network_wide ) { // This is a single-site activation. 
  5.  
  6. wp_schedule_event( time(), 'daily', 'ninja_forms_daily_action' ); 
  7.  
  8. require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
  9.  
  10. $plugin_settings = nf_get_settings(); 
  11.  
  12. $current_version = isset ( $plugin_settings['version'] ) ? $plugin_settings['version'] : ''; 
  13.  
  14. if ( $current_version != '' ) { 
  15. update_option( 'nf_version_upgraded_from', $current_version ); 
  16.  
  17. $forms = ''; 
  18.  
  19. $opt = $plugin_settings; 
  20.  
  21. $sql = "CREATE TABLE IF NOT EXISTS ".NINJA_FORMS_FAV_FIELDS_TABLE_NAME." ( 
  22. `id` int(11) NOT NULL AUTO_INCREMENT,  
  23. `row_type` int(11) NOT NULL,  
  24. `type` varchar(255) CHARACTER SET utf8 NOT NULL,  
  25. `order` int(11) NOT NULL,  
  26. `data` longtext CHARACTER SET utf8 NOT NULL,  
  27. `name` varchar(255) CHARACTER SET utf8 NOT NULL,  
  28. PRIMARY KEY (`id`) 
  29. ) DEFAULT CHARSET=utf8;"; 
  30.  
  31. dbDelta($sql); 
  32.  
  33. if (!function_exists('nf_change_email_fav')) { 
  34. require_once dirname(__FILE__).'/admin/upgrades/upgrade-functions.php'; 
  35. // Remove old email settings. 
  36.  
  37. $state_dropdown = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM ".NINJA_FORMS_FAV_FIELDS_TABLE_NAME." WHERE name = %s AND row_type = 0", 'State Dropdown' ), ARRAY_A ); 
  38. if( !isset($state_dropdown['id']) ) { 
  39. $sql = 'INSERT INTO `'.NINJA_FORMS_FAV_FIELDS_TABLE_NAME.'` (`id`, `row_type`, `type`, `order`, `data`, `name`) VALUES 
  40. (2, 0, \'_list\', 0, \'a:10:{s:5:\"label\";s:14:\"State Dropdown\";s:9:\"label_pos\";s:4:\"left\";s:9:\"list_type\";s:8:\"dropdown\";s:10:\"multi_size\";s:1:\"5\";s:15:\"list_show_value\";s:1:\"1\";s:4:\"list\";a:1:{s:7:\"options\";a:51:{i:0;a:3:{s:5:\"label\";s:7:\"Alabama\";s:5:\"value\";s:2:\"AL\";s:8:\"selected\";s:1:\"0\";}i:1;a:3:{s:5:\"label\";s:6:\"Alaska\";s:5:\"value\";s:2:\"AK\";s:8:\"selected\";s:1:\"0\";}i:2;a:3:{s:5:\"label\";s:7:\"Arizona\";s:5:\"value\";s:2:\"AZ\";s:8:\"selected\";s:1:\"0\";}i:3;a:3:{s:5:\"label\";s:8:\"Arkansas\";s:5:\"value\";s:2:\"AR\";s:8:\"selected\";s:1:\"0\";}i:4;a:3:{s:5:\"label\";s:10:\"California\";s:5:\"value\";s:2:\"CA\";s:8:\"selected\";s:1:\"0\";}i:5;a:3:{s:5:\"label\";s:8:\"Colorado\";s:5:\"value\";s:2:\"CO\";s:8:\"selected\";s:1:\"0\";}i:6;a:3:{s:5:\"label\";s:11:\"Connecticut\";s:5:\"value\";s:2:\"CT\";s:8:\"selected\";s:1:\"0\";}i:7;a:3:{s:5:\"label\";s:8:\"Delaware\";s:5:\"value\";s:2:\"DE\";s:8:\"selected\";s:1:\"0\";}i:8;a:3:{s:5:\"label\";s:20:\"District of Columbia\";s:5:\"value\";s:2:\"DC\";s:8:\"selected\";s:1:\"0\";}i:9;a:3:{s:5:\"label\";s:7:\"Florida\";s:5:\"value\";s:2:\"FL\";s:8:\"selected\";s:1:\"0\";}i:10;a:3:{s:5:\"label\";s:7:\"Georgia\";s:5:\"value\";s:2:\"GA\";s:8:\"selected\";s:1:\"0\";}i:11;a:3:{s:5:\"label\";s:6:\"Hawaii\";s:5:\"value\";s:2:\"HI\";s:8:\"selected\";s:1:\"0\";}i:12;a:3:{s:5:\"label\";s:5:\"Idaho\";s:5:\"value\";s:2:\"ID\";s:8:\"selected\";s:1:\"0\";}i:13;a:3:{s:5:\"label\";s:8:\"Illinois\";s:5:\"value\";s:2:\"IL\";s:8:\"selected\";s:1:\"0\";}i:14;a:3:{s:5:\"label\";s:7:\"Indiana\";s:5:\"value\";s:2:\"IN\";s:8:\"selected\";s:1:\"0\";}i:15;a:3:{s:5:\"label\";s:4:\"Iowa\";s:5:\"value\";s:2:\"IA\";s:8:\"selected\";s:1:\"0\";}i:16;a:3:{s:5:\"label\";s:6:\"Kansas\";s:5:\"value\";s:2:\"KS\";s:8:\"selected\";s:1:\"0\";}i:17;a:3:{s:5:\"label\";s:8:\"Kentucky\";s:5:\"value\";s:2:\"KY\";s:8:\"selected\";s:1:\"0\";}i:18;a:3:{s:5:\"label\";s:9:\"Louisiana\";s:5:\"value\";s:2:\"LA\";s:8:\"selected\";s:1:\"0\";}i:19;a:3:{s:5:\"label\";s:5:\"Maine\";s:5:\"value\";s:2:\"ME\";s:8:\"selected\";s:1:\"0\";}i:20;a:3:{s:5:\"label\";s:8:\"Maryland\";s:5:\"value\";s:2:\"MD\";s:8:\"selected\";s:1:\"0\";}i:21;a:3:{s:5:\"label\";s:13:\"Massachusetts\";s:5:\"value\";s:2:\"MA\";s:8:\"selected\";s:1:\"0\";}i:22;a:3:{s:5:\"label\";s:8:\"Michigan\";s:5:\"value\";s:2:\"MI\";s:8:\"selected\";s:1:\"0\";}i:23;a:3:{s:5:\"label\";s:9:\"Minnesota\";s:5:\"value\";s:2:\"MN\";s:8:\"selected\";s:1:\"0\";}i:24;a:3:{s:5:\"label\";s:11:\"Mississippi\";s:5:\"value\";s:2:\"MS\";s:8:\"selected\";s:1:\"0\";}i:25;a:3:{s:5:\"label\";s:8:\"Missouri\";s:5:\"value\";s:2:\"MO\";s:8:\"selected\";s:1:\"0\";}i:26;a:3:{s:5:\"label\";s:7:\"Montana\";s:5:\"value\";s:2:\"MT\";s:8:\"selected\";s:1:\"0\";}i:27;a:3:{s:5:\"label\";s:8:\"Nebraska\";s:5:\"value\";s:2:\"NE\";s:8:\"selected\";s:1:\"0\";}i:28;a:3:{s:5:\"label\";s:6:\"Nevada\";s:5:\"value\";s:2:\"NV\";s:8:\"selected\";s:1:\"0\";}i:29;a:3:{s:5:\"label\";s:13:\"New Hampshire\";s:5:\"value\";s:2:\"NH\";s:8:\"selected\";s:1:\"0\";}i:30;a:3:{s:5:\"label\";s:10:\"New Jersey\";s:5:\"value\";s:2:\"NJ\";s:8:\"selected\";s:1:\"0\";}i:31;a:3:{s:5:\"label\";s:10:\"New Mexico\";s:5:\"value\";s:2:\"NM\";s:8:\"selected\";s:1:\"0\";}i:32;a:3:{s:5:\"label\";s:8:\"New York\";s:5:\"value\";s:2:\"NY\";s:8:\"selected\";s:1:\"0\";}i:33;a:3:{s:5:\"label\";s:14:\"North Carolina\";s:5:\"value\";s:2:\"NC\";s:8:\"selected\";s:1:\"0\";}i:34;a:3:{s:5:\"label\";s:12:\"North Dakota\";s:5:\"value\";s:2:\"ND\";s:8:\"selected\";s:1:\"0\";}i:35;a:3:{s:5:\"label\";s:4:\"Ohio\";s:5:\"value\";s:2:\"OH\";s:8:\"selected\";s:1:\"0\";}i:36;a:3:{s:5:\"label\";s:8:\"Oklahoma\";s:5:\"value\";s:2:\"OK\";s:8:\"selected\";s:1:\"0\";}i:37;a:3:{s:5:\"label\";s:6:\"Oregon\";s:5:\"value\";s:2:\"OR\";s:8:\"selected\";s:1:\"0\";}i:38;a:3:{s:5:\"label\";s:12:\"Pennsylvania\";s:5:\"value\";s:2:\"PA\";s:8:\"selected\";s:1:\"0\";}i:39;a:3:{s:5:\"label\";s:12:\"Rhode Island\";s:5:\"value\";s:2:\"RI\";s:8:\"selected\";s:1:\"0\";}i:40;a:3:{s:5:\"label\";s:14:\"South Carolina\";s:5:\"value\";s:2:\"SC\";s:8:\"selected\";s:1:\"0\";}i:41;a:3:{s:5:\"label\";s:12:\"South Dakota\";s:5:\"value\";s:2:\"SD\";s:8:\"selected\";s:1:\"0\";}i:42;a:3:{s:5:\"label\";s:9:\"Tennessee\";s:5:\"value\";s:2:\"TN\";s:8:\"selected\";s:1:\"0\";}i:43;a:3:{s:5:\"label\";s:5:\"Texas\";s:5:\"value\";s:2:\"TX\";s:8:\"selected\";s:1:\"0\";}i:44;a:3:{s:5:\"label\";s:4:\"Utah\";s:5:\"value\";s:2:\"UT\";s:8:\"selected\";s:1:\"0\";}i:45;a:3:{s:5:\"label\";s:7:\"Vermont\";s:5:\"value\";s:2:\"VT\";s:8:\"selected\";s:1:\"0\";}i:46;a:3:{s:5:\"label\";s:8:\"Virginia\";s:5:\"value\";s:2:\"VA\";s:8:\"selected\";s:1:\"0\";}i:47;a:3:{s:5:\"label\";s:10:\"Washington\";s:5:\"value\";s:2:\"WA\";s:8:\"selected\";s:1:\"0\";}i:48;a:3:{s:5:\"label\";s:13:\"West Virginia\";s:5:\"value\";s:2:\"WV\";s:8:\"selected\";s:1:\"0\";}i:49;a:3:{s:5:\"label\";s:9:\"Wisconsin\";s:5:\"value\";s:2:\"WI\";s:8:\"selected\";s:1:\"0\";}i:50;a:3:{s:5:\"label\";s:7:\"Wyoming\";s:5:\"value\";s:2:\"WY\";s:8:\"selected\";s:1:\"0\";}}}s:3:\"req\";s:1:\"0\";s:5:\"class\";s:0:\"\";s:9:\"show_help\";s:1:\"0\";s:9:\"help_text\";s:0:\"\";}\', \'State Dropdown\')'; 
  41. $wpdb->query($sql); 
  42.  
  43. $anti_spam = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM ".NINJA_FORMS_FAV_FIELDS_TABLE_NAME." WHERE name = %s AND row_type = 0", 'Anti-Spam' ), ARRAY_A ); 
  44. if( !isset($anti_spam['id']) ) { 
  45. $sql = 'INSERT INTO `'.NINJA_FORMS_FAV_FIELDS_TABLE_NAME.'` (`id`, `row_type`, `type`, `order`, `data`, `name`) VALUES 
  46. (3, 0, \'_spam\', 0, \'a:6:{s:9:"label_pos";s:4:"left";s:5:"label";s:18:"Anti-Spam Question";s:6:"answer";s:16:"Anti-Spam Answer";s:5:"class";s:0:"";s:9:"show_help";s:1:"0";s:9:"help_text";s:0:"";}\', \'Anti-Spam\')'; 
  47. $wpdb->query($sql); 
  48.  
  49. $submit = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM ".NINJA_FORMS_FAV_FIELDS_TABLE_NAME." WHERE name = %s AND row_type = 0", 'Submit' ), ARRAY_A ); 
  50. if( !isset($submit['id']) ) { 
  51. $sql = 'INSERT INTO `'.NINJA_FORMS_FAV_FIELDS_TABLE_NAME.'` (`id`, `row_type`, `type`, `order`, `data`, `name`) VALUES 
  52. (4, 0, \'_submit\', 0, \'a:4:{s:5:\"label\";s:6:\"Submit\";s:5:\"class\";s:0:\"\";s:9:\"show_help\";s:1:\"0\";s:9:\"help_text\";s:0:\"\";}\', \'Submit\');'; 
  53. $wpdb->query($sql); 
  54.  
  55. $sql = "CREATE TABLE IF NOT EXISTS ".NINJA_FORMS_FIELDS_TABLE_NAME." ( 
  56. `id` int(11) NOT NULL AUTO_INCREMENT,  
  57. `form_id` int(11) NOT NULL,  
  58. `type` varchar(255) CHARACTER SET utf8 NOT NULL,  
  59. `order` int(11) NOT NULL,  
  60. `data` longtext CHARACTER SET utf8 NOT NULL,  
  61. `fav_id` int(11) DEFAULT NULL,  
  62. `def_id` int(11) DEFAULT NULL,  
  63. PRIMARY KEY (`id`) 
  64. ) DEFAULT CHARSET=utf8 ;"; 
  65.  
  66. dbDelta($sql); 
  67.  
  68. /** 
  69. * Add our table structure for version 2.8. 
  70. */ 
  71.  
  72. // Create our object meta table 
  73. $sql = "CREATE TABLE IF NOT EXISTS ". NF_OBJECT_META_TABLE_NAME . " ( 
  74. `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  75. `object_id` bigint(20) NOT NULL,  
  76. `meta_key` varchar(255) NOT NULL,  
  77. `meta_value` longtext NOT NULL,  
  78. PRIMARY KEY (`id`) 
  79. ) DEFAULT CHARSET=utf8;"; 
  80.  
  81. dbDelta( $sql ); 
  82.  
  83. // Create our object table 
  84. $sql = "CREATE TABLE IF NOT EXISTS " . NF_OBJECTS_TABLE_NAME . " ( 
  85. `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  86. `type` varchar(255) NOT NULL,  
  87. PRIMARY KEY (`id`) 
  88. ) DEFAULT CHARSET=utf8;"; 
  89.  
  90. dbDelta( $sql ); 
  91.  
  92. // Create our object relationships table 
  93.  
  94. $sql = "CREATE TABLE IF NOT EXISTS " . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . " ( 
  95. `id` bigint(20) NOT NULL AUTO_INCREMENT,  
  96. `child_id` bigint(20) NOT NULL,  
  97. `parent_id` bigint(20) NOT NULL,  
  98. `child_type` varchar(255) NOT NULL,  
  99. `parent_type` varchar(255) NOT NULL,  
  100. PRIMARY KEY (`id`) 
  101. ) DEFAULT CHARSET=utf8;"; 
  102.  
  103. dbDelta( $sql ); 
  104.  
  105. $preview_page = get_page_by_title( $title ); 
  106. if( !$preview_page ) { 
  107. // Create preview page object 
  108. $preview_post = array( 
  109. 'post_title' => $title,  
  110. 'post_content' => 'This is a preview of how this form will appear on your website',  
  111. 'post_status' => 'draft',  
  112. 'post_type' => 'page' 
  113. ); 
  114.  
  115. // Insert the page into the database 
  116. $page_id = wp_insert_post( $preview_post ); 
  117. }else{ 
  118. $page_id = $preview_page->ID; 
  119.  
  120. $opt['preview_id'] = $page_id; 
  121.  
  122. $opt['version'] = NF_PLUGIN_VERSION
  123.  
  124. $current_settings = get_option( 'ninja_forms_settings', false ); 
  125.  
  126. if ( ! $current_settings ) { 
  127. update_option( 'nf_convert_notifications_complete', true ); 
  128. update_option( 'nf_convert_subs_step', 'complete' ); 
  129. update_option( 'nf_upgrade_notice', 'closed' ); 
  130. update_option( 'nf_update_email_settings_complete', true ); 
  131. update_option( 'nf_email_fav_updated', true ); 
  132. update_option( 'nf_convert_forms_complete', true ); 
  133. update_option( nf_database_migrations, true ); 
  134.  
  135. update_option( "ninja_forms_settings", $opt ); 
  136. update_option( 'ninja_forms_version', NF_PLUGIN_VERSION ); 
  137.  
  138. // check for an existing form 
  139. $starter_form_exists = ninja_forms_starter_form_exists(); 
  140.  
  141. if ( ! $starter_form_exists ) { 
  142. // if a starter form doesn't exist them create it 
  143.  
  144. // Add the transient to redirect 
  145. // set_transient( '_nf_activation_redirect', true, 30 ); 
  146.  
  147. } else { // We're network activating. 
  148. header( 'Location: ' . network_admin_url( 'plugins.php?deactivate=true&nf_action=network_activation_error' ) ); 
  149. exit;