Last active
September 7, 2017 11:13
-
-
Save danielpataki/2bbe395f732c7ee90f0a to your computer and use it in GitHub Desktop.
Getting Started With Plugins
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
function my_tracking_code() { | |
echo 'Paste tracking code from Google Analytics here'; | |
} | |
add_action( 'wp_footer', 'my_tracking_code' ); |
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
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' ); | |
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
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 ); |
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
function our_excerpt_more( $more ) { | |
return 'there's more...'; | |
} | |
add_filter( 'excerpt_more', 'our_excerpt_more' ); |
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
/** | |
* 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 | |
*/ |
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
add_filter( 'product_count', 'carousel_product_count' ); | |
function carousel_product_count( $count ) { | |
return 3; | |
} |
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
$product_count = apply_filters( 'product_count', 10 ); | |
$products = get_products( $product_count ); | |
show_products(); |
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
$products = get_products( 10 ); | |
show_products(); |
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
add_action( 'admin_init', 'tweetlink_settings' ); | |
function tweetlink_settings() { | |
register_setting( 'tweetlink_settings', 'twitter_account' ); | |
} |
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
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 | |
} |
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
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>'; | |
} |
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
function tweet_link( $content ) { | |
return $content . '<p><a href="https://twitter.com/intent/tweet?url='.get_permalink().'">Tweet about this</a></p>'; | |
} | |
add_action( 'the_content', 'tweet_link' ); |
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
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
just thought you'd want to know that article is spelled wrong in 'email.php'
your lessons are amazing. this is my first course with WPMUDEV and I feel like an idiot for not jumping on the bandwagon sooner.