post_content;
if ( ! empty( $post_obj->post_excerpt ) ) {
$source_content = $post_obj->post_excerpt;
}
$source_content = preg_replace( '`\[[^\]]*\]`', '', $source_content );
$trimmed_content = wp_trim_words( $source_content, $length, '…' );
return $trimmed_content;
}
endif;
if( ! function_exists( 'cafeteria_elementor_get_sidebar_options' ) ) :
/**
* Get sidebar options.
*
* @since 1.0.0
*/
function cafeteria_elementor_get_sidebar_options() {
global $wp_registered_sidebars;
$output = array();
if ( ! empty( $wp_registered_sidebars ) && is_array( $wp_registered_sidebars ) ) {
foreach ( $wp_registered_sidebars as $key => $sidebar ) {
$output[$key] = $sidebar['name'];
}
}
return $output;
}
endif;
if( ! function_exists( 'cafeteria_elementor_primary_navigation_fallback' ) ) :
/**
* Fallback for primary navigation.
*
* @since 1.0.0
*/
function cafeteria_elementor_primary_navigation_fallback() {
echo '
';
}
endif;
if ( ! function_exists( 'cafeteria_elementor_the_custom_logo' ) ) :
/**
* Render logo.
*
* @since 2.0
*/
function cafeteria_elementor_the_custom_logo() {
if ( function_exists( 'the_custom_logo' ) ) {
the_custom_logo();
}
}
endif;
/**
* Sanitize post ID.
*
* @since 1.0.0
*
* @param string $key Field key.
* @param array $field Field detail.
* @param mixed $value Raw value.
* @return mixed Sanitized value.
*/
function cafeteria_elementor_widget_sanitize_post_id( $key, $field, $value ) {
$output = '';
$value = absint( $value );
if ( $value ) {
$not_allowed = array( 'revision', 'attachment', 'nav_menu_item' );
$post_type = get_post_type( $value );
if ( ! in_array( $post_type, $not_allowed ) && 'publish' === get_post_status( $value ) ) {
$output = $value;
}
}
return $output;
}
if ( ! function_exists( 'cafeteria_elementor_get_index_page_id' ) ) :
/**
* Get front index page ID.
*
* @since 1.0.0
*
* @param string $type Type.
* @return int Corresponding Page ID.
*/
function cafeteria_elementor_get_index_page_id( $type = 'front' ) {
$page = '';
switch ( $type ) {
case 'front':
$page = get_option( 'page_on_front' );
break;
case 'blog':
$page = get_option( 'page_for_posts' );
break;
default:
break;
}
$page = absint( $page );
return $page;
}
endif;
if ( ! function_exists( 'cafeteria_elementor_render_select_dropdown' ) ) :
/**
* Render select dropdown.
*
* @since 1.0.0
*
* @param array $main_args Main arguments.
* @param string $callback Callback method.
* @param array $callback_args Callback arguments.
* @return string Rendered markup.
*/
function cafeteria_elementor_render_select_dropdown( $main_args, $callback, $callback_args = array() ) {
$defaults = array(
'id' => '',
'name' => '',
'selected' => 0,
'echo' => true,
'add_default' => false,
);
$r = wp_parse_args( $main_args, $defaults );
$output = '';
$choices = array();
if ( is_callable( $callback ) ) {
$choices = call_user_func_array( $callback, $callback_args );
}
if ( ! empty( $choices ) || true === $r['add_default'] ) {
$output = "\n";
}
if ( $r['echo'] ) {
echo $output;
}
return $output;
}
endif;
/**
* Splice array preserving array keys.
*
* @param array &$input Input array.
* @param int $offset Offset.
* @param int $length Length.
* @param array $replacement Sub array.
* @return array New array.
*/
function cafeteria_elementor_array_splice_preserve_keys( &$input, $offset, $length = null, $replacement = array() ) {
if ( empty( $replacement ) ) {
return array_splice( $input, $offset, $length );
}
$part_before = array_slice( $input, 0, $offset, $preserve_keys = true );
$part_removed = array_slice( $input, $offset, $length, $preserve_keys = true );
$part_after = array_slice( $input, $offset + $length, null, $preserve_keys = true );
$input = $part_before + $replacement + $part_after;
return $part_removed;
}
if ( ! function_exists( 'cafeteria_elementor_get_active_homepage_sections' ) ) :
/**
* Returns active homepage sections.
*
* @since 1.0.0
*
* @return array Active sections.
*/
function cafeteria_elementor_get_active_homepage_sections() {
$output = array();
$homepage_sections_raw = (array)cafeteria_elementor_get_option( 'homepage_sections' );
if ( ! empty( $homepage_sections_raw ) ) {
$default_sections = cafeteria_elementor_get_home_sections_options();
foreach ( $homepage_sections_raw as $key ) {
if ( isset( $default_sections[ $key ] ) ) {
$output[ $key ] = $default_sections[ $key ];
}
}
}
return $output;
}
endif;