Openlabnotebooks.org software

Here is the code that we used to customize the open-source WordPress package and make openlabnotebooks.org. Feel free to use it if you want to create your open lab notebook on your own machine. But you are welcome to use directly our interface if you prefer (contact us and we will set you up).

/*
  Based on Category Checklist Tree, by scribu
  Preserves the category hierarchy on the post editing screen
  Removes parent categories checkbox selection
*/
class Category_Checklist {

    function init() {
        add_filter( 'wp_terms_checklist_args', array( __CLASS__, 'checklist_args' ) );
    }

    function checklist_args( $args ) {
        add_action( 'admin_footer', array( __CLASS__, 'script' ) );

        $args['checked_ontop'] = false;

        return $args;
    }

    // Scrolls to first checked category
    function script() {
<script type="text/javascript">
    jQuery(function(){
        jQuery('[id$="-all"] > ul.categorychecklist').each(function() {
            var $list = jQuery(this);
            var $firstChecked = $list.find(':checked').first();

            if ( !$firstChecked.length )
                return;

            var pos_first = $list.find(':checkbox').position().top;
            var pos_checked = $firstChecked.position().top;

            $list.closest('.tabs-panel').scrollTop(pos_checked - pos_first + 5);
        });
        
    var listItems = jQuery("#categorychecklist>li");
    listItems.each(function(li) {
        var id = this.id;
            if (id != "category-1") { //Uncategorised
                jQuery(this).children("label").children("input").each(function(){
                    jQuery(this).remove();
                });
            }
        });
    });
</script>
<?php
    }
}

Category_Checklist::init();

/**
 * Enqueue the LESS stylesheet
 */
wp_enqueue_style( 'less-style', get_stylesheet_directory_uri() . '/less/custom.less' );

/**
 * Add category class to body of posts
 */
function add_category_name( $classes = '' ) {
   if(is_single()) {
      $category = get_the_category();
      $classes[] = 'category-'.$category[0]->term_taxonomy_id;
   }
   return $classes;
}

add_filter( 'body_class', 'add_category_name' );

/**
 * Remove tags from posts
 */
function sgc_unregister_tags() {
    unregister_taxonomy_for_object_type( 'post_tag', 'post' );
}

add_action( 'init', 'sgc_unregister_tags' );

/**
 * Remove the word category before title on category pages
 */
add_filter( 'get_the_archive_title', function ($title) {
    if ( is_category() ) {
       $title = single_cat_title( '', false );
    }
    elseif ( is_tag() ) {
       $title = single_tag_title( '', false );
    }
    elseif ( is_author() ) {
       $title = '<span class="vcard">' . get_the_author() . '</span>' ;
    }

    return $title;
});

/**
 * Truncate HTML
 */
function truncate_html($string, $length, $postfix = '&hellip;', $isHtml = true) {
    $string = trim($string);
    $postfix = (strlen(strip_tags($string)) > $length) ? $postfix : '';
    $i = 0;
    $tags = [];

    if($isHtml) {
        preg_match_all('/<[^>]+>([^<]*)/', $string, $tagMatches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
        foreach($tagMatches as $tagMatch) {
            if ($tagMatch[0][1] - $i >= $length) {
                break;
            }

            $tag = substr(strtok($tagMatch[0][0], " \t\n\r\0\x0B>"), 1);
            if ($tag[0] != '/') {
                $tags[] = $tag;
            }
            elseif (end($tags) == substr($tag, 1)) {
                array_pop($tags);
            }

            $i += $tagMatch[1][1] - $tagMatch[0][1];
        }
    }

    return substr($string, 0, $length = min(strlen($string), $length + $i)) . (count($tags = array_reverse($tags)) ? '</' . implode('></', $tags) . '>' : '') . $postfix;
}

/**
 * Hide page attributes for all users except administrator
 */
function remove_page_attribute_box() {
    if( is_admin() ) {
        $user = wp_get_current_user();
        $allowed_roles = array('administrator');
            
    if( array_diff( $allowed_roles, $user->roles ) ) {
            remove_meta_box('pageparentdiv', 'page', 'normal');
        }
    }
}

add_action( 'admin_menu', 'remove_page_attribute_box' );

/**
 * Change link of the header logo
 */
/**
add_filter( 'get_custom_logo', 'clean_journal_pro_logo' );

function clean_journal_pro_logo() {
    $custom_logo_id = get_theme_mod( 'custom_logo' );
    $html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
        esc_url( '//www.thesgc.org' ),
    wp_get_attachment_image( $custom_logo_id, 'full', false, array(
        'class'    => 'custom-logo',
    ) )
    );
    return $html;
} */

/**
 * Get the author's email address from the author meta info.
 */
function cf7_get_author_email($atts){
    $value = '';

    if(get_the_author_meta( 'user_email' )) {
        $value = get_the_author_meta( 'user_email' );
    }

    return $value;
 }

add_shortcode( 'CF7_AUTHOR_EMAIL', 'cf7_get_author_email' );

/**
 * Exclude Pingback comments from sidebar recent comments.
 */
function sgc_pingback_recent_comments( $array ) {
    $array['type'] = 'comment';
    return $array;
}

add_filter( 'widget_comments_args', 'sgc_pingback_recent_comments');

/**
 * Exclude people from Past Scientists category to appear in sidebar categories.
 */
function sgc_exclude_widget_categories($args){
    $exclude = "1, 14, 25";
    $args["exclude"] = $exclude;
    return $args;
}
add_filter("widget_categories_args","sgc_exclude_widget_categories");