$user_id, 'king_readlater', true ); $output = ''; if ( $rlposts ) { $recent_query = new WP_Query( [ 'post__in' => array_reverse( $rlposts ), 'orderby' => 'post__in', 'post_type' => king_post_types(), ] ); if ( $recent_query->have_posts() ) { $output .= '
' . esc_html__( 'Remove All List', 'king' ) . '
'; while ( $recent_query->have_posts() ) { $recent_query->the_post(); $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'medium' ); $output .= '
  • '; $output .= ''; $output .= '
    '; $output .= '
    '; $output .= '' . get_the_title() . ''; $output .= ''; $output .= '
    '; $output .= king_bookmark_button( $user_id, get_the_ID(), 'in-bookmarks' ); $output .= '
    '; $output .= '
  • '; } wp_reset_postdata(); } } else { $output .= '

    ' . esc_html__( 'Nothing Found ! Please add some posts to see your added bookmarks.', 'king' ) . '
    '; } echo wp_kses_post( $output ); die(); } add_action( 'wp_ajax_nopriv_king_readlater_posts', 'king_readlater_posts' ); add_action( 'wp_ajax_king_readlater_posts', 'king_readlater_posts' ); if ( ! function_exists( 'king_clean_readlater' ) ) : /** * Clean button for bookmarked posts. */ function king_clean_readlater() { $user_id = get_current_user_id(); delete_user_meta( $user_id, 'king_readlater' ); $output = '

    ' . esc_html__( 'Nothing Found ! Please add some posts to see your added bookmarks.', 'king' ) . '
    '; echo wp_kses_post( $output ); die(); } add_action( 'wp_ajax_nopriv_king_clean_readlater', 'king_clean_readlater' ); add_action( 'wp_ajax_king_clean_readlater', 'king_clean_readlater' ); endif; if ( ! function_exists( 'king_bookmark_button' ) ) : /** * King Bookmark Button. * * @param $user_id The user identifier. * @param $post_id The post identifier. * @param $bclass The user identifier. * * @return string ( description_of_the_return_value ) */ function king_bookmark_button( $user_id, $post_id, $bclass = null ) { $bookmarks = get_user_meta( $user_id, 'king_readlater', true ); $class = 'far'; $class2 = ''; if ( is_array( $bookmarks ) && in_array( $post_id, $bookmarks ) ) { $class = 'fas'; $class2 = ' added'; } $output = ''; return $output; } endif; if ( ! function_exists( 'king_header_bookmark' ) ) : /** * { function_description } * * @return string ( description_of_the_return_value ) */ function king_header_bookmark() { $user_id = get_current_user_id(); $rlposts = get_user_meta( $user_id, 'king_readlater' ); $count = isset( $rlposts['0'] ) ? count( $rlposts['0'] ) : 0; $output = '
    ' . esc_attr( $count ) . '
    '; return $output; } endif; endif; if ( ! function_exists( 'king_mega_menu' ) ) : /** * Mega Menu posts. * * @param $nmenu The nmenu. * @param $mformat The mformat. * @param $pnumber The pnumber. * @param string $porder The porder. * @param $type The type. * @param $nivm The nivm. * * @return string ( description_of_the_return_value ) */ function king_mega_menu( $nmenu, $mformat, $pnumber, $porder, $type, $nivm = null, $dleft = array() ) { $repeaters =is_array($nmenu) ? $nmenu['links_in_mega_menu'] :''; $output = '
    '; if ( $dleft ) { $output .= '

    '.wp_kses_post($dleft['title']).'

    '.wp_kses_post( $dleft['desc'] ).'
    '; } $args = array( 'post_type' => $type, 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => $pnumber, ); if ( 'c' === $nivm ) : $args['cat'] = $mformat; elseif ( 't' === $nivm ) : $args['tag_id'] = $mformat; endif; if ( 'f' === $nivm ) : $args['tax_query'] = array( array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-' . $mformat ), ), ); endif; if ( $porder === 'popular' ) : $args['meta_query'] = array( 'relation' => 'AND', '_post_views' => array( 'key' => '_post_views', 'type' => 'NUMERIC', 'compare' => 'LIKE', ), 'king_like_count' => array( 'key' => 'king_like_count', 'type' => 'NUMERIC', 'compare' => 'LIKE', ), ); $args['orderby'] = array( '_post_views' => 'DESC', 'king_like_count' => 'DESC', ); endif; if ( $repeaters ) : $output .= ''; endif; $query = new WP_query( $args ); while ( $query->have_posts() ) : $query->the_post(); ob_start(); get_template_part( 'template-parts/posts/content', 'toosimple-post' ); $output .= ob_get_contents(); ob_end_clean(); endwhile; wp_reset_postdata(); $output .= '
    '; return $output; } endif; if ( ! function_exists( 'check_array' ) ) : /** * Check Array if added or not. * * @param $user_id The user identifier. * @param $posts The post identifier. * * @return array|string ( description_of_the_return_value ) */ function check_array( $user_id, $posts ) { $post_users = ''; if ( count( $posts ) !== 0 ) { $post_users = $posts[0]; } if ( ! is_array( $post_users ) ) { $post_users = array(); } if ( ! in_array( $user_id, $post_users ) ) { $post_users[] = $user_id; } return $post_users; } endif; if ( ! function_exists( 'king_submit_newsletter' ) ) { /** * Newsletter submit code. */ function king_submit_newsletter() { if ( empty( $_POST['email'] ) || ! is_email( wp_unslash( $_POST['email'] ) ) || ( strlen( wp_unslash( $_POST['email'] ) ) > 50 ) ) { wp_send_json( array( 'error' => esc_html__( 'Email is not valid.', 'king' ) ) ); die(); } if ( isset( $_POST['privacy'] ) && empty( $_POST['privacy'] ) ) { wp_send_json( array( 'error' => esc_html__( 'Please accept the terms of our newsletter.', 'king' ) ) ); die(); } $email = sanitize_email( wp_unslash( $_POST['email'] ) ); $subscribers = get_option( 'king_subscribers' ); if ( empty( $subscribers ) || ! is_array( $subscribers ) ) { update_option( 'king_subscribers', array( $email ) ); wp_send_json( array( 'success' => esc_html__( 'Your email successfully sent.', 'king' ) ) ); die(); } else { if ( in_array( $email, $subscribers ) ) { wp_send_json( array( 'error' => esc_html__( 'This email already added.', 'king' ) ) ); die(); } array_push( $subscribers, $email ); update_option( 'king_subscribers', $subscribers ); wp_send_json( array( 'success' => esc_html__( 'Your email successfully sent.', 'king' ) ) ); die(); } } add_action( 'wp_ajax_nopriv_king_submit_newsletter', 'king_submit_newsletter' ); add_action( 'wp_ajax_king_submit_newsletter', 'king_submit_newsletter' ); } if ( ! function_exists( 'king_subscribers' ) ) { /** * Subscribers */ function king_subscribers() { if ( ! is_admin() ) { return; } global $pagenow; if ( $pagenow == 'tools.php' && current_user_can( 'download_subscribes' ) && isset( $_GET['download'] ) && $_GET['download'] == 'subscribers.csv' ) { header( 'Content-type: application/x-msdownload' ); header( 'Content-Disposition: attachment; filename=subscribers.csv' ); header( 'Pragma: no-cache' ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); echo king_generate_subscribes_csv(); exit(); } } add_action( 'admin_init', 'king_subscribers', 90 ); } if ( ! function_exists( 'king_generate_subscribes_csv' ) ) : /** * Generate csv file to download. * * @return string ( description_of_the_return_value ) */ function king_generate_subscribes_csv() { $subscribers = get_option( 'king_subscribers' ); $output = 'Email Address'; $output .= "\n"; if ( ! empty( $subscribers ) && is_array( $subscribers ) ) { foreach ( $subscribers as $nemail ) { $output .= $nemail; $output .= "\n"; } } return $output; } endif; /** * Download permission for subscribers. */ function king_subscribers_download() { $role = get_role( 'administrator' ); $role->add_cap( 'download_subscribes' ); } add_action( 'admin_init', 'king_subscribers_download', 10 ); function king_bucket() { if ( ! is_user_logged_in() ) { die( '-1' ); } $cid = ( isset( $_POST['cid'] ) && is_numeric( $_POST['cid'] ) ) ? $_POST['cid'] : ''; $pid = ( isset( $_POST['pid'] ) && is_numeric( $_POST['pid'] ) ) ? $_POST['pid'] : ''; if ( empty( $cid ) ) { die( '-1' ); } $userid = get_current_user_id(); $post_likes = get_user_meta( $userid, 'king_collection_'.$cid ); $post_users = $post_likes[0]; if ( is_array( $post_users ) && in_array( $pid, $post_users ) ) { $post_users = check_array( $pid, $post_likes ); if ( $post_users ) { $uid_key = array_search( $pid, $post_users ); unset( $post_users[ $uid_key ] ); update_user_meta( $userid, 'king_collection_'.$cid, $post_users ); } } else { $post_users = check_array( $pid, $post_likes ); if ( $post_users ) { update_user_meta( $userid, 'king_collection_'.$cid, $post_users ); } echo '1'; } die(); } add_action( 'wp_ajax_nopriv_king_bucket', 'king_bucket' ); add_action( 'wp_ajax_king_bucket', 'king_bucket' ); function king_create_bucket() { $nonce =isset( $_POST['nonce'] ) ? $_POST['nonce'] : ''; if ( wp_verify_nonce( $nonce, 'king_ccollecn' ) ) { $king_cerrors = array(); $title = sanitize_text_field( $_POST['title'] ); $uid = get_current_user_id(); if ( trim( $title ) === '' ) { $king_cerrors['title_empty'] = esc_html__( 'Title is required.', 'king' ); die( '-1' ); } if ( empty( $king_cerrors ) ) { $get_message = get_user_meta( $uid, 'king_collections', true ); if ( $get_message === '' ) { $get_message = array(); } $random = wp_rand( 10000, 999990 ); $desc = sanitize_text_field( $_POST['desc'] ); $prv = isset( $_POST['pri'] ) ? true : false ; $out = array('t' => $title, 'd' => $desc, 'p' => $prv); array_push( $get_message, $random ); update_user_meta( $uid, 'king_collections', $get_message ); update_user_meta( $uid, 'king_collect_'.$random, $out ); echo '1'; } } die(); } add_action( 'wp_ajax_nopriv_king_create_bucket', 'king_create_bucket' ); add_action( 'wp_ajax_king_create_bucket', 'king_create_bucket' ); function king_add_free_mode() { $out = true; $usid = get_current_user_id(); if ( get_field( 'enable_adfree_mode', 'option' ) ) : if ( get_field( 'hide_ads_for_logged_users', 'option' ) && is_user_logged_in() ) : $out = false; else : if ( get_field( 'hide_ads_for_verified_users', 'option' ) && get_field( 'verified_account', 'user_' . $usid ) ) : $out = false; elseif ( get_field( 'hide_ads_with_enough_points', 'option' ) ) : $user_point = get_user_meta( $usid, 'king_user_points', true ); if ( $user_point >= get_field( 'users_ad_points', 'option' ) ) : $out = false; endif; elseif ( get_field( 'hide_ads_for_premium_members', 'option' ) && get_field( 'enable_membership', 'option' ) && function_exists( 'is_woocommerce' ) && king_check_membership( null, $usid ) ) : $out = false; elseif ( get_field( 'enable_user_groups', 'option' ) && king_groups_permissions( 'groups_display_ads' ) && get_field( 'groups_display_ads', 'option' ) ) : $out = false; endif; endif; endif; return $out; } function king_ai_writer() { $input = sanitize_text_field( wp_unslash( $_POST['input'] ) ); $select = sanitize_text_field( wp_unslash( $_POST['select'] ) ); $selecti = ( $select === 'image' ) ? true : false; $openaiapi = get_field( 'openai_api_key', 'options' ); if ($selecti) { $url = 'https://api.openai.com/v1/images/generations'; $image_size = get_field( 'select_image_size', 'options' ); $imagen = get_field( 'number_of_image_generation', 'options' ); $params = array( 'prompt'=> $input, 'n'=> (int)$imagen, 'size'=> $image_size, // 512×512 1024x1024 ); } else { $url = 'https://api.openai.com/v1/chat/completions'; $max_tokens = get_field( 'max_tokens_for_content', 'options' ); $params = array( 'model' => 'gpt-3.5-turbo', 'messages' => array( array( 'role' => 'user', 'content' => $input, ), ), 'max_tokens' => (int)$max_tokens, 'stop' => '', ); } $params_json = wp_json_encode($params); $options = [ 'body' => $params_json, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer '.$openaiapi.'', ], 'timeout' => 200, ]; $response = wp_remote_post( $url, $options ); if (is_wp_error($response)) { wp_die('API request failed'); } $response_body = wp_remote_retrieve_body($response); $response_obj = json_decode($response_body, true); if ($response_obj['error']) { $text = $response_obj['error']['message']; echo wp_send_json_error($text); } else { if ($selecti) { $text = $response_obj['data']; } else { $text = preg_replace('/^\n+/', '', $response_obj['choices'][0]['message']['content']); } echo wp_send_json_success($text); } wp_die(); } add_action('wp_ajax_king_ai_writer', 'king_ai_writer'); add_action('wp_ajax_nopriv_king_ai_writer', 'king_ai_writer'); function king_ai_upload() { $url = $_POST['iurl']; require_once KING_INCLUDES_PATH . 'videothumbs.php'; $attach_id = king_upload_user_file_video( $url ); echo wp_send_json($attach_id); wp_die(); } add_action('wp_ajax_king_ai_upload', 'king_ai_upload'); add_action('wp_ajax_nopriv_king_ai_upload', 'king_ai_upload'); endif;