| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/www.huomanshiye.com/wp-content/themes/betheme/functions/ |
Upload File : |
<?php
if( ! defined( 'ABSPATH' ) ){
exit; // Exit if accessed directly
}
if (! class_exists('Mfn_Love')) {
class Mfn_Love
{
public function __construct() {
add_action('wp_ajax_mfn_love', array( $this, 'ajax' ));
add_action('wp_ajax_nopriv_mfn_love', array( $this, 'ajax' ));
add_action('wp_ajax_mfn_love_randomize', array( $this, 'randomize' ));
add_action('wp_ajax_nopriv_mfn_love_randomize', array( $this, 'randomize' ));
}
public function ajax($post_id) {
echo esc_attr($this->love($_POST['post_id']));
exit;
}
public function randomize() {
$post_type = htmlspecialchars(stripslashes($_POST['post_type']));
$aPosts = get_posts(array(
'posts_per_page' => -1,
'post_type' => $post_type ? $post_type : false,
'fields' => 'ids',
));
if (is_array($aPosts)) {
foreach ($aPosts as $post) {
$love_count = rand(10, 100); // Random number of loves [min:10, max:100]
update_post_meta($post, 'mfn-post-love', $love_count);
}
esc_html_e('Love randomized', 'mfn-opts');
}
exit;
}
public function love($post_id) {
if (! is_numeric($post_id)) {
return;
}
$love_count = get_post_meta($post_id, 'mfn-post-love', true);
if (isset($_COOKIE['mfn-post-love-'. $post_id])) {
return $love_count;
}
$love_count++;
update_post_meta($post_id, 'mfn-post-love', $love_count);
setcookie('mfn-post-love-'. $post_id, $post_id, time() + (365 * 24 * 60 * 60), '/');
return $love_count;
}
public static function get() {
global $post;
if (! mfn_opts_get('love')) {
return false;
}
$love_count = get_post_meta($post->ID, 'mfn-post-love', true);
if (!$love_count) {
$love_count = 0;
add_post_meta($post->ID, 'mfn-post-love', $love_count, true);
}
$class = '';
if (isset($_COOKIE['mfn-post-love-'. $post->ID])) {
$class = 'loved';
}
return '<a href="#" class="mfn-love '. esc_attr($class) .'" data-id="'. esc_attr($post->ID) .'"><span class="icons-wrapper"><i class="icon-heart-empty-fa"></i><i class="icon-heart-fa"></i></span><span class="label">'. esc_html($love_count) .'</span></a>';
}
}
}
new Mfn_Love();
if (! function_exists('mfn_love')) {
function mfn_love($return = '')
{
return Mfn_Love::get();
}
}