Tag Archives: function

Add admin menu and submenu page


add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('None Members', 'None Members', 'manage_options', 'none-member', 'my_menu_output' );
add_submenu_page('none-member', 'Send bulk email', 'Send bulk email', 'manage_options', 'none-member' );
add_submenu_page('none-member', 'Members list', 'Members list', 'manage_options', 'my-menu2', 'memberslist' );
}
function my_menu_output(){
echo "<h2>Send Bulk Email</h2>";
}
function memberslist(){
echo "<h2>All Non members User</h2>";
}

Refrence:

http://wordpress.stackexchange.com/questions/66498/add-menu-page-with-different-name-for-first-submenu-item

Add encrypted code into URL for specific page in wordpres

add encrypted code into URL

https://codex.wordpress.org/WordPress_Nonces

https://codex.wordpress.org/Function_Reference/wp_nonce_url

$urllink = “http://steve.seomonastery.com/jig-free-report/&#8221;;
$actionurl = wp_nonce_url( $urllink );

echo $actionurl;

Redirect Non-Administrators User After Login in WordPress

/* Redirect Non-Administrators user After Login */
function acme_login_redirect( $redirect_to, $request, $user  ) {
//  $perticular_page = get_permalink(4); Use site_url() to $perticular_page for redirect on perticular page
return ( is_array( $user->roles ) && in_array( ‘administrator’, $user->roles ) ) ? admin_url() : site_url();
}
add_filter( ‘login_redirect’, ‘acme_login_redirect’, 10, 3 );

Add custom media field

Paste in functions.php

Field displaying in Edit media

/* custom media fild */
add_filter( ‘attachment_fields_to_edit’,  ‘attachment_fields_edit_hfp’, null, 2 );
add_filter( ‘attachment_fields_to_save’,  ‘attachment_fields_save_hfp’, null, 2 );
add_action( ‘admin_init’, ‘hfp_columns’);

function attachment_fields_edit_hfp( $form_fields, $post ) {

$hfp_prevention = (bool) get_post_meta($post->ID, ‘_myhfp_prevention’, true);
$checked = ($hfp_prevention) ? ‘checked’ : ”;
$form_fields[‘hfp’] = array(
‘label’ => ”,
‘input’ => ‘html’,
‘html’ => “<label><strong>Show for visitors</strong></label><br/><input type=’checkbox’ {$checked} name=’attachments[{$post->ID}][hfp_prevention]’ id=’attachments[{$post->ID}][hfp_prevention]’ />Show for visitors?”,
‘value’ => $hfp_prevention,
‘helps’ => ”
);
return $form_fields;

}
function attachment_fields_save_hfp($post, $attachment) {

if (isset($attachment[‘hfp_prevention’]))
$hfp_prevention = ($attachment[‘hfp_prevention’] == ‘on’) ? 1 : 0;
else $hfp_prevention=0;
update_post_meta($post[‘ID’], ‘_myhfp_prevention’, $hfp_prevention);

return $post;

}

function hfp_column( $cols ) {

$cols[“hfp”] = “Show for visitors”;
return $cols;

}

function hfp_column_value( $column_name, $id ) {

$meta = wp_get_attachment_metadata($id);
$hfp=get_post_meta($id, ‘_myhfp_prevention’, true);
if ($hfp==1) echo “Yes”;

}

function hfp_column_sortable( $cols ) {

$cols[“hfp”] = “hfp”;
return $cols;

}
function hfp_columns() {

add_filter( ‘manage_media_columns’, ‘hfp_column’ );
add_action( ‘manage_media_custom_column’, ‘hfp_column_value’, 10, 2 );
add_filter( ‘manage_upload_sortable_columns’, ‘hfp_column_sortable’ );

}

Display admin email address

<?php echo $admin_email = get_option( ‘admin_email’ );  ?>

Send email on multypal email address

$multiple_to_recipients = array(
$to,
‘raviradadiya.ommune@gmail.com’
);
wp_mail( $multiple_to_recipients, $sbj, $msg, $headers );

%d bloggers like this: