Skip to content

Instantly share code, notes, and snippets.

View 1naveengiri's full-sized avatar
🏠
Working from home

Naveen Giri 1naveengiri

🏠
Working from home
View GitHub Profile
@1naveengiri
1naveengiri / tinymce-char-length.js
Created March 14, 2018 11:40
Set Character limit for tinymce Text Editor
/**
* This was an expamle of tinymce in repeatable field
* I hav't handled case for copy paste text in the editor so max limit will not be checked when you cntl+c&cntl+v
* but on texteditor change I have reset the content to max char limit.
*/
jQuery( document ).on( 'tinymce-editor-init', function( event, editor ) {
jQuery(".games-section .repeatable-item").each(function(){
var this_id = jQuery(this).attr('data-items');
var this_id = 'book_game_item_description_' + this_id;
@1naveengiri
1naveengiri / function.php
Last active March 30, 2018 19:09
How to add page/post as menu Item programmatically in WordPress?
<?php
/**
* To add a page/post in WordPress menu
*/
$menu_id = 4; //menu ID.
$_post_id = 5; // post/page ID.
// note here $menu_item_db_id is already added menu item ID, if it will be 0 new menu will be added otherwise we can edit previous menu with code.
$menu_response_data = wp_update_nav_menu_item( $menu_id , $menu_item_db_id=0, array(
'menu-item-object-id' => $_post_id,
'menu-item-object' => 'page',
@1naveengiri
1naveengiri / function.php
Last active March 30, 2018 19:10
How to add custom link as menu Item programmatically in WordPress Menu?
<?php
/**
* To add a custom link as custom menu item in WordPress menu
*/
$menu_id = 4; // WordPress menu ID.
wp_update_nav_menu_item($menu_id, 0, array(
'menu-item-title' => __('Home'),
'menu-item-classes' => 'home',
'menu-item-url' => 'http://buddydevelopers.com',
'menu-item-status' => 'publish'
@1naveengiri
1naveengiri / class-top-post-widget.php
Last active April 13, 2018 18:05
Top/Popular post by Google analytics in WordPress
<?php
/**
* This widget is depend on https://wordpress.org/plugins/google-analytics-post-pageviews/
*
* Steps:
* 1. Create a Google developer project - http://console.developers.google.com/
*
* 2.enable google analytics service, you can check
* - https://www.youtube.com/watch?v=AX9PtgKPnuM,
* - https://developers.google.com/ad-exchange/rtb/open-bidder/google-app-guide
@1naveengiri
1naveengiri / social-sharing-bar.php
Last active April 16, 2018 17:07
Social sharing feature in few lines of code
<?php
/**
* Social share bar
* @param int $post_id post id
* @param string $title post title
* @param string $twitter_via twitter handle
*/
function custom_social_share( $post_id, $title, $twitter_via ){
if( !empty( $post_id ) && !empty( $title ) && !empty( $twitter_via )):
$post_url = get_permalink( $post_id );
@1naveengiri
1naveengiri / function.php
Last active August 3, 2018 08:27
Add new consent in Awesome Support
<?php
add_filter('wpas_gdpr_consents', 'add_new_gdpr_consent_item', 10, 1 );
/**
* Function to add new consent in AS settings.
*
* @param array $gdpr_consent_options GDPR consent options
*/
function add_new_gdpr_consent_item( $gdpr_consent_options ){
$consent_short_desc = wpas_get_option( 'join_mailing_list_short_note', false );
$gdpr_id = wpas_get_gdpr_data( $consent_short_desc );
@1naveengiri
1naveengiri / functions.php
Created September 7, 2018 07:59
Contact form 7 and Mailchimp Integration without plugin with action URL
<?php
/**
* This is a demo of mailchimp integration with contact form 7 with the help of Action URL.
*
* You can get these action URL from the mailchimp list
* follow this https://www.youtube.com/watch?v=sybmI8HgxFo
*
*/
// define the wpcf7_mail_sent callback
function cf7_action_wpcf7_mail_sent( $contact_form ) {
<div id="address_search" class="slp search_box layout row wrap">
<div class="filter-online-dealer-section"><img class="new-cart-icon" src="http://staging.bennetttrimtabs.com/wp-content/uploads/2015/05/ws-cart.png" /><a href="http://staging.bennetttrimtabs.com/dealers-list/">View Online Dealers</a><img class="new-right-arrow" src="http://staging.bennetttrimtabs.com/wp-content/uploads/2018/10/right-arrow.png" /></div>
<div class='filter-heading section'>
<h3>Filters</h3>
<a href='#' class='dx_hide_form_data dx_left'>hide all</a>
<a href='#' class='reset_form_data dx_right'>reset all</a>
</div>
<div class="flex xs12 section dx-cat-shortable">[slp_search_element dropdown_with_label="category"]</div>
<div class='section dx-address-shortable'>
<div class="flex xs4"><label>Location: </label> <a href='#' class="dx_link" id="dx_addressSubmit" >find my locations</a> [slp_search_element input_with_label="address"]</div>
@1naveengiri
1naveengiri / xpath.php
Created November 15, 2018 14:46
Extract content from a html using Xpath
<?php
/**
* Function to extract content from html.
* $html HTML data
* $expression Expression used to extract the data ex. //div[@id='breadcrumbs']/span
*/
function extract_content_from_html( $html, $expression ){
$dom = new DOMDocument();
$output = '';
libxml_use_internal_errors( true );
@1naveengiri
1naveengiri / strong-pws-check.php
Last active January 4, 2019 07:01
Awesome Support strong password check
<?php
// this action get fire during registration process.
add_action('wpas_pre_register_account','wpas_pre_register_account_callback', 10, 3);
function wpas_pre_register_account_callback( $user, $redirect_to, $data ){
if( !is_pwd_strong( $user['pwd'] ) ){
wpas_add_error( 'accept_terms_conditions', esc_html__( 'Add strong password', 'awesome-support' ) );
wp_safe_redirect( $redirect_to );
exit;
}
}