__('Front Page Menu', 'one-page'), 'subpage-menu' => __('Main Menu', 'one-page') ) ); // onepage_default_menu(); } add_action('after_setup_theme', 'onepage_setup'); /** * function to setup default theme menu */ function onepage_default_menu() { $menuname = 'OnePage Theme Menu'; $menulocation = 'frontpage-menu'; // Does the menu exist already? $menu_exists = wp_get_nav_menu_object($menuname); // If it doesn't exist, let's create it. if (!$menu_exists) { $menu_id = wp_create_nav_menu($menuname); // Set up default OnePage Menu links and add them to the menu. wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Home', 'one-page'), 'menu-item-classes' => 'home', 'menu-item-url' => '#page-top', 'menu-item-status' => 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Services', 'one-page'), 'menu-item-classes' => 'services', 'menu-item-url' => '#services', 'menu-item-status' => 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Blog', 'one-page'), 'menu-item-classes' => 'blog', 'menu-item-url' => '#blog', 'menu-item-status' => 'publish')); // wp_update_nav_menu_item($menu_id, 0, array( // 'menu-item-title' => __('Gallery', 'one-page'), // 'menu-item-classes' => 'gallery', // 'menu-item-url' => '#gallery', // 'menu-item-status' => 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Pricing', 'one-page'), 'menu-item-classes' => 'pricing', 'menu-item-url' => '#pricing', 'menu-item-status' => 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Team', 'one-page'), 'menu-item-classes' => 'team', 'menu-item-url' => '#team', 'menu-item-status' => 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Contact', 'one-page'), 'menu-item-classes' => 'contact', 'menu-item-url' => '#contact', 'menu-item-status' => 'publish')); // Grab the theme locations and assign our newly-created menu // to the OnePage Theme front Page menu location. if (!has_nav_menu($menulocation)) { $locations = get_theme_mod('nav_menu_locations'); $locations[$menulocation] = $menu_id; set_theme_mod('nav_menu_locations', $locations); } } } // Add CLASS attributes to the first
/i', $post->post_content, $matches); $first_img = isset($matches[1][0]) ? $matches[1][0] : null; if (empty($first_img)) { $first_img = ''; } return $first_img; } /** * Alter brightness */ function alter_brightness($colourstr, $steps) { $colourstr = str_replace('#', '', $colourstr); $rhex = substr($colourstr, 0, 2); $ghex = substr($colourstr, 2, 2); $bhex = substr($colourstr, 4, 2); $r = hexdec($rhex); $g = hexdec($ghex); $b = hexdec($bhex); $r = max(0, min(255, $r + $steps)); $g = max(0, min(255, $g + $steps)); $b = max(0, min(255, $b + $steps)); return '#' . dechex($r) . dechex($g) . dechex($b); } /** * Customizer CSS for the theme */ add_action('wp_head', 'customizer_css'); function section_strip_color($bg_color) { if ($bg_color == "#FFFFFF" || $bg_color == "#FFF" || $bg_color == "white" || $bg_color == "#ffffff" || $bg_color == "#fff" || $bg_color == "WHITE") { $bg_color = '#FFFFFF'; $border_color = '#DCDCDB'; } else { $border_color = alter_brightness($bg_color, 100); } return $border_color; } function customizer_css() { //// Blogs & News section $output = ""; echo $output; } /** * Migrate Option Panel To Customizer */ function onepage_migrate_option() { if (get_option('onepage_options') && !get_option('onepage_option_migrate')) { $theme_options = array('onepage_logo', 'onepage_favicon', 'onepage_slideimage1', 'onepage_our_services_image1', 'onepage_our_services_image2', 'onepage_our_services_image3', 'onepage_our_services_image4'); $wp_upload_dir = wp_upload_dir(); require ( ABSPATH . 'wp-admin/includes/image.php' ); foreach ($theme_options as $option) { $option_value = onepage_get_option($option); if ($option_value && $option_value != '') { $filetype = wp_check_filetype(basename($option_value), null); $image_name = preg_replace('/\.[^.]+$/', '', basename($option_value)); $new_image_url = $wp_upload_dir['path'] . '/' . $image_name . '.' . $filetype['ext']; onepage_import_file($new_image_url); } } update_option('onepage_option_migrate', true); } if (get_option('onepage_options') && !get_option('onepage_option_replace')) { $options = onepage_option_replace(); foreach ($options as $prev_key => $next_key) { $prev_value = onepage_get_option($prev_key); $next_value = onepage_get_option($next_key); if (empty($next_value) || $next_value != '') { onepage_update_option($next_key, $prev_value); } } update_option('onepage_option_replace', true); } } add_action('init', 'onepage_migrate_option'); /** * Import Files From Uploads To Attachment */ function onepage_import_file($file, $post_id = 0, $import_date = 'file') { set_time_limit(120); // Initially, Base it on the -current- time. $time = current_time('mysql', 1); // Next, If it's post to base the upload off: $time = gmdate('Y-m-d H:i:s', @filemtime($file)); // A writable uploads dir will pass this test. Again, there's no point overriding this one. if (!( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] )) { return new WP_Error('upload_error', $uploads['error']); } $wp_filetype = wp_check_filetype($file, null); extract($wp_filetype); if ((!$type || !$ext ) && !current_user_can('unfiltered_upload')) { return new WP_Error('wrong_file_type', __('Sorry, this file type is not permitted for security reasons.', 'one-page')); //A WP-core string.. } $file_name = str_replace('\\', '/', $file); if (preg_match('|^' . preg_quote(str_replace('\\', '/', $uploads['basedir'])) . '(.*)$|i', $file_name, $mat)) { $filename = basename($file); $new_file = $file; $url = $uploads['baseurl'] . $mat[1]; $attachment = get_posts(array('post_type' => 'attachment', 'meta_key' => '_wp_attached_file', 'meta_value' => ltrim($mat[1], '/'))); if (!empty($attachment)) { return new WP_Error('file_exists', __('Sorry, That file already exists in the WordPress media library.', 'one-page')); } //Ok, Its in the uploads folder, But NOT in WordPress's media library. if ('file' == $import_date) { $time = @filemtime($file); if (preg_match("|(\d+)/(\d+)|", $mat[1], $datemat)) { //So lets set the date of the import to the date folder its in, IF its in a date folder. $hour = $min = $sec = 0; $day = 1; $year = $datemat[1]; $month = $datemat[2]; // If the files datetime is set, and it's in the same region of upload directory, set the minute details to that too, else, override it. if ($time && date('Y-m', $time) == "$year-$month") { list($hour, $min, $sec, $day) = explode(';', date('H;i;s;j', $time)); } $time = mktime($hour, $min, $sec, $month, $day, $year); } $time = gmdate('Y-m-d H:i:s', $time); // A new time has been found! Get the new uploads folder: // A writable uploads dir will pass this test. Again, there's no point overriding this one. if (!( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] )) return new WP_Error('upload_error', $uploads['error']); $url = $uploads['baseurl'] . $mat[1]; } } else { $filename = wp_unique_filename($uploads['path'], basename($file)); // copy the file to the uploads dir $new_file = $uploads['path'] . '/' . $filename; if (false === @copy($file, $new_file)) return new WP_Error('upload_error', sprintf(__('The selected file could not be copied to %s.', 'one-page'), $uploads['path'])); // Set correct file permissions $stat = stat(dirname($new_file)); $perms = $stat['mode'] & 0000666; @ chmod($new_file, $perms); // Compute the URL $url = $uploads['url'] . '/' . $filename; if ('file' == $import_date) $time = gmdate('Y-m-d H:i:s', @filemtime($file)); } //Apply upload filters $return = apply_filters('wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type)); $new_file = $return['file']; $url = $return['url']; $type = $return['type']; $title = preg_replace('!\.[^.]+$!', '', basename($file)); $content = ''; if ($time) { $post_date_gmt = $time; $post_date = $time; } else { $post_date = current_time('mysql'); $post_date_gmt = current_time('mysql', 1); } // Construct the attachment array $attachment = array( 'post_mime_type' => $type, 'guid' => $url, 'post_parent' => $post_id, 'post_title' => $title, 'post_name' => $title, 'post_content' => $content, 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt ); $attachment = apply_filters('afs-import_details', $attachment, $file, $post_id, $import_date); //Win32 fix: $new_file = str_replace(strtolower(str_replace('\\', '/', $uploads['basedir'])), $uploads['basedir'], $new_file); // Save the data $id = wp_insert_attachment($attachment, $new_file, $post_id); if (!is_wp_error($id)) { $data = wp_generate_attachment_metadata($id, $new_file); wp_update_attachment_metadata($id, $data); } //update_post_meta( $id, '_wp_attached_file', $uploads['subdir'] . '/' . $filename ); return $id; } function onepage_option_replace() { return array( 'onepage_logo' => 'onepage_header_logo_img', 'onepage_contact_number' => 'onepage_top_call_us', 'onepage_slideimage1' => 'onepage_slider_image_1', 'onepage_sliderheading1' => 'onepage_slider_heading_1', 'onepage_sliderdes1' => 'onepage_slider_subheading_1', 'onepage_our_services_heading' => 'onepage_service_section_heading', 'onepage_our_services_title1' => 'onepage_service_box_heading_1', 'onepage_our_services_desc1' => 'onepage_service_box_desc_1', 'onepage_our_services_title2' => 'onepage_service_box_heading_2', 'onepage_our_services_desc2' => 'onepage_service_box_desc_2', 'onepage_our_services_title3' => 'onepage_service_box_heading_3', 'onepage_our_services_desc3' => 'onepage_service_box_desc_3', 'onepage_our_services_title4' => 'onepage_service_box_heading_4', 'onepage_our_services_desc4' => 'onepage_service_box_desc_4', 'onepage_recent_blog_heading' => 'onepage_blog_main_heading', 'onepage_our_contact_heading' => 'onepage_contact_main_heading', 'onepage_our_contact_sub_heading' => 'onepage_contact_sub_heading' ); } function onepage_portfolio_tag_list() { $terms = get_tags('tag'); if (empty($terms)) { return; } $tag_list = array(); $tag_list[''] = __('Select Tag', 'one-page'); foreach ($terms as $value) { $tag_list[$value->term_id] = $value->name; } return $tag_list; }