Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Get the option for the current page/post
- *
- * @param string $option
- * @param int $post_id
- * @return string
- */
- function arts_elementor_get_document_option( $option, $post_id = null ) {
- if ( $post_id == null ) {
- $post_id = get_the_ID();
- }
- if ( ! empty( $option ) ) {
- // Get the page settings manager
- $page_settings_manager = \Elementor\Core\Settings\Manager::get_settings_managers( 'page' );
- // Get the settings model for current post
- $page_settings_model = $page_settings_manager->get_model( $post_id );
- // Retrieve the settings we added before
- return $page_settings_model->get_settings( $option );
- }
- return false;
- }
- /**
- * ACF Helper Functions
- */
- if ( ! function_exists( 'arts_have_rows' ) ) {
- function arts_have_rows( $args, $options = '' ) {
- if ( function_exists( 'have_rows' ) ) {
- return have_rows( $args, $options );
- } else {
- return false;
- }
- }
- }
- if ( ! function_exists( 'arts_get_field' ) ) {
- function arts_get_field( $args, $options = '' ) {
- if ( function_exists( 'get_field' ) ) {
- return get_field( $args, $options );
- } else {
- return false;
- }
- }
- }
- /**
- * Markup for lazy background/image/video
- */
- if ( ! function_exists( 'arts_the_lazy_image' ) ) {
- function arts_the_lazy_image( $args ) {
- $defaults = array(
- 'id' => null,
- 'type' => 'background',
- 'size' => 'full',
- 'class' => array(
- 'section' => array(),
- 'wrapper' => array(),
- 'image' => array()
- ),
- 'attribute' => array(
- 'image' => array()
- ),
- 'parallax' => array(
- 'enabled' => false,
- 'factor' => 0.1
- ),
- );
- $class_section = '';
- $attrs_section = '';
- $attrs_wrapper = '';
- $class_wrapper = '';
- $class_media = '';
- $attrs_media = '';
- $args = wp_parse_args( $args, $defaults );
- if ( ! $args['id'] || ! $args['type'] ) {
- return;
- }
- // section
- if ( array_key_exists( 'section', $args['class'] ) && is_array( $args['class']['section'] ) && ! empty ( $args['class']['section'] ) ) {
- $class_section = implode(' ', $args['class']['section'] );
- }
- // wrapper
- if ( array_key_exists( 'wrapper', $args['class'] ) && is_array( $args['class']['wrapper'] ) && ! empty ( $args['class']['wrapper'] ) ) {
- $class_wrapper = implode(' ', $args['class']['wrapper'] );
- }
- // image class
- if ( array_key_exists( 'image', $args['class'] ) && is_array( $args['class']['image'] ) && ! empty ( $args['class']['image'] ) ) {
- $class_media = implode(' ', $args['class']['image'] );
- }
- // image attributes
- if ( array_key_exists( 'image', $args['attribute'] ) && is_array( $args['attribute']['image'] ) && ! empty ( $args['attribute']['image'] ) ) {
- $attrs_media = implode(' ', $args['attribute']['image'] );
- }
- // parallax
- if ( array_key_exists( 'parallax', $args ) && is_array( $args['parallax'] ) && $args['parallax']['enabled'] ) {
- $attrs_wrapper .= ' data-art-parallax=true';
- $attrs_wrapper .= ' data-art-parallax-factor=' . floatval( $args['parallax']['factor'] );
- }
- switch ( $args['type'] ) {
- case 'background':
- $class_media .= ' lazy-bg of-cover';
- break;
- case 'image':
- if ( $args['class']['wrapper'] !== false ) {
- $class_wrapper .= ' lazy';
- }
- break;
- case 'background-video':
- $class_media .= ' of-cover';
- break;
- case 'video':
- //
- break;
- }
- if ( $args['type'] === 'background' || $args['type'] === 'image' ) {
- $attrs = wp_get_attachment_image_src( $args['id'], $args['size'] );
- $alt = get_post_meta( $args['id'], '_wp_attachment_image_alt', true );
- }
- ?>
- <?php if ( ! empty( $class_section ) || ! empty( $attrs_section ) ) : ?>
- <div class="<?php echo esc_attr( $class_section ); ?>" <?php echo esc_attr( $attrs_section ); ?>>
- <?php endif; ?>
- <?php if ( ! empty( $class_wrapper ) || ! empty( $attrs_wrapper ) ) : ?>
- <?php if ( $args['type'] === 'image' ) : ?>
- <div class="<?php echo esc_attr( $class_wrapper ); ?>" <?php echo esc_attr( $attrs_wrapper ); ?> style="padding-bottom: calc( (<?php echo esc_attr( $attrs[2] ); ?> / <?php echo esc_attr( $attrs[1] ); ?>) * 100% ); height: 0;">
- <?php else : ?>
- <div class="<?php echo esc_attr( $class_wrapper ); ?>" <?php echo esc_attr( $attrs_wrapper ); ?>>
- <?php endif; ?>
- <?php endif; ?>
- <?php
- switch ( $args['type'] ) {
- case 'background':
- ?>
- <img class="<?php echo esc_attr( $class_media ); ?>" src="#" data-src="<?php echo esc_attr( $attrs[0] ); ?>" alt="<?php echo esc_attr( $alt ); ?>" <?php echo esc_attr( $attrs_media ); ?> />
- <?php
- break;
- case 'image':
- ?>
- <img class="<?php echo esc_attr( $class_media ); ?>" src="#" data-src="<?php echo esc_attr( $attrs[0] ); ?>" width="<?php echo esc_attr( $attrs[1] ); ?>" height="<?php echo esc_attr( $attrs[2] ); ?>" alt="<?php echo esc_attr( $alt ); ?>"/>
- <?php
- break;
- case 'background-video':
- ?>
- <video class="<?php echo esc_attr( $class_media ); ?>" src="<?php echo esc_url( wp_get_attachment_url( $args['id'] ) ); ?>" playsinline loop muted autoplay></video>
- <?php
- break;
- case 'video':
- ?>
- <video class="<?php echo esc_attr( $class_media ); ?>" src="<?php echo esc_url( wp_get_attachment_url( $args['id'] ) ); ?>" playsinline loop muted autoplay></video>
- <?php
- break;
- }
- ?>
- <?php if ( ! empty( $class_wrapper ) ) : ?>
- </div>
- <?php endif; ?>
- <?php if ( ! empty( $class_section ) || ! empty( $attrs_section ) ) : ?>
- </div>
- <?php endif; ?>
- <?php
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement