Apr.16

Working on wordpress multisite for plugin relation to user table

We have one Global variable which will show all the (global $wpdb;) database related object.  I have to show all global user for the global user relational plugin.

global $wpdb;

echo $wpdb->base_prefix;

/* This is the name of our global prefix table name*/

Apr.16

Adding Styles Css page on our plugin in Front or Admin Side

We need to initialize the function activation on loading the plugin path we have generally two option for loading the file content on initialization of plugin or initialization on admin section.

If we have object oriented concept on plugin we generally call the function on __constructor function.

public function __construct( $file )
{
/* Adding styles sheet page when my plugin activated for the front part */
add_action(‘init’,array($this,’add_my_style_page’));

/* Initialize on loading the admin part styles sheet */
add_action(‘admin_init’,array($this,’add_my_style_page’));

/* Initialize when loading admin menu for the  admin part styles sheet */

add_action( ‘admin_menu’, ‘my_plugin_admin_menu’ );
}

function add_my_style_page(){
wp_enqueue_style(‘style-name’,  plugins_url(‘/css/style.css’,__FILE__));
}

function my_plugin_admin_menu() {

/* Register our plugin page */

$page = add_submenu_page( ‘edit.php’, __( ‘My Plugin’, ‘myPlugin’ ), __( ‘My Plugin’, ‘myPlugin’ ), ‘administrator’, __FILE__, ‘my_plugin_manage_menu’ );

/* Using registered $page handle to hook stylesheet loading */

add_action( ‘admin_print_styles-‘ . $page, ‘my_plugin_admin_styles’ );

}

function my_plugin_admin_styles() {

/* * It will be called only on your plugin admin page, enqueue our stylesheet here */

wp_enqueue_style( ‘myPluginStylesheet’ );

}

function my_plugin_manage_menu() {

/* Output our admin page */

}

Apr.11

Adding Content on Plugin Desciption Row

I have used the wordpress function for other detail of my plugin.  These Meta text caontent are html, link or content.  I have added the content text of Faq, Read Me, Donate Link and Other Icon for my facebook and other social media link.

Code Used

add_filter( ‘plugin_row_meta’,’pkb_advert_pop_links’,10,2);
function pkb_advert_pop_links($links, $file)
{
$base = plugin_basename(PKB_ADVERTISE_PLUGIN_FILE);
if ($file == $base)
{

$links[] = ‘<a href=”http://prakashbhandari.info.np/wordpress/wordpress-plugins/advertise-pop/”  title=”FAQ”>FAQ</a>’;
$links[] = ‘<a href=”http://prakashbhandari.info.np/wordpress/wordpress-plugins/advertise-pop/”  title=”Read Me”>README</a>’;
$links[] = ‘<a href=”http://prakashbhandari.info.np/donate/1″ title=”Donate”>DONATE</a>’;

$links[] = ‘<a href=”http://prakashbhandari.info.np/” title=”Support”></a>’;
$links[] = ‘<a href=”https://www.facebook.com/prakashkumarbhandari” title=”Facebook”></a>’;
$links[] = ‘<a href=”https://plus.google.com/110174231559558592568″ title=”+1 us on Google+”></a>’;
}
return $links;
}

 

 

Replacing the wordpress thumbnail (html) display area

WordPress have the add_filter function which can remove or add text to the relevant content area.

We have changed the Title Content and Thumbnail Image by other text or image in my project.

function pkb_my_post_image_html($html, $post_id, $post_image_id ) {

$html = “<a href='”.$pkb_replaced_thumb_href.”‘ target=’_blank’><img src='”.site_url().”/image/myimage.jpg’></a>”;

return $html;
}
add_filter( ‘post_thumbnail_html’, ‘pkb_my_post_image_html’, 10, 3 );

 

There are other filters which we use to our plugin or theme function.

 

Add / Remove Modify Title :

function my_title_replace_filter($title) {

return ‘My added title ::’.$title;

}

add_filter(‘the_title’, ‘my_title_replace_filter’ );

 

Add / Remove Modify Content :

function my_content_replace_filter($content) {

return ‘My added Content::’.$content;

}

add_filter(‘the_content’, ‘my_content_replace_filter’ );

 

add_action( ‘wp_head’, ‘wpcandy_actionhook_example’ );
function wpcandy_actionhook_example () {
echo ‘<meta name=”description” content=”This is the meta description for this page.” />’ ;
} // End wpcandy_actionhook_example()