Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.47 KB | None | 0 0
  1. <?php
  2. /**
  3. * GeneratePress functions and definitions
  4. *
  5. * @package GeneratePress
  6. */
  7.  
  8.  
  9. // No direct access, please
  10. if ( ! defined( 'ABSPATH' ) ) exit;
  11.  
  12. define( 'GENERATE_VERSION', '1.3.40');
  13. define( 'GENERATE_URI', get_template_directory_uri() );
  14. define( 'GENERATE_DIR', get_template_directory() );
  15.  
  16. if ( ! function_exists( 'generate_setup' ) ) :
  17. /**
  18. * Sets up theme defaults and registers support for various WordPress features.
  19. *
  20. * Note that this function is hooked into the after_setup_theme hook, which runs
  21. * before the init hook. The init hook is too late for some features, such as indicating
  22. * support post thumbnails.
  23. */
  24. add_action( 'after_setup_theme', 'generate_setup' );
  25. function generate_setup()
  26. {
  27. /**
  28. * Make theme available for translation
  29. */
  30. load_theme_textdomain( 'generatepress' );
  31.  
  32. /**
  33. * Add default posts and comments RSS feed links to head
  34. */
  35. add_theme_support( 'automatic-feed-links' );
  36.  
  37. /**
  38. * Enable support for Post Thumbnails on posts and pages
  39. *
  40. * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
  41. */
  42. add_theme_support( 'post-thumbnails' );
  43.  
  44. /**
  45. * Register primary menu
  46. */
  47. register_nav_menus( array(
  48. 'primary' => __( 'Primary Menu', 'generatepress' ),
  49. ) );
  50.  
  51. /**
  52. * Enable support for Post Formats
  53. */
  54. add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'status' ) );
  55.  
  56. /**
  57. * Enable support for WooCommerce
  58. */
  59. add_theme_support( 'woocommerce' );
  60.  
  61. /**
  62. * Enable support for <title> tag
  63. */
  64. add_theme_support( 'title-tag' );
  65.  
  66. /*
  67. * Add HTML5 theme support
  68. */
  69. add_theme_support( 'html5', array(
  70. 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
  71. ) );
  72.  
  73. /*
  74. * Add Logo support
  75. */
  76. add_theme_support( 'custom-logo', array(
  77. 'height' => 70,
  78. 'width' => 350,
  79. 'flex-height' => true,
  80. 'flex-width' => true,
  81. ) );
  82.  
  83. /*
  84. * Indicate widget sidebars can use selective refresh in the Customizer.
  85. */
  86. add_theme_support( 'customize-selective-refresh-widgets' );
  87.  
  88. /**
  89. * Set the content width to something large
  90. * We set a more accurate width in generate_smart_content_width()
  91. */
  92. global $content_width;
  93. if ( ! isset( $content_width ) )
  94. $content_width = 1200; /* pixels */
  95.  
  96. /*
  97. * This theme styles the visual editor to resemble the theme style
  98. */
  99. add_editor_style( 'inc/css/editor-style.css' );
  100. }
  101. endif; // generate_setup
  102.  
  103. if ( ! function_exists( 'generate_get_defaults' ) ) :
  104. /**
  105. * Set default options
  106. */
  107.  
  108.  
  109. function generate_get_defaults()
  110. {
  111. $generate_defaults = array(
  112. 'hide_title' => '',
  113. 'hide_tagline' => '',
  114. 'logo' => '',
  115. 'container_width' => '1100',
  116. 'header_layout_setting' => 'fluid-header',
  117. 'nav_alignment_setting' => ( is_rtl() ) ? 'right' : 'left',
  118. 'header_alignment_setting' => ( is_rtl() ) ? 'right' : 'left',
  119. 'nav_layout_setting' => 'fluid-nav',
  120. 'nav_position_setting' => 'nav-below-header',
  121. 'nav_dropdown_type' => 'hover',
  122. 'nav_search' => 'disable',
  123. 'content_layout_setting' => 'separate-containers',
  124. 'layout_setting' => 'right-sidebar',
  125. 'blog_layout_setting' => 'right-sidebar',
  126. 'single_layout_setting' => 'right-sidebar',
  127. 'post_content' => 'full',
  128. 'footer_layout_setting' => 'fluid-footer',
  129. 'footer_widget_setting' => '3',
  130. 'back_to_top' => '',
  131. 'background_color' => '#efefef',
  132. 'text_color' => '#3a3a3a',
  133. 'link_color' => '#1e73be',
  134. 'link_color_hover' => '#000000',
  135. 'link_color_visited' => '',
  136. );
  137.  
  138. return apply_filters( 'generate_option_defaults', $generate_defaults );
  139. }
  140. endif;
  141.  
  142. if ( ! function_exists( 'generate_get_setting' ) ) :
  143. /**
  144. * A wrapper function to get our settings
  145. * @since 1.3.40
  146. */
  147. function generate_get_setting( $setting ) {
  148. $generate_settings = wp_parse_args(
  149. get_option( 'generate_settings', array() ),
  150. generate_get_defaults()
  151. );
  152.  
  153. return $generate_settings[ $setting ];
  154. }
  155. endif;
  156.  
  157. if ( ! function_exists( 'generate_widgets_init' ) ) :
  158. /**
  159. * Register widgetized area and update sidebar with default widgets
  160. */
  161. add_action( 'widgets_init', 'generate_widgets_init' );
  162. function generate_widgets_init()
  163. {
  164. // Set up our array of widgets
  165. $widgets = array(
  166. 'sidebar-1' => array(
  167. 'name' => __( 'Right Sidebar', 'generatepress' )
  168. ),
  169. 'sidebar-2' => array(
  170. 'name' => __( 'Left Sidebar', 'generatepress' )
  171. ),
  172. 'header' => array(
  173. 'name' => __( 'Header', 'generatepress' )
  174. ),
  175. 'footer-1' => array(
  176. 'name' => __( 'Footer Widget 1', 'generatepress' )
  177. ),
  178. 'footer-2' => array(
  179. 'name' => __( 'Footer Widget 2', 'generatepress' )
  180. ),
  181. 'footer-3' => array(
  182. 'name' => __( 'Footer Widget 3', 'generatepress' )
  183. ),
  184. 'footer-4' => array(
  185. 'name' => __( 'Footer Widget 4', 'generatepress' )
  186. ),
  187. 'footer-5' => array(
  188. 'name' => __( 'Footer Widget 5', 'generatepress' )
  189. ),
  190. );
  191.  
  192. // Loop through them to create our widget areas
  193. foreach ( $widgets as $widget => $id ) {
  194. register_sidebar( array(
  195. 'name' => $id[ 'name' ],
  196. 'id' => $widget,
  197. 'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
  198. 'after_widget' => '</aside>',
  199. 'before_title' => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
  200. 'after_title' => apply_filters( 'generate_end_widget_title', '</h4>' ),
  201. ) );
  202. }
  203. }
  204. endif;
  205.  
  206. /**
  207. * Custom template tags for this theme.
  208. */
  209. require get_template_directory() . '/inc/template-tags.php';
  210.  
  211. /**
  212. * Custom functions that act independently of the theme templates.
  213. */
  214. require get_template_directory() . '/inc/extras.php';
  215.  
  216. /**
  217. * Build the navigation
  218. */
  219. require get_template_directory() . '/inc/navigation.php';
  220.  
  221. /**
  222. * Customizer additions.
  223. */
  224. require get_template_directory() . '/inc/customizer.php';
  225.  
  226. /**
  227. * Load element classes
  228. */
  229. require get_template_directory() . '/inc/element-classes.php';
  230.  
  231. /**
  232. * Load metaboxes
  233. */
  234. require get_template_directory() . '/inc/metaboxes.php';
  235.  
  236. /**
  237. * Load options
  238. */
  239. require get_template_directory() . '/inc/options.php';
  240.  
  241. /**
  242. * Load add-on options
  243. */
  244. require get_template_directory() . '/inc/add-ons.php';
  245.  
  246. /**
  247. * Load WooCommerce compatibility
  248. */
  249. require get_template_directory() . '/inc/woocommerce.php';
  250.  
  251. if ( ! function_exists( 'generate_get_min_suffix' ) ) :
  252. /**
  253. * Figure out if we should use minified scripts or not
  254. * @since 1.3.29
  255. */
  256. function generate_get_min_suffix()
  257. {
  258. return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
  259. }
  260. endif;
  261.  
  262. if ( ! function_exists( 'generate_scripts' ) ) :
  263. /**
  264. * Enqueue scripts and styles
  265. */
  266. add_action( 'wp_enqueue_scripts', 'generate_scripts' );
  267. function generate_scripts()
  268. {
  269. // Get our options.
  270. $generate_settings = wp_parse_args(
  271. get_option( 'generate_settings', array() ),
  272. generate_get_defaults()
  273. );
  274.  
  275. // Get the minified suffix.
  276. $suffix = generate_get_min_suffix();
  277.  
  278. // Enqueue our CSS.
  279. wp_enqueue_style( 'generate-style-grid', get_template_directory_uri() . "/css/unsemantic-grid{$suffix}.css", false, GENERATE_VERSION, 'all' );
  280. wp_enqueue_style( 'generate-style', get_template_directory_uri() . '/style.css', array( 'generate-style-grid' ), GENERATE_VERSION, 'all' );
  281. wp_enqueue_style( 'generate-mobile-style', get_template_directory_uri() . "/css/mobile{$suffix}.css", array( 'generate-style' ), GENERATE_VERSION, 'all' );
  282. wp_add_inline_style( 'generate-style', generate_base_css() );
  283.  
  284. // Add the child theme CSS if child theme is active.
  285. if ( is_child_theme() )
  286. wp_enqueue_style( 'generate-child', get_stylesheet_uri(), true, filemtime( get_stylesheet_directory() . '/style.css' ), 'all' );
  287.  
  288. // Font Awesome
  289. $icon_essentials = apply_filters( 'generate_fontawesome_essentials', false );
  290. $icon_essentials = ( $icon_essentials ) ? '-essentials' : false;
  291. wp_enqueue_style( "fontawesome{$icon_essentials}", get_template_directory_uri() . "/css/font-awesome{$icon_essentials}{$suffix}.css", false, '4.6.3', 'all' );
  292.  
  293. // IE 8
  294. wp_enqueue_style( 'generate-ie', get_template_directory_uri() . "/css/ie{$suffix}.css", array( 'generate-style-grid' ), GENERATE_VERSION, 'all' );
  295. wp_style_add_data( 'generate-ie', 'conditional', 'lt IE 9' );
  296.  
  297. // Add jQuery
  298. wp_enqueue_script( 'jquery' );
  299.  
  300. // Add our mobile navigation
  301. wp_enqueue_script( 'generate-navigation', get_template_directory_uri() . "/js/navigation{$suffix}.js", array( 'jquery' ), GENERATE_VERSION, true );
  302.  
  303. // Add our hover or click dropdown menu scripts
  304. if ( 'click' == $generate_settings[ 'nav_dropdown_type' ] || 'click-arrow' == $generate_settings[ 'nav_dropdown_type' ] ) {
  305. wp_enqueue_script( 'generate-dropdown-click', get_template_directory_uri() . "/js/dropdown-click{$suffix}.js", array( 'jquery' ), GENERATE_VERSION, true );
  306. } else {
  307. wp_enqueue_script( 'generate-dropdown', get_template_directory_uri() . "/js/dropdown{$suffix}.js", array( 'jquery' ), GENERATE_VERSION, true );
  308. }
  309.  
  310. // Add our navigation search if it's enabled
  311. if ( 'enable' == $generate_settings['nav_search'] ) {
  312. wp_enqueue_script( 'generate-navigation-search', get_template_directory_uri() . "/js/navigation-search{$suffix}.js", array( 'jquery' ), GENERATE_VERSION, true );
  313. }
  314.  
  315. // Add the back to top script if it's enabled
  316. if ( 'enable' == $generate_settings['back_to_top'] ) {
  317. wp_enqueue_script( 'generate-back-to-top', get_template_directory_uri() . "/js/back-to-top{$suffix}.js", array( 'jquery' ), GENERATE_VERSION, true );
  318. }
  319.  
  320. // Move the navigation from below the content on mobile to below the header if it's in a sidebar
  321. if ( 'nav-left-sidebar' == $generate_settings['nav_position_setting'] || 'nav-right-sidebar' == $generate_settings['nav_position_setting'] ) {
  322. wp_enqueue_script( 'generate-move-navigation', get_template_directory_uri() . "/js/move-navigation{$suffix}.js", array( 'jquery' ), GENERATE_VERSION, true );
  323. }
  324.  
  325. // IE 8
  326. if ( function_exists( 'wp_script_add_data' ) ) :
  327. wp_enqueue_script( 'generate-html5', get_template_directory_uri() . "/js/html5shiv{$suffix}.js", array( 'jquery' ), GENERATE_VERSION, true );
  328. wp_script_add_data( 'generate-html5', 'conditional', 'lt IE 9' );
  329. endif;
  330.  
  331. // Add the threaded comments script
  332. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  333. wp_enqueue_script( 'comment-reply' );
  334. }
  335. }
  336. endif;
  337.  
  338. if ( ! function_exists( 'generate_get_layout' ) ) :
  339. /**
  340. * Get the layout for the current page
  341. */
  342. function generate_get_layout()
  343. {
  344. // Get current post
  345. global $post;
  346.  
  347. // Get Customizer options
  348. $generate_settings = wp_parse_args(
  349. get_option( 'generate_settings', array() ),
  350. generate_get_defaults()
  351. );
  352.  
  353. // Set up the layout variable for pages
  354. $layout = $generate_settings['layout_setting'];
  355.  
  356. // Get the individual page/post sidebar metabox value
  357. $layout_meta = ( isset( $post ) ) ? get_post_meta( $post->ID, '_generate-sidebar-layout-meta', true ) : '';
  358.  
  359. // Set up BuddyPress variable
  360. $buddypress = false;
  361. if ( function_exists( 'is_buddypress' ) ) :
  362. $buddypress = ( is_buddypress() ) ? true : false;
  363. endif;
  364.  
  365. // If we're on the single post page
  366. // And if we're not on a BuddyPress page - fixes a bug where BP thinks is_single() is true
  367. if ( is_single() && ! $buddypress ) :
  368. $layout = null;
  369. $layout = $generate_settings['single_layout_setting'];
  370. endif;
  371.  
  372. // If the metabox is set, use it instead of the global settings
  373. if ( '' !== $layout_meta && false !== $layout_meta ) :
  374. $layout = $layout_meta;
  375. endif;
  376.  
  377. // If we're on the blog, archive, attachment etc..
  378. if ( is_home() || is_archive() || is_search() || is_tax() ) :
  379. $layout = null;
  380. $layout = $generate_settings['blog_layout_setting'];
  381. endif;
  382.  
  383. // Finally, return the layout
  384. return apply_filters( 'generate_sidebar_layout', $layout );
  385. }
  386. endif;
  387.  
  388. if ( ! function_exists( 'generate_get_footer_widgets' ) ) :
  389. /**
  390. * Get the footer widgets for the current page
  391. */
  392. function generate_get_footer_widgets()
  393. {
  394. // Get current post
  395. global $post;
  396.  
  397. // Get Customizer options
  398. $generate_settings = wp_parse_args(
  399. get_option( 'generate_settings', array() ),
  400. generate_get_defaults()
  401. );
  402.  
  403. // Set up the footer widget variable
  404. $widgets = $generate_settings['footer_widget_setting'];
  405.  
  406. // Get the individual footer widget metabox value
  407. $widgets_meta = ( isset( $post ) ) ? get_post_meta( $post->ID, '_generate-footer-widget-meta', true ) : '';
  408.  
  409. // If we're not on a single page or post, the metabox hasn't been set
  410. if ( ! is_singular() ) :
  411. $widgets_meta = '';
  412. endif;
  413.  
  414. // If we have a metabox option set, use it
  415. if ( '' !== $widgets_meta && false !== $widgets_meta ) :
  416. $widgets = $widgets_meta;
  417. endif;
  418.  
  419. // Finally, return the layout
  420. return apply_filters( 'generate_footer_widgets', $widgets );
  421. }
  422. endif;
  423.  
  424. if ( ! function_exists( 'generate_construct_sidebars' ) ) :
  425. /**
  426. * Construct the sidebars
  427. * @since 0.1
  428. */
  429. add_action('generate_sidebars','generate_construct_sidebars');
  430. function generate_construct_sidebars()
  431. {
  432. // Get the layout
  433. $layout = generate_get_layout();
  434.  
  435. // When to show the right sidebar
  436. $rs = array('right-sidebar','both-sidebars','both-right','both-left');
  437.  
  438. // When to show the left sidebar
  439. $ls = array('left-sidebar','both-sidebars','both-right','both-left');
  440.  
  441. // If left sidebar, show it
  442. if ( in_array( $layout, $ls ) ) :
  443. get_sidebar('left');
  444. endif;
  445.  
  446. // If right sidebar, show it
  447. if ( in_array( $layout, $rs ) ) :
  448. get_sidebar();
  449. endif;
  450. }
  451. endif;
  452.  
  453. if ( ! function_exists( 'generate_add_footer_info' ) ) :
  454. add_action('generate_credits','generate_add_footer_info');
  455. function generate_add_footer_info()
  456. {
  457. ?>
  458. <span class="copyright"><?php _e('Copyright','generatepress');?> &copy; <?php echo date('Y'); ?></span> <?php do_action('generate_copyright_line');?>
  459. <?php
  460. }
  461. endif;
  462.  
  463. if ( ! function_exists( 'generate_add_login_attribution' ) ) :
  464. add_action('generate_copyright_line','generate_add_login_attribution');
  465. function generate_add_login_attribution()
  466. {
  467. ?>
  468. &#x000B7; <a href="<?php echo esc_url('https://generatepress.com');?>" target="_blank" title="GeneratePress" itemprop="url">GeneratePress</a>
  469. <?php
  470. }
  471. endif;
  472.  
  473. if ( ! function_exists( 'generate_base_css' ) ) :
  474. /**
  475. * Generate the CSS in the <head> section using the Theme Customizer
  476. * @since 0.1
  477. */
  478. function generate_base_css()
  479. {
  480.  
  481. $generate_settings = wp_parse_args(
  482. get_option( 'generate_settings', array() ),
  483. generate_get_defaults()
  484. );
  485.  
  486. // Start the magic
  487. $visual_css = array (
  488.  
  489. // Body CSS
  490. 'body' => array(
  491. 'background-color' => $generate_settings['background_color'],
  492. 'color' => $generate_settings['text_color']
  493. ),
  494.  
  495. // Link CSS
  496. 'a, a:visited' => array(
  497. 'color' => $generate_settings['link_color'],
  498. 'text-decoration' => 'none'
  499. ),
  500.  
  501. // Visited link color if specified
  502. 'a:visited' => array(
  503. 'color' => ( !empty( $generate_settings['link_color_visited'] ) ) ? $generate_settings['link_color_visited'] : null,
  504. ),
  505.  
  506. // Link hover
  507. 'a:hover, a:focus, a:active' => array(
  508. 'color' => $generate_settings['link_color_hover'],
  509. 'text-decoration' => null
  510. ),
  511.  
  512. // Grid container
  513. 'body .grid-container' => array(
  514. 'max-width' => $generate_settings['container_width'] . 'px'
  515. )
  516.  
  517. );
  518.  
  519. // Output the above CSS
  520. $output = '';
  521. foreach($visual_css as $k => $properties) {
  522. if(!count($properties))
  523. continue;
  524.  
  525. $temporary_output = $k . ' {';
  526. $elements_added = 0;
  527.  
  528. foreach($properties as $p => $v) {
  529. if(empty($v))
  530. continue;
  531.  
  532. $elements_added++;
  533. $temporary_output .= $p . ': ' . $v . '; ';
  534. }
  535.  
  536. $temporary_output .= "}";
  537.  
  538. if($elements_added > 0)
  539. $output .= $temporary_output;
  540. }
  541.  
  542. $output = str_replace(array("\r", "\n"), '', $output);
  543. return $output;
  544. }
  545. endif;
  546.  
  547. if ( ! function_exists( 'generate_add_viewport' ) ) :
  548. /**
  549. * Add viewport to wp_head
  550. * @since 1.1.0
  551. */
  552. add_action('wp_head','generate_add_viewport');
  553. function generate_add_viewport()
  554. {
  555. echo '<meta name="viewport" content="width=device-width, initial-scale=1">';
  556. }
  557. endif;
  558.  
  559. if ( ! function_exists( 'generate_ie_compatibility' ) ) :
  560. /**
  561. * Add compatibility for IE8 and lower
  562. * No need to run this if wp_script_add_data() exists
  563. * @since 1.1.9
  564. */
  565. add_action('wp_footer','generate_ie_compatibility');
  566. function generate_ie_compatibility()
  567. {
  568. if ( function_exists( 'wp_script_add_data' ) )
  569. return;
  570.  
  571. $suffix = generate_get_min_suffix();
  572. ?>
  573. <!--[if lt IE 9]>
  574. <script src="<?php echo get_template_directory_uri();?>/js/html5shiv<?php echo $suffix;?>.js"></script>
  575. <![endif]-->
  576. <?php
  577. }
  578. endif;
  579.  
  580. if ( ! function_exists( 'generate_remove_caption_padding' ) ) :
  581. /**
  582. * Remove WordPress's default padding on images with captions
  583. *
  584. * @param int $width Default WP .wp-caption width (image width + 10px)
  585. * @return int Updated width to remove 10px padding
  586. */
  587. add_filter( 'img_caption_shortcode_width', 'generate_remove_caption_padding' );
  588. function generate_remove_caption_padding( $width ) {
  589. return $width - 10;
  590. }
  591. endif;
  592.  
  593. if ( ! function_exists( 'generate_smart_content_width' ) ) :
  594. /**
  595. * Set the $content_width depending on layout of current page
  596. * Hook into "wp" so we have the correct layout setting from generate_get_layout()
  597. * Hooking into "after_setup_theme" doesn't get the correct layout setting
  598. */
  599. add_action( 'wp', 'generate_smart_content_width' );
  600. function generate_smart_content_width()
  601. {
  602.  
  603. global $content_width, $post;
  604.  
  605. // Get Customizer options
  606. $generate_settings = wp_parse_args(
  607. get_option( 'generate_settings', array() ),
  608. generate_get_defaults()
  609. );
  610.  
  611. // Get sidebar widths
  612. $right_sidebar_width = apply_filters( 'generate_right_sidebar_width', '25' );
  613. $left_sidebar_width = apply_filters( 'generate_left_sidebar_width', '25' );
  614.  
  615. // Get the layout
  616. $layout = generate_get_layout();
  617.  
  618. // Find the real content width
  619. if ( 'left-sidebar' == $layout ) {
  620. // If left sidebar is present
  621. $content_width = $generate_settings['container_width'] * ( ( 100 - $left_sidebar_width ) / 100 );
  622. } elseif ( 'right-sidebar' == $layout ) {
  623. // If right sidebar is present
  624. $content_width = $generate_settings['container_width'] * ( ( 100 - $right_sidebar_width ) / 100 );
  625. } elseif ( 'no-sidebar' == $layout ) {
  626. // If no sidebars are present
  627. $content_width = $generate_settings['container_width'];
  628. } else {
  629. // If both sidebars are present
  630. $content_width = $generate_settings['container_width'] * ( ( 100 - ( $left_sidebar_width + $right_sidebar_width ) ) / 100 );
  631. }
  632. }
  633. endif;
  634.  
  635. if ( ! function_exists( 'generate_body_schema' ) ) :
  636. /**
  637. * Figure out which schema tags to apply to the <body> element
  638. * @since 1.3.15
  639. */
  640. function generate_body_schema()
  641. {
  642. // Set up blog variable
  643. $blog = ( is_home() || is_archive() || is_attachment() || is_tax() || is_single() ) ? true : false;
  644.  
  645. // Set up default itemtype
  646. $itemtype = 'WebPage';
  647.  
  648. // Get itemtype for the blog
  649. $itemtype = ( $blog ) ? 'Blog' : $itemtype;
  650.  
  651. // Get itemtype for search results
  652. $itemtype = ( is_search() ) ? 'SearchResultsPage' : $itemtype;
  653.  
  654. // Get the result
  655. $result = apply_filters( 'generate_body_itemtype', $itemtype );
  656.  
  657. // Return our HTML
  658. echo "itemtype='http://schema.org/$result' itemscope='itemscope'";
  659. }
  660. endif;
  661.  
  662. if ( ! function_exists( 'generate_article_schema' ) ) :
  663. /**
  664. * Figure out which schema tags to apply to the <article> element
  665. * The function determines the itemtype: generate_article_schema( 'BlogPosting' )
  666. * @since 1.3.15
  667. */
  668. function generate_article_schema( $type = 'CreativeWork' )
  669. {
  670. // Get the itemtype
  671. $itemtype = apply_filters( 'generate_article_itemtype', $type );
  672.  
  673. // Print the results
  674. echo "itemtype='http://schema.org/$itemtype' itemscope='itemscope'";
  675. }
  676. endif;
  677.  
  678. if ( ! function_exists( 'generate_show_excerpt' ) ) :
  679. /**
  680. * Figure out if we should show the blog excerpts or full posts
  681. * @since 1.3.15
  682. */
  683. function generate_show_excerpt()
  684. {
  685. // Get current post
  686. global $post;
  687.  
  688. // Get Customizer settings
  689. $generate_settings = wp_parse_args(
  690. get_option( 'generate_settings', array() ),
  691. generate_get_defaults()
  692. );
  693.  
  694. // Check to see if the more tag is being used
  695. $more_tag = apply_filters( 'generate_more_tag', @strpos( $post->post_content, '<!--more-->' ) );
  696.  
  697. // Check the post format
  698. $format = ( false !== get_post_format() ) ? get_post_format() : 'standard';
  699.  
  700. // Get the excerpt setting from the Customizer
  701. $show_excerpt = ( 'excerpt' == $generate_settings['post_content'] ) ? true : false;
  702.  
  703. // If our post format isn't standard, show the full content
  704. $show_excerpt = ( 'standard' !== $format ) ? false : $show_excerpt;
  705.  
  706. // If the more tag is found, show the full content
  707. $show_excerpt = ( $more_tag ) ? false : $show_excerpt;
  708.  
  709. // If we're on a search results page, show the excerpt
  710. $show_excerpt = ( is_search() ) ? true : $show_excerpt;
  711.  
  712. // Return our value
  713. return apply_filters( 'generate_show_excerpt', $show_excerpt );
  714. }
  715. endif;
  716.  
  717. if ( ! function_exists( 'generate_show_title' ) ) :
  718. /**
  719. * Check to see if we should show our page/post title or not
  720. * @since 1.3.18
  721. */
  722. function generate_show_title()
  723. {
  724. return apply_filters( 'generate_show_title', true );
  725. }
  726. endif;
  727.  
  728. if ( ! function_exists( 'generate_update_logo_setting' ) ) :
  729. /**
  730. * Migrate the old logo database entry to the new custom_logo theme mod (WordPress 4.5)
  731. *
  732. * @since 1.3.29
  733. */
  734. add_action( 'after_setup_theme', 'generate_update_logo_setting' );
  735. function generate_update_logo_setting()
  736. {
  737. // If we're not running WordPress 4.5, bail.
  738. if ( ! function_exists( 'the_custom_logo' ) )
  739. return;
  740.  
  741. // If we already have a custom logo, bail.
  742. if ( get_theme_mod( 'custom_logo' ) )
  743. return;
  744.  
  745. // Get our settings.
  746. $generate_settings = wp_parse_args(
  747. get_option( 'generate_settings', array() ),
  748. generate_get_defaults()
  749. );
  750.  
  751. // Get the old logo value.
  752. $old_value = $generate_settings['logo'];
  753.  
  754. // If there's no old value, bail.
  755. if ( empty( $old_value ) )
  756. return;
  757.  
  758. // We made it this far, that means we have an old logo, and no new logo.
  759.  
  760. // Let's get the ID from our old value.
  761. $logo = attachment_url_to_postid( $old_value );
  762.  
  763. // Now let's update the new logo setting with our ID.
  764. if ( is_int( $logo ) )
  765. set_theme_mod( 'custom_logo', $logo );
  766.  
  767. // Got our custom logo? Time to delete the old value
  768. if ( get_theme_mod( 'custom_logo' ) ) :
  769. $new_settings[ 'logo' ] = '';
  770. $update_settings = wp_parse_args( $new_settings, $generate_settings );
  771. update_option( 'generate_settings', $update_settings );
  772. endif;
  773. }
  774. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement