2. pluggable plugins are...
• also known as core plugins
• built by a team of developers rather than a single developer
• more secure
• less buggy
• easier to customize than a traditional plugin
• supported by original developers
• ever changing
7. class subClass extends baseClass {
protected function publish( $obj ) {
// method must be defined
wp_insert_post( $obj );
}
abstract class baseClass { protected function update( $obj ) {
// method must be defined
abstract protected function publish( $obj ); wp_update_post( $obj );
abstract protected function update( $obj ); }
abstract protected function delete( $obj );
protected function delete( $obj ) {
public function get_post( $id ) { // method must be defined
$post = get_posts( 'p='.$id ); wp_delete_post( $obj );
return $post; }
}
} }
$sub = new subClass;
$my_post = $sub->get_post( 1 );
$my_post[0]->post_content = 'Some new content';
$sub->update( $my_post[0] );
$sub->delete( 1 );
PHP5 OOP implementation
8. WordPress concepts: actions & filters
• actions allow themes and plugins to execute code
• filters allow themes and plugins to modify output
• these are what make WordPress REALLY awesome
9. WordPress actions
do_action( 'non_clashing_action_name', $args );
add_action( 'non_clashing_action_name', 'my_hooking_function', (int) priority, (int) arguments );
function my_hooking_function( $args ) {
// execute some code here
}
10. class subClass extends baseClass {
function __construct() {
add_action( 'base_class_publish',
array( &$this, 'notify_me' ), 1, 1 );
}
protected function publish( $obj ) {
do_action( 'base_class_publish', $obj );
wp_insert_post( $obj );
}
abstract class baseClass { protected function notify_me( $obj ) {
wp_mail(
abstract protected function publish( $obj ); 'brandon@pixeljar.net',
abstract protected function update( $obj ); 'post published',
abstract protected function delete( $obj ); print_r( $obj, true )
);
public function get_post( $id ) { }
$post = get_posts( 'p='.$id );
return $post; protected function update( $obj ) {}
} protected function delete( $obj ) {}
} }
$sub = new subClass;
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8, 39 ) );
$sub->publish( $my_post );
PHP5 OOP + WordPress actions implementation
18. real-world example: social me
• custom post types for storing social media content
• opt-in extension manager
• extensions handle social networks
19. real-world example: social me twitter
• authenticates with oauth
• imports tweets as custom post type
• custom taxonomies for hash tags and @mentions
• post to twitter via actions
• changed defaults via filters