function __construct() { $this->url = DP_Helpers::get_dir_url(__FILE__); add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); add_action('_admin_menu', array($this, 'add_admin_page')); //add_action('admin_menu', array($this, 'acf_add_local_field_group')); add_action('pre_get_posts', array($this, 'pre_get_posts')); add_action('wp_head', array($this, 'wp_head')); }
function button($post_id, $args = '') { $defaults = array('tag' => 'button', 'class' => '', 'atts' => array(), 'attr' => '', 'show_icon' => true, 'show_text' => true, 'echo' => true); $args = wp_parse_args($args, $defaults); $default_labels = array('add' => __('Favorite', 'dp'), 'remove' => __('Favorited', 'dp'), 'ing' => __('Working...'), 'remove_title' => __('Add to favorite', 'dp'), 'add_title' => __('Remove from favorite', 'dp')); $args['labels'] = !empty($args['labels']) ? wp_parse_args($args['labels'], $default_labels) : $default_labels; extract($args); if (!$post_id) { global $post; $post_id = $post->ID; } $post_id = (int) $post_id; $login_required = true; // Like Button $button_atts = array('href' => '#', 'onclick' => ';return false;', 'class' => 'dp-favorite-posts-button', 'data-pid' => $post_id, 'disabled' => 'disabled', 'data-labels' => wp_json_encode($labels)); $content = ''; if ($show_icon) { $content .= '<i class="icon"></i>'; } $text = ''; if ($this->in_list($post_id)) { $button_atts['class'] .= ' added'; $button_atts['title'] = $labels['remove_title']; $text = $labels['remove']; } else { $button_atts['title'] = $labels['add_title']; $text = $labels['remove']; } if ($show_text) { $content .= '<span class="text">' . $text . '</span>'; } $r = '<div class="dp-favorite-posts">'; $r .= '<a' . DP_Helpers::array2attr($button_atts) . '>' . $content . '</a>'; $r .= '</div>'; if ($echo) { echo $r; } else { return $r; } }
function render_button($object_id, $vote_type, $args = array()) { extract($args); $atts = array('href' => '#', 'class' => $vote_type); $text = ''; if ($this->is_current_user_voted($object_id, $vote_type)) { //$text = $labels['voted']; $atts['class'] .= ' voted'; //$atts['title'] = $labels['voted_title']; } else { //$text = $labels['vote']; //$atts['title'] = $labels['vote_title']; } $content = ''; if ($show_icon) { $content .= '<i class="icon"></i>'; } if ($show_text) { $content .= '<span class="text">' . $text . '</span>'; } if ($show_count) { $content .= '<span class="count">' . $this->get_vote_count($object_id, $vote_type) . '</span>'; } return '<a' . DP_Helpers::array2attr($atts) . '>' . $content . '</a>'; }