WordPress 4.6 Beta

WordPress 4.6 Beta 1

Posted June 30, 2016 by Dominik Schilling. Filed under Development, Releases.
WordPress 4.6 Beta 1 is now available!

This software is still in development, so we don’t recommend you run it on a production site. Consider setting up a test site just to play with the new version. To test WordPress 4.6, try the WordPress Beta Tester plugin (you’ll want “bleeding edge nightlies”). Or you can download the beta here (zip).

WordPress 4.6 is slated for release on August 16, but to get there, we need your help testing what we have been working on, including:

Shiny Updates v2 ([37714]) – Shiny Updates replaces progress updates with a simpler and more straight forward experience when installing, updating, and deleting plugins and themes.
Native Fonts in the Admin (#36753) – Experience faster load times, especially when working offline, a removal of a third-party dependency, and a more native-feeling experience as the lines between the mobile web and native applications continue to blur.
Editor Improvements – A more reliable recovery mode (#37025) and detection of broken URLs while you type them (#36638).
There have been changes for developers to explore as well:

Resource Hints (#34292) – Allow browsers to prefetch specific pages, render them in the background, perform DNS lookups, or to begin the connection handshake (DNS, TCP, TLS) in the background.
New WP_Site_Query (#35791) and WP_Network_Query (#32504) classes to query sites and networks with lazy loading for details.
Requests (#33055) – A new PHP library for HTTP requests that supports parallel requests and more.
WP_Term_Query (#35381) is modeled on existing query classes and provides a more consistent structure for generating term queries.
Language Packs (#34114, #34213) – Translations managed through translate.wordpress.org now have a higher priority and are loaded just-in-time.
WP_Post_Type (#36217) provides easier access to post type objects and their underlying properties.
The Widgets API (#28216) was enhanced to support registering pre-instantiated widgets.
Index definitions are now normalized by dbDelta() ([37583]).
Comments can now be stored in a persistent object cache (#36906).
External Libraries were updated to the latest versions – Masonry to 3.3.2 and imagesLoaded to 3.2.0 (#32802), MediaElement.js to 2.21.2 (#36759), and TinyMCE to 4.3.13 (#37225).
REST API responses now include an auto-discovery header (#35580) and a refreshed nonce when responding to an authenticated response (#35662).
Expanded Meta Registration API via register_meta() (#35658).
Customizer – Improved API for setting validation (#34893, #36944).
If you want a more in-depth view of what major changes have made it into 4.6, check out posts tagged with 4.6 on the main development blog, or look at a list of everything that’s changed.

If you think you’ve found a bug, you can post to the Alpha/Beta area in the support forums. We’d love to hear from you! If you’re comfortable writing a reproducible bug report, file one on the WordPress Trac. There, you can also find a list of known bugs.

Happy testing!

More Shiny Updates
In 4.6 Beta 1.
And Font Natively.

How to add custom post type thumbnail in WordPress

1. Add code in finctions.php file.

add_theme_support( 'post-thumbnails', array( 'post', 'page', 'movie', 'product', 'artist');

2. Then add Custom Post Type

add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'artist',
array(
'labels' => array(
'name' => __( 'Artists' ),
'singular_name' => __( 'Artist' )
),
'public' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
)
);
}

How to create meta boxes

How to create meta boxes in WordPress

First, copy the following code in functions.php file, that will take you two fields – phone and email

/*********************************************************************************************************
* Mete box Phone
**********************************************************************************************************/
function myplugin_add_meta_box() {
$screens = array( 'post', 'page' );
foreach ( $screens as $screen ) {
add_meta_box(
'myplugin_sectionid',
__( 'Phone', 'myplugin_textdomain' ),
'myplugin_meta_box_callback',
$screen
);
}
}
add_action( 'add_meta_boxes', 'myplugin_add_meta_box' );
/**
* Prints the box content.
*
* @param WP_Post $post The object for the current post/page.
*/
function myplugin_meta_box_callback( $post ) {
// Add an nonce field so we can check for it later.
wp_nonce_field( 'myplugin_meta_box', 'myplugin_meta_box_nonce' );
/*
* Use get_post_meta() to retrieve an existing value
* from the database and use the value for the form.
*/
$value = get_post_meta( $post->ID, '_my_meta_value_key', true );
_e( ' Phone: ', 'myplugin_textdomain' );
echo '<input type="text" id="myplugin_new_field" name="myplugin_new_field" value="' . esc_attr( $value ) . '" size="25" />';
}
function myplugin_meta_box_vision( $post ) {
// Add an nonce field so we can check for it later.
wp_nonce_field( 'myplugin_meta_box', 'myplugin_meta_box_nonce' );
/*
* Use get_post_meta() to retrieve an existing value
* from the database and use the value for the form.
*/
$value = get_post_meta( $post->ID, '_my_meta_value_key', true );
if ($value) {
_e( '', 'myplugin_textdomain' );
echo '<p class="noselectmeta" name="myplugin_new_field" />'."Phone ". esc_attr( $value ) . '</p>' ;
}
else
{
echo "";
}
}
/**
* When the post is saved, saves our custom data.
*
* @param int $post_id The ID of the post being saved.
*/
function myplugin_save_meta_box_data( $post_id ) {
/*
* We need to verify this came from our screen and with proper authorization,
* because the save_post action can be triggered at other times.
*/
// Check if our nonce is set.
if ( ! isset( $_POST['myplugin_meta_box_nonce'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['myplugin_meta_box_nonce'], 'myplugin_meta_box' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
/* OK, it's safe for us to save the data now. */
// Make sure that it is set.
if ( ! isset( $_POST['myplugin_new_field'] ) ) {
return;
}
// Sanitize user input.
$my_data = sanitize_text_field( $_POST['myplugin_new_field'] );
// Update the meta field in the database.
update_post_meta( $post_id, '_my_meta_value_key', $my_data );
}
add_action( 'save_post', 'myplugin_save_meta_box_data' );
/*********************************************************************************************************
* Mete box E-mail
**********************************************************************************************************/
<?php
function myplugin_add_meta_box1() {
$screens1 = array( 'post', 'page' );
foreach ( $screens1 as $screen1 ) {
add_meta_box(
'myplugin_sectionid1',
__( 'E-mail' ),
'myplugin_meta_box_callback1',
$screen1
);
}
}
add_action( 'add_meta_boxes', 'myplugin_add_meta_box1' );
/**
* Prints the box content.
*
* @param WP_Post $post1 The object for the current post1/page.
*/
function myplugin_meta_box_callback1( $post1 ) {
// Add an nonce field so we can check for it later.
wp_nonce_field( 'myplugin_meta_box1', 'myplugin_meta_box_nonce1' );
/*
* Use get_post_meta() to retrieve an existing value
* from the database and use the value for the form.
*/
$value1 = get_post_meta( $post1->ID, '_my_meta_value_key1', true );
_e( ' E-mail: ', 'myplugin_textdomain' );
echo '<input type="text" id="myplugin_new_field1" name="myplugin_new_field1" value="' . esc_attr( $value1 ) . '" size="25" />';
}
function myplugin_meta_box_vision1( $post1 ) {
// Add an nonce field so we can check for it later.
wp_nonce_field( 'myplugin_meta_box1', 'myplugin_meta_box_nonce1' );
/*
* Use get_post_meta() to retrieve an existing value
* from the database and use the value for the form.
*/
$value1 = get_post_meta( $post1->ID, '_my_meta_value_key1', true );
if ($value1) {
_e( '', 'myplugin_textdomain' );
echo '<p class="noselectmeta" name="myplugin_new_field1" />'."E-mail ". esc_attr( $value1 ) . '</p>' ;
}
else
{
echo "";
}
}
/**
* When the post is saved, saves our custom data.
*
* @param int $post_id The ID of the post being saved.
*/
function myplugin_save_meta_box_data1( $post_id1 ) {
/*
* We need to verify this came from our screen and with proper authorization,
* because the save_post action can be triggered at other times.
*/
// Check if our nonce is set.
if ( ! isset( $_POST['myplugin_meta_box_nonce1'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['myplugin_meta_box_nonce1'], 'myplugin_meta_box1' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Check the user's permissions.
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
}
/* OK, it's safe for us to save the data now. */
// Make sure that it is set.
if ( ! isset( $_POST['myplugin_new_field1'] ) ) {
return;
}
// Sanitize user input.
$my_data1 = sanitize_text_field( $_POST['myplugin_new_field1'] );
// Update the meta field in the database.
update_post_meta( $post_id1, '_my_meta_value_key1', $my_data1 );
}
add_action( 'save_post', 'myplugin_save_meta_box_data1' );

Then put the code in the document where is your phone and email

<?php myplugin_meta_box_vision( $post ); ?>
<?php myplugin_meta_box_vision1( $post ); ?>

How to add styles in WordPress admin

Copy the code into functions.php file

add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo '<style>
#wpcontent {
webkit-box-shadow: inset 0px 17px 56px -13px rgba(91,91,91,1);
-moz-box-shadow: inset 0px 17px 56px -13px rgba(91,91,91,1);
box-shadow: inset 0px 17px 56px -13px rgba(91,91,91,1);
}
.wrap input,
.wrap textarea {
background: #23282d;
}
</style>';
}

How to create js slider

1. HTML code

<ul id="slidesimg">
<li class="slidimg" style="opacity:0.9;">
<img src="flag_en.png" alt="" />
</li>
<li class="slidimg" >
<img src="flag_fr.png" alt="" />
</li>
<li class="slidimg">
<img src="flag_bg.png" alt="" />
</li>
<li class="slidimg">
<img src="flag_fr.png" alt="" />
</li>
<li class="slidimg">
<img src="flag_bg.png" alt="" />
</li>
</ul>

 

2. PHP code

<script>
function hide(element, index, array) {
if (index > 0) {
slides[index].setAttribute('style', 'opacity:0;');
}
}
var slidesimg = document.getElementById("slidesimg"),
slides = slidesimg.querySelectorAll('li.slidimg'),
counter = 0,
list = Array.prototype.slice.call(slides);
setInterval(function() {
slides[counter].setAttribute('style', 'opacity:1;');
counter++;
if (counter == slides.length) {
counter = 0;
setTimeout(function() {
list.forEach(hide);
}, 1000);
}
}, 1000);
</script>

3. CSS code

#slidesimg {
position: relative;
padding: 0;
margin: 0;
width: 600px;
height: 300px;
}
#slidesimg li {
position: absolute;
opacity: 0;
list-style: outside none none;
width: 600px;
background: #FFFFFF;
transition: opacity 4s;
}

How to create js dynamic clock

1. Еxample

<script type="text/javascript">
function GetClock(){
d = new Date();
nhour = d.getHours();
nmin = d.getMinutes();
nsec = d.getSeconds();
if(nhour == 0) {ap = " AM";nhour = 12;}
else if(nhour <= 11) {ap = " AM";}
else if(nhour == 12) {ap = " PM";}
else if(nhour >= 13) {ap = " PM";nhour -= 12;}
if(nmin <= 9) {nmin = "0" +nmin;}
document.getElementById('clockbox').innerHTML=" "+nhour+":"+nmin+":"+nsec+" "+ap+" ";
setTimeout("GetClock()", 1000);
}
window.onload=GetClock;
</script>
<div id="clockbox"></div>

 
2. Еxample
 

<!DOCTYPE html>
<html>
<body onload="startTime()">
<div id="txt"></div>
<script>
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
// add a zero in front of numbers<10
m = checkTime(m);
s = checkTime(s);
document.getElementById("txt").innerHTML = h + ":" + m + ":" + s;
var t = setTimeout(function(){ startTime() }, 500);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
</script>
</body>
</html>

How to add back to top button in WordPress

1. Copy the code below into <head>

<script src=”http://code.jquery.com/jquery-1.11.2.min.js”></script>

 

2 Then create a new file top.js . Put the following code and save it in the same folder.

 

$(document).ready(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$(‘.scrollup’).fadeIn();
} else {
$(‘.scrollup’).fadeOut();
}
});
>$(‘.back-to-top-link’).click(function () {
$(“html, body”).animate({
scrollTop: 0
}, 600);
return false;
});
});

3. Copy the code below into functions.php file.

function theme_name_scripts() {
wp_enqueue_script( ‘top’, get_template_directory_uri() . ‘/js/top.js’, array(), ‘1.0.0’, true );
}
add_action( ‘wp_enqueue_scripts’, ‘theme_name_scripts’ );

 

4. Now we go to the place in the page where you want to stand back to top button and place the following code

<div class=”back-to-top-link”>
<a href=”#top”>
<span class=”arrow”></span>
Top
</a>
</div>

 

Upload Logo into Customize

How to Upload Logo into Customize

1. Add code below into functions.php file

function upload_logo ($wp_customize) {
$wp_customize->add_section(‘section’, array(
‘title’ => __(‘Upload Logo’, ‘text-dom’), // Your photo should be sized – max height 65px!
‘type’ => ‘option’,
‘description’ => ‘Your photo should be sized – max height 65px!’
));

$wp_customize->add_setting(‘logo_setting’, array(
‘sanitize_callback’ => ‘esc_url_raw’
));

$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, ‘logo’, array(
‘label’ => __(‘Logo’, ‘seosbusiness’),
‘section’ => ‘section’,
‘settings’ => ‘logo_setting’
)));
}

add_action(‘customize_register’, ‘upload_logo’);

2. Add into html page where we want to display the logo.

<a class=”site-name” href=”<?php echo esc_url(home_url(‘/’)); ?>”>
<?php if (get_theme_mod(‘logo_setting’)) : ?>

<img class=”logo” src=”<?php echo get_theme_mod(‘logo_setting’); ?>” alt=”<?php bloginfo(‘name’); ?>” />
<?php else : ?>
<h1><?php bloginfo(‘name’); ?></h1>
<?php endif; ?>
</a>