get( 'Version' ); // Load the stylesheet wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'oceanwp-style' ), $version ); } add_action( 'wp_enqueue_scripts', 'oceanwp_child_enqueue_parent_style' ); /** * Link custom javascript file * * @return void */ function my_custom_scripts() { wp_enqueue_script( 'custom-js', get_stylesheet_directory_uri() . '/app.js', array( 'jquery' ),'',true ); } add_action( 'wp_enqueue_scripts', 'my_custom_scripts' ); require_once 'custom-elementor.php'; require_once 'widgets/float-widget-recent-post.php'; /** * Enqueue scripts and styles. */ function float_scripts() { wp_enqueue_script( 'custom-js' ); wp_localize_script('custom-js', 'ajax_object', array('ajax_url' => admin_url( 'admin-ajax.php'), 'google_client_id' => defined("GOOGLE_CLIENT_APP_ID") ? GOOGLE_CLIENT_APP_ID : "343605975098-i4p86p4la6lpff0rmsq3mg36vi9do9rb.apps.googleusercontent.com" )); wp_localize_script('custom-js', 'contact_settings', array( 'sg_contact' => defined("SG_CONTACT_LIST") ? SG_CONTACT_LIST : "f6ff7833-d6cf-425e-a426-395ac201b794", 'us_contact' => defined("US_CONTACT_LIST") ? US_CONTACT_LIST : "a646ee53-dfec-4a6a-a0c3-102c6840df06", 'default_list' => defined("DEFAULT_CONTACT_LIST") ? DEFAULT_CONTACT_LIST : "6e36b912-7cc3-4fb2-ba50-a664fbefb11b" )); } add_action( 'wp_enqueue_scripts', 'float_scripts' ); function get_user_location() { $ip = get_user_ip(); $result = [ 'country'=>'', 'city'=>'', 'timezone' => 'Asia/Singapore', 'region_name'=>'', 'country_code'=>'', 'lat'=>'', 'lng'=>'' ]; $ip_data = @json_decode(file_get_contents('http://www.geoplugin.net/json.gp?ip='.$ip)); if($ip_data && $ip_data->geoplugin_countryName != null){ $result['country'] = $ip_data->geoplugin_countryName; $result['city'] = $ip_data->geoplugin_city; $result['timezone'] = $ip_data->geoplugin_timezone; $result['region_name'] = $ip_data->geoplugin_region; $result['country_code'] = $ip_data->geoplugin_countryCode; $result['lat'] = $ip_data->geoplugin_latitude; $result['lng'] = $ip_data->geoplugin_longitude; } return $result; } function get_user_ip() { $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = @$_SERVER['REMOTE_ADDR']; if(filter_var($client, FILTER_VALIDATE_IP)){ $ip = $client; }elseif(filter_var($forward, FILTER_VALIDATE_IP)){ $ip = $forward; }else{ $ip = $remote; } return $ip; } /** * set Popular Posts by Views */ function float_set_post_views($postID) { $count_key = 'float_post_views_count'; $count = get_post_meta($postID, $count_key, true); if (empty($count)) { delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, 1); } else { $count++; update_post_meta($postID, $count_key, $count); } } function get_latest_articles($request) { $limit = isset($_GET['limit']) ? intval(trim($_GET['limit'])) : 10; $page = isset($_GET['page']) ? intval(trim($_GET['page'])) : 1; if (!isset($limit) || !is_int($limit) || $limit <= 0) { $limit = 10; // Set limit to by 10 as default } if (!isset($page) || !is_int($page) || $page <= 0) { $page = 1; // Set default page } $query = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $limit, 'paged' => $page, 'orderby' => 'date', 'order' => 'DESC' ) ); if ( !$query->have_posts() ) { return new WP_Error( 'empty_post', 'there is no post ', array('status' => 404) ); } // add meta to post $newPost = array(); foreach ( $query->posts as $key => $post ) { add_meta_value_to_posts( $post ); array_push( $newPost, $post ); } wp_reset_postdata(); // Add co-authors to post if exists foreach ( $newPost as $post ) { $co_authors = get_coauthors( $post->ID ); $result = []; foreach ( $co_authors as $co_author ) { if (get_class($co_author) !== 'WP_User') { array_push($result, $co_author->display_name); continue; } array_push($result, $co_author->data->display_name); } if ( !empty($result) ) { $post->co_authors = $result; } } $response = new WP_REST_Response( $newPost ); $response->set_status(200); return $response; } function get_article_by_id($request) { $post_id = isset($request['id']) && intval($request['id']) ? intval($request['id']) : NULL; if (empty($post_id)) { return new WP_Error( 'error', 'missing post id params ', array('status' => 400) ); } $post = get_post( $post_id ); if (empty($post)) { return new WP_Error( 'empty_post', 'there is no post ', array('status' => 404) ); } add_meta_value_to_posts( $post ); // Add co-authors to post if exists $co_authors = get_coauthors( $post->ID ); $result = []; foreach ( $co_authors as $co_author ) { if (get_class($co_author) !== 'WP_User') { array_push($result, $co_author->display_name); continue; } array_push($result, $co_author->data->display_name); } if ( !empty($result) ) { $post->co_authors = $result; } $response = new WP_REST_Response($post); $response->set_status(200); return $response; } add_action('rest_api_init', function () { register_rest_route( 'float/v1', 'latest-articles',array( 'methods' => 'GET', 'callback' => 'get_latest_articles', 'permission_callback' => '__return_true' )); register_rest_route( 'float/v1', 'articles/(?P\d+)',array( 'methods' => 'GET', 'callback' => 'get_article_by_id', 'permission_callback' => '__return_true' )); }); /** * add more menu item */ function add_signup_link( $items, $args ) { if ($args->theme_location == 'main_menu') { $items .= ''; } return $items; } add_filter( 'wp_nav_menu_items', 'add_signup_link', 10, 2 ); /** * Add meta tags for marketing * * @return void */ function add_meta_tags() { global $post; if ( is_single() ) { $des_post = strip_tags( $post->post_content ); $des_post = strip_shortcodes( $des_post ); $des_post = str_replace( array("\n", "\r", "\t"), ' ', $des_post ); $des_post = trim( $des_post ); $des_post = mb_substr( $des_post, 0, 300, 'utf8' ); echo "\n" . '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } if ( is_page() ) { echo "\n" . '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } if ( is_home() ) { echo "\n" . '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } if ( is_category() ) { $des_cat = strip_tags(category_description()); echo "\n" . '' . "\n"; } } add_action('wp_head', 'add_meta_tags'); /** * Additional meta data to post * @param WP_POST &$post */ function add_meta_value_to_posts( &$post ) { if ( !$post ) { return; } // get all custom fields if ( function_exists( 'get_fields' ) ) { $post_meta = get_fields( $post->ID ); if ( $post_meta ) { foreach ( $post_meta as $key => $meta ) { if ( !empty($meta) && is_string($meta) && preg_match( '/^http|^https:\/\/.*?/m', $meta ) ) { $meta = encodeURI( $meta ); } $post->$key = $meta; } } } // get post author $post->display_name = get_the_author_meta( 'display_name', $post->post_author ); // get featured image $post->featured_image = encodeURI( get_the_post_thumbnail_url( $post ) ); $post->_wp_attachment_metadata = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); } function encodeURI($url) { // http://php.net/manual/en/function.rawurlencode.php // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURI $unescaped = array( '%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!', '%7E'=>'~', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')' ); $reserved = array( '%3B'=>';','%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':', '%40'=>'@','%26'=>'&','%3D'=>'=','%2B'=>'+','%24'=>'$' ); $score = array( '%23'=>'#' ); return strtr(rawurlencode($url), array_merge($reserved,$unescaped,$score)); } /** * Comment fields * * @since 1.0.0 */ if ( ! function_exists( 'oceanwp_modify_comment_form_fields' ) ) { function oceanwp_modify_comment_form_fields( $fields ) { $commenter = wp_get_current_commenter(); $req = get_option( 'require_name_email' ); // Labels. if ( $req ) { $comment_name = oceanwp_theme_strings( 'owp-string-comment-name-req', false, 'oceanwp' ); $comment_email = oceanwp_theme_strings( 'owp-string-comment-email-req', false, 'oceanwp' ); } else { $comment_name = oceanwp_theme_strings( 'owp-string-comment-name', false, 'oceanwp' ); $comment_email = oceanwp_theme_strings( 'owp-string-comment-email', false, 'oceanwp' ); } $comment_site = oceanwp_theme_strings( 'owp-string-comment-website', false, 'oceanwp' ); $fields['author'] = '
'; $fields['email'] = '
'; $fields['url'] = ''; $fields['cookies'] = ''; return $fields; } add_filter( 'comment_form_default_fields', 'oceanwp_modify_comment_form_fields' ); }