This file contains 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
<!-- Image preview Script --> | |
<script> | |
jQuery(document).ready(function($){ | |
function imagePreview(uploader) { | |
if (uploader.files && uploader.files[0]) { | |
$("#display-upload-image").attr("src", window.URL.createObjectURL(uploader.files[0])); | |
} | |
} | |
$("#sample_image").change(function() { | |
imagePreview(this); |
This file contains 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 | |
if (isset($_GET['download-users'])) { | |
global $wpdb; | |
// Fetch data from a sepecific table(wp_users) from database | |
$query = $wpdb->get_results("SELECT * FROM `wp_users`"); | |
$filename = "wp_users_" . date('Y-m-d') . ".csv"; | |
$path = wp_upload_dir(); // or where ever you want the file to go | |
$outstream = fopen( 'php://output', 'w' ); | |
$user_fields_csv = array('Row','ID','user_login','user_pass','user_email','user_registered'); | |
ob_end_clean(); |
This file contains 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 | |
global $wpdb; | |
// Fetch data from a sepecific table(wp_users) from database | |
$get_users = $wpdb->get_results("SELECT * FROM `wp_users`"); | |
//Sample output | |
Array | |
( | |
[0] => stdClass Object | |
( | |
[ID] => 1 |
This file contains 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 | |
// add this filter to recognise meta key when you do your order query | |
add_filter( 'woocommerce_order_data_store_cpt_get_orders_query', 'my_function', 10, 2 ); | |
function my_function( $query, $query_vars ) { | |
if ( ! empty( $query_vars['_my_custom_order_meta'] ) ) { | |
$query['meta_query'][] = array( | |
'key' => '_my_custom_order_meta', | |
'value' => esc_attr( $query_vars['_my_custom_order_meta'] ), | |
); | |
} |
This file contains 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 | |
// Let's assume this is your main plugin file | |
register_activation_hook( __FILE__, array( 'YOURTEXTDOMAIN', 'function_to_call_upon_activation' ) ); | |
//register_activation_hook( __FILE__, array ( $my_class, 'function_to_call') ); // If inside a Class | |
function function_to_call_upon_activation() { | |
// Check PHP Version and deactivate & die if it doesn't meet minimum requirements. | |
if ( version_compare( PHP_VERSION, '5.4', '<=' ) ) { | |
deactivate_plugins( plugin_basename( __FILE__ ) ); | |
add_action( 'admin_notices', 'my_plugin_notice' ); |
This file contains 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 | |
add_action( 'admin_menu', 'my_admin_menu' ); | |
function my_admin_menu() { | |
add_menu_page( | |
__( 'My page name', 'my-textdomain' ), | |
__( 'My menu name', 'my-textdomain' ), | |
'manage_options', | |
'sample-page', | |
'my_admin_page_contents', | |
'dashicons-schedule', |
This file contains 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 | |
$time_start = 1619164800; //8:00:00 AM converted to integer | |
$time_end = 1619197200; //5:00:00 PM converted to integer | |
$interval = 1800; // 30min interval in seconds | |
$x = 1; | |
for( $item_time = $time_start; $item_time < $time_end; $item_time += $interval ) { | |
echo date('g:i a', $item_time); ?> | |
$x++; | |
} | |
?> |
This file contains 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 | |
// Create global variable for another db | |
add_action('init', 'get_certain_db'); | |
function get_certain_db() { | |
global $another_db; | |
$another_db = new wpdb(USERNAME, PASSWORD, DATABASE_NAME, HOSTNAME); | |
} | |
// Example #1 Get taxonomies from another db | |
function listing_cat_list() { |
This file contains 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 | |
register_activation_hook( __FILE__, array( 'SAMPLE_CLASS', 'plugin_activated' ) ); | |
class SAMPLE_CLASS { | |
public function plugin_activated() { | |
$add_custom_table = $wpdb->prefix . 'table_name'; | |
if($wpdb->get_var("SHOW TABLES LIKE '$add_custom_table'") != $add_custom_table) { | |
$charset_collate = $wpdb->get_charset_collate(); | |
$sql = "CREATE TABLE IF NOT EXISTS $add_custom_table ( | |
`id` int(100) NOT NULL auto_increment, | |
`field_label` int(100) NOT NULL, |
NewerOlder