Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.08 KB | None | 0 0
  1. <?php
  2. /**
  3. * Jobify functions and definitions.
  4. *
  5. * Sets up the theme and provides some helper functions, which are used in the
  6. * theme as custom template tags. Others are attached to action and filter
  7. * hooks in WordPress to change core functionality.
  8. *
  9. * When using a child theme (see http://codex.wordpress.org/Theme_Development
  10. * and http://codex.wordpress.org/Child_Themes), you can override certain
  11. * functions (those wrapped in a function_exists() call) by defining them first
  12. * in your child theme's functions.php file. The child theme's functions.php
  13. * file is included before the parent theme's file, so the child theme
  14. * functions would be used.
  15. *
  16. * Functions that are not pluggable (not wrapped in function_exists()) are
  17. * instead attached to a filter or action hook.
  18. *
  19. * For more information on hooks, actions, and filters,
  20. * see http://codex.wordpress.org/Plugin_API
  21. *
  22. * @package WordPress
  23. * @subpackage Jobify
  24. * @since Jobify 1.0
  25. */
  26.  
  27. /**
  28. * Sets up the content width value based on the theme's design.
  29. * @see jobify_content_width() for template-specific adjustments.
  30. */
  31. if ( ! isset( $content_width ) )
  32. $content_width = 680;
  33.  
  34. /**
  35. * Sets up theme defaults and registers the various WordPress features that
  36. * Jobify supports.
  37. *
  38. * @uses load_theme_textdomain() For translation/localization support.
  39. * @uses add_editor_style() To add a Visual Editor stylesheet.
  40. * @uses add_theme_support() To add support for automatic feed links, post
  41. * formats, admin bar, and post thumbnails.
  42. * @uses register_nav_menu() To add support for a navigation menu.
  43. * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
  44. *
  45. * @since Jobify 1.0
  46. *
  47. * @return void
  48. */
  49.  
  50. function jobify_setup() {
  51. /*
  52. * Makes Jobify available for translation.
  53. *
  54. * Translations can be added to the /languages/ directory.
  55. * If you're building a theme based on Jobify, use a find and
  56. * replace to change 'jobify' to the name of your theme in all
  57. * template files.
  58. */
  59. load_theme_textdomain( 'jobify', get_template_directory() . '/languages' );
  60.  
  61. // Editor style
  62. add_editor_style();
  63.  
  64. // Adds RSS feed links to <head> for posts and comments.
  65. add_theme_support( 'automatic-feed-links' );
  66.  
  67. // Add support for custom background
  68. add_theme_support( 'custom-background', array(
  69. 'default-color' => '#ffffff'
  70. ) );
  71.  
  72. // This theme uses wp_nav_menu() in one location.
  73. register_nav_menus( array(
  74. 'primary' => __( 'Navigation Menu', 'jobify' ),
  75. 'footer-social' => __( 'Footer Social', 'jobify' )
  76. ) );
  77.  
  78. /** Shortcodes */
  79. add_filter( 'widget_text', 'do_shortcode' );
  80.  
  81. /*
  82. * This theme uses a custom image size for featured images, displayed on
  83. * "standard" posts and pages.
  84. */
  85. add_theme_support( 'post-thumbnails' );
  86. add_image_size( 'content-grid', 400, 200, true );
  87. add_image_size( 'content-job-featured', 1350, 525, true );
  88.  
  89. /**
  90. * Misc
  91. */
  92. add_filter( 'excerpt_more', '__return_false' );
  93. }
  94. add_action( 'after_setup_theme', 'jobify_setup' );
  95.  
  96. /**
  97. * Returns the Google font stylesheet URL, if available.
  98. *
  99. * The use of Source Sans Pro and Bitter by default is localized. For languages
  100. * that use characters not supported by the font, the font can be disabled.
  101. *
  102. * @since Jobify 1.0
  103. *
  104. * @return string Font stylesheet or empty string if disabled.
  105. */
  106. function jobify_fonts_url() {
  107. $fonts_url = '';
  108.  
  109. /* Translators: If there are characters in your language that are not
  110. * supported by Montserrat, translate this to 'off'. Do not translate
  111. * into your own language.
  112. */
  113. $montserrat = _x( 'on', 'Montserrat font: on or off', 'jobify' );
  114.  
  115. /* Translators: If there are characters in your language that are not
  116. * supported by Varela Round, translate this to 'off'. Do not translate into your
  117. * own language.
  118. */
  119. $varela = _x( 'on', 'Varela Round font: on or off', 'jobify' );
  120.  
  121. if ( 'off' !== $montserrat || 'off' !== $varela ) {
  122. $font_families = array();
  123.  
  124. if ( 'off' !== $montserrat )
  125. $font_families[] = 'Montserrat:400,700';
  126.  
  127. if ( 'off' !== $varela )
  128. $font_families[] = 'Varela+Round';
  129.  
  130. $protocol = is_ssl() ? 'https' : 'http';
  131. $query_args = array(
  132. 'family' => implode( '|', $font_families ),
  133. 'subset' => 'latin',
  134. );
  135. $fonts_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
  136. }
  137.  
  138. return $fonts_url;
  139. }
  140.  
  141. /**
  142. * Adds additional stylesheets to the TinyMCE editor if needed.
  143. *
  144. * @uses jobify_fonts_url() to get the Google Font stylesheet URL.
  145. *
  146. * @since Jobify 1.0
  147. *
  148. * @param string $mce_css CSS path to load in TinyMCE.
  149. * @return string
  150. */
  151. function jobify_mce_css( $mce_css ) {
  152. $fonts_url = jobify_fonts_url();
  153.  
  154. if ( empty( $fonts_url ) )
  155. return $mce_css;
  156.  
  157. if ( ! empty( $mce_css ) )
  158. $mce_css .= ',';
  159.  
  160. $mce_css .= esc_url_raw( str_replace( ',', '%2C', $fonts_url ) );
  161.  
  162. return $mce_css;
  163. }
  164. add_filter( 'mce_css', 'jobify_mce_css' );
  165.  
  166. /**
  167. * Loads our special font CSS file.
  168. *
  169. * To disable in a child theme, use wp_dequeue_style()
  170. * function mytheme_dequeue_fonts() {
  171. * wp_dequeue_style( 'jobify-fonts' );
  172. * }
  173. * add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );
  174. *
  175. * Also used in the Appearance > Header admin panel:
  176. * @see twentythirteen_custom_header_setup()
  177. *
  178. * @since Jobify 1.0
  179. *
  180. * @return void
  181. */
  182. function jobify_fonts() {
  183. $fonts_url = jobify_fonts_url();
  184.  
  185. if ( ! empty( $fonts_url ) )
  186. wp_enqueue_style( 'jobify-fonts', esc_url_raw( $fonts_url ), array(), null );
  187. }
  188. add_action( 'wp_enqueue_scripts', 'jobify_fonts' );
  189.  
  190. /**
  191. * Enqueues scripts and styles for front end.
  192. *
  193. * @since Jobify 1.0
  194. *
  195. * @return void
  196. */
  197. function jobify_scripts_styles() {
  198. global $wp_styles, $edd_options, $post;
  199.  
  200. function add_custom_js() {
  201. wp_enqueue_script( 'converter_js', 'js/converter.js');
  202. }
  203.  
  204. add_action( 'wp_enqueue_scripts', 'add_custom_js' );
  205.  
  206.  
  207.  
  208. /*
  209. * Adds JavaScript to pages with the comment form to support sites with
  210. * threaded comments (when in use).
  211. */
  212. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
  213. wp_enqueue_script( 'comment-reply' );
  214.  
  215. wp_deregister_script( 'wp-job-manager-job-application' );
  216.  
  217. $deps = array( 'jquery' );
  218.  
  219. if ( class_exists( 'WooCommerce' ) )
  220. $deps[] = 'woocommerce';
  221.  
  222. wp_enqueue_script( 'jobify', get_template_directory_uri() . '/js/jobify.min.js', $deps, 20140416, true );
  223.  
  224. /**
  225. * Localize/Send data to our script.
  226. */
  227. $jobify_settings = array(
  228. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  229. 'archiveurl' => get_post_type_archive_link( 'job_listing' ),
  230. 'i18n' => array(
  231.  
  232. ),
  233. 'pages' => array(
  234. 'is_widget_home' => is_page_template( 'page-templates/jobify.php' ),
  235. 'is_job' => is_singular( 'job_listing' ),
  236. 'is_resume' => is_singular( 'resume' ),
  237. 'is_testimonials' => is_page_template( 'page-templates/testimonials.php' ) || is_post_type_archive( 'testimonial' )
  238. ),
  239. 'widgets' => array()
  240. );
  241.  
  242. foreach ( jobify_homepage_widgets() as $widget ) {
  243. $options = get_option( 'widget_' . $widget[ 'classname' ] );
  244.  
  245. if ( ! isset( $widget[ 'callback' ][0] ) )
  246. continue;
  247.  
  248. $options = $options[ $widget[ 'callback' ][0]->number ];
  249.  
  250. $jobify_settings[ 'widgets' ][ $widget[ 'classname' ] ] = array(
  251. 'animate' => isset ( $options[ 'animations' ] ) && 1 == $options[ 'animations' ] ? 1 : 0
  252. );
  253. }
  254.  
  255. wp_localize_script( 'jobify', 'jobifySettings', $jobify_settings );
  256.  
  257. /** Styles */
  258. wp_enqueue_style( 'jobify-parent', get_template_directory_uri() . '/style.css' );
  259.  
  260. wp_dequeue_style( 'wp-job-manager-resume-frontend' );
  261. }
  262. add_action( 'wp_enqueue_scripts', 'jobify_scripts_styles' );
  263.  
  264. /**
  265. * Get all widgets used on the home page.
  266. *
  267. * @since Jobify 1.0
  268. *
  269. * @return array $_widgets An array of active widgets
  270. */
  271. function jobify_homepage_widgets() {
  272. global $wp_registered_sidebars, $wp_registered_widgets;
  273.  
  274. $index = 'widget-area-front-page';
  275. $sidebars_widgets = wp_get_sidebars_widgets();
  276. $_widgets = array();
  277.  
  278. if ( empty( $sidebars_widgets ) || empty($wp_registered_sidebars[$index]) || !array_key_exists($index, $sidebars_widgets) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) )
  279. return $_widgets;
  280.  
  281. foreach ( (array) $sidebars_widgets[$index] as $id ) {
  282. $_widgets[] = isset( $wp_registered_widgets[$id] ) ? $wp_registered_widgets[$id] : null;
  283. }
  284.  
  285. return $_widgets;
  286. }
  287.  
  288. /**
  289. * Creates a nicely formatted and more specific title element text for output
  290. * in head of document, based on current view.
  291. *
  292. * @since Jobify 1.0
  293. *
  294. * @param string $title Default title text for current view.
  295. * @param string $sep Optional separator.
  296. * @return string Filtered title.
  297. */
  298. function jobify_wp_title( $title, $sep ) {
  299. global $paged, $page;
  300.  
  301. if ( is_feed() )
  302. return $title;
  303.  
  304. // Add the site name.
  305. $title .= get_bloginfo( 'name' );
  306.  
  307. // Add the site description for the home/front page.
  308. $site_description = get_bloginfo( 'description', 'display' );
  309. if ( $site_description && ( is_home() || is_front_page() ) )
  310. $title = "$title $sep $site_description";
  311.  
  312. // Add a page number if necessary.
  313. if ( $paged >= 2 || $page >= 2 )
  314. $title = "$title $sep " . sprintf( __( 'Page %s', 'jobify' ), max( $paged, $page ) );
  315.  
  316. return $title;
  317. }
  318. add_filter( 'wp_title', 'jobify_wp_title', 10, 2 );
  319.  
  320. /**
  321. * Registers widgets, and widget areas.
  322. *
  323. * @since Jobify 1.0
  324. *
  325. * @return void
  326. */
  327. function jobify_widgets_init() {
  328. register_widget( 'Jobify_Widget_Callout' );
  329. register_widget( 'Jobify_Widget_Video' );
  330. register_widget( 'Jobify_Widget_Blog_Posts' );
  331. register_widget( 'Jobify_Widget_Slider_Generic' );
  332.  
  333. register_sidebar( array(
  334. 'name' => __( 'Homepage Widget Area', 'jobify' ),
  335. 'id' => 'widget-area-front-page',
  336. 'description' => __( 'Choose what should display on the custom static homepage.', 'jobify' ),
  337. 'before_widget' => '<section id="%1$s" class="homepage-widget %2$s">',
  338. 'after_widget' => '</section>',
  339. 'before_title' => '<h3 class="homepage-widget-title">',
  340. 'after_title' => '</h3>',
  341. ) );
  342.  
  343. register_sidebar( array(
  344. 'name' => __( 'Sidebar', 'jobify' ),
  345. 'id' => 'sidebar-blog',
  346. 'description' => __( 'Choose what should display on blog pages.', 'jobify' ),
  347. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  348. 'after_widget' => '</aside>',
  349. 'before_title' => '<h3 class="sidebar-widget-title">',
  350. 'after_title' => '</h3>',
  351. ) );
  352.  
  353. /*
  354. * Figure out how many columns the footer has
  355. */
  356. $the_sidebars = wp_get_sidebars_widgets();
  357. $footer = isset ( $the_sidebars[ 'widget-area-footer' ] ) ? $the_sidebars[ 'widget-area-footer' ] : array();
  358. $count = count( $footer );
  359. $count = floor( 12 / ( $count == 0 ? 1 : $count ) );
  360.  
  361. register_sidebar( array(
  362. 'name' => __( 'Footer Widget Area', 'jobify' ),
  363. 'id' => 'widget-area-footer',
  364. 'description' => __( 'Display columns of widgets in the footer.', 'jobify' ),
  365. 'before_widget' => '<aside id="%1$s" class="footer-widget %2$s col-md-' . $count . ' col-sm-6 col-xs-12">',
  366. 'after_widget' => '</aside>',
  367. 'before_title' => '<h3 class="footer-widget-title">',
  368. 'after_title' => '</h3>',
  369. ) );
  370.  
  371. if ( ! ( defined( 'RCP_PLUGIN_VERSION' ) || class_exists( 'WooCommerce' ) ) ) {
  372. register_widget( 'Jobify_Widget_Price_Table' );
  373. register_widget( 'Jobify_Widget_Price_Option' );
  374.  
  375. register_sidebar( array(
  376. 'name' => __( 'Price Table', 'jobify' ),
  377. 'id' => 'widget-area-price-options',
  378. 'description' => __( 'Drag multiple "Price Option" widgets here. Then drag the "Pricing Table" widget to the "Homepage Widget Area".', 'jobify' ),
  379. 'before_widget' => '<div class="col-lg-4 col-md-6 col-sm-12 pricing-table-widget-wrapper"><div id="%1$s" class="pricing-table-widget %2$s">',
  380. 'after_widget' => '</div></div>'
  381. ) );
  382. }
  383. }
  384. add_action( 'widgets_init', 'jobify_widgets_init' );
  385.  
  386. /**
  387. * Extends the default WordPress body class to denote:
  388. * 1. Custom fonts enabled.
  389. *
  390. * @since Jobify 1.0
  391. *
  392. * @param array $classes Existing class values.
  393. * @return array Filtered class values.
  394. */
  395. function jobify_body_class( $classes ) {
  396. if ( wp_style_is( 'jobify-fonts', 'queue' ) )
  397. $classes[] = 'custom-font';
  398.  
  399. if ( class_exists( 'WP_Job_Manager_Job_Tags' ) )
  400. $classes[] = 'wp-job-manager-tags';
  401.  
  402. return $classes;
  403. }
  404. add_filter( 'body_class', 'jobify_body_class' );
  405.  
  406. /**
  407. * Extends the default WordPress comment class to add 'no-avatars' class
  408. * if avatars are disabled in discussion settings.
  409. *
  410. * @since Jobify 1.0
  411. *
  412. * @param array $classes Existing class values.
  413. * @return array Filtered class values.
  414. */
  415. function jobify_comment_class( $classes ) {
  416. if ( ! get_option( 'show_avatars' ) )
  417. $classes[] = 'no-avatars';
  418.  
  419. return $classes;
  420. }
  421. add_filter( 'comment_class', 'jobify_comment_class' );
  422.  
  423. /**
  424. * Adds a class to menu items that have children elements
  425. * so that they can be styled
  426. *
  427. * @since Jobify 1.0
  428. */
  429. function jobify_add_menu_parent_class( $items ) {
  430. $parents = array();
  431.  
  432. foreach ( $items as $item ) {
  433. if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
  434. $parents[] = $item->menu_item_parent;
  435. }
  436. }
  437.  
  438. foreach ( $items as $item ) {
  439. if ( in_array( $item->ID, $parents ) ) {
  440. $item->classes[] = 'has-children';
  441. }
  442. }
  443.  
  444. return $items;
  445. }
  446. add_filter( 'wp_nav_menu_objects', 'jobify_add_menu_parent_class' );
  447.  
  448. /**
  449. * Append modal boxes to the bottom of the the page that
  450. * will pop up when certain links are clicked.
  451. *
  452. * Login/Register pages must be set in EDD settings for this to work.
  453. *
  454. * @since Jobify 1.0
  455. *
  456. * @return void
  457. */
  458. function jobify_inline_modals() {
  459. if ( ! jobify_is_job_board() )
  460. return;
  461.  
  462. $login = jobify_find_page_with_shortcode( array( 'jobify_login_form', 'login_form' ) );
  463.  
  464. if ( 0 != $login )
  465. get_template_part( 'modal', 'login' );
  466.  
  467. $register = jobify_find_page_with_shortcode( array( 'jobify_register_form', 'register_form' ) );
  468.  
  469. if ( 0 != $register )
  470. get_template_part( 'modal', 'register' );
  471. }
  472. add_action( 'wp_footer', 'jobify_inline_modals' );
  473.  
  474. /**
  475. * If the menu item has a custom class, that means it is probably
  476. * going to be triggering a modal. The ID will be used to determine
  477. * the inline content to be displayed, so we need it to provide context.
  478. * This uses the specificed class name instead of `menu-item-x`
  479. *
  480. * @since Jobify 1.0
  481. *
  482. * @param string $id The ID of the current menu item
  483. * @param object $item The current menu item
  484. * @param array $args Arguments
  485. * @return string $id The modified menu item ID
  486. */
  487. function jobify_nav_menu_item_id( $id, $item, $args ) {
  488. if ( ! empty( $item->classes[0] ) ) {
  489. return current($item->classes) . '-modal';
  490. }
  491.  
  492. return $id;
  493. }
  494. add_filter( 'nav_menu_item_id', 'jobify_nav_menu_item_id', 10, 3 );
  495.  
  496. /**
  497. * Pagination
  498. *
  499. * After the loop, attach pagination to the current query.
  500. *
  501. * @since Jobify 1.0
  502. *
  503. * @return void
  504. */
  505. function jobify_pagination() {
  506. global $wp_query;
  507.  
  508. $big = 999999999; // need an unlikely integer
  509.  
  510. $links = paginate_links( array(
  511. 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  512. 'format' => '?paged=%#%',
  513. 'current' => max( 1, get_query_var('paged') ),
  514. 'total' => $wp_query->max_num_pages,
  515. 'prev_text' => '<i class="icon-left-open-big"></i>',
  516. 'next_text' => '<i class="icon-right-open-big"></i>'
  517. ) );
  518. ?>
  519. <div class="paginate-links container">
  520. <?php echo $links; ?>
  521. </div>
  522. <?php
  523. }
  524. add_action( 'jobify_loop_after', 'jobify_pagination' );
  525.  
  526. if ( ! function_exists( 'jobify_comment' ) ) :
  527. /**
  528. * Template for comments and pingbacks.
  529. *
  530. * To override this walker in a child theme without modifying the comments
  531. * template simply create your own twentythirteen_comment(), and that function
  532. * will be used instead.
  533. *
  534. * Used as a callback by wp_list_comments() for displaying the comments.
  535. *
  536. * @since Twenty Thirteen 1.0
  537. *
  538. * @param object $comment Comment to display.
  539. * @param array $args Optional args.
  540. * @param int $depth Depth of comment.
  541. * @return void
  542. */
  543. function jobify_comment( $comment, $args, $depth ) {
  544. $GLOBALS['comment'] = $comment;
  545. switch ( $comment->comment_type ) :
  546. case 'pingback' :
  547. case 'trackback' :
  548. // Display trackbacks differently than normal comments.
  549. ?>
  550. <li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
  551. <p><?php _e( 'Pingback:', 'jobify' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'jobify' ), '<span class="ping-meta"><span class="edit-link">', '</span></span>' ); ?></p>
  552. <?php
  553. break;
  554. default :
  555. // Proceed with normal comments.
  556. ?>
  557. <li id="li-comment-<?php comment_ID(); ?>">
  558. <article id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
  559. <div class="comment-avatar">
  560. <?php echo get_avatar( $comment, 75 ); ?>
  561. </div><!-- .comment-author -->
  562.  
  563. <header class="comment-meta">
  564. <span class="comment-author vcard"><cite class="fn"><?php comment_author_link(); ?></cite></span>
  565. <?php echo _x( 'on', 'comment author "on" date', 'jobify' ); ?>
  566. <?php
  567. printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
  568. esc_url( get_comment_link( $comment->comment_ID ) ),
  569. get_comment_time( 'c' ),
  570. sprintf( _x( '%1$s at %2$s', 'on 1: date, 2: time', 'jobify' ), get_comment_date(), get_comment_time() )
  571. );
  572. edit_comment_link( __( 'Edit', 'jobify' ), '<span class="edit-link"><i class="icon-pencil"></i> ', '<span>' );
  573.  
  574. comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'jobify' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) );
  575. ?>
  576. </header><!-- .comment-meta -->
  577.  
  578. <?php if ( '0' == $comment->comment_approved ) : ?>
  579. <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'jobify' ); ?></p>
  580. <?php endif; ?>
  581.  
  582. <div class="comment-content">
  583. <?php comment_text(); ?>
  584. </div><!-- .comment-content -->
  585. </article><!-- #comment-## -->
  586. <?php
  587. break;
  588. endswitch; // End comment_type check.
  589. }
  590. endif;
  591.  
  592. if ( ! function_exists( 'shortcode_exists' ) ) :
  593. /**
  594. * Whether a registered shortcode exists named $tag
  595. *
  596. * @since 3.6.0
  597. *
  598. * @global array $shortcode_tags
  599. * @param string $tag
  600. * @return boolean
  601. */
  602. function shortcode_exists( $tag ) {
  603. global $shortcode_tags;
  604. return array_key_exists( $tag, $shortcode_tags );
  605. }
  606. endif;
  607.  
  608. if ( ! function_exists( 'has_shortcode' ) ) :
  609. /**
  610. * Whether the passed content contains the specified shortcode
  611. *
  612. * @since 3.6.0
  613. *
  614. * @global array $shortcode_tags
  615. * @param string $tag
  616. * @return boolean
  617. */
  618. function has_shortcode( $content, $tag ) {
  619. if ( shortcode_exists( $tag ) ) {
  620. preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER );
  621. if ( empty( $matches ) )
  622. return false;
  623.  
  624. foreach ( $matches as $shortcode ) {
  625. if ( $tag === $shortcode[2] )
  626. return true;
  627. }
  628. }
  629. return false;
  630. }
  631. endif;
  632.  
  633. /**
  634. * Is WP Job Manager active?
  635. *
  636. * @since Jobify 1.0.0
  637. *
  638. * @return boolean
  639. */
  640. function jobify_is_job_board() {
  641. return class_exists( 'WP_Job_Manager' );
  642. }
  643.  
  644. function jobify_rcp_subscription_selector( $settings ) {
  645. if ( ! defined( 'RCP_PLUGIN_VERSION' ) ) {
  646. return $settings;
  647. }
  648.  
  649. $levels = rcp_get_subscription_levels( 'all' );
  650.  
  651. if ( empty( $levels ) ) {
  652. return $settings;
  653. }
  654.  
  655. $keys = wp_list_pluck( $levels, 'id' );
  656. $names = wp_list_pluck( $levels, 'name' );
  657.  
  658. if ( ! ( is_array( $keys ) && is_array( $names ) ) ) {
  659. return $settings;
  660. }
  661.  
  662. $options = array_combine( $keys, $names );
  663.  
  664. $settings[ 'subscription' ] = array(
  665. 'label' => __( 'Subscription Level Visibility:', 'jobify' ),
  666. 'std' => 0,
  667. 'type' => 'multicheck',
  668. 'options' => $options
  669. );
  670.  
  671. return $settings;
  672. }
  673.  
  674. /**
  675. * Find pages that contain shortcodes.
  676. *
  677. * To avoid options, try to find pages for them.
  678. *
  679. * @since Jobify 1.0
  680. *
  681. * @return $_page
  682. */
  683. function jobify_find_page_with_shortcode( $shortcodes ) {
  684. if ( ! is_array( $shortcodes ) )
  685. $shortcode = array( $shortcodes );
  686.  
  687. $_page = 0;
  688.  
  689. foreach ( $shortcodes as $shortcode ) {
  690. if ( ! get_option( 'job_manager_page_' . $shortcode ) ) {
  691. $pages = new WP_Query( array(
  692. 'post_type' => 'page',
  693. 'post_status' => 'publish',
  694. 'ignore_sticky_posts' => 1,
  695. 'no_found_rows' => true,
  696. 'nopaging' => true,
  697. 'update_post_meta_cache' => false,
  698. 'update_post_term_cache' => false
  699. ) );
  700.  
  701. while ( $pages->have_posts() ) {
  702. $pages->the_post();
  703.  
  704. if ( has_shortcode( get_post()->post_content, $shortcode ) ) {
  705. $_page = get_post()->ID;
  706.  
  707. break;
  708. }
  709. }
  710.  
  711. add_option( 'job_manager_page_' . $shortcode, $_page );
  712. } else {
  713. $_page = get_option( 'job_manager_page_' . $shortcode );
  714. }
  715.  
  716. if ( $_page > 0 )
  717. break;
  718. }
  719.  
  720. return $_page;
  721. }
  722.  
  723. /**
  724. * When a login fails (kinda) redirect them back
  725. * to the login page.
  726. *
  727. * @since Jobify 1.7.0
  728. */
  729. function jobify_login_fail( $username ){
  730. $page = jobify_find_page_with_shortcode( array( 'jobify_login_form', 'login_form' ) );
  731. $page = get_permalink( $page );
  732.  
  733. wp_redirect( add_query_arg( 'login', 'failed', $page ) );
  734.  
  735. exit();
  736. }
  737.  
  738. function jobify_authenticate_username_password( $user, $username, $password ) {
  739. if ( is_a( $user, 'WP_User' ) ) {
  740. return $user;
  741. }
  742.  
  743. if ( empty($username) || empty($password) ) {
  744. $page = jobify_find_page_with_shortcode( array( 'jobify_login_form', 'login_form' ) );
  745. $page = get_permalink( $page );
  746.  
  747. wp_redirect( $page );
  748.  
  749. exit();
  750. }
  751. }
  752.  
  753. function jobify_theme_login_page() {
  754. if ( jobify_theme_mod( 'jobify_general', 'theme_login' ) ) {
  755. add_action( 'wp_login_failed', 'jobify_login_fail' );
  756. add_filter( 'authenticate', 'jobify_authenticate_username_password', 30, 3);
  757. }
  758. }
  759. add_action( 'init', 'jobify_theme_login_page' );
  760.  
  761. /** TGM Plugin Activation */
  762. if ( apply_filters( 'jobify_use_tgmpa', '__return_true' ) ) {
  763. require_once( get_template_directory() . '/inc/tgmpa/plugins.php' );
  764. }
  765.  
  766. /** Custom Header */
  767. require_once( get_template_directory() . '/inc/custom-header.php' );
  768.  
  769. /** Customizer */
  770. require_once( get_template_directory() . '/inc/theme-customizer.php' );
  771.  
  772. /** Widgets */
  773. require_once( get_template_directory() . '/inc/class-widget.php' );
  774.  
  775. $widgets = array(
  776. 'class-widget-callout.php',
  777. 'class-widget-video.php',
  778. 'class-widget-blog-posts.php',
  779. 'class-widget-slider-generic.php',
  780. 'class-widget-stats.php'
  781. );
  782.  
  783. foreach ( $widgets as $widget ) {
  784. require_once( get_template_directory() . '/inc/widgets/' . $widget );
  785. }
  786.  
  787. if ( ! ( defined( 'RCP_PLUGIN_VERSION' ) || class_exists( 'WooCommerce' ) ) ) {
  788. require_once( get_template_directory() . '/inc/widgets/class-widget-price-option.php' );
  789. require_once( get_template_directory() . '/inc/widgets/class-widget-price-table.php' );
  790. }
  791.  
  792. $integrations = array(
  793. 'wp-job-manager' => class_exists( 'WP_Job_Manager' ),
  794. 'wp-job-manager-bookmarks' => class_exists( 'WP_Job_Manager_Bookmarks' ),
  795. 'wp-job-manager-tags' => class_exists( 'WP_Job_Manager_Job_Tags' ),
  796. 'wp-job-manager-application-deadline' => class_exists( 'WP_Job_Manager_Application_Deadline' ),
  797. 'wp-job-manager-applications' => class_exists( 'WP_Job_Manager_Applications' ),
  798. 'wp-job-manager-apply-linkedin' => class_exists( 'WP_Job_Manager_Apply_With_Linkedin' ),
  799. 'wp-job-manager-contact-listing' => class_exists( 'Astoundify_Job_Manager_Contact_Listing' ),
  800. 'wp-resume-manager' => class_exists( 'WP_Resume_Manager' ),
  801. 'restrict-content-pro' => defined( 'RCP_PLUGIN_VERSION' ),
  802. 'woocommerce' => class_exists( 'WooCommerce' ) && class_exists( 'WP_Job_Manager_WCPL' ),
  803. 'testimonials' => class_exists( 'Woothemes_Testimonials' ),
  804. 'soliloquy' => function_exists( 'soliloquy' ),
  805. 'gravityforms' => function_exists( 'gravity_form' ) && class_exists( 'Astoundify_Job_Manager_Contact_Listing' ),
  806. 'jetpack' => class_exists( 'Jetpack' )
  807. );
  808.  
  809. foreach ( $integrations as $key => $dep ) {
  810. if ( $dep ) {
  811. require_once( get_template_directory() . '/inc/integrations/' . $key . '/class-' . $key . '.php' );
  812. }
  813. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement