Skip to content

Instantly share code, notes, and snippets.

View hayskytech's full-sized avatar

Sufyan Haysky hayskytech

View GitHub Profile
@hayskytech
hayskytech / hide_adminbar.php
Last active August 20, 2022 00:58
WP Hide Admin Bar for non-admin
<?php
function haysky_disable_admin_bar() {
if (current_user_can('administrator') ) {
show_admin_bar(true);
} else {
show_admin_bar(false);
}
}
add_action('after_setup_theme', 'haysky_disable_admin_bar');
<?php
add_action( 'init', function() {
if ( is_admin() && ! current_user_can( 'administrator' ) && is_user_logged_in() && ! wp_doing_ajax() ) {
wp_redirect( home_url().'/account' );
exit;
}
});
<?php
/*** Sort and Filter Users ***/
add_action('restrict_manage_users', 'filter_by_gender');
function filter_by_gender($which){
// template for filtering
$st = '<select name="gender_%s" style="float:none;margin-left:10px;">
<option value="">%s</option>%s</select>';
// generate options
<?php
add_filter('manage_users_columns','remove_users_columns');
function remove_users_columns($column_headers) {
// if (current_user_can('moderator')) {
unset($column_headers['name']);
// }
return $column_headers;
}
<?php
add_action( 'wp_enqueue_scripts',function(){
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'mathematics_exam') ) {
wp_enqueue_script( 'jquery');
}
});
@hayskytech
hayskytech / upi-html-link.html
Last active March 2, 2023 07:26
UPI-HTML-Link
@hayskytech
hayskytech / preselect-category-new-post.php
Last active December 30, 2022 04:33
preselect-category-new-post.php
<?php
function ws_preselect_post_category() {
if ( isset($_GET['category']) && is_numeric($_GET['category']) ) {
$catId = intval($_GET['category']);
?>
<script type="text/javascript">
jQuery(function() {
var catId = <?php echo json_encode($catId); ?>;
jQuery('#in-category-' + catId).click();
});
<?php
$args = array(
'taxonomy' => 'place',
'parent' => 0,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true, //can be 1, '1' too
'number' => false, //can be 0, '0', '' too
'offset' => '',
'fields' => 'all',
@hayskytech
hayskytech / Prevent-form-resubmit.html
Created January 27, 2023 15:25
Prevent form resubmission when page is refreshed.
<script>
if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
</script>
<div id="myElement">
<h1>My Title</h1>
<p>Some text...</p>
</div>
<button onclick="downloadAsImage()">Download as Image</button>
<button onclick="downloadAsPDF()">Download as PDF</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.2/html2canvas.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>