: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Returns a collection of options: yes, no and default which means the theme settings will be used.
function themify_ternary_options( $yes = '', $no = '', $default = '', $args = array() ) {
return wp_parse_args( $args, array(
'name' => !empty( $default ) ? $default : __( 'Default', 'themify' ),
'name' => !empty( $yes ) ? $yes : __( 'Yes', 'themify' ),
'name' => !empty( $no ) ? $no : __( 'No', 'themify' ),
* Returns a collection of states: yes, no and default which means the theme settings will be used.
function themify_ternary_states( $args = array(), $all = array() ) {
$args = wp_parse_args( $args, array(
'icon_yes' => THEMIFY_URI . '/img/ddbtn-check.svg',
'icon_no' => THEMIFY_URI . '/img/ddbtn-cross.svg',
return wp_parse_args( $all, array(
'name' => empty( $args['label_yes'] ) ? __('Hide', 'themify') : $args['label_yes'],
'icon' => $args['icon_no'],
'title' => __('Hide this', 'themify')
'name' => empty( $args['label_no'] ) ? __('Show', 'themify') : $args['label_no'],
'icon' => $args['icon_yes'],
'title' => __('Show this', 'themify')
'name' => empty( $args['default'] ) ? __('Theme default', 'themify') : $args['default'],
'value' => $args['value_default'],
'icon' => THEMIFY_URI . '/img/ddbtn-blank.png',
'title' => __('Use theme settings', 'themify'),
if( ! function_exists( 'themify_multi_meta_field' ) ) {
* Definition for tri-state hide meta buttons
function themify_multi_meta_field( $args = array(), $prefix = 'hide_meta' ) {
$states = themify_ternary_states( array( 'label_no' => __('Show', 'themify') ) );
'name' => $prefix . '_multi',
'title' => __('Post Meta', 'themify'),
'name' => $prefix . '_all',
'title' => __('Hide All', 'themify'),
'type' => 'dropdownbutton',
'name' => $prefix . '_author',
'title' => __('Author', 'themify'),
'type' => 'dropdownbutton',
'name' => $prefix . '_category',
'title' => __('Category', 'themify'),
'type' => 'dropdownbutton',
'name' => $prefix . '_comment',
'title' => __('Comment', 'themify'),
'type' => 'dropdownbutton',
'name' => $prefix . '_tag',
'title' => __('Tag', 'themify'),
'type' => 'dropdownbutton',
$field = wp_parse_args( $args, $defaults );
return apply_filters( 'themify_multi_meta_field', $field );
function themify_meta_field_fontawesome( $args, $call_before_after = true, $echo = true ) {
$meta_box = $args['meta_box'];
$meta_value = $args['meta_value'];
$class = isset( $meta_box['meta']['size'] ) && 'small' === $meta_box['meta']['size']?'small': '';
$html = '<div class="icon-preview font-icon-preview">
<i class="fa ' . esc_attr( $meta_value ) . '"></i>
$html .= sprintf( '<input type="text" id="%s" name="%s" value="%s" size="55" class="themify_input_field themify_fa %s" /> <a class="button button-secondary hide-if-no-js themify_fa_toggle" href="#" data-target="#%s">%s</a>',
esc_attr( $meta_box['name'] ),
esc_attr( $meta_box['name'] ),
esc_attr( $meta_box['name'] ),
__( 'Insert Icon', 'themify' ) );
if ( !empty( $meta_box['label'] )) {
$html = sprintf( '<label for="%s">%s %s</label>',
esc_attr( $meta_box['name'] ),
esc_html( $meta_box['label'] )
if ( isset( $meta_box['description'] ) ) {
$html .= themify_meta_field_get_description( $meta_box['description'] );
if ( !empty( $meta_box['before'] )) {
$html = $meta_box['before'] . $html;
if ( !empty( $meta_box['after'] )) {
$html .= $meta_box['after'];
* Build custom write panels
* This function is required to provide backward compatibility
function themify_build_write_panels( $args = null ) {
* featimgdropdown field type, creates an option to select image sizes
function themify_meta_field_featimgdropdown( $args ) {
/** Define WP Featured Image sizes + blank + Themify's image script*/
$themify_fi_sizes = themify_get_image_sizes_list();
$meta_box = $args['meta_box'];
<select name="<?php esc_attr_e( $meta_box['name'] ); ?>">
<?php foreach($themify_fi_sizes as $option): ?>
<option value="<?php esc_attr_e( $option['value'] ); ?>" <?php selected( $option['value'], $args['meta_value'] ); ?>><?php echo esc_html( $option['name'] ); ?></option>
<?php if ( isset( $meta_box['description'] ) ) : ?>
<span class="themify_field_description"><?php echo wp_kses_post( $meta_box['description'] ); ?></span>
<?php endif; // meta_box description
* Outputs html to display alert messages in post edit/new screens. Excludes pages.
function themify_prompt_message() {
if(class_exists('Themify_Builder_Model',false)){
Themify_Builder_Model::check_plugins_compatible();
if(!Themify_Enqueue_Assets::createDir()){
echo '<div class="notice notice-error"><p><strong>'.__('Themify:','themify').'</strong></p><p>'.__('It looks like the WordPress upload folder path is set wrong or have file permission issue. Please check the upload path on WP Settings > Media. Make sure the folder is set correctly and it has correct file permission.','themify').'</p></div>';
add_action( 'admin_enqueue_scripts', 'themify_enqueue_scripts', 12 );
// register custom field types only available in the framework
function themify_meta_field_page_layout( $args ) {
$option_name = isset( $args['meta_box']['name'] ) ? $args['meta_box']['name'] : 'page_layout';
$page_layout = get_post_meta( get_the_ID(), $option_name, true );
$content_width = get_post_meta( get_the_ID(), 'content_width', true );
$section_scroll = get_post_meta( get_the_ID(), 'section_full_scrolling', true );
if ( $section_scroll === 'yes' ) {
$args['meta_value'] = 'section_scroll';
} else if ( $content_width === 'full_width' ) {
$args['meta_value'] = 'full_width';
echo '<div class="themify_field-layout">';
$meta_box = $args['meta_box'];
$meta_value = $args['meta_value'];
extract( $args, EXTR_OVERWRITE );
foreach ( $meta_box['meta'] as $options ) {
if ( ( '' == $meta_value || !$meta_value || !isset($meta_value)) && ( isset( $options['selected'] ) && $options['selected'] ) ) {
$meta_value = $options['value'];
$class = $meta_value == $options['value']?'selected':'';
if(isset($meta_box['show_title'])){
$title = isset($options['title'])? $options['title']: ucwords(str_replace('-', ' ', $options['value']));
$w= isset($option['w'])?$option['w']:'46';
$h= isset($option['w'])?$option['w']:'35';
// Check image src whether absolute url or relative url
$img_src = ( '' != parse_url( $options['img'], PHP_URL_SCHEME) ) ? $options['img'] : get_template_directory_uri() . '/' . $options['img'];
$ops_html .= sprintf('<a href="#" class="preview-icon %s"><img src="%s" alt="%s" width="'.$w.'" height="'.$h.'" loading="lazy" decoding="async"/><span class="tm-option-title">%s</span></a>',
esc_attr( $options['value'] ),
$page_layout = empty( $page_layout ) ? 'default' : $page_layout;
/* data-selected is the selected option, whereas 'value' is the thing stored in db */
$html = sprintf('%s<input type="hidden" name="%s" value="%s" class="val" data-selected="%s" />',
$ops_html, esc_attr( $meta_box['name'] ), esc_attr( $page_layout ), $meta_value );
if(isset($meta_box['label']) && '' != $meta_box['label'])
$html = sprintf('<label for="%s">%s %s</label>', esc_attr( $meta_box['name'] ), $html, esc_attr( $meta_box['label'] ));
$html .= isset( $meta_box['description'] )? themify_meta_field_get_description($meta_box['description']) : '';
if( isset( $meta_box['before'] ) ) $html = $meta_box['before'] . $html;
if( isset( $meta_box['after'] ) ) $html .= $meta_box['after'];
add_action( 'themify_metabox/field/page_layout', 'themify_meta_field_page_layout', 10, 3 );
add_action( 'themify_metabox/field/fontawesome', 'themify_meta_field_fontawesome', 10, 1 );
add_action( 'themify_metabox/field/sidebar_visibility', 'themify_meta_field_sidebar_visibility', 10, 1 );
add_action( 'themify_metabox/field/featimgdropdown', 'themify_meta_field_featimgdropdown', 10, 1 );
add_action( 'themify_metabox/field/page_builder', 'themify_meta_field_page_builder', 10, 1 );
add_action( 'admin_notices', 'themify_prompt_message' );
require_once THEMIFY_DIR . '/themify-import-functions.php';
require_once THEMIFY_DIR . '/themify-wpajax.php';
if ( themify_is_themify_theme() ) {
* In this hook current user is authenticated so we can check for capabilities.
function themify_after_user_is_authenticated() {
if ( current_theme_supports( 'themify-exclude-theme-from-wp-update' ) ) {
add_filter( 'http_request_args', 'themify_hide_themes', 10, 2 );
*******************************************************/
add_action( 'admin_menu', 'themify_admin_nav', 1 );
if ( current_user_can( 'manage_options' ) ) {
add_action( 'load-toplevel_page_themify', function() {
if ( isset( $_GET['tf_clean_gz'] ) ) {
// clean gz files from the theme
themify_remove_gzip( THEME_DIR );
// clean gz files from all Themify plugins
$plugins = get_plugins();
foreach ( $plugins as $path => $data ) {
if ( isset( $data['Author'] ) && $data['Author'] === 'Themify' ) {
themify_remove_gzip( trailingslashit( WP_PLUGIN_DIR ) . dirname( $path ) );
add_action( 'init', 'themify_after_user_is_authenticated' );
* Hijacks themes passed for upgrade checking and remove those from Themify
* This feature is only required for legacy themes without "themify-" prefix,
* to prevent updates from wp.org overwriting theme files.
* @param Array $r List of themes
* @param String $url URL of upgrade check
function themify_hide_themes( $response, $url ){
if ( 0 === strpos( $url, 'https://api.wordpress.org/themes/update-check' ) ) {
$themes = json_decode( $response['body']['themes'] );
unset( $themes->themes->{get_option( 'template' )},$themes->themes->{get_option( 'stylesheet' )} );
$response['body']['themes'] = json_encode( $themes );
require_once THEMIFY_DIR . '/class-tgm-plugin-activation.php';
* List all files in a directory, recursively
function themify_glob_recursive( $pattern, $flags = 0 ) {
$files = glob( $pattern, $flags );
foreach ( glob( dirname( $pattern ) . '/*', GLOB_ONLYDIR|GLOB_NOSORT ) as $dir ) {
$files = array_merge( $files, themify_glob_recursive( $dir . '/' . basename( $pattern ), $flags ) );
* Removes all .gz files found in the $path
function themify_remove_gzip( $path ) {
$search = themify_glob_recursive( $path . '/*.gz' );
foreach ( $search as $file ) {
* Loads Term Cover feature, an option to add an image to taxonomy terms
function themify_load_term_cover_feature() {
if ( current_theme_supports( 'themify-term-cover' ) ) {
require_once THEMIFY_DIR . '/class-tf-term-image.php';
add_action( 'admin_init', 'themify_load_term_cover_feature' );
function themify_gutenberg_admin_css() {
$screen=get_current_screen();
if (!empty($screen) && $screen->is_block_editor() ) {
font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;
.themify-gutenberg-editor :is(.editor-post-title,.block-editor-block-list__layout){
add_action( 'admin_head', 'themify_gutenberg_admin_css' );