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 | |
/** | |
* Basic CSV Export | |
* | |
* (c) 2016 Max Kostinevich - All rights reserved | |
* https://maxkostinevich.com | |
*/ | |
// Do some security check here |
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 | |
/** | |
* Export Data to CSV file | |
* Could be used in WordPress plugin or theme | |
*/ | |
// A sample link to Download CSV, could be placed somewhere in plugin settings page | |
?> | |
<a href="<?php echo admin_url( 'admin.php?page=myplugin-settings-page' ) ?>&action=download_csv&_wpnonce=<?php echo wp_create_nonce( 'download_csv' )?>" class="page-title-action"><?php _e('Export to CSV','my-plugin-slug');?></a> |
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
function Emitter() { | |
this.events = {}; | |
} | |
Emitter.prototype.on = function (type, listener) { | |
this.events[type] = this.events[type] || []; | |
this.events[type].push(listener); | |
} |
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 | |
// Determine how many bytes sent over http | |
ignore_user_abort(true); | |
$handle = fopen($file_path, 'r'); | |
while ( ! feof($handle)) { | |
echo fread($handle, 4096); | |
if (connection_aborted()) { | |
$transfer_success = false; | |
$bytes_transferred = ftell($handle); |
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 | |
function search_json($obj, $field, $value) { | |
foreach($obj as $item) { | |
foreach($item as $child) { | |
if(isset($child[$field]) && ($child[$field] == $value)) { | |
return $child; | |
} | |
} | |
} | |
return null; |
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('print_media_templates', function(){ | |
// define your backbone template; | |
// the "tmpl-" prefix is required, | |
// and your input field should have a data-setting attribute | |
// matching the shortcode name | |
?> | |
<script type="text/html" id="tmpl-my-custom-gallery-setting"> | |
<label class="setting"> |
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
/* Add before submit action to fix checkbox issue | |
Change value to "off" for not-checked checkboxes and check them. | |
In this case value "off" (instead of original value) will be stored. | |
*/ | |
$('form#post').submit(function(e) { | |
$('#some-wrapper input[type=checkbox]:not(:checked)').each(function(){ | |
var curItem=$(this); | |
curItem.val('off'); | |
curItem.prop('checked', true); |
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 | |
$host='http://'.$_SERVER['SERVER_NAME']; | |
function get_files($path,&$files = array()){ | |
global $host; | |
$dir = opendir($path."/."); | |
while($item = readdir($dir)){ | |
if(is_file($sub = $path."/".$item)){ | |
$file_path = $host.substr( $path, strlen( $_SERVER[ 'DOCUMENT_ROOT' ] )).'/'.$item; | |
$file_info =pathinfo($sub); |
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_filter( 'enter_title_here', 'my_filter' ); | |
function my_filter( $title ){ | |
$screen = get_current_screen(); | |
if ( 'invoice' == $screen->post_type ){ | |
$title = 'Your placeholder here'; | |
} | |
return $title; | |
} |