WP Post Like (Heart) System Plugin or integrated?


#1

Hi :), i am developing small portfolio wp theme, it has post LIKE (heart) system, should i make plugin for my LIKE (heart) system ?or just include in the theme? thanks :slight_smile:


#2

Your best approach is to have a plugin for this as users can change themes and still have a way of using their likes.


#3

A plugin of course. :slight_smile: And use WP hooks to integrate it.


#5

OK, thanks everyone.

This Post LIke System is integrated into the theme, the main function which displays likes is called in index.php within the loop. I’m wondering how could other themes use this system
if it can be shown only by calling function within the theme?


#6

Well that is your problem. The whole functionality of the system needs to be in the plugin and the themes should only call a function to display the markup. So any theme can do that.


#7

ok thanks.

As you said if I have all functionality in plugin and only function is needed for Like System to be work thats ok, I will do that, but

  1. if user changes the theme (from my theme to another) than he/she should edit new theme’s file and copy/pase my plugins main function which displays actual content of Like System? Am I right?

  2. if I won’t put this functionality in plugin will my theme be rejected for that?

Many thanks in advance :slight_smile:


#8
avmna said

OK, thanks everyone.

This Post LIke System is integrated into the theme, the main function which displays likes is called in index.php within the loop. I’m wondering how could other themes use this system
if it can be shown only by calling function within the theme?

Well, why I said WP hooks? Because it makes simple to extend any plugin or theme.

Separate this functionalitty in a plugin and make sure it works. Once you got that done add the following line in your theme where the likes button should be.

do_action('theme_likes_area');

Now in your functions.php add this:

function add_to_theme_likes_area(){
    if( function_exists('pl_likes') ){
       echo pl_likes(); 
   }
}
add_action('theme_likes_area', 'add_to_theme_likes_area');

Replace: pl_likes with the function name that calls your plugin.

If I would like to use your plugin in a nother theme all what I’ll have to do is to copy the code above in my theme and add do_action in the place where I need the likes button. Or change add_action and the function to avoid theme modification. like this:

function add_to_theme_likes_area($content){
    if( function_exists('pl_likes') ){
       return $content . pl_likes(); 
   }
   else{
       return $content;
   }
}
add_filter('the_content', 'add_to_theme_likes_area');

See, everything is possible and simple, you just make sure that your plugin is theme independent.

Cheers, Andrei.


#9

Thanks Andrei.

Yes everything is simple there but, copy/paste of that function won’t help to everyone, there are some styling, custom functionality which are controlled from theme customizer.

Will my theme be rejected if I don’t put that functionality into the plugin, please answer…


#10
avmna said

Thanks Andrei.

Yes everything is simple there but, copy/paste of that function won’t help to everyone, there are some styling, custom functionality which are controlled from theme customizer.

Will my theme be rejected if I don’t put that functionality into the plugin, please answer…

Add the minimal styles to the plugin in a static file, for settings use WP Settings API and if you want to allow the user to change the style you can use the customizer as a bonus.