Last active
April 5, 2019 13:00
-
-
Save danielpataki/c0dd60f310eac47df91e to your computer and use it in GitHub Desktop.
Creating a Plugin
This file contains hidden or 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
<?php | |
/** | |
* Plugin Name: My Facebook Tags | |
* Plugin URI: http://danielpataki.com | |
* Description: This plugin adds some Facebook Open Graph tags to our single posts. | |
* Version: 1.0.0 | |
* Author: Daniel Pataki | |
* Author URI: http://danielpataki.com | |
* License: GPL2 | |
*/ |
This file contains hidden or 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
add_action( 'wp_enqueue_scripts', 'my_enqueued_assets' ); | |
function my_enqueued_assets() { | |
wp_enqueue_script( 'my-script', plugin_dir_url( __FILE__ ) . '/js/my-script.js', array( 'jquery' ), '1.0', true ); | |
} |
This file contains hidden or 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
add_action( 'wp_enqueue_scripts', 'my_enqueued_assets' ); | |
function my_enqueued_assets() { | |
wp_enqueue_style( 'my-font', '//fonts.googleapis.com/css?family=Roboto' ); | |
} |
This file contains hidden or 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
add_filter('login_errors','login_error_message'); | |
function login_error_message( $error ){ | |
$error = "Incorrect login information, stay out!"; | |
return $error; | |
} |
This file contains hidden or 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
<div class="wrap"> | |
<h2>Staff Details</h2> | |
<form method="post" action="options.php"> | |
<?php settings_fields( 'my-plugin-settings-group' ); ?> | |
<?php do_settings_sections( 'my-plugin-settings-group' ); ?> | |
<table class="form-table"> | |
<tr valign="top"> | |
<th scope="row">Accountant Name</th> | |
<td><input type="text" name="accountant_name" value="<?php echo esc_attr( get_option('accountant_name') ); ?>" /></td> | |
</tr> | |
<tr valign="top"> | |
<th scope="row">Accountant Phone Number</th> | |
<td><input type="text" name="accountant_phone" value="<?php echo esc_attr( get_option('accountant_phone') ); ?>" /></td> | |
</tr> | |
<tr valign="top"> | |
<th scope="row">Accountant Email</th> | |
<td><input type="text" name="accountant_email" value="<?php echo esc_attr( get_option('accountant_email') ); ?>" /></td> | |
</tr> | |
</table> | |
<?php submit_button(); ?> | |
</form> | |
</div> |
This file contains hidden or 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
add_action( 'publish_post', 'post_published_notification', 10, 2 ); | |
function post_published_notification( $ID, $post ) { | |
$email = get_the_author_meta( 'user_email', $post->post_author ); | |
$subject = 'Published ' . $post->post_title; | |
$message = 'We just published your post: ' . $post->post_title . ' take a look: ' . get_permalink( $ID ); | |
wp_mail( $email, $subject, $message ); | |
} |
This file contains hidden or 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
add_action( 'admin_init', 'my_plugin_settings' ); | |
function my_plugin_settings() { | |
register_setting( 'my-plugin-settings-group', 'accountant_name' ); | |
register_setting( 'my-plugin-settings-group', 'accountant_phone' ); | |
register_setting( 'my-plugin-settings-group', 'accountant_email' ); | |
} |
This file contains hidden or 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
<h2><?php _e( 'Staff Details', 'my-staff-plugin' ) ?></h2> |
This file contains hidden or 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
add_action( 'wp_head', 'my_facebook_tags' ); | |
function my_facebook_tags() { | |
echo 'I am in the head section'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment