file and moves it to new location. If the destination folder does not exist, it is created. * * @since 4.3.1 * @param string $old_file * @param string $new_file * @return boolean|WP_Error */ function avia_backend_rename_file( $old_file, $new_file ) { $split = pathinfo( $new_file ); $folder = $split['dirname']; if( ! avia_backend_create_folder( $folder, false ) ) { return new WP_Error( 'filesystem', sprintf( __( 'Unable to create folder %s.', 'avia_framework' ), $folder ) ); } if( file_exists( $new_file ) ) { if( ! unlink( $new_file ) ) { return new WP_Error( 'filesystem', sprintf( __( 'Unable to delete file %s.', 'avia_framework' ), $new_file ) ); } } if( ! rename( $old_file, $new_file ) ) { return new WP_Error( 'filesystem', sprintf( __( 'Unable to rename/move file %s to %s', 'avia_framework' ), $old_file, $new_file ) ); } return true; } } if(!function_exists('av_backend_registered_sidebars')) { function av_backend_registered_sidebars($sidebars = array(), $exclude = array()) { //fetch all registered sidebars and save them to the sidebars array global $wp_registered_sidebars; foreach($wp_registered_sidebars as $sidebar) { if( !in_array($sidebar['name'], $exclude)) { $sidebars[$sidebar['name']] = $sidebar['name']; } } return $sidebars; } } // ADMIN MENU if( ! function_exists( 'avia_backend_admin_bar_menu' ) ) { add_action( 'admin_bar_menu', 'avia_backend_admin_bar_menu', 99 ); /** * Extend the admin bar */ function avia_backend_admin_bar_menu() { global $avia, $wp_admin_bar; if( ! current_user_can( 'manage_options' ) ) { return; } $real_id = is_admin() ? false : avia_get_the_ID(); $meta_target_edit = array(); $meta_target_dynamic = array(); $meta_target_options = array(); if( ! is_admin() ) { /** * Allow to change WP default behaviour to stay on same tab (also ADA complience). * * @used_by currently unused * @since 4.5.4 * @return string anything different from '' sets value for target (e.g. "_blank") */ $target_edit = apply_filters( 'avf_admin_bar_link_target_frontend', '', 'edit_button' ); $target_dynamic = apply_filters( 'avf_admin_bar_link_target_frontend', '', 'dynamic_template' ); $target_options = apply_filters( 'avf_admin_bar_link_target_frontend', '', 'theme_options' ); if( ! empty( $target_edit ) ) { $meta_target_edit['target'] = $target_edit; } if( ! empty( $target_dynamic ) ) { $meta_target_dynamic['target'] = $target_dynamic; } if( ! empty( $target_options ) ) { $meta_target_options['target'] = $target_options; } } /** * Replace WP edit link with Edit Frontpage message */ if( is_front_page() ) { $front_id = avia_get_option( 'frontpage' ); if( $front_id && $real_id == $front_id ) { $menu = array( 'id' => 'edit', 'title' => __( 'Edit Frontpage', 'avia_framework' ), 'href' => admin_url( 'post.php?post=' . $real_id . '&action=edit' ), 'meta' => $target_edit ); $wp_admin_bar->add_menu( $menu ); } } /** * dynamic template edit for current entry, in case a dynamic template is applied */ if( $real_id && $template = avia_is_dynamic_template() ) { $safeSlug = avia_backend_safe_string( $template ); $menu = array( 'id' => 'avia_edit', 'title' => __( 'Edit this entry', 'avia_framework' ), 'href' => admin_url( 'post.php?post=' . $real_id . '&action=edit' ), 'meta' => $meta_target_dynamic, 'parent' => 'edit' ); $wp_admin_bar->add_menu($menu); $menu = array( 'id' => 'avia_edit_dynamic', 'title' => __( 'Edit Dynamic Template of this entry', 'avia_framework' ), 'href' => admin_url( "admin.php?page=templates#goto_" . $safeSlug ), 'meta' => $meta_target_dynamic, 'parent' => 'edit' ); $wp_admin_bar->add_menu($menu); } /** * add all option pages */ if( empty( $avia->option_pages ) ) { return; } $urlBase = admin_url( 'admin.php' ); foreach( $avia->option_pages as $avia_page ) { $safeSlug = avia_backend_safe_string( $avia_page['title'] ); $menu = array( 'id' => $avia_page['slug'], 'title' => strip_tags($avia_page['title']), 'href' => $urlBase."?page=".$avia_page['slug'], 'meta' => $meta_target_options ); if( $avia_page['slug'] != $avia_page['parent'] ) { $menu['parent'] = $avia_page['parent']; $menu['href'] = $urlBase . "?page=" . $avia_page['parent'] . "#goto_" . $avia_page['slug']; } /* removed by tinabillinger - breaks theme option links in Safari */ // if(is_admin()) $menu['meta'] = array('onclick' => 'self.location.replace(encodeURI("'.$menu['href'].'")); window.location.reload(true); '); $wp_admin_bar->add_menu( $menu ); } } } //avia_backend_admin_bar_menu if( ! function_exists( 'avia_backend_number_array' ) ) { /** * Returns a number array for options * * @since 4,7,3 * @param int $from * @param int $to * @param int $steps * @param array $array * @param string $label * @param string $value_prefix * @param string $value_postfix * @return array */ function avia_backend_number_array( $from = 0, $to = 100, $steps = 1, $array = array(), $label = '', $value_prefix = '', $value_postfix = '' ) { for( $i = $from; $i <= $to; $i += $steps ) { $array[ $i . $label ] = $value_prefix . $i . $value_postfix; } return $array; } } if( ! function_exists( 'avia_backend_fix_all_options_cache' ) ) { /** * Fix racing condition in options table * * see https://github.com/pantheon-systems/wp-redis/issues/221 * see https://core.trac.wordpress.org/ticket/31245#comment:57 * * @since 4.7.6.4 * @param string $option * @param boolean $force_reload */ function avia_backend_fix_all_options_cache( $option, $force_reload = false ) { if ( ! wp_installing() ) { $alloptions = wp_load_alloptions(); //alloptions should be cached at this point if( isset( $alloptions[ $option ] ) || $force_reload ) //only if option is among alloptions { wp_cache_delete( 'alloptions', 'options' ); } } } } if( ! function_exists( 'avia_backend_alb_color_option_palette' ) ) { /** * Returns theme option or default (if empty default is returned). * Does NOT check correctness of input !! * * @since 4.8.3 * @return array */ function avia_backend_alb_color_option_palette() { global $avia_config; if( 'alb_use_custom_colors' != avia_get_option( 'alb_use_custom_colors' ) ) { return $avia_config['default_alb_color_palette']; } if( isset( $avia_config['alb_color_palette'] ) ) { return $avia_config['alb_color_palette']; } $input = trim( avia_get_option( 'alb_custom_color_palette' ) ); if( empty( $input ) ) { $avia_config['alb_color_palette'] = $avia_config['default_alb_color_palette']; } else { $input = str_replace( "\r", "\n", $input ); $input = explode( "\n", $input ); $input = array_map( function ( $value ) { return trim( $value ); }, $input ); $avia_config['alb_color_palette'] = array_filter( $input ); } return $avia_config['alb_color_palette']; } }