Skip to content

Instantly share code, notes, and snippets.

View obiPlabon's full-sized avatar
🎯
1 goal

Md Obidullah obiPlabon

🎯
1 goal
View GitHub Profile
@obiPlabon
obiPlabon / dummy-data-array.php
Created January 14, 2018 13:25
WordPress list utility functions and class tutorial
<?php
$tasks = array(
array(
'id' => 1,
'name' => 'Write down some tasks',
'priority' => 1,
'completed' => true,
),
array(
'id' => 2,
<?php
/**
* Show posts which are only under uncategorized term
* 1 is the id of Uncategorized term
*/
function op_show_only_uncategorized( $query ) {
if ( is_admin() || ! $query->is_main_query() || ! $query->is_category( 1 ) ) {
return;
}
<?php
/**
* Enqueue assets (js/css)
*/
function prefix_enqueue_assets() {
wp_enqueue_script(
'prefix-script',
get_template_directory_uri() . '/assets/js/scripts.js',
array('jquery'),
null,
<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'paged' => $paged,
'post__not_in' => get_option( 'sticky_posts' ),
'ignore_sticky_posts' => true,
'tax_query' => array(
array(
'taxonomy' => 'post_format',
@obiPlabon
obiPlabon / wp-category-rewrite-rule.php
Last active November 6, 2017 19:23
Append category id with category name in this format: http://example.com/category_base/category_name-category_id
<?php
function op_add_category_rule( $rules ) {
$rule = array(
'category/(.+?)-([0-9]+)/?$' => 'index.php?category_name=$matches[1]&category_id=$matches[2]'
);
return $rule + $rules;
}
add_filter( 'category_rewrite_rules', 'op_add_category_rule' );
@obiPlabon
obiPlabon / wc-add-meta-tab.php
Last active November 6, 2017 20:55
Create WooCommerce meta tab. বাংলা টিউটোরিয়ালঃ https://obiplabon.im/755/working-with-woocommerce-metabox-and-metadata/
<?php
/**
* Add awesome tab to tab list
*
* @param array $tabs Tabs list
* @return array
*/
function op_add_awesome_tab( $tabs ) {
$tabs['awesome-tab'] = array(
'label' => esc_html__( 'Awesome Tab', 'text-domain' ),
@obiPlabon
obiPlabon / bypass-wp-theme-update.php
Last active November 6, 2017 20:56
Bypass WordPress theme update notification. বাংলা টিউটোরিয়ালঃ http://obiplabon.im/745/bypass-wordpress-theme-update-notification/
<?php
/**
* Disable theme update notification
*
* Disabled this notification because there is a theme
* in WP theme directory with same name.
* We'll do this based on author name as author won't be same
*
* @param array $theme Installed themes information
* @return array Modified information
@obiPlabon
obiPlabon / wp-time-constants.txt
Created October 19, 2017 11:08
WordPress time constants added in 3.5
// WordPress Time Constants
MINUTE_IN_SECONDS = 60 (seconds)
HOUR_IN_SECONDS = 60 * MINUTE_IN_SECONDS
DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS
WEEK_IN_SECONDS = 7 * DAY_IN_SECONDS
MONTH_IN_SECONDS = 30 * DAY_IN_SECONDS
YEAR_IN_SECONDS = 365 * DAY_IN_SECONDS
@obiPlabon
obiPlabon / wc-block-add-to-cart-sl2.php
Last active September 20, 2023 08:18
Prevent WooCommerce to add more than 1 item in cart
<?php
/**
* Simple & concise Solution
*/
function op_block_add_to_cart() {
wc_add_notice( sprintf(
/** translators: %1$s is cart url, %2$s is checkout url */
esc_html__( 'You cannot purchase more than 1 item at a time. %1$s or %2$s', 'op' ),
'<a href="' . esc_url( wc_get_cart_url() ) . '">' . esc_html__( 'View cart', 'op' ) . '</a>',
'<a href="' . esc_url( wc_get_checkout_url() ) . '">' . esc_html__( 'checkout', 'op' ) . '</a>'
@obiPlabon
obiPlabon / wp-attachment-query-args-update.php
Last active April 11, 2018 06:09
Modify WordPress attachment ajax query
<?php
/**
* Show last 5 attachments in media popup
*/
/**
* Attachment query arguments
* @param array $args Query arguments
* @return array Update query argumnets
*/