Last active
August 29, 2015 14:08
-
-
Save jrobinsonc/bc6b7c185e7b67075eae to your computer and use it in GitHub Desktop.
Wordpress addon sample 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
_ |
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
<?php defined('ABSPATH') or die("No script kiddies please!"); | |
class WP_Addon | |
{ | |
public function __construct() | |
{ | |
add_shortcode('WP_Addon_shortcode', array($this, 'add_shortcode')); | |
add_action('wp_head', array($this, 'wp_head')); | |
add_action('wp_footer', array($this, 'wp_footer')); | |
add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts')); | |
} | |
public function wp_enqueue_scripts() | |
{ | |
wp_enqueue_style('WP_Addon', $this->get_file_url('styles.css'), array(), filemtime(dirname(__FILE__) .'/styles.css')); | |
wp_enqueue_script('WP_Addon', $this->get_file_url('scripts.js'), array(), filemtime(dirname(__FILE__) .'/scripts.js'), true); | |
} | |
public function add_shortcode($atts, $content) | |
{ | |
$atts = shortcode_atts(array( | |
'param1' => 'default value', | |
), $atts); | |
return $content; | |
} | |
public function wp_head() | |
{ | |
} | |
public function wp_footer() | |
{ | |
} | |
############################################### | |
# UTILS | |
############################################### | |
private function get_file_url($file_name) | |
{ | |
$file_path = dirname(__FILE__) . '/' . $file_name; | |
return str_replace(get_template_directory(), get_template_directory_uri(), $file_path); | |
} | |
} | |
new WP_Addon; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment