Created
July 14, 2021 11:36
-
-
Save jorpdesigns/e532e048360869e01207583a9e68658b to your computer and use it in GitHub Desktop.
Snippet to output Impreza theme page block along with internal element CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example usage: [custom_page_block id="55"] | |
add_shortcode( 'custom_page_block', 'custom_page_block' ); | |
function custom_page_block( $atts ) { | |
// Attributes | |
$atts = shortcode_atts( | |
array( | |
'id' => '' | |
), $atts); | |
$the_ID = $atts['id']; | |
global $items_jsoncss_collection; | |
if ( ! $items_jsoncss_collection ) { | |
$items_jsoncss_collection = array(); | |
} | |
if ( $jsoncss_data = get_post_meta( $the_ID, '_us_jsoncss_data', TRUE ) ) { | |
if ( ! empty( $jsoncss_data ) AND is_array( $jsoncss_data ) ) { | |
foreach ( $jsoncss_data as $jsoncss ) { | |
if ( ! empty( $jsoncss ) AND is_string( $jsoncss ) ) { | |
$class_name = us_get_design_css_class( $jsoncss ); | |
$jsoncss = rawurldecode( $jsoncss ); | |
if ( $jsoncss AND $jsoncss = json_decode( $jsoncss, TRUE ) ) { | |
foreach ( array( 'default', 'tablets', 'mobiles' ) as $device_type ) { | |
if ( $css_options = us_arr_path( $jsoncss, $device_type, FALSE ) ) { | |
if ( ! empty( $items_jsoncss_collection[ $device_type ] ) AND in_array( $class_name, $items_jsoncss_collection[ $device_type ] ) ) { | |
continue; | |
} | |
$css_options = apply_filters( 'us_output_design_css_options', $css_options, $device_type ); | |
$items_jsoncss_collection[ $device_type ][ $class_name ] = $css_options; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
$output = do_shortcode( '[us_page_block id="' . $the_ID . '" remove_rows="1"]' ); | |
if ( ! empty( $items_jsoncss_collection ) AND $items_custom_css = us_jsoncss_compile( $items_jsoncss_collection ) ) { | |
$output .= '<style id="shortcode-css">' . $items_custom_css . '</style>'; | |
} | |
return $output; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment