Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active April 5, 2019 13:00
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save danielpataki/c0dd60f310eac47df91e to your computer and use it in GitHub Desktop.
Save danielpataki/c0dd60f310eac47df91e to your computer and use it in GitHub Desktop.
Creating a Plugin
<?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
*/
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 );
}
add_action( 'wp_enqueue_scripts', 'my_enqueued_assets' );
function my_enqueued_assets() {
wp_enqueue_style( 'my-font', '//fonts.googleapis.com/css?family=Roboto' );
}
add_filter('login_errors','login_error_message');
function login_error_message( $error ){
$error = "Incorrect login information, stay out!";
return $error;
}
<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>
add_action( 'wp_head', 'my_facebook_tags' );
function my_facebook_tags() {
if( is_single() ) {
?>
<meta property="og:title" content="<?php the_title() ?>" />
<meta property="og:site_name" content="<?php bloginfo( 'name' ) ?>" />
<meta property="og:url" content="<?php the_permalink() ?>" />
<meta property="og:description" content="<?php the_excerpt() ?>" />
<meta property="og:type" content="article" />
<?php
if ( has_post_thumbnail() ) :
$image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
?>
<meta property="og:image" content="<?php echo $image[0]; ?>"/>
<?php endif; ?>
<?php
}
}
<meta property="og:title" content="A Beginner's Guide To Creating A WordPress Plugin" />
<meta property="og:site_name" content="WPMU DEV Blog" />
<meta property="og:url" content="http://premium.wpmudev.org/blog/a-beginners-guide-to-creating-a-wordrdpress-plugin" />
<meta property="og:description" content="A guide for beginners to help them get started with plugin creation in WordPress" />
<meta property="og:type" content="article" />
<meta property="og:image" content="http://premium.wpmudev.org/blog/wp-content/uploads/2014/12/plugin-creation.jpg"/>
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 );
}
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' );
}
add_action('admin_menu', 'my_plugin_menu');
function my_plugin_menu() {
add_menu_page('My Plugin Settings', 'Plugin Settings', 'administrator', 'my-plugin-settings', 'my_plugin_settings_page', 'dashicons-admin-generic');
}
function my_plugin_settings_page() {
//
}
<h2><?php _e( 'Staff Details', 'my-staff-plugin' ) ?></h2>
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