Skip to content

Instantly share code, notes, and snippets.

View nfmohit's full-sized avatar

Nahid F Mohit nfmohit

View GitHub Profile
@nfmohit
nfmohit / post-state.php
Created November 23, 2017 02:00
Assign a post state to a WordPress post
<?php
add_filter( 'display_post_states', 'wpmudev_add_post_state', 10, 2 );
function wpmudev_add_post_state( $states, $post ) {
if( $post->post_name == 'contact' ) { //Slug of the page, this should be unique
$states[] = 'Contact Page';
}
return $states;
}
@nfmohit
nfmohit / wphead-css.php
Last active November 23, 2017 04:38
CSS in wp_head
<?php
add_action('wp_head', 'cust_css_wpmudev_head');
function cust_css_wpmudev_head() {
echo '<style>@media only screen and (min-width: 1080px) { #wrapper-1507244077357-1047, #wrapper-1507244115701-1068, #wrapper-1507267210188-1550 { display:none; } }</style>';
}
@nfmohit
nfmohit / js-wp-head.php
Last active November 23, 2017 04:19
JS in wp_head
<?php
add_action('wp_head', 'cust_js_wpmudev_head');
function cust_js_wpmudev_head() {
echo '<script>(function($) {
if ($(window).width() > 1079) {
$( document ).ready(function() {
$("#wrapper-1507244077357-1047").hide();
});
$(window).load(function() {
$("#wrapper-1507244115701-1068").hide();
@nfmohit
nfmohit / bp_private_profile.php
Last active February 3, 2020 12:18
BuddyPress private profile (Redirect to homepage if it is not the current user's profile)
<?php
add_action('template_redirect', 'bp_private_profile');
function bp_private_profile() {
if ( ! current_user_can( 'manage_options' ) ) {
if ( bp_is_user_profile() && ! bp_is_my_profile() ) {
wp_redirect( home_url() );
exit;
}
}
}
@nfmohit
nfmohit / prosites_form.css
Last active January 22, 2018 12:34
Styles for WordPress Multisite (Pro Sites) Signup form
#prosites-signup-form-checkout form#prosites-user-register {
margin-left: auto;
margin-right: auto;
max-width: 450px;
}
#prosites-user-register label {
display: block;
font-size: 15px;
line-height: 22px;
@nfmohit
nfmohit / Hiding TGMPA notice
Created November 27, 2017 04:48
This mu-plugin will hide the TGMPA notice from WordPress Dashboard
<?php
add_action('admin_head', 'hide_tgmpa_notif');
function hide_tgmpa_notif() {
echo '<style>#setting-error-tgmpa{display:none;}</style>';
}
@nfmohit
nfmohit / print_date.php
Last active November 29, 2017 01:47
Shortcode for showing date in WordPress | Put [nahid_print_date] as the shortcode | Will show as "Current as of 12/2017"
<?php
function nahid_print_date_shortcode() {
echo 'Current as of ' . date("m/Y");
}
add_shortcode( 'nahid_print_date', 'nahid_print_date_shortcode' );
<?php
add_action('wp_head', 'gscChangePlaceholder');
function gscChangePlaceholder() {
?>
<script type="text/javascript">
(function($) {
$( document ).ready(function() {
$("#gsc-i-id1").attr("placeholder", "New Placeholder Text");
}
})(jQuery);
@nfmohit
nfmohit / marketpress_custom_shortcodes.php
Created December 12, 2017 07:56
Shortcodes for Continue Shopping and Review Order - MarketPress
<?php
function mp_cus_continue_shopping_shortcode() {
return '<a href="' . mp_products_link( false, true ) . '" class="mp_button mp_button-continue-shopping mp_button-large">Continue Shopping?</a>';
}
add_shortcode('mp_continue_shopping_btn', 'mp_cus_continue_shopping_shortcode');
function mp_cus_review_order_shortcode() {
return '<a href="' . mp_cart_link( false, true ) . '" class="mp_button mp_button-continue-shopping mp_button-large">Review Order</a>';
}
add_shortcode('mp_review_order_btn', 'mp_cus_review_order_shortcode');
<?php
$member = MS_MODEL_MEMBER::get_current_member();
foreach ( $member->subscriptions as $subscription ) {
$membership = $subscription->get_membership();
$has_access = $membership->has_access_to_post( $post_id );
if ( $has_access ) {
//Content that you want to show if member has access to the queried post
}
}