term_id : false; } function leapin_get_yoast_primary_category($id = false) { // SHOW YOAST PRIMARY CATEGORY, OR FIRST CATEGORY $category = $id ? get_the_category($id) : get_the_category(); // If post has a category assigned. if ($category) { if (class_exists('WPSEO_Primary_Term')) { // Show the post's 'Primary' category, if this Yoast feature is available, & one is set $wpseo_primary_term = new WPSEO_Primary_Term('category', get_the_id()); $wpseo_primary_term = $wpseo_primary_term->get_primary_term(); $term = get_term($wpseo_primary_term); if (is_wp_error($term)) { // Default to first category id (not Yoast) if an error is returned $cat = $category[0]; } else { // Yoast Primary category id $cat = $term; } } else { // Default, get the first category id in WP's list of assigned categories $cat = $category[0]; } return $cat; } } /** * Converts Hex to RGBA * * @param $color * @param bool $opacity (0 ~ 1) * @return string */ function leapin_hex2rgba($color, $opacity = false) { $default = 'rgb(0,0,0)'; //Return default if no color provided if (empty($color)) return $default; //Sanitize $color if "#" is provided if ($color[0] == '#') { $color = substr($color, 1); } //Check if color has 6 or 3 characters and get values if (strlen($color) == 6) { $hex = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]); } elseif (strlen($color) == 3) { $hex = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]); } else { return $color; } //Convert hexadec to rgb $rgb = array_map('hexdec', $hex); //Check if opacity is set(rgba or rgb) if ($opacity) { if (abs($opacity) > 1) $opacity = 1.0; $output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')'; } else { $output = 'rgb(' . implode(",", $rgb) . ')'; } //Return rgb(a) color string return $output; } function leapin_get_eyecatch_image($size = 'leapin-medium', $id = false, $is_post_id = true) { $thumbnail_id = $id; if ($is_post_id) { $thumbnail_id = $id ? get_post_thumbnail_id($id) : get_post_thumbnail_id(get_the_ID()); } $img = wp_get_attachment_image_src($thumbnail_id, $size); if (empty($img)) { $default_img = LEAPIN_Theme_Mod::get_instance() ->get(LEAPIN_IDs::$leapin_single_default_image, LEAPIN_Theme_Mod::$default_leapin_single_default_image); if (isset($default_img)) { $img_size = leapin_get_image_width_and_height($default_img); $img[0] = $default_img; $img[1] = $img_size['width']; $img[2] = $img_size['height']; } } return $img; } function leapin_sanity_check($mixed_data) { if (!empty ($mixed_data)) { return $mixed_data; } return ""; } function leapin_adjust_color_brightness($hex, $steps) { // Steps should be between -255 and 255. Negative = darker, positive = lighter $steps = max(-255, min(255, $steps)); // Normalize into a six character long hex string $hex = str_replace('#', '', $hex); if (strlen($hex) == 3) { $hex = str_repeat(substr($hex, 0, 1), 2) . str_repeat(substr($hex, 1, 1), 2) . str_repeat(substr($hex, 2, 1), 2); } // Split into three parts: R, G and B $color_parts = str_split($hex, 2); $return = '#'; foreach ($color_parts as $color) { $color = hexdec($color); // Convert to decimal $color = max(0, min(255, $color + $steps)); // Adjust color $return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code } return $return; } function leapin_includes_site_url($url) { // if url doesn't include site url if (strpos($url, site_url()) === false) { return false; } else { return true; } } function leapin_sanitize_text($str) { return sanitize_text_field($str); } function leapin_sanitize_checkbox($input) { return (bool)$input; } function leapin_sanitize_widget_checkbox($instance, $key) { if (!array_key_exists($key, $instance)) { return false; } return (bool)$instance[$key]; } function leapin_sanitize_id_comma_text($comma_text) { $removed_comma_text = trim(leapin_sanitize_text($comma_text)); $removed_comma_text = preg_replace('/[^\d,]/i', '', $removed_comma_text); return $removed_comma_text; } function leapin_sanitize_number($int) { return absint($int); } function leapin_sanitize_mock($value) { return $value; } function leapin_sanitize_i_tag($value) { return wp_kses($value, array( 'i' => array( 'class' => array() ) )); } function leapin_is_barba_call() { if (array_key_exists('HTTP_X_BARBA', $_SERVER) && $_SERVER['HTTP_X_BARBA'] === 'yes') { return true; } return false; } function leapin_sanitize_rgba_color($color) { if ('' === $color) return ''; if (false === strpos($color, 'rgba')) { $color = maybe_hash_hex_color($color); return $color; } else { $color = str_replace(' ', '', $color); $red = $green = $blue = $alpha = ''; sscanf($color, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha); return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; } } function leapin_mod_sr_only($key = false) { $inst = LEAPIN_Theme_Mod::get_instance(); return $inst->get($key) ? ' sr-only' : ''; } /** * @param bool $key - theme mods hide key which should be hiding content if its value is true. * @param bool $default - visibility when key isn't set * @return bool - true if it's visible */ function leapin_is_mod_visible($key = false, $default = false) { $inst = LEAPIN_Theme_Mod::get_instance(); return $inst->get($key, $default) ? false : true; } function leapin_get_old_browser_msg($SCRIPT_MODs) { $SCRIPT_MODs['old_browser_notification'] = __('Oops, Your browser is too old. Please use newer one or alternative browser such as Chrome or Firefox!', 'pjax-blog'); $SCRIPT_MODs['message_open_with_chrome'] = __('Open with Chrome', 'pjax-blog'); $SCRIPT_MODs['message_open_with_firefox'] = __('Open with Firefox', 'pjax-blog'); return $SCRIPT_MODs; } add_filter('leapin_add_script_properties', 'leapin_get_old_browser_msg'); function leapin_amp_head() { do_action('leapin_amp_head'); } function leapin_the_non_supported_ie_browser() { $old_browser_notification = __('Oops, IE is not supported. Please use the latest version of the modern browser such as Chrome, Firefox, Safari, Edge!', 'pjax-blog'); ?> get(LEAPIN_IDs::$leapin_publisher_name, false); if (!empty($publisher)):?> get(LEAPIN_IDs::$leapin_other_address_bar_color, false); if (!empty($address_bar_color)): ?> array( 'widget_id-1', 'widget_id-2' ... ); $sidebars_widgets = wp_get_sidebars_widgets(); $widget_ids = $sidebars_widgets[$sidebar_id]; if (!$widget_ids) { // Without proper widget_ids we can't continue. return array(); } // Loop over each widget_id so we can fetch the data out of the wp_options table. foreach ($widget_ids as $id) { // The name of the option in the database is the name of the widget class. $option_name = $wp_registered_widgets[$id]['callback'][0]->option_name; // Widget data is stored as an associative array. To get the right data we need to get the right key which is stored in $wp_registered_widgets $key = $wp_registered_widgets[$id]['params'][0]['number']; $widget_data = get_option($option_name); // Add the widget data on to the end of the output array. $output[] = (object)$widget_data[$key]; } return $output; } /** * Get Sidebar ID from Widget ID * * @since 1.7.2 * @param string $widget_id Widget ID e.g. 'recent-posts-5' * @return string|boolean $sidebar_id Sidebar ID e.g. 'sidebar-1' */ function leapin_get_sidebar_id_from_widget_id($widget_id) { $sidebars = wp_get_sidebars_widgets(); foreach ((array)$sidebars as $sidebar_id => $sidebar) { if (in_array($widget_id, (array)$sidebar, true)) return $sidebar_id; } return false; // not found case } function leapin_get_neighbor_posts_tag() { if (false) { /** * Do not delete this condition. Theme Check (http://wordpress.org/plugins/theme-check/) * is constantly warning that it needs this code in the theme * even though we use get_adjacent_post instead. The REAL Code is from the end of this "if". */ the_posts_pagination(); } $hide_neighbor_post = leapin_mod_sr_only(LEAPIN_IDs::$leapin_hide_pagination_below_article); ob_start(); ?>
ID); $img_tag = sprintf('', $img[0]); echo '
' . $title . '
' . $img_tag . '

' . get_post_field('post_title', $neighborpost->ID, 'raw') . '

'; } else { // neighbor not exists echo '
HOME
' . '' . '

' . __('Go Back To Home', 'pjax-blog') . '

'; } } function leapin_tag_cloud_custom_ex($output) { // remove style attr in tag cloud widget $output = preg_replace('/\s*?style="[^"]+?"/i', '', $output); return $output; } add_filter('wp_tag_cloud', 'leapin_tag_cloud_custom_ex'); function leapin_is_comment_open() { global $post; if (isset($post->comment_status)) { return $post->comment_status == 'open'; } return false; } /** * Get image width and height * * @param $image_url * @return array|bool */ function leapin_get_image_width_and_height($image_url) { if (!leapin_includes_site_url($image_url)) { return false; } $wp_upload_dir = wp_upload_dir(); $uploads_dir = $wp_upload_dir['basedir']; $uploads_url = $wp_upload_dir['baseurl']; $image_file = str_replace($uploads_url, $uploads_dir, $image_url); $res = array(); if (file_exists($image_file) && ($imagesize = getimagesize($image_file)) ) { $res['width'] = $imagesize[0]; $res['height'] = $imagesize[1]; return $res; } else { return false; } } function leapin_load_css_on_each_pjax() { $css = ''; echo ''; } add_action('leapin_footer', 'leapin_load_css_on_each_pjax'); function leapin_footer() { do_action('leapin_footer'); } /** * Check if the current theme is pro version * * @return bool true in pro edition */ function leapin_is_pro() { return class_exists('LEAPIN_Theme_Grade') && !LEAPIN_Theme_Grade::is_free_mode(); } /** * Implode Array Values * * @param string $glue * @param array $arry * @return string glued array values * return "" if $arry is empty. * @since 1.6.6 */ function leapin_implode($glue, $arry) { $rtn = ""; if (is_array($arry)) { if (count($arry) == 1) { $rtn = $arry[0]; } else if (count($arry) > 1) { $rtn = implode($glue, $arry); } } return $rtn; } if (is_plugin_active('siteorigin-panels/siteorigin-panels.php')) { add_filter('siteorigin_panels_row_style_css', 'leapin_change_background_size', 10, 2); add_filter('siteorigin_panels_cell_style_css', 'leapin_change_background_size', 10, 2); add_filter('siteorigin_panels_widget_style_css', 'leapin_change_background_size', 10, 2); function leapin_change_background_size($css, $style) { if (!empty($css['background-image'])) { $url = wp_get_attachment_image_src($style['background_image_attachment'], 'large'); if (!empty($url)) { $css['background-image'] = 'url(' . (is_array($url) ? $url[0] : $url) . ')'; } } return $css; } add_filter('siteorigin_panels_row_style_attributes', 'leapin_change_background_size_attr', 10, 2); add_filter('siteorigin_panels_cell_style_attributes', 'leapin_change_background_size_attr', 10, 2); add_filter('siteorigin_panels_widget_style_attributes', 'leapin_change_background_size_attr', 10, 2); function leapin_change_background_size_attr($attributes, $style) { if (!empty($style['background_image_attachment'])) { $url = wp_get_attachment_image_src($style['background_image_attachment'], 'large'); if ( !empty($url) && ($style['background_display'] == 'parallax' || $style['background_display'] == 'parallax-original') ) { $parallax_args = array( 'backgroundUrl' => $url[0], 'backgroundSize' => array($url[1], $url[2]), 'backgroundSizing' => $style['background_display'] == 'parallax-original' ? 'original' : 'scaled', 'limitMotion' => siteorigin_panels_setting('parallax-motion') ? floatval(siteorigin_panels_setting('parallax-motion')) : 'auto', ); $attributes['data-siteorigin-parallax'] = json_encode($parallax_args); } } return $attributes; } } function leapin_get_home_url() { return esc_url(home_url()); } function leapin_get_permalink($post = 0) { return esc_url(get_permalink($post)); } function leapin_get_author_credit() { if (!leapin_is_pro()) { printf('.', __('Pjax Blog Theme Developed by LeapIn', 'pjax-blog')); } } add_action('leapin_loc_footer_author_credit', 'leapin_get_author_credit'); function leapin_str_replace_n($search, $replace, $str, $n) { if (preg_match_all($search, $str, $m, PREG_OFFSET_CAPTURE) > $n) { $str = substr_replace($str, $replace, $m[0][$n][1], strlen($m[0][$n][0])); } return $str; } /** * Check if Pjax Blog Bundle is activated * * @return bool - true activated */ function leapin_is_bundle() { return is_plugin_active('leapin-bundle/leapin-bundle.php'); } /** * Check if Pjax Blog Bundle version is compatible with the theme. * * @param $version minimum compatible version * @return bool true if it's compatible or not installed * @since 1.7.1 */ function leapin_is_compatible_bundle_ver($version, $operator) { if (leapin_is_bundle()) { $data = get_file_data(ABSPATH . 'wp-content/plugins/leapin-bundle/leapin-bundle.php', array('version' => 'Version', 'uri' => 'Plugin URI', 'description' => 'Description', 'author' => 'Author', 'author_uri' => 'Author URI', 'textdomain' => 'Text Domain', 'textdomain_path' => 'Domain Path', )); // is installed and current version is not compatible if (is_array($data) && !version_compare($data['version'], $version, $operator)) { return false; } } else { // is not installed return true; } return true; } function leapin_get_post_meta($key = '', $post_id = null, $single = true) { if (!isset($post_id)) { if (is_front_page()) { $post_id = get_option('page_on_front'); } else { $post_id = get_the_ID(); } } return get_post_meta($post_id, $key, $single); } function leapin_add_post_meta_field($args) { $type = $args['type']; $meta_key = $args['meta_key']; $meta_value = leapin_get_post_meta($meta_key); if (empty($meta_value) && array_key_exists('default', $args)) { $meta_value = $args['default']; } $howto = array_key_exists('howto', $args) ? $args['howto'] : ""; $label = $args['label']; $echo = "
"; if ($type === "select") { $echo .= "
"; $echo .= ""; } elseif ($type === "checkbox") { $echo .= ""; } // $echo .= "

$howto

"; add_action('save_post', function () use ($type, $meta_key) { $meta_value = null; if (isset($_POST[$meta_key])) { $meta_value = $_POST[$meta_key]; } if (isset($meta_value) || $type === "checkbox") { leapin_update_post_meta($meta_key, $meta_value); } }); return $echo . "
"; } function leapin_update_post_meta($meta_key = '', $meta_value = '', $post_id = null, $prev_value = '') { if (!isset($post_id)) { $post_id = LEAPIN_Single::$save_post_id; } return update_post_meta($post_id, $meta_key, $meta_value, $prev_value); } function leapin_bbp_no_breadcrumb($param) { return true; } add_filter('bbp_no_breadcrumb', 'leapin_bbp_no_breadcrumb'); function leapin_get_meta_box_screens() { global $leapin_vars; $post_types = null; if (isset($leapin_vars)) { $post_types = []; foreach ($leapin_vars['post_types'] as $val) { $post_types[] = $val->name; } } else { $post_types = array('post', 'page', 'forum'); } return apply_filters('leapin_meta_box_screens', $post_types); } /** * sort multi array * * @param $array * @param $sort_key * @param int $order * @return mixed * @since 1.8.0 */ function leapin_array_multisort($array, $sort_key, $order = SORT_ASC) { if (empty($array)) return $array; foreach ((array)$array as $key => $value) { if (array_key_exists($sort_key, $value)) { $sort[$key] = (int)$value[$sort_key]; } else { $sort[$key] = 100; } } array_multisort($sort, $order, $array); return $array; } /** * is user stuff * * @return bool true if user is a stuff * @since 1.8.0 */ function leapin_is_user_stuff() { $ret = false; $capabilities = apply_filters('leapin_is_user_stuff', ['editor', 'administrator']); foreach ($capabilities as $cap) { if (current_user_can($cap)) { $ret = true; break; }; } return is_user_logged_in() && $ret; } function leapin_is_woocommerce() { if (function_exists("is_woocommerce") && is_woocommerce()) { return true; } $woocommerce_keys = array("woocommerce_shop_page_id", "woocommerce_terms_page_id", "woocommerce_cart_page_id", "woocommerce_checkout_page_id", "woocommerce_pay_page_id", "woocommerce_thanks_page_id", "woocommerce_myaccount_page_id", "woocommerce_edit_address_page_id", "woocommerce_view_order_page_id", "woocommerce_change_password_page_id", "woocommerce_logout_page_id", "woocommerce_lost_password_page_id"); foreach ($woocommerce_keys as $wc_page_id) { if (get_the_ID() === (int)get_option($wc_page_id, 0)) { return true; } } return false; } function leapin_is_bbpress() { if (function_exists("is_bbpress") && is_bbpress()) { return true; } return false; } function leapin_is_buddypress() { if (function_exists("is_buddypress") && is_buddypress()) { return true; } return false; } add_action('leapin_loc_end_of_body', 'leapin_white_bg_till_load', 2); function leapin_white_bg_till_load() { echo "
"; } add_filter('leapin_body_class', 'gradeBodyClass'); function gradeBodyClass($cls) { $cls[] = leapin_is_pro() ? "pro" : "free"; return $cls; }