Skip to content

Instantly share code, notes, and snippets.

@devuri
Forked from danielpataki/basichook.php
Created September 7, 2017 11:13
Show Gist options
  • Select an option

  • Save devuri/8108c23cd5a997a2ed51739694f091df to your computer and use it in GitHub Desktop.

Select an option

Save devuri/8108c23cd5a997a2ed51739694f091df to your computer and use it in GitHub Desktop.
Getting Started With Plugins
function my_tracking_code() {
echo 'Paste tracking code from Google Analytics here';
}
add_action( 'wp_footer', 'my_tracking_code' );
function in_content_ad( $content ) {
$ad = '<div class="in-content-ad"><img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=Advertisement&w=250&h=250"></div>';
return $ad . $content;
}
add_filter( 'the_content', 'in_content_ad' );
function our_author_notification( $id, $post ) {
$author = $post->post_author;
$name = get_the_author_meta( 'display_name', $author );
$email = get_the_author_meta( 'user_email', $author );
$link = get_permalink( $id );
$message = 'Hello ' . $name . ", \n\n" . "Your artcile <a href='" . $link . "'>" . $post->post_title . "</a> has been published.";
wp_mail( $email, 'One of your posts has been published', $message );
}
add_action( 'publish_post', 'our_author_notification', 10, 2 );
function our_excerpt_more( $more ) {
return 'there's more...';
}
add_filter( 'excerpt_more', 'our_excerpt_more' );
/**
* Plugin Name: Tweet Plugin Tutorial
* Plugin URI: http://danielpataki.com
* Description: This plugin adds a simple tweet link below posts.
* Version: 1.0.0
* Author: Daniel Pataki
* Author URI: http://danielpataki.com
* License: GPL2
*/
add_filter( 'product_count', 'carousel_product_count' );
function carousel_product_count( $count ) {
return 3;
}
$product_count = apply_filters( 'product_count', 10 );
$products = get_products( $product_count );
show_products();
$products = get_products( 10 );
show_products();
add_action( 'admin_init', 'tweetlink_settings' );
function tweetlink_settings() {
register_setting( 'tweetlink_settings', 'twitter_account' );
}
function tweetlink_settings_page() {
?>
<div class="wrap">
<h2>Tweet Link Settings</h2>
<form method="post" action="options.php">
<?php settings_fields( 'tweetlink_settings' ); ?>
<?php do_settings_sections( 'tweetlink_settings' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Twitter Account</th>
<td><input type="text" name="twitter_account" value="<?php echo esc_attr( get_option('twitter_account') ); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
add_action('admin_menu', 'tweetlink_settings_menu');
function tweetlink_settings_menu() {
add_menu_page('Tweet Link Settings', 'Tweet Link', 'manage_options', 'tweetlink-settings', 'tweetlink_settings_page', 'dashicons-twitter');
}
function tweetlink_settings_page() {
echo '<div class="wrap"><h2>Tweet Link Options</h2></div>';
}
function tweet_link( $content ) {
$url = 'https://twitter.com/intent/tweet';
$url .= '?url=' . get_permalink();
$account = get_option( 'twitter_account' );
if( !empty( $account ) ) {
$url .= '&via=' . $account;
}
return $content . '<p><a href="' . $url . '">Tweet about this</a></p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment