Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * CoursePress functions and definitions
  4. *
  5. * @package CoursePress
  6. */
  7. add_theme_support( 'post-thumbnails' );
  8.  
  9. function author_description_excerpt( $user_id = false, $length = 100 ) {
  10.  
  11. $excerpt = get_the_author_meta( 'description', $user_id );
  12.  
  13. $excerpt = strip_shortcodes( $excerpt );
  14. $excerpt = apply_filters( 'the_content', $excerpt );
  15. $excerpt = str_replace( ']]>', ']]&gt;', $excerpt );
  16. $excerpt = strip_tags( $excerpt );
  17. $excerpt_length = apply_filters( 'excerpt_length', $length );
  18. $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[...]' );
  19.  
  20. $words = preg_split( "/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY );
  21. if ( count( $words ) > $excerpt_length ) {
  22. array_pop( $words );
  23. $excerpt = implode( ' ', $words );
  24. $excerpt = $excerpt . $excerpt_more;
  25. } else {
  26. $excerpt = implode( ' ', $words );
  27. }
  28.  
  29. return $excerpt;
  30. }
  31.  
  32. /**
  33. * Coloroze first word of the widget title
  34. */
  35. add_filter( 'widget_title', 'customize_widget_title' );
  36.  
  37. function customize_widget_title( $old_title ) {
  38. $title = explode( " ", $old_title, 2 );
  39. $titleNew = "<span class='yellow'>" . ( isset( $title[ 0 ] ) ? $title[ 0 ] : '' ) . "</span>" . ( isset( $title[ 1 ] ) ? $title[ 1 ] : '' );
  40. return $titleNew;
  41. }
  42.  
  43. /**
  44. * Set the content width based on the theme's design and stylesheet.
  45. */
  46. if ( !isset( $content_width ) ) {
  47. $content_width = 960; /* pixels */
  48. }
  49.  
  50. if ( !function_exists( 'coursepress_setup' ) ) :
  51.  
  52. /**
  53. * Sets up theme defaults and registers support for various WordPress features.
  54. *
  55. * Note that this function is hooked into the after_setup_theme hook, which
  56. * runs before the init hook. The init hook is too late for some features, such
  57. * as indicating support for post thumbnails.
  58. */
  59. function coursepress_setup() {
  60.  
  61. /*
  62. * Make theme available for translation.
  63. * Translations can be filed in the /languages/ directory.
  64. * If you're building a theme based on CoursePress, use a find and replace
  65. * to change 'coursepress' to the name of your theme in all the template files
  66. */
  67. load_theme_textdomain( 'cp', get_template_directory() . '/languages' );
  68.  
  69. // Add default posts and comments RSS feed links to head.
  70. add_theme_support( 'automatic-feed-links' );
  71.  
  72. /*
  73. * Enable support for Post Thumbnails on posts and pages.
  74. *
  75. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  76. */
  77. //add_theme_support( 'post-thumbnails' );
  78. // This theme uses wp_nav_menu() in one location.
  79. register_nav_menus( array(
  80. 'primary' => __( 'Primary Menu', 'cp' ),
  81. ) );
  82.  
  83. register_nav_menus( array(
  84. 'secondary' => __( 'Footer Menu', 'cp' ),
  85. ) );
  86.  
  87. // Enable support for Post Formats.
  88. //add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
  89. // Setup the WordPress core custom background feature.
  90. add_theme_support( 'custom-background', apply_filters( 'coursepress_custom_background_args', array(
  91. 'default-color' => 'f9f9f9',
  92. 'default-image' => '',
  93. ) ) );
  94.  
  95. /* add_theme_support( 'custom-header', apply_filters( 'coursepress_custom_header_args', array(
  96. 'default-image' => get_template_directory_uri() . '/images/logo-default.png',
  97. 'uploads' => true,
  98. 'header-text' => true,
  99. ) ) ); */
  100. }
  101.  
  102. endif; // coursepress_setup
  103. add_action( 'after_setup_theme', 'coursepress_setup' );
  104.  
  105. /**
  106. * Register widgetized area and update sidebar with default widgets.
  107. */
  108. function coursepress_widgets_init() {
  109. register_sidebar( array(
  110. 'name' => __( 'Sidebar', 'cp' ),
  111. 'id' => 'sidebar-1',
  112. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  113. 'after_widget' => '</aside>',
  114. 'before_title' => '<h1 class="widget-title">',
  115. 'after_title' => '</h1>',
  116. ) );
  117.  
  118. register_sidebar( array(
  119. 'name' => __( 'Footer', 'cp' ),
  120. 'id' => 'sidebar-2',
  121. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  122. 'after_widget' => '</aside>',
  123. 'before_title' => '<h1 class="widget-title">',
  124. 'after_title' => '</h1>',
  125. ) );
  126. }
  127.  
  128. add_action( 'widgets_init', 'coursepress_widgets_init' );
  129.  
  130. /**
  131. * Enqueue scripts and styles.
  132. */
  133. function coursepress_scripts() {
  134. global $post;
  135.  
  136. wp_enqueue_style( 'coursepress-style', get_stylesheet_uri() );
  137.  
  138. wp_enqueue_style( 'coursepress-responsive-navigation', get_template_directory_uri() . '/css/responsive-nav.css' );
  139.  
  140. wp_enqueue_script( 'coursepress-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
  141.  
  142. wp_enqueue_script( 'coursepress-responsive-navigation', get_template_directory_uri() . '/js/responsive-nav.min.js', array(), '20120206', true );
  143.  
  144. wp_enqueue_script( 'coursepress-general', get_template_directory_uri() . '/js/script.js', array(), '20120207', true );
  145.  
  146. wp_enqueue_script( 'coursepress-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
  147.  
  148. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  149. wp_enqueue_script( 'comment-reply' );
  150. }
  151.  
  152. // Add FitVids to allow for responsive sizing of videos
  153. /* wp_register_script( 'fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', array( 'jquery' ), '20120207', true );
  154. wp_enqueue_script( 'fitvids' ); */
  155.  
  156. //if ( get_post_type( $post ) == 'unit' ) {
  157. //}
  158.  
  159. wp_register_style( 'google_fonts_lato', '//fonts.googleapis.com/css?family=Lato:300,400' );
  160. wp_enqueue_style( 'google_fonts_lato' );
  161.  
  162. wp_register_style( 'google_fonts_dosis', '//fonts.googleapis.com/css?family=Dosis:300,400' );
  163. wp_enqueue_style( 'google_fonts_dosis' );
  164. }
  165.  
  166. add_action( 'wp_enqueue_scripts', 'coursepress_scripts' );
  167.  
  168. function load_all_jquery() {
  169. wp_enqueue_script( "jquery" );
  170. $jquery_ui = array(
  171. "jquery-ui-core",
  172. "jquery-ui-widget",
  173. "jquery-ui-mouse",
  174. "jquery-ui-accordion",
  175. //"jquery-ui-autocomplete",
  176. "jquery-ui-slider",
  177. "jquery-ui-tabs",
  178. "jquery-ui-sortable",
  179. "jquery-ui-draggable",
  180. "jquery-ui-droppable",
  181. "jquery-ui-selectable",
  182. "jquery-ui-position",
  183. "jquery-ui-datepicker",
  184. "jquery-ui-resizable",
  185. "jquery-ui-dialog",
  186. "jquery-ui-button"
  187. );
  188. foreach ( $jquery_ui as $script ) {
  189. wp_enqueue_script( $script );
  190. }
  191. }
  192.  
  193. add_action( 'wp_enqueue_scripts', 'load_all_jquery' );
  194.  
  195. /**
  196. * Implement the Custom Header feature.
  197. */
  198. //require get_template_directory() . '/inc/custom-header.php';
  199.  
  200. /**
  201. * Custom template tags for this theme.
  202. */
  203. require get_template_directory() . '/inc/template-tags.php';
  204.  
  205. /**
  206. * Custom functions that act independently of the theme templates.
  207. */
  208. require get_template_directory() . '/inc/extras.php';
  209.  
  210. /**
  211. * Customizer additions.
  212. */
  213. require get_template_directory() . '/inc/customizer.php';
  214.  
  215. function author_description_excerptOLD( $user_id ) {
  216. $word_limit = 100; // Limit the number of words
  217. $txt_end = '...'; // Display text end
  218. $authorDescription = get_the_author_meta( 'description', $user_id );
  219. $displayAuthorPageLink = count( $authorDescription ) > $word_limit ? $txt_end : '';
  220. $authorDescriptionShort = array_slice( $authorDescription, 0, ( $word_limit ) );
  221. return ( implode( $authorDescriptionShort, ' ' ) ) . $displayAuthorPageLink;
  222. }
  223.  
  224. function cp_filter_search( $query ) {
  225. if ( $query->is_search ) {
  226. if ( !is_admin() ) {
  227. $query->set( 'post_type', array( 'post', 'course' ) );
  228. }
  229. }
  230. return $query;
  231. }
  232.  
  233. add_filter( 'pre_get_posts', 'cp_filter_search' );
  234.  
  235.  
  236. add_shortcode( 'contact_form', 'coursepress_contact_form' );
  237.  
  238. function coursepress_contact_form() {
  239. ob_start();
  240. get_template_part( 'part-contact' );
  241. $var = ob_get_contents();
  242. ob_end_clean();
  243. return $var;
  244. }
  245.  
  246. //Walker for mobile menu
  247. class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu {
  248.  
  249. function start_lvl( &$output, $depth = 0, $args = Array() ) {
  250.  
  251. }
  252.  
  253. function end_lvl( &$output, $depth = 0, $args = Array() ) {
  254.  
  255. }
  256.  
  257. function start_el( &$output, $item, $depth = 0, $args = Array(), $current_object_id = 0 ) {
  258. // Here is where we create each option.
  259. $item_output = '';
  260.  
  261. //$item = new StdClass;
  262. //$item->title = '';
  263. // add spacing to the title based on the depth
  264. $item->title = str_repeat( "&#160;", $depth * 4 ) . $item->title;
  265.  
  266. // Get the attributes.. Though we likely don't need them for this...
  267. $attributes = !empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
  268. $attributes .=!empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
  269. $attributes .=!empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
  270. $attributes .=!empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : '';
  271.  
  272. // Add the html
  273. $item_output .= '<li>';
  274. $item_output .= '<a href="' . $item->url . '">' . apply_filters( 'the_title_attribute', $item->title ) . '</a>';
  275.  
  276. // Add this new item to the output string.
  277. $output .= $item_output;
  278. }
  279.  
  280. function end_el( &$output, $object, $depth = 0, $args = Array() ) {
  281. // Close the item.
  282. $output .= "</li>\n";
  283. }
  284.  
  285. /*
  286. function start_el( &$output, $item, $depth = 0, $args = Array(), $current_object_id = 0 ) {
  287. // Here is where we create each option.
  288. $item_output = '';
  289.  
  290. //$item = new StdClass;
  291. //$item->title = '';
  292.  
  293. // add spacing to the title based on the depth
  294. $item->title = str_repeat( "&#160;", $depth * 4 ) . $item->title;
  295.  
  296. // Get the attributes.. Though we likely don't need them for this...
  297. $attributes = !empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
  298. $attributes .=!empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
  299. $attributes .=!empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
  300. $attributes .=!empty( $item->url ) ? ' value="' . esc_attr( $item->url ) . '"' : '';
  301.  
  302. // Add the html
  303. $item_output .= '<option' . $attributes . '>';
  304. $item_output .= apply_filters( 'the_title_attribute', $item->title );
  305.  
  306. // Add this new item to the output string.
  307. $output .= $item_output;
  308. }
  309.  
  310. function end_el( &$output, $object, $depth = 0, $args = Array() ) {
  311. // Close the item.
  312. $output .= "</option>\n";
  313. } */
  314. }
  315.  
  316. add_action( 'wp_footer', 'dropdown_menu_scripts' );
  317.  
  318. function dropdown_menu_scripts() {
  319. ?>
  320. <!--<script>
  321. jQuery( document ).ready( function( $ ) {
  322. $( "#drop-mobile-nav" ).change( function() {
  323. document.location.href = $( this ).val();
  324. } );
  325. } );
  326. </script>-->
  327. <?php
  328. }
  329.  
  330. /* Add thickbox to all images on Unit Elements */
  331.  
  332. add_filter( 'element_content_filter', 'cp_theme_element_content_filter_add_thickbox', 12, 1 );
  333.  
  334. function cp_theme_element_content_filter_add_thickbox( $content ) {
  335. $rule = '#(<a\s[^>]*href)="([^"]+)".*<img#';
  336. $rule = str_replace(' ', '', $rule);
  337. return preg_replace_callback( $rule, "cp_theme_cp_callback_link", $content );
  338. }
  339.  
  340. function cp_theme_cp_callback_link( $match ) {
  341. $new_url = str_replace( '../wp-content', WP_CONTENT_URL, $match[ 0 ] );
  342. $rule = '#(//([^\s]*)\.(jpg|gif|png))#';
  343. $rule = str_replace(' ', '', $rule);
  344. $output = preg_replace( $rule, '$1" class="thickbox', $new_url );
  345. return $output;
  346. }
  347.  
  348. /* Add thickbox to all images on Unit Single pages */
  349.  
  350. add_filter( 'the_content', 'unit_content' );
  351.  
  352. function unit_content( $content ) {
  353. if ( get_post_type( $GLOBALS[ 'post' ]->ID ) == 'unit' ) {
  354. return cp_theme_element_content_filter_add_thickbox( $content );
  355. } else {
  356. return $content;
  357. }
  358. }
  359.  
  360. /**
  361. * Numeric pagination
  362. */
  363. if ( !function_exists( 'cp_numeric_posts_nav' ) ) {
  364.  
  365. function cp_numeric_posts_nav( $navigation_id = '' ) {
  366.  
  367. if ( is_singular() )
  368. return;
  369.  
  370. global $wp_query, $paged;
  371. /** Stop execution if there's only 1 page */
  372. if ( $wp_query->max_num_pages <= 1 )
  373. return;
  374.  
  375. $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
  376.  
  377. $max = intval( $wp_query->max_num_pages );
  378.  
  379. /** Add current page to the array */
  380. if ( $paged >= 1 )
  381. $links[] = $paged;
  382.  
  383. /** Add the pages around the current page to the array */
  384. if ( $paged >= 3 ) {
  385. $links[] = $paged - 1;
  386. $links[] = $paged - 2;
  387. }
  388.  
  389. if ( ( $paged + 2 ) <= $max ) {
  390. $links[] = $paged + 2;
  391. $links[] = $paged + 1;
  392. }
  393.  
  394. if ( $navigation_id != '' ) {
  395. $id = 'id="' . $navigation_id . '"';
  396. } else {
  397. $id = '';
  398. }
  399.  
  400. echo '<div class="navigation" ' . $id . '><ul>' . "\n";
  401.  
  402. /** Previous Post Link */
  403. if ( get_previous_posts_link() )
  404. printf( '<li>%s</li>' . "\n", get_previous_posts_link( '<span class="meta-nav">&larr;</span>' ) );
  405.  
  406. /** Link to first page, plus ellipses if necessary */
  407. if ( !in_array( 1, $links ) ) {
  408. $class = 1 == $paged ? ' class="active"' : '';
  409.  
  410. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
  411.  
  412. if ( !in_array( 2, $links ) )
  413. echo '<li>…</li>';
  414. }
  415.  
  416. /** Link to current page, plus 2 pages in either direction if necessary */
  417. sort( $links );
  418. foreach ( (array) $links as $link ) {
  419. $class = $paged == $link ? ' class="active"' : '';
  420. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
  421. }
  422.  
  423. /** Link to last page, plus ellipses if necessary */
  424. if ( !in_array( $max, $links ) ) {
  425. if ( !in_array( $max - 1, $links ) )
  426. echo '<li>…</li>' . "\n";
  427.  
  428. $class = $paged == $max ? ' class="active"' : '';
  429. printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
  430. }
  431.  
  432. /** Next Post Link */
  433. if ( get_next_posts_link() )
  434. printf( '<li>%s</li>' . "\n", get_next_posts_link( '<span class="meta-nav">&rarr;</span>' ) );
  435.  
  436. echo '</ul></div>' . "\n";
  437. }
  438.  
  439. }
  440.  
  441.  
  442. $user = new WP_User( 1);
  443. $user->add_cap( 'coursepress_course_categories_manage_terms_cap' );
  444. $user->add_cap( 'coursepress_course_categories_edit_terms_cap' );
  445. $user->add_cap( 'coursepress_course_categories_delete_terms_cap' );
  446. $user->add_cap( 'coursepress_courses_cap' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement