-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from MichelleBlanchette/07-01-audio-video
Module 07 • Lesson 01 • Audio + Video and Functional Code Examples
- Loading branch information
Showing
4 changed files
with
81 additions
and
91 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
plugin-developer-learning-pathway/07-Custom-Database-Tables/.wp-env.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
plugin-developer-learning-pathway/07-Custom-Database-Tables/my-plugin.php
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
plugin-developer-learning-pathway/07-Custom-Database-Tables/wpl-form-submissions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Form submissions | ||
* Version: 1.0.0 | ||
* Author: Learn WordPress | ||
* Author URI: https: //learn.wordpress.org/ | ||
* | ||
* @package wp-learn-form-submissions | ||
*/ | ||
|
||
$wp_learn_custom_table_db_version = '1.1.0'; | ||
|
||
// Only triggered when the plugin is activated, NOT when the plugin is updated. | ||
register_activation_hook( __FILE__, 'wp_learn_custom_table_create_submissions_table' ); | ||
function wp_learn_custom_table_create_submissions_table() { | ||
global $wpdb; | ||
$charset_collate = $wpdb->get_charset_collate(); | ||
|
||
// Creates table `wp_wpl_submissions`. | ||
$sql = "CREATE TABLE {$wpdb->prefix}wpl_submissions ( | ||
id mediumint(9) NOT NULL AUTO_INCREMENT, | ||
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, | ||
name tinytext NOT NULL, | ||
message text NOT NULL, | ||
url varchar(55) DEFAULT '' NOT NULL, | ||
PRIMARY KEY (id) | ||
) {$charset_collate};"; | ||
|
||
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; | ||
dbDelta( $sql ); | ||
|
||
// Set or update the currently installed version. | ||
global $wp_learn_custom_table_db_version; | ||
update_option( 'wp_learn_custom_table_db_version', $wp_learn_custom_table_db_version ); | ||
} | ||
|
||
add_action( 'plugins_loaded', 'wp_learn_custom_table_update_db_check' ); | ||
function wp_learn_custom_table_update_db_check() { | ||
global $wp_learn_custom_table_db_version; | ||
$current_custom_table_db_version = get_option( 'wp_learn_custom_table_db_version', '1.0.0' ); | ||
if ( version_compare( $current_custom_table_db_version, $wp_learn_custom_table_db_version ) ) { | ||
wp_learn_custom_table_create_submissions_table(); | ||
} | ||
} | ||
|
||
register_uninstall_hook( __FILE__, 'wp_learn_custom_table_delete_submissions_table' ); | ||
function wp_learn_custom_table_delete_submissions_table() { | ||
global $wpdb; | ||
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wpl_submissions" ); | ||
delete_option( 'wp_learn_custom_table_db_version' ); | ||
} |