get( 'Version' ) );
// scripts
wp_enqueue_script( 'meridian-one-importer-js', get_parent_theme_file_uri() . '/inc/importer/js/main.js', array( 'jquery' ), $theme->get( 'Version' ) );
wp_localize_script( 'meridian-one-importer-js', 'MeridianOneImporterAjax', array( 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ) ) );
}
} add_action( 'admin_enqueue_scripts', 'meridian_one_importer_scripts' );
/**
* Display importer
*
* @since 1.0
*/
function meridian_one_importer_display() {
?>
$widgets ) {
// do not add if sidebar has widgets
if ( ! empty( $sidebar_options[$sidebar_id] ) && $ignore_sidebar_with_content) { continue; }
// loop through new widgets in sidebar
foreach ( $widgets as $index => $widget ) {
$widget_id_base = $widget['id_base'];
$widget_instance = $widget['instance'];
$widget_instances = get_option('widget_'.$widget_id_base);
if( ! is_array( $widget_instances ) ) {
$widget_instances = array();
}
$count = count($widget_instances) + 1;
$sidebar_options[$sidebar_id][] = $widget_id_base.'-'.$count;
$widget_instances[$count] = $widget_instance;
// save options
update_option('widget_'.$widget_id_base,$widget_instances);
}
}
// save options
update_option('sidebars_widgets',$sidebar_options);
}
}
/**
* Add images to media library
*
* @since 1.0
*/
function meridian_one_add_media_to_library( $url = false ) {
if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
// stop if no URL supplied
if ( ! $url ) return;
// download image
$tmp = download_url( $url );
$post_id = 0;
$desc = 'Placeholder';
$file_array = array();
// Set variables for storage
// fix file filename for query strings
preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png)/i', $url, $matches);
$file_array['name'] = 'placeholder.jpg';
$file_array['tmp_name'] = $tmp;
// If error storing temporarily, unlink
if ( is_wp_error( $tmp ) ) {
unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
// do the validation and storage stuff
$id = media_handle_sideload( $file_array, $post_id, $desc );
// If error storing permanently, unlink
if ( is_wp_error($id) ) {
unlink($file_array['tmp_name']);
return false;
}
// return ID
return $id;
}
}