WordPress get current page url with query string — June 7, 2017
wordpress wp_enqueue_script() and ajax example — March 14, 2017

wordpress wp_enqueue_script() and ajax example


//register script

function load_custom_wp_admin_style($hook) {
if($hook != 'settings_page_swot-email-status') {
return;
}
// Register the script
wp_register_script( 'my_custom_adminscript', plugin_dir_url( __FILE__ ) . 'js/admin/adminscript.js', array('jquery') );
// Localize the script with new data
$translation_array = array(
'cresscap_nonce' => wp_create_nonce('swot-form')
);
wp_localize_script( 'my_custom_adminscript', 'adminscript_swotform', $translation_array );
// Enqueued script with localized data.
wp_enqueue_script( 'my_custom_adminscript' );

}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
/*admin section add scripts*/



/*add menu page in admin area*/
function swot_email_status() 
{

    $args = array(
        'post_type'  => 'swot',
        'posts_per_page' => -1,
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key'     => 'initial_email_status',
                'value'   => array('0', '1'),
                'compare' => 'IN',
            ),
        ),
    );
    $total_waiting_query = new WP_Query( $args );
    $total_waiting =  $total_waiting_query->post_count;
        // echo "Last SQL-Query: {$total_waiting_query->request}";
    wp_reset_query();


    $args = array(
        'post_type'  => 'swot',
        'posts_per_page' => -1,
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key'     => 'initial_email_status',
                'value'   => '2',
                'compare' => '=',
            ),
        ),
    );
    $total_sent_query = new WP_Query( $args );
    $total_sent =  $total_sent_query->post_count;
    wp_reset_query();

    echo '
    ';
}
/*admin section enqueue scripts*/
/*add menu page in admin area*/


/*jquery to make a request*/
jQuery(document).ready(function(){
	jQuery('#send_swot_email_submit').click(function(){
		jQuery(this).prop('disabled', true);
		var send_swot_email_result = jQuery('#send_swot_email_result');
		send_swot_email_result.html('Processing...').show();

		jQuery.ajax({
	        type: 'POST',
	        url: ajaxurl,
	        dataType: 'json',
	        data: {
	            'action':   'send_swot_email_submit',
	            'cresscap_nonce' : adminscript_swotform.cresscap_nonce
	        },
    
	    success: function (response) {
	    	jQuery('#send_swot_email_submit').prop('disabled', false);
	        // console.log(response);
	        send_swot_email_result.html('');
	        if( response.failed_mails )
			{
				var result;
				result = 'Not able to deliver email to : '+ response.failed_mails;
				send_swot_email_result.html(result).show();
			}
			if( response.success_mails )
			{
				var result;
				result = 'Email successfully delivered to : '+ response.success_mails;
				send_swot_email_result.html(result).show();
				// setTimeout(function(){ location.reload(true); }, 2000);

			}
	       
	    }

    });
/*jquery to make a request*/

wordpress ACF create front end form, submit and edit — March 8, 2017

wordpress ACF create front end form, submit and edit

always add acf_form_head(); in head tag
acf_form_head();

$options = array(
'post_id' => $_GET['listing_edit'], // $user_profile,
'field_groups' => array(1199),
'submit_value' => 'Submit',
// ‘uploader’ => ‘basic’,
'class' => 'btn green'

);

acf_form( $options );

$value = get_field( 'add_feed_links_here', $_GET['listing_edit'] );
print_r($value);

And to add validation to this field
add_filter('acf/validate_value/name=add_feed_links_here', 'my_acf_validate_value', 10, 4);

function my_acf_validate_value( $valid, $value, $field, $input ){

// bail early if value is already invalid
if( !$valid ) {

return $valid;

}

// load image data
$data = wp_get_attachment_image_src( $value, 'full' );
$width = $data[1];
$height = $data[2];

if( $width < 960 ) {

$valid = 'Image must be at least 960px wide';

}

// return
return $valid;

}
WordPress not able to upload plugin or theme in linux server — March 7, 2017
WordPress Could not create directory while core or plugin update — February 19, 2017

WordPress Could not create directory while core or plugin update

1. Web Server Ownership
The first level is actually to make sure that your web server has ownership over the directories:
chown -R www-data:www-data your-wordpress-directory

 

2. Directory Permissions
The second level is also required – you must make sure that the directory permissions are properly set:
sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;

 

I found this information here. I helped me when I was in problem.

Every Information about ACF, using field keys — February 14, 2017
WordPress send html mail — October 6, 2016

WordPress send html mail

This code is tested with WordPress 4.6.1

Only thing you need to add is ‘Content-type’.

<?php
$message = ‘<html>
<head></head>
<body>
<h1>See It is simple</h1>
</body>
</html>’;
$headers .= “Content-type:text/html;charset=UTF-8” . “\r\n”;
$headers .= ‘From: Yourname <test@test.com>’ . “\r\n”;
$subject = ‘Here is subject’;
$mail = wp_mail( $email_to, $subject, $message, $headers);

if ( $mail ){
echo ‘Mail sent successfully’;
} else {
echo ‘Oops, some error while sending email’;
}
?>