';
return $output;
}
function blogpost_get_blog_url_info() {
global $wp_query;
$max_pages = $wp_query->max_num_pages;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$current_url = blogpost_curPageURL();
$output = '
';
return $output;
}
/* Filter categories */
function blogpost_filter_categories($list) {
$find = '(';
$replace = '[';
$list = str_replace( $find, $replace, $list );
$find = ')';
$replace = ']';
$list = str_replace( $find, $replace, $list );
return $list;
}
add_filter('wp_list_categories', 'blogpost_filter_categories');
// Custom Login Logo
function blogpost_login_logo() {
$login_logo = get_theme_mod('blogpost_login_logo', false);
if ($login_logo != false) {
echo '
';
}
}
add_action('login_head', 'blogpost_login_logo');
// Sets the post excerpt length to 40 words.
function blogpost_excerpt_length($length) {
return 9;
}
add_filter('excerpt_length', 'blogpost_excerpt_length');
function blogpost_new_excerpt_more( $more ) {
return '...';
}
add_filter('excerpt_more', 'blogpost_new_excerpt_more');
// Returns a "Continue Reading" link for excerpts
function blogpost_continue_reading_link() {
return '
' . __('Read more', 'blogpost') . '';
}
function blogpost_widget_class($params) {
// its your widget so you add your classes
$classe_to_add = (strtolower(str_replace(array(' '), array(''), $params[0]['widget_name']))); // make sure you leave a space at the end
$classe_to_add = 'class=" '.$classe_to_add . ' ';
$params[0]['before_widget'] = str_replace('class="', $classe_to_add, $params[0]['before_widget']);
return $params;
}
add_filter('dynamic_sidebar_params', 'blogpost_widget_class');
function blogpost_startsWith($haystack,$needle,$case=true) {
if($case){return (strcmp(substr($haystack, 0, strlen($needle)),$needle)===0);}
return (strcasecmp(substr($haystack, 0, strlen($needle)),$needle)===0);
}
function blogpost_curPageURL() {
$pageURL = 'http';
if ( isset( $_SERVER["HTTPS"] ) && strtolower( $_SERVER["HTTPS"] ) == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
function blogpost_convertToHoursMins($time, $format = '%d:%d') {
settype($time, 'integer');
if ($time < 1) {
return;
}
$hours = floor($time / 60);
$minutes = ($time % 60);
return sprintf($format, $hours, $minutes);
}
function blogpost_wp_tag_cloud_filter($return, $args) {
return '
' . $return . '
';
}
add_filter('wp_tag_cloud', 'blogpost_wp_tag_cloud_filter', 10, 2);
// Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
function blogpost_page_menu_args($args) {
$args['show_home'] = true;
return $args;
}
add_filter('wp_page_menu_args', 'blogpost_page_menu_args');
// Register menus
function blogpost_register_menus () {
register_nav_menus(
array (
'primary-menu' => __('Primary Menu', 'blogpost')
)
);
}
add_action('init', 'blogpost_register_menus');
// Adds classes to the array of body classes.
function blogpost_body_classes($classes) {
global $post, $wp_version;
if (is_singular() && !is_home()) {
$classes[] = 'singular';
}
if ( !is_front_page() ) {
$classes[] = 'not_front_page';
}
if (is_search()) {
$search_key = array_search('search', $classes);
if ($search_key !== false) {
unset($classes[$search_key]);
}
}
// Color scheme class
$blogpost_color_scheme = get_theme_mod( 'blogpost_color_scheme');
if ( !empty($blogpost_color_scheme) ) {
$classes[] = $blogpost_color_scheme;
}
// If blog shortcode
if (isset($post->post_content) && false !== stripos($post->post_content, '[blog')) {
$classes[] = 'page-template-blog';
}
if ( BLOGPOST_DEMO_COMMENTS ) {
$classes[] = 'demo_comments';
}
// Breadcrumbs class
$disable_breadcrumb = get_option('blogpost_breadcrumb') ? get_option('blogpost_breadcrumb') : 'false';
if (!is_home() && !is_front_page() && $disable_breadcrumb == 'false') {
$classes[] = 'has_breadcrumb';
}
$classes[] = 'disable-animations';
if ( version_compare($wp_version, '4.4', '>=') ) {
$classes[] = 'wp-post-4-4';
}
return $classes;
}
add_filter('body_class', 'blogpost_body_classes');
if (!function_exists('blogpost_posted_on')) {
// Prints HTML with meta information for the current post.
function blogpost_posted_on() {
printf(__('Posted: %4$s by %7$s', 'blogpost'),
esc_url(get_permalink()),
esc_attr(get_the_time()),
esc_attr(get_the_date('c')),
esc_html(get_the_date()),
esc_url(get_author_posts_url(get_the_author_meta('ID'))),
sprintf(esc_attr__('View all posts by %s', 'blogpost'), get_the_author()),
esc_html(get_the_author())
);
}
}
function blogpost_clear_nav_menu_item_id($id, $item, $args) {
return "";
}
add_filter('nav_menu_item_id', 'blogpost_clear_nav_menu_item_id', 10, 3);
function blogpost_add_nofollow_cat( $text ) {
$text = str_replace('rel="category"', "", $text);
return $text;
}
add_filter( 'the_category', 'blogpost_add_nofollow_cat' );
function blogpost_addhttp($url) {
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://" . $url;
}
return $url;
}
function blogpost_checkShortcode($string) {
global $post;
if (isset($post->post_content) && false !== stripos($post->post_content, $string)) {
return true;
} else {
return false;
}
}
// custom comment fields
function blogpost_custom_comment_fields($fields) {
global $post, $commenter;
$fields['author'] = '
' . __('Enter your name', 'blogpost') . '
';
$fields['email'] = '
' . __('Enter your email', 'blogpost') . '
';
$fields['url'] = '
';
$fields = array( $fields['author'], $fields['email'] );
return $fields;
}
add_filter( 'comment_form_default_fields', 'blogpost_custom_comment_fields' );
if ( ! function_exists( 'blogpost_comment' ) ) {
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own ac_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
*/
function blogpost_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
// Display trackbacks differently than normal comments.
?>
prepare("SELECT COUNT(comment_post_id) AS count FROM $wpdb->comments WHERE `comment_approved` = 1 AND `comment_parent` = %s", $id);
$parents = $wpdb->get_row($query);
return $parents->count;
}
function blogpost_breadcrumbs() {
$disable_breadcrumb = get_option('blogpost_breadcrumb') ? get_option('blogpost_breadcrumb') : 'false';
$delimiter = get_option('blogpost_breadcrumb_delimiter') ? sanitize_text_field( get_option('blogpost_breadcrumb_delimiter') ) : '';
$home = __('Home', 'blogpost'); // text for the 'Home' link
$before = ''; // tag before the current crumb
$after = ''; // tag after the current crumb
if (!is_home() && !is_front_page() && $disable_breadcrumb == 'false') {
global $post;
$homeLink = home_url();
$output = '
';
return $output;
}
}
/*
* This theme supports custom background color and image, and here
* we also set up the default background color.
*/
add_theme_support( 'custom-background', array(
'default-color' => 'fcfcfc'
) );
function blogpost_sanitize_color( $input ) {
return (string) $input;
}
/**
* Add postMessage support for the Theme Customizer.
*/
function blogpost_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
}
add_action( 'customize_register', 'blogpost_customize_register' );
/**
* Binds CSS and JS handlers to make Theme Customizer preview reload changes asynchronously.
*/
function blogpost_customize_preview_js_css() {
wp_enqueue_script( 'vh-customizer-js', get_template_directory_uri() . '/functions/admin/js/theme-customizer.js', array( 'jquery', 'customize-preview' ), '', true );
}
add_action( 'customize_preview_init', 'blogpost_customize_preview_js_css' );
/**
* Register the required plugins for this theme.
*
* In this example, we register two plugins - one included with the TGMPA library
* and one from the .org repo.
*
* The variable passed to tgmpa_register_plugins() should be an array of plugin
* arrays.
*
* This function is hooked into tgmpa_init, which is fired within the
* TGM_Plugin_Activation class constructor.
*/
function blogpost_register_required_plugins() {
/**
* Array of plugin arrays. Required keys are name and slug.
* If the source is NOT from the .org repo, then source is also required.
*/
$plugins = array(
array(
'name' => 'Functionality for Blogpost Lite theme', // The plugin name
'slug' => 'functionality-for-blogpost-lite-theme', // The plugin slug (typically the folder name)
'required' => false, // If false, the plugin is only 'recommended' instead of required
'version' => '1.2', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
'external_url' => '', // If set, overrides default API URL and points to an external URL
)
);
/**
* Array of configuration settings. Amend each line as needed.
* If you want the default strings to be available under your own theme domain,
* leave the strings uncommented.
* Some of the strings are added into a sprintf, so see the comments at the
* end of each line for what each argument will be.
*/
$config = array(
'domain' => 'blogpost', // Text domain - likely want to be the same as your theme.
'default_path' => '', // Default absolute path to pre-packaged plugins
'parent_slug' => 'themes.php', // Default parent slug
'menu' => 'install-required-plugins', // Menu slug
'has_notices' => true, // Show admin notices or not
'is_automatic' => true, // Automatically activate plugins after installation or not
'message' => '', // Message to output right before the plugins table
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'blogpost' ),
'menu_title' => __( 'Install Plugins', 'blogpost' ),
'installing' => __( 'Installing Plugin: %s', 'blogpost' ), // %1$s = plugin name
'oops' => __( 'Something went wrong with the plugin API.', 'blogpost' ),
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'blogpost' ), // %1$s = plugin name(s)
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'blogpost' ), // %1$s = plugin name(s)
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'blogpost' ), // %1$s = plugin name(s)
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'blogpost' ), // %1$s = plugin name(s)
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'blogpost' ), // %1$s = plugin name(s)
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'blogpost' ), // %1$s = plugin name(s)
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'blogpost' ), // %1$s = plugin name(s)
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'blogpost' ), // %1$s = plugin name(s)
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'blogpost' ),
'activate_link' => _n_noop( 'Activate installed plugin', 'Activate installed plugins', 'blogpost' ),
'return' => __( 'Return to Required Plugins Installer', 'blogpost' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'blogpost' ),
'complete' => __( 'All plugins installed and activated successfully. %s', 'blogpost' ), // %1$s = dashboard link
'nag_type' => 'updated' // Determines admin notice type - can only be 'updated' or 'error'
)
);
tgmpa( $plugins, $config );
}
add_action( 'tgmpa_register', 'blogpost_register_required_plugins' );
function blogpost_vcSetAsTheme() {
vc_set_as_theme( true );
}
add_action( 'vc_before_init', 'blogpost_vcSetAsTheme' );
function blogpost_profile_editor_activation() {
global $wpdb;
$skype = $wpdb->get_results('SELECT NAME FROM ' . $wpdb->prefix . 'profile_editor_fields WHERE NAME = "skype"');
$twitter = $wpdb->get_results('SELECT NAME FROM ' . $wpdb->prefix . 'profile_editor_fields WHERE NAME = "twitter"');
$yahoo = $wpdb->get_results('SELECT NAME FROM ' . $wpdb->prefix . 'profile_editor_fields WHERE NAME = "yahoo"');
$aim = $wpdb->get_results('SELECT NAME FROM ' . $wpdb->prefix . 'profile_editor_fields WHERE NAME = "aim"');
$profile_background = $wpdb->get_results('SELECT NAME FROM ' . $wpdb->prefix . 'profile_editor_fields WHERE NAME = "profile_background"');
if ( empty($skype) ) {
$wpdb->query('INSERT INTO ' . $wpdb->prefix . 'profile_editor_fields (NAME,TYPE,LABEL,PLACEHOLDER,RULES,DESCRIPTION) VALUES ("skype","text","Skype","Skype name","{\"field_empty\":\"off\",\"field_syntax\":\"off\",\"field_min\":\"\",\"field_max\":\"\",\"field_registration\":\"on\"}","Your skype name")');
$wpdb->query('UPDATE ' . $wpdb->prefix . 'usermeta SET meta_key="pe_skype" WHERE meta_key="skype"');
}
if ( empty($twitter) ) {
$wpdb->query('INSERT INTO ' . $wpdb->prefix . 'profile_editor_fields (NAME,TYPE,LABEL,PLACEHOLDER,RULES,DESCRIPTION) VALUES ("twitter","text","Twitter","Twitter name","{\"field_empty\":\"off\",\"field_syntax\":\"off\",\"field_min\":\"\",\"field_max\":\"\",\"field_registration\":\"on\"}","Your twitter name")');
$wpdb->query('UPDATE ' . $wpdb->prefix . 'usermeta SET meta_key="pe_twitter" WHERE meta_key="twitter"');
}
if ( empty($yahoo) ) {
$wpdb->query('INSERT INTO ' . $wpdb->prefix . 'profile_editor_fields (NAME,TYPE,LABEL,PLACEHOLDER,RULES,DESCRIPTION) VALUES ("yahoo","text","Yahoo","Yahoo name","{\"field_empty\":\"off\",\"field_syntax\":\"off\",\"field_min\":\"\",\"field_max\":\"\",\"field_registration\":\"on\"}","Your yahoo name")');
$wpdb->query('UPDATE ' . $wpdb->prefix . 'usermeta SET meta_key="pe_yahoo" WHERE meta_key="yahoo"');
}
if ( empty($aim) ) {
$wpdb->query('INSERT INTO ' . $wpdb->prefix . 'profile_editor_fields (NAME,TYPE,LABEL,PLACEHOLDER,RULES,DESCRIPTION) VALUES ("aim","text","Aim","Aim name","{\"field_empty\":\"off\",\"field_syntax\":\"off\",\"field_min\":\"\",\"field_max\":\"\",\"field_registration\":\"on\"}","Your aim name")');
$wpdb->query('UPDATE ' . $wpdb->prefix . 'usermeta SET meta_key="pe_aim" WHERE meta_key="aim"');
}
if ( empty($profile_background) ) {
$wpdb->query('INSERT INTO ' . $wpdb->prefix . 'profile_editor_fields (NAME,TYPE,LABEL,RULES,DESCRIPTION) VALUES ("profile_background","picture","Profile background","{\"field_empty\":\"off\",\"field_max_size\":\"\",\"field_extensions\":\"all\",\"field_registration\":\"on\"}","Background for author page")');
// Get old values
$user_backgrounds = $wpdb->get_results('SELECT cmfdata.USER_ID, cmfdata.VALUE FROM ' . $wpdb->prefix . 'cimy_uef_data as cmfdata, ' . $wpdb->prefix . 'cimy_uef_fields as cmffields WHERE cmffields.NAME="PROFILE_BACKGROUND" AND cmffields.ID=cmfdata.FIELD_ID');
require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
foreach ($user_backgrounds as $user_key => $user_value) {
$image = media_sideload_image($user_value->VALUE, '1', '', 'src');
$user_backgrounds[$user_key]->VALUE = $image;
}
// Set for prodile-editor
foreach ($user_backgrounds as $pe_key => $pe_value) {
update_user_meta($pe_value->USER_ID, 'pe_profile_background', blogpost_get_image_id($pe_value->VALUE));
}
}
}
register_activation_hook( WP_PLUGIN_DIR.'/profile-editor/profile-editor.php', 'blogpost_profile_editor_activation' );
function blogpost_get_image_id($image_url) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
}