Ripro9.0免扩展二开版WordPress博客主题Ripro全解密无后门
2024-12-26 13:58
<?php
if (!defined('ABSPATH')) {
die;
} // Cannot access directly.
/
function ajax_getcat_post()
{
global $wp_query;
header('Content-type:application/html; Charset=utf-8');
// $paged = !empty($_POST['paged']) ? esc_sql($_POST['paged']) : 1;
$cat = !empty($_POST['cat']) ? (int)$_POST['cat'] : '';
/////////////
$is_cao_site_list_blog = is_cao_site_list_blog();
if ($is_cao_site_list_blog) {
$latest_layout = 'bloglist';
} else {
$latest_layout = _cao('latest_layout', 'grid');
}
/////////////
$args = array(
'cat' => $cat,
'post_status' => 'publish',
);
$data = new WP_Query($args);
if ($data->have_posts()) {
while ($data->have_posts()) : $data->the_post();
get_template_part('parts/template-parts/content', $latest_layout);
endwhile;
} else {
get_template_part('parts/template-parts/content', 'none');
}
wp_reset_postdata();
exit();
}
add_action('wp_ajax_ajax_getcat_post', 'ajax_getcat_post');
add_action('wp_ajax_nopriv_ajax_getcat_post', 'ajax_getcat_post');
function ajax_search()
{
global $wp_query;
header('Content-type:application/json; Charset=utf-8');
$text = !empty($_POST['text']) ? esc_sql($_POST['text']) : null;
$args = array('s' => $text,'posts_per_page' => 5);
$array_posts = array();
$data = new WP_Query($args);
while ($data->have_posts()) : $data->the_post();
array_push($array_posts, array("title"=>get_the_title(),"url"=>get_permalink(),"img"=>_get_post_timthumb_src() ));
endwhile;
echo json_encode($array_posts);
exit();
}
add_action('wp_ajax_ajax_search', 'ajax_search');
add_action('wp_ajax_nopriv_ajax_search', 'ajax_search');
function get_mpweixin_qr()
{
header('Content-type:application/json; Charset=utf-8');
$wxConfig = _cao('oauth_mpweixin');
$CaoMpWeixin = new CaoMpWeixin($wxConfig);
echo json_encode($CaoMpWeixin->getLoginQr());
exit;
}
add_action('wp_ajax_get_mpweixin_qr', 'get_mpweixin_qr');
add_action('wp_ajax_nopriv_get_mpweixin_qr', 'get_mpweixin_qr');
function check_mpweixin_qr()
{
header('Content-type:application/json; Charset=utf-8');
$scene_id = !empty($_POST['scene_id']) ? sanitize_text_field(wp_unslash($_POST[ 'scene_id' ])) : null;
global $current_user;
$current_user_id =$current_user->ID;
// 查询数据库
global $wpdb, $mpwx_log_table_name;
$res = $wpdb->get_row($wpdb->prepare("SELECT * FROM $mpwx_log_table_name WHERE scene_id = %s ", esc_sql($scene_id)));
if (($res->create_time+180)<time()) {
echo json_encode(array('status' => 0));
exit;
//180秒内有效
}
// 查询openid
$_prefix = 'mpweixin';
$_openid_meta_key = 'open_' . $_prefix . '_openid';
$user_exist = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key=%s AND meta_value=%s", $_openid_meta_key, $res->openid));
if (!$current_user_id && !empty($res) && $res->scene_id == $scene_id && !empty($res->openid)) {
if (!empty($user_exist)) {
wp_set_auth_cookie($user_exist, true, false);
$user = get_user_by('id', $user_exist);
do_action('wp_login', $user->user_login, $user); // 保证挂载的action执行
}
$status = 1;
} else {
$status = 0;
}
echo json_encode(array('status' => $status));
exit;
}
add_action('wp_ajax_check_mpweixin_qr', 'check_mpweixin_qr');
add_action('wp_ajax_nopriv_check_mpweixin_qr', 'check_mpweixin_qr');
function user_login()
{
header('Content-type:application/json; Charset=utf-8');
$username = !empty($_POST['username']) ? esc_sql($_POST['username']) : null;
$password = !empty($_POST['password']) ? esc_sql($_POST['password']) : null;
$rememberme = !empty($_POST['rememberme']) ? esc_sql($_POST['rememberme']) : null;
if (_cao('is_close_wplogin')) {
echo json_encode(array('status' => '0', 'msg' => '仅开放社交账号登录'));
exit;
}
$login_data = array();
$login_data['user_login'] = $username;
$login_data['user_password'] = $password;
$login_data['remember'] = false;