Plugin Directory

Changeset 1108796


Ignore:
Timestamp:
03/09/2015 02:27:45 PM (11 years ago)
Author:
richymilo
Message:

Added support for single post

Location:
simple-custom-post-likes/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • simple-custom-post-likes/trunk/admin.php

    r1103117 r1108796  
    1717    <tr>
    1818        <th scope="row"><label for="content_element">Select Element to append to</label></th>
    19         <td><input id="content_element" type="text" name="content_element" value="<?php if(get_option( 'favourates_element' )) {
     19        <td><input type="text" name="content_element" placeholder="<?php if(get_option( 'favourates_element', 'post' )) {
    2020            echo get_option( 'favourates_element' );
    2121            } ?>"></td>
     
    4949        $type = $_POST['content_element'];
    5050            update_option( 'favourates_element', $type , '', 'yes' );
    51             ?>
    52         <script>
    53         jQuery(document).ready(function($) {
    54             jQuery('#content_element').val("<?php echo $type; ?>");
    55         });</script>
    56             <?php
    5751    }
    5852?>
  • simple-custom-post-likes/trunk/index.php

    r1103165 r1108796  
    11<?php
    2 /**
    3  * Plugin Name: Simple Featured post likes
    4  * Description: Adds Likes/Favorites to Wordpress post or custom post type.
    5  * Author: Richard Miles
    6  * Version: 1.0.1
    7  * Author URI: http://richymiles.wordpress.com
    8  */
    9 
     2/*
     3Plugin Name: Simple Featured post likes
     4Description: Adds Likes/Favorites to Wordpress post or custom post type.
     5Author: Richard Miles
     6Version: 1.0
     7Author URI: http://richymiles.wordpress.com
     8*/
    109
    1110function get_users_array($post_id) {
    1211    $new_array = array();
    1312    $array = get_post_meta($post_id,'favourite_users');
    14     if (!$array) {
     13    if (empty($array) || is_null($array)) {
    1514        return false;
    1615     }
    17     foreach($array[0] as $key => $value)
     16    foreach($array[0] as $key => $value) {
    1817     $new_array[$key] = $value;
     18    }
    1919    return $new_array;
    2020}
     
    2323    $new_array = array();
    2424    $array = get_post_meta($post_id,'favourite_users');
    25     if (! $array) {
    26         return false;
     25    if (empty($array) || is_null($array)) {
     26        return 0;
    2727     }
    2828     $count = 0;
     
    3939        if (isset($_REQUEST['post_id'])) {
    4040            $users = get_users_array($_REQUEST['post_id']);
    41             $liked;
     41            $liked = false;
    4242            if ($users) {
    4343                if(!in_array(get_user_id(), $users)) {
    44                     ?>
    45                     <?php
    46                     $liked = false;
    47             array_push($users, get_user_id());
    48             update_post_meta($_REQUEST['post_id'], 'favourite_users', $users);
     44                    array_push($users, get_user_id());
     45                    update_post_meta($_REQUEST['post_id'], 'favourite_users', $users);
    4946                } else {
    5047                    $liked = true;
     
    7976// }
    8077
    81 add_action('admin_menu', 'add_likes_menu');
     78add_action('admin_menu', 'my_plugin_menu');
    8279
    83 function add_likes_menu() {
     80function my_plugin_menu() {
    8481    add_options_page('My Options', 'Favourite Posts', 'manage_options', plugin_dir_path( __FILE__ ) . 'admin.php');
    8582}
    8683
    8784
    88 add_action('wp_head','simple_likes_ajaxurl');
     85add_action('wp_head','pluginname_ajaxurl');
    8986
    90 function simple_likes_ajaxurl() {
     87function pluginname_ajaxurl() {
    9188?>
    9289<script type="text/javascript">
     
    138135//status is the http request status - 200 for all good, 404 not found e.t.c
    139136    jQuery('#user_favourite').val(value);
    140     console.log("success");
     137    console.log(value);
    141138    if (obj.liked) {
    142139        jQuery('#user_favourite').css('background' , 'tomato');
     
    153150            <?php
    154151            // echo get_user_id();
    155             $content .= ob_get_contents();
     152            if (is_single()) {
     153                $content .= ob_get_contents();
     154            }
     155       
    156156            ob_end_clean();
    157157        }
  • simple-custom-post-likes/trunk/readme.txt

    r1103168 r1108796  
    11=== Simple custom post likes ===
    2 Contributors: richymilo, leogopal
    3 Donate link: http://richymiles.wordpress.com
    4 Tags: custom post types, likes, featured, voting, rating, polling
    5 Requires at least: 3.9
     2Contributors: richymilo
     3Donate link: http://wobble.co.za/
     4Tags: custom post types, likes, featured
     5Requires at least: 3.0.1
    66Tested up to: 4.1.1
    7 Stable tag: 1.0.1
     7Stable tag: 4.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3636
    3737== Changelog ==
    38 = 1.0.1 =
    39 * Minor Changes
    40 * Added Uninstall.php to clean up database when uninstalled.
    41 
    4238= 1.0 =
    4339* First Version, Basic Working copy
    44 * Fixed a few backend bugs, uses value now instead of placeholder
     40
     41= 1.0.1 =
     42* Support added for single post
Note: See TracChangeset for help on using the changeset viewer.