Advertisement
Guest User

Untitled

a guest
May 13th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.59 KB | None | 0 0
  1. <?php
  2. /**
  3. * Listify functions and definitions
  4. *
  5. * @package Listify
  6. */
  7.  
  8. /**
  9. * Set the content width based on the theme's design and stylesheet.
  10. */
  11. if ( ! isset( $content_width ) )
  12. $content_width = 750;
  13.  
  14. if ( ! function_exists( 'listify_setup' ) ) :
  15. /**
  16. * Sets up theme defaults and registers support for various WordPress features.
  17. *
  18. * Note that this function is hooked into the after_setup_theme hook, which runs
  19. * before the init hook. The init hook is too late for some features, such as indicating
  20. * support post thumbnails.
  21. *
  22. * @since Listify 1.0.0
  23. *
  24. * @return void
  25. */
  26. function listify_setup() {
  27. /**
  28. * Translations can be filed in the /languages/ directory.
  29. */
  30. $locale = apply_filters( 'plugin_locale', get_locale(), 'listify' );
  31. load_textdomain( 'listify', WP_LANG_DIR . "/listify-$locale.mo" );
  32. load_theme_textdomain( 'listify', get_template_directory() . '/languages' );
  33.  
  34. /**
  35. * Add default posts and comments RSS feed links to head
  36. */
  37. add_theme_support( 'automatic-feed-links' );
  38.  
  39. /**
  40. * Enable support for Post Thumbnails on posts and pages
  41. *
  42. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  43. */
  44. add_theme_support( 'post-thumbnails' );
  45.  
  46. /**
  47. * Let WP set the title
  48. */
  49. add_theme_support( 'title-tag' );
  50.  
  51. /**
  52. * This theme uses wp_nav_menu() in one location.
  53. */
  54. register_nav_menus( array(
  55. 'primary' => __( 'Primary Menu (header)', 'listify' ),
  56. 'secondary' => __( 'Secondary Menu', 'listify' ),
  57. 'tertiary' => __( 'Tertiary Menu', 'listify' ),
  58. 'social' => __( 'Social Menu (footer)', 'listify' )
  59. ) );
  60.  
  61. /*
  62. * Switch default core markup for search form, comment form, and comments
  63. * to output valid HTML5.
  64. */
  65. add_theme_support( 'html5', array(
  66. 'search-form', 'comment-form', 'commentlist', 'gallery', 'caption'
  67. ) );
  68.  
  69. /**
  70. * Editor Style
  71. */
  72. add_editor_style( 'css/editor-style.css' );
  73.  
  74. /**
  75. * Setup the WordPress core custom background feature.
  76. */
  77. add_theme_support( 'custom-background', apply_filters( 'listify_custom_background_args', array(
  78. 'default-color' => 'f0f3f6',
  79. 'default-image' => '',
  80. ) ) );
  81.  
  82. /**
  83. * Post thumbnails
  84. */
  85. set_post_thumbnail_size( 100, 100, true );
  86. }
  87. endif;
  88. add_action( 'after_setup_theme', 'listify_setup' );
  89.  
  90. /**
  91. * Sidebars and Widgets
  92. *
  93. * @since Listify 1.0.0
  94. *
  95. * @return void
  96. */
  97. function listify_widgets_init() {
  98. register_widget( 'Listify_Widget_Ad' );
  99. register_widget( 'Listify_Widget_Features' );
  100. register_widget( 'Listify_Widget_Feature_Callout' );
  101.  
  102. /* Standard Sidebar */
  103. register_sidebar( array(
  104. 'name' => __( 'Sidebar', 'listify' ),
  105. 'id' => 'widget-area-sidebar-1',
  106. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  107. 'after_widget' => '</aside>',
  108. 'before_title' => '<h3 class="widget-title">',
  109. 'after_title' => '</h3>',
  110. ) );
  111.  
  112. /* Custom Homepage */
  113. register_sidebar( array(
  114. 'name' => __( 'Homepage', 'listify' ),
  115. 'description' => __( 'Widgets that appear on the "Homepage" Page Template', 'listify' ),
  116. 'id' => 'widget-area-home',
  117. 'before_widget' => '<aside id="%1$s" class="home-widget %2$s">',
  118. 'after_widget' => '</aside>',
  119. 'before_title' => '<div class="home-widget-section-title"><h2 class="home-widget-title">',
  120. 'after_title' => '</h2></div>',
  121. ) );
  122.  
  123. /* Footer Column 1 */
  124. register_sidebar( array(
  125. 'name' => __( 'Footer Column 1 (wide)', 'listify' ),
  126. 'id' => 'widget-area-footer-1',
  127. 'before_widget' => '<aside id="%1$s" class="footer-widget %2$s">',
  128. 'after_widget' => '</aside>',
  129. 'before_title' => '<h4 class="footer-widget-title">',
  130. 'after_title' => '</h4>',
  131. ) );
  132.  
  133. /* Footer Column 2 */
  134. register_sidebar( array(
  135. 'name' => __( 'Footer Column 2', 'listify' ),
  136. 'id' => 'widget-area-footer-2',
  137. 'before_widget' => '<aside id="%1$s" class="footer-widget %2$s">',
  138. 'after_widget' => '</aside>',
  139. 'before_title' => '<h4 class="footer-widget-title">',
  140. 'after_title' => '</h4>',
  141. ) );
  142.  
  143. /* Footer Column 3 */
  144. register_sidebar( array(
  145. 'name' => __( 'Footer Column 3', 'listify' ),
  146. 'id' => 'widget-area-footer-3',
  147. 'before_widget' => '<aside id="%1$s" class="footer-widget %2$s">',
  148. 'after_widget' => '</aside>',
  149. 'before_title' => '<h4 class="footer-widget-title">',
  150. 'after_title' => '</h4>',
  151. ) );
  152. }
  153. add_action( 'widgets_init', 'listify_widgets_init' );
  154.  
  155. /**
  156. * Returns the Google font stylesheet URL, if available.
  157. *
  158. * The use of Source Sans Pro and Varela Round by default is localized. For languages
  159. * that use characters not supported by the font, the font can be disabled.
  160. *
  161. * @since Listify 1.0.0
  162. *
  163. * @return string Font stylesheet or empty string if disabled.
  164. */
  165. function listify_fonts_url() {
  166. $fonts_url = '';
  167.  
  168. /* Translators: If there are characters in your language that are not
  169. * supported by Montserrat, translate this to 'off'. Do not translate into your
  170. * own language.
  171. */
  172. $montserrat = _x( 'on', 'Montserrat font: on or off', 'listify' );
  173.  
  174. if ( 'off' !== $montserrat ) {
  175. $font_families = array();
  176.  
  177. if ( 'off' !== $montserrat )
  178. $font_families[] = apply_filters( 'listify_font_montserrat', 'Montserrat:400,700' );
  179.  
  180. $query_args = array(
  181. 'family' => urlencode( implode( '|', apply_filters( 'listify_font_families', $font_families ) ) ),
  182. 'subset' => urlencode( 'latin,latin-ext' ),
  183. );
  184.  
  185. $fonts_url = esc_url_raw( add_query_arg( $query_args, "//fonts.googleapis.com/css" ) );
  186. }
  187.  
  188. return $fonts_url;
  189. }
  190.  
  191. /**
  192. * Load fonts in TinyMCE
  193. *
  194. * @since Listify 1.0.0
  195. *
  196. * @return string $css
  197. */
  198. function listify_mce_css( $css ) {
  199. $css .= ', ' . listify_fonts_url();
  200.  
  201. return $css;
  202. }
  203. add_filter( 'mce_css', 'listify_mce_css' );
  204.  
  205. /**
  206. * Scripts and Styles
  207. *
  208. * Load Styles and Scripts depending on certain conditions. Not all assets
  209. * will be loaded on every page.
  210. *
  211. * @since Listify 1.0.0
  212. *
  213. * @return void
  214. */
  215. function listify_scripts() {
  216. /*
  217. * Styles
  218. */
  219. do_action( 'listify_output_customizer_css' );
  220.  
  221. /* Supplimentary CSS */
  222. wp_enqueue_style( 'listify-fonts', listify_fonts_url() );
  223.  
  224. /* Custom CSS */
  225. wp_enqueue_style( 'listify', get_template_directory_uri() . '/css/style.min.css' );
  226. wp_style_add_data( 'listify', 'rtl', 'replace' );
  227.  
  228. /* Output customizer CSS after theme CSS */
  229. $listify_customizer_css = new Listify_Customizer_CSS();
  230. $listify_customizer_css->output();
  231.  
  232. /*
  233. * Scripts
  234. */
  235.  
  236. /* Comments */
  237. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  238. wp_enqueue_script( 'comment-reply' );
  239. }
  240.  
  241. $deps = array( 'jquery' );
  242.  
  243. if ( listify_has_integration( 'wp-job-manager-regions' ) && get_option( 'job_manager_regions_filter' ) ) {
  244. $deps[] = 'job-regions';
  245. }
  246.  
  247. wp_enqueue_script( 'listify', get_template_directory_uri() . '/js/app.min.js', $deps, 20141204, true );
  248. wp_enqueue_script( 'salvattore', get_template_directory_uri() . '/js/vendor/salvattore.min.js', array(), '', true );
  249.  
  250. wp_localize_script( 'listify', 'listifySettings', array(
  251. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  252. 'homeurl' => home_url( '/' ),
  253. 'archiveurl' => get_post_type_archive_link( 'job_listing' ),
  254. 'is_job_manager_archive' => listify_is_job_manager_archive(),
  255. 'l10n' => array(
  256. 'closed' => __( 'Closed', 'listify' ),
  257. 'timeFormat' => get_option( 'time_format' )
  258. )
  259. ));
  260. }
  261. add_action( 'wp_enqueue_scripts', 'listify_scripts' );
  262.  
  263. /**
  264. * Adds custom classes to the array of body classes.
  265. */
  266. function listify_body_classes( $classes ) {
  267. global $wp_query, $post;
  268.  
  269. if ( is_page_template( 'page-templates/template-archive-job_listing.php' ) ) {
  270. $classes[] = 'template-archive-job_listing';
  271. }
  272.  
  273. if ( listify_is_widgetized_page() ) {
  274. $classes[] = 'template-home';
  275. }
  276.  
  277. if (
  278. is_page_template( 'page-templates/template-full-width-blank.php' ) ||
  279. ( isset( $post ) && has_shortcode( get_post()->post_content, 'jobs' ) )
  280. ) {
  281. $classes[] = 'unboxed';
  282. }
  283.  
  284. if ( is_singular() && get_post()->enable_tertiary_navigation ) {
  285. $classes[] = 'tertiary-enabled';
  286. }
  287.  
  288. if ( listify_theme_mod( 'fixed-header' ) ) {
  289. $classes[] = 'fixed-header';
  290. }
  291.  
  292. if ( listify_theme_mod( 'custom-submission' ) ) {
  293. $classes[] = 'directory-fields';
  294. }
  295.  
  296. $classes[] = 'color-scheme-' . sanitize_title( listify_theme_mod( 'color-scheme' ) );
  297.  
  298. $classes[] = 'footer-' . listify_theme_mod( 'footer-display' );
  299.  
  300. $theme = wp_get_theme( 'listify' );
  301.  
  302. if ( $theme->get( 'Name' ) ) {
  303. $classes[] = sanitize_title( $theme->get( 'Name' ) );
  304. $classes[] = sanitize_title( $theme->get( 'Name' ) . '-' . str_replace( '.', '', $theme->get( 'Version' ) ) );
  305. }
  306.  
  307. return $classes;
  308. }
  309. add_filter( 'body_class', 'listify_body_classes' );
  310.  
  311. /**
  312. * Adds custom classes to the array of post classes.
  313. */
  314. function listify_post_classes( $classes ) {
  315. global $post;
  316.  
  317. if (
  318. in_array( $post->post_type, array( 'post', 'page' ) ) ||
  319. is_search() &&
  320. ! has_shortcode( $post->post_content, 'jobs' )
  321. ) {
  322. $classes[] = 'content-box content-box-wrapper';
  323. }
  324.  
  325. return $classes;
  326. }
  327. add_filter( 'post_class', 'listify_post_classes' );
  328.  
  329. /**
  330. * "Cover" images for pages and other content.
  331. *
  332. * If on an archive the current query will be used. Otherwise it will
  333. * look for a single item's featured image or an image from its gallery.
  334. *
  335. * @since Listify 1.0.0
  336. *
  337. * @param string $class
  338. * @return string $atts
  339. */
  340. function listify_cover( $class, $args = array() ) {
  341. $defaults = apply_filters( 'listify_cover_defaults', array(
  342. 'images' => false,
  343. 'object_ids' => false,
  344. 'size' => 'large'
  345. ) );
  346.  
  347. $args = wp_parse_args( $args, $defaults );
  348. $image = $atts = false;
  349.  
  350. global $post, $wp_query;
  351.  
  352. // special for WooCommerce
  353. if ( ( function_exists( 'is_shop' ) && is_shop() ) || is_singular( 'product' )) {
  354. $image = wp_get_attachment_image_src( get_post_thumbnail_id( wc_get_page_id( 'shop' ) ),
  355. $args[ 'size' ] );
  356. } else if ( ( is_home() || is_singular( array( 'post', 'page' ) ) ) && ! in_the_loop() ) {
  357. $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_option( 'page_for_posts' )
  358. ), $args[ 'size' ] );
  359. } else if ( ( ! did_action( 'loop_start' ) && is_archive() ) || ( $args[ 'images' ] || $args[ 'object_ids' ] ) ) {
  360. $image = listify_get_cover_from_group( $args );
  361. } else if ( is_a( $post, 'WP_Post' ) ) {
  362. if ( ! listify_has_integration( 'wp-job-manager' ) || has_post_thumbnail( $post->ID ) ) {
  363. $image = wp_get_attachment_image_src( get_post_thumbnail_id(), $args[ 'size' ] );
  364. } else {
  365. $gallery = Listify_WP_Job_Manager_Gallery::get( $post->ID );
  366.  
  367. $args[ 'images' ] = $gallery;
  368. unset( $args[ 'object_ids' ] );
  369.  
  370. if ( $gallery ) {
  371. $image = listify_get_cover_from_group( $args );
  372. }
  373. }
  374. }
  375.  
  376. $image = apply_filters( 'listify_cover_image', $image, $args );
  377.  
  378. if ( ! $image ) {
  379. $class .= ' no-image';
  380.  
  381. return sprintf( 'class="%s"', $class );
  382. }
  383.  
  384. $class .= ' has-image';
  385.  
  386. $atts .= sprintf( 'style="background-image: url(%s);"', $image[0] );
  387. $atts .= sprintf( 'class="%s"', $class );
  388.  
  389. return $atts;
  390. }
  391. add_filter( 'listify_cover', 'listify_cover', 10, 2 );
  392.  
  393. /**
  394. * Get a cover image from a "group" (WP_Query or array of IDS)
  395. *
  396. * @see listify_cover()
  397. *
  398. * @since Listify 1.0.0
  399. *
  400. * @param array|object $group
  401. * @return array $image
  402. */
  403. function listify_get_cover_from_group( $args ) {
  404. $image = false;
  405.  
  406. if ( empty( $args[ 'object_ids' ] ) && ( ! isset( $args[ 'images' ] ) || empty( $args[ 'images' ] ) ) ) {
  407. global $wp_query, $wpdb;
  408.  
  409. if ( empty( $wp_query->posts ) ) {
  410. return $image;
  411. }
  412.  
  413. $args[ 'object_ids' ] = wp_list_pluck( $wp_query->posts, 'ID' );
  414. }
  415.  
  416. if ( ( ! isset( $args[ 'images' ] ) || empty( $args[ 'images' ] ) ) && ( isset( $args[ 'object_ids' ] ) && ! empty( $args[ 'object_ids' ] ) ) ) {
  417.  
  418. $objects_key = md5( json_encode( $args[ 'object_ids' ] ) );
  419.  
  420. if ( false === ( $image = get_transient( $objects_key ) ) ) {
  421. global $wpdb;
  422.  
  423. $args[ 'object_ids' ] = implode( ',', $args[ 'object_ids' ] );
  424. $ids = $args[ 'object_ids' ];
  425.  
  426. $published = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' and ID IN ($ids)" );
  427.  
  428. if ( empty( $published ) ) {
  429. return $image;
  430. }
  431.  
  432. $published = wp_list_pluck( $published, 'ID' );
  433.  
  434. $attachments = new WP_Query( array(
  435. 'post_parent__in' => $published,
  436. 'post_type' => 'attachment',
  437. 'post_status' => 'inherit',
  438. 'fields' => 'ids',
  439. 'posts_per_page' => 1,
  440. 'orderby' => 'rand',
  441. 'update_post_term_cache' => false,
  442. 'update_post_meta_cache' => false,
  443. 'no_found_rows' => true
  444. ) );
  445.  
  446. if ( $attachments->have_posts() ) {
  447. $image = wp_get_attachment_image_src( $attachments->posts[0], $args[ 'size' ] );
  448.  
  449. if ( file_exists( $image[0] ) ) {
  450. set_transient( $objects_key, $image, 3 * HOUR_IN_SECONDS );
  451. }
  452. }
  453. }
  454. } elseif ( isset( $args[ 'images' ] ) && ! empty( $args[ 'images' ] ) ) {
  455. shuffle( $args[ 'images' ] );
  456.  
  457. $image = wp_get_attachment_image_src( current( $args[ 'images' ] ), $args[ 'size' ] );
  458. }
  459.  
  460. return $image;
  461. }
  462.  
  463. /**
  464. * Count the number of posts for a specific user.
  465. *
  466. * @since Listify 1.0.0
  467. *
  468. * @param string $post_type
  469. * @param int $user_id
  470. * @return int $count
  471. */
  472. function listify_count_posts( $post_type, $user_id ) {
  473. global $wpdb;
  474.  
  475. if ( false === ( $count = get_transient( $post_type . $user_id ) ) ) {
  476. $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$user_id' AND post_type = '$post_type' and post_status = 'publish'" );
  477.  
  478. set_transient( $post_type . $user_id, $count );
  479. }
  480.  
  481. return $count;
  482. }
  483.  
  484. /**
  485. * Check if a specific integration is active.
  486. *
  487. * @since Listify 1.0.0
  488. *
  489. * @param string $integration
  490. * @return boolean
  491. */
  492. function listify_has_integration( $integration ) {
  493. return array_key_exists( $integration, Listify_Integration::get_integrations() );
  494. }
  495.  
  496. /** Standard Includes */
  497. $includes = array(
  498. 'class-activation.php',
  499. 'customizer/class-customizer.php',
  500. 'class-setup.php',
  501. 'class-navigation.php',
  502. 'class-strings.php',
  503. 'class-tgmpa.php',
  504. 'class-integration.php',
  505. 'class-widget.php',
  506. 'class-page-settings.php',
  507. 'class-widgetized-pages.php',
  508. 'class-search.php',
  509. 'widgets/class-widget-ad.php',
  510. 'widgets/class-widget-home-features.php',
  511. 'widgets/class-widget-home-feature-callout.php',
  512. 'custom-header.php',
  513. 'template-tags.php',
  514. 'extras.php',
  515. );
  516.  
  517. foreach ( $includes as $file ) {
  518. require( get_template_directory() . '/inc/' . $file );
  519. }
  520.  
  521. /** Integrations */
  522. $integrations = apply_filters( 'listify_integrations', array(
  523. 'wp-job-manager' => defined( 'JOB_MANAGER_VERSION' ),
  524. 'wp-job-manager-bookmarks' => defined( 'JOB_MANAGER_BOOKMARKS_VERSION' ),
  525. 'wp-job-manager-wc-paid-listings' => defined( 'JOB_MANAGER_WCPL_VERSION' ),
  526. 'wp-job-manager-tags' => defined( 'JOB_MANAGER_TAGS_PLUGIN_URL' ),
  527.  
  528. 'wp-job-manager-regions' => class_exists( 'Astoundify_Job_Manager_Regions' ),
  529. 'wp-job-manager-reviews' => class_exists( 'WP_Job_Manager_Reviews' ),
  530. 'wp-job-manager-products' => class_exists( 'WP_Job_Manager_Products' ),
  531. 'wp-job-manager-claim-listing' => class_exists( 'WP_Job_Manager_Claim_Listing' ),
  532.  
  533. 'woocommerce' => class_exists( 'Woocommerce' ),
  534. 'woocommerce-bookings' => class_exists( 'WC_Bookings' ),
  535.  
  536. 'facetwp' => class_exists( 'FacetWP' ),
  537. 'jetpack' => defined( 'JETPACK__VERSION' ),
  538. 'ratings' => true
  539. ) );
  540.  
  541. foreach ( $integrations as $file => $dependancy ) {
  542. if ( $dependancy ) {
  543. require( get_template_directory() . sprintf( '/inc/integrations/%1$s/class-%1$s.php', $file ) );
  544. }
  545. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement