Skip to content

Instantly share code, notes, and snippets.

@payamomrani
Last active February 24, 2020 05:12
Show Gist options
  • Save payamomrani/4b5fa9606bdfc71afe16b9c045001dbe to your computer and use it in GitHub Desktop.
Save payamomrani/4b5fa9606bdfc71afe16b9c045001dbe to your computer and use it in GitHub Desktop.
if ( ! wp_next_scheduled( 'parna_reset_all_credits_hook' ) ) {
wp_clear_scheduled_hook( 'parna_reset_all_credits_hook' );
$timestamp = strtotime('today midnight') - 12600;
wp_schedule_event( $timestamp, 'daily', 'parna_reset_all_credits_hook' );
}
add_action('parna_reset_all_credits_hook', 'parna_reset_all_credits');
function parna_reset_all_credits() {
$args = array(
'posts_per_page' => -1,
'post_type' => 'ywcmbs-membership',
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$credits = get_post_meta($post->ID,'_credits',true);
$plan_id = get_post_meta($post->ID,'_plan_id',true);
$download_limit = get_post_meta($plan_id,'_download-limit',true);
if($credits != $download_limit){
update_post_meta( $post->ID, '_credits', $download_limit );
}
}
}
if(isset($_GET['resetcredits']) && $_GET['resetcredits'] == 1){
$args = array(
'posts_per_page' => -1,
'post_type' => 'ywcmbs-membership',
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$credits = get_post_meta($post->ID,'_credits',true);
$plan_id = get_post_meta($post->ID,'_plan_id',true);
$download_limit = get_post_meta($plan_id,'_download-limit',true);
if($credits != $download_limit){
update_post_meta( $post->ID, '_credits', $download_limit );
}
}
echo '<pre>';print_r('All DB Reset');echo '</pre>';exit;
}
function wp_plugin_event_handler () {
$url = 'http://your-end-point';
$foo = 'bar';
$post_data = array(
'email' => urlencode($foo));
$result = wp_remote_post( $url, array( 'body' => $post_data ) );
}
add_action("wp_plugin_event", "wp_plugin_event_handler");
$THEurl = $scheme . $url['host'] . $url['path'];
$response = wp_remote_post( $THEurl, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $query,
'cookies' => array()
)
);
if ( is_wp_error( $response ) ) {
$errorResponse = $response->get_error_message();
require_once("FBAOutboundServiceMWS/Exception.php");
throw new FBAOutboundServiceMWS_Exception(
array(
'Message' => $errorResponse,
'ErrorType' => 'HTTP'
)
);
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment