This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Restricting Users to View Only Media Library Items When They Upload | |
*/ | |
add_filter( 'ajax_query_attachments_args','mmr_show_current_user_attachments' ); | |
function mmr_show_current_user_attachments( $query ) { | |
$user_id = get_current_user_id(); | |
if ( $user_id && | |
!current_user_can('activate_plugins') && | |
!current_user_can('edit_others_posts') ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$content = $testimonial->post_content; | |
$content = preg_replace('#\[[^\]]+\]#', '',$content); | |
apply_filters('the_content', $content); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** The "Select Key File" button. */ | |
jQuery( '.mdp-select-key-file-btn' ).on( 'click', function( e ) { | |
e.preventDefault(); | |
var send_attachment_bkp = wp.media.editor.send.attachment; | |
var button = jQuery( this ); | |
wp.media.editor.send.attachment = function( props, attachment ) { | |
jQuery( button ).prev().val( attachment.id ); | |
jQuery( button ).prev().prev().text( attachment.filename ); | |
wp.media.editor.send.attachment = send_attachment_bkp; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$time = microtime(TRUE); | |
$mem = memory_get_usage(); | |
[the code you want to measure here] | |
print_r(array( | |
'memory' => (memory_get_usage() - $mem) / (1024 * 1024), | |
'seconds' => microtime(TRUE) - $time | |
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#place_order").on('click',function(e){ | |
var mobile = $("#billing_phone").val(); | |
var pattern = /\+?(88)?01[3456789][0-9]{8}\b/; | |
// return false; | |
if(!pattern.test(mobile) && mobile !== ''){ | |
e.preventDefault(); | |
// $("#on_form").find(".phone-valid").after('<p class="on_warning">Please enter a valid mobile number.</p>'); | |
alert('Please enter a valid mobile number.'); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get all type posts | |
* | |
* @return void | |
* @author alispx/dompl | |
**/ | |
function alispx_get_type_posts_data($post_type = 'post') | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'http://example.org/api'; | |
$response = wp_remote_get( esc_url_raw( $url ) ); | |
/* Will result in $api_response being an array of data, | |
parsed from the JSON response of the API listed above */ | |
$api_response = json_decode( wp_remote_retrieve_body( $response ), true ); | |
// details: https://codex.wordpress.org/Function_Reference/wp_remote_retrieve_body |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
functions.php | |
=============== | |
function mmr_add_to_cart_fragment( $fragments ) { | |
global $woocommerce; | |
ob_start(); | |
// $count = WC()->cart->cart_contents_count; | |
//$count = WC()->cart->get_cart_contents_count(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create log file | |
*/ | |
function create_log_file($arr,$arr1 = array()) | |
{ | |
/* write log file */ | |
// $time = date( "F jS Y, H:i", time() ); | |
$time = (new DateTime('America/New_York'))->format('F jS Y, H:i A'); | |
$output = "Time: " . "$time\r\n"; | |
$output .= "Browser: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preg_match_all( '/' . get_shortcode_regex() . '/s', $text, $matches ); | |
$output = array(); | |
if( isset( $matches[2] ) ) | |
{ | |
foreach( (array) $matches[2] as $key => $value ) | |
{ | |
if( $tag === $value ) { | |
$output[] = shortcode_parse_atts( $matches[3][$key] ); | |
} | |
} |