Skip to content

Instantly share code, notes, and snippets.

View Jany-M's full-sized avatar
🎯
Focusing

Jany Martelli Jany-M

🎯
Focusing
View GitHub Profile
@Jany-M
Jany-M / WP_WPML_Custom_Lang_Selector.php
Last active June 6, 2021 16:35
[WordPress] WPML Custom Language Selector
<?php
if (function_exists('icl_get_languages')) {
// Native Lang Name
function get_language_name($code=''){
global $sitepress;
$details = $sitepress->get_language_details($code);
$language_name = $details['display_name']; //english_name //display_name
return $language_name;
}
// Custom Lang Selector
@Jany-M
Jany-M / WP_Change_Author_on_Post_Update.php
Last active June 6, 2021 16:35
[WordPress] Update Author on post update
<?php
// Change Author on Update
function change_on_edit() {
global $post;
$id = $post->ID;
$original_author = $post-> post_author ;
$current_author = get_current_user_id();
if (!wp_is_post_revision($id)) {
remove_action('publish_post', 'change_on_edit');
@Jany-M
Jany-M / WP_Post_Pagination.php
Last active June 6, 2021 16:34
[WordPress] Post Internal custom Pagination
<?php
// Custom Post Pagination
function custom_wp_link_pages( $args = '' ) {
global $post;
// Get Post Type name
$post_type_name = ucfirst(get_post_type(get_the_ID()));
$defaults = array(
@Jany-M
Jany-M / WP_PF_custom_classes.php
Last active August 29, 2015 14:24
[WordPress] Print Friendly Plugin Template Add-On - Add custom classes inside nested iFrames for customization based on Post Type
<?php if(is_singular('slug-of-post-type')) :
global $post;
$p_type = get_post_type(get_the_ID());
?>
<script type="text/javascript">
jQuery(document).ready(function() {
$( ".printfriendly a" ).click(function() {
$("#pf-core").load(function() {
setTimeout( function () {
//console.log( $('#pf-core').contents().find('iframe').contents().find('#pf-print-area') );
@Jany-M
Jany-M / WP_WC_auto-confirm-bookings.php
Last active June 29, 2022 10:52
[WordPress] [WooCommerce] [Bookings] Auto-Confirm Booking upon Order Complete
<?php
add_action( 'woocommerce_order_status_completed', 'mark_confirm_bookings', 20, 1 );
function mark_confirm_bookings( $order_id ) {
global $wpdb;
$order = new WC_Order( $order_id );
$bookings = array();
foreach ( $order->get_items() as $order_item_id => $item ) {
@Jany-M
Jany-M / WP_is_plugin_active.php
Created August 12, 2015 14:54
[WordPress] Check from Frontend/Theme if a plugin is active
<?php // Check from theme if a plugin is active - Place in functions.php or similar
if(!function_exists('plugin_is_active')) {
function plugin_is_active($plugin_folder, $plugin_file) {
if(!isset($plugin_file) || $plugin_file == '') $plugin_file = $plugin_folder;
return in_array($plugin_folder.'/'.$plugin_file.'.php', apply_filters('active_plugins', get_option('active_plugins')));
}
}
?>
@Jany-M
Jany-M / WP_IDX_language_selector.php
Created August 26, 2015 11:40
[WordPress] WPML custom language selector for dsIDXpress IDX plugin compatibility
<?php
// Custom Lang Selector
if (function_exists('icl_get_languages')) {
// Get Native Lang Name
function get_language_name($code=''){
global $sitepress;
$details = $sitepress->get_language_details($code);
$language_name = $details['display_name']; // options are: english_name / display_name
return $language_name;
}
@Jany-M
Jany-M / WP_merge_multiple_queries.php
Last active November 9, 2021 16:56
[WP] Merge Multiple Queries / Loops into one
<?php
// Check if values are cached, if not cache them
//delete_transient('home_slider_24h');
if(get_transient('home_slider_24h') === false) {
// RM Blog (post) query
$rm_blog_args = array(
'posts_per_page' => 1,
'cat' => 10,
@Jany-M
Jany-M / WP_remove_product_name_woocommerce_breadcrumbs.php
Created November 30, 2015 12:54
[WordPress] Remove Product Name & URL from WooCommerce Breadcrumbs
<?php
// In your theme, make a new folder woocommerce/global/
// Add this function in a file called breadcrumbs.php, in that folder
// or integrate the existing function accordingly.
/**
* Shop breadcrumb
*
* @author WooThemes
* @package WooCommerce/Templates
@Jany-M
Jany-M / WP_query_repeater.php
Last active February 2, 2016 18:05
[WordPress] Repeat a Query/Loop with automatic offset, query caching through transients and cutom post type, no children, order by title
<?php
$i = 0;
$num = 30;
$offset = 30;
$cpt = 'rate-plan';
$qty = '1,2,3,4,5,6,7,8,9,10,11,12';
$times = explode(',', $qty);
foreach($times as $item) {
$i++;