Instantiate class to be available to all plugin functions

Ryan McCue had a nice idea for his plugin Hopper: add a callback for a custom filter to return the current instance. Sample code for the plugin: class Plugin_Class { public function __construct() { add_filter( ‘get_plugin_class’, array ( $this, ‘provide_instance’ ) ); } function provide_instance() { return $this; } } In a theme or a … Read more

WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page

I’ll preface this by saying I think it’s a really bad idea, but you could circumvent the admin UI by hooking an action that happens after things are initialized, but before any output occurs: function my_admin_ui(){ if( isset( $_GET[‘page’] ) && ‘myPlugin-ui’ == $_GET[‘page’] ){ include( plugin_dir_path( __FILE__ ) . ‘views/myPlugin-ui.php’ ); exit; } } … Read more

PHP code to call image Caption, Alternative Text, and Decription?

WordPress stores image (attachment) data as follows: Description: post_content field Caption: post_excerpt field Alt: _wp_attachment_image_alt meta value And in code, that translates to: // Description echo $post->post_content; // Raw the_content(); // Caption (description as fallback) the_excerpt(); // Caption (explicitly) echo $post->post_excerpt; // Raw if ( has_excerpt() ) { the_excerpt(); } // Alt echo get_post_meta( $post->ID, … Read more

WordPress with php 5.5 and zend opcache

Opcache is transparent for WordPress (as it is to any PHP application). However if you had been using APC for object cache (key/value store) via plugin — that function is not available in new bundled Zend cache, it only does opcode caching. You would need to replace object cache with something different (APCu/Memcache/Redis/etc).

have_posts() execution failure

Your problem is the weird code at the top of the page. To understand what’s happening let me state a standard loop in pseudocode: if we still have posts to process while we still have posts to process mark this post as processed and move to the next one do things with it ( like … Read more