Skip to content

Instantly share code, notes, and snippets.

@generatepress
Created August 22, 2014 16:21
Show Gist options
  • Save generatepress/4bd77ee0b11688a59ee6 to your computer and use it in GitHub Desktop.
Save generatepress/4bd77ee0b11688a59ee6 to your computer and use it in GitHub Desktop.
<?php
require_once( '../../wp-load.php' );
if ( $_POST['generate_action'] == 'get_email' ) :
$args = array(
'post_type' => 'edd_license',
'showposts' => -1,
's' => $_POST['email']
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$posts = $the_query->get_posts();
//wp_die(print_r($posts));
$names = array();
$licenses = array();
foreach ( $posts as $post ) {
$license = get_post_meta( $post->ID, '_edd_sl_key', true );
$item_name = $post->post_title;
$items[] = substr( $item_name, 0, strrpos($item_name,' -') );
}
echo json_encode($items);
} else {
}
wp_reset_postdata();
endif;
if ( $_POST['generate_action'] == 'get_license' ) :
$downloads = array(
'gen_colors_license_key' => 'Generate Colors',
'gen_fonts_license_key' => 'Generate Typography',
'gen_backgrounds_license_key' => 'Generate Backgrounds',
'gen_page_header_license_key' => 'Generate Page Header',
'gen_copyright_license_key' => 'Generate Copyright',
'gen_spacing_license_key' => 'Generate Spacing',
'gen_blog_license_key' => 'Generate Blog',
'gen_disable_elements_license_key' => 'Generate Disable Elements',
'gen_hooks_license_key' => 'Generate Hooks',
'gen_ie_license_key' => 'Generate Import Export'
);
foreach ( $downloads as $key => $value ) {
$args = array(
'post_type' => 'edd_license',
'showposts' => -1,
's' => $_POST['email'] . ' ' . $value
);
$license_entries = get_posts($args);
$i = 0;
$result = array();
foreach ( $license_entries as $post ) : setup_postdata($post);
$license = get_post_meta( $post->ID, '_edd_sl_key', true );
$data[] = array(
'id' => $key,
'name' => $value,
'license' => $license
);
endforeach;
}
echo json_encode( $data );
endif;
if ( $_POST['generate_action'] == 'get_single_license' ) :
$args = array(
'post_type' => 'edd_license',
'showposts' => -1,
's' => $_POST['email'] . ' ' . $_POST['download']
);
$license_entries = get_posts($args);
$result = array();
foreach ( $license_entries as $post ) : setup_postdata($post);
$license = get_post_meta( $post->ID, '_edd_sl_key', true );
$data = array(
'license' => $license
);
endforeach;
echo json_encode( $data );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment