nd_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;