-
-
Save gMagicScott/e2d5a6e254d443a0898f to your computer and use it in GitHub Desktop.
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 | |
/* | |
Plugin Name: 1MinuteSites | |
Plugin URI: http://www.1minutesites.com/ | |
Description: The FASTEST Way To Create Landing Pages In 60 Seconds Or Less... Even If You're A Brand New Beginner | |
Version: 1.2 | |
Author: 1MinuteSites | |
Author URI: http://www.1minutesites.com/ | |
Copyright 2014 Get Profits Fast (http://www.getprofitsfast.com) | |
*/ | |
define( 'OMS_PATH', plugin_dir_path(__FILE__) ); | |
define( 'OMS_VERSION', '1.2' ); | |
require_once (OMS_PATH.'api.php'); | |
function oms_add_meta_box() { | |
if ( !function_exists( 'add_meta_box' ) ) | |
return; | |
global $pagenow; | |
if (! empty($pagenow) && ('post-new.php' === $pagenow || 'post.php' === $pagenow )) | |
add_action('admin_footer', 'oms_admin_scripts'); | |
add_action("admin_print_styles-post.php", 'oms_admin_styles'); | |
add_action("admin_print_styles-post-new.php", 'oms_admin_styles'); | |
add_meta_box( 'oms-meta-box', '<span id="oms-logo"></span>', 'oms_meta_box', 'page', 'normal', 'high' ); | |
add_meta_box( 'oms-meta-box', '<span id="oms-logo"></span>', 'oms_meta_box', 'post', 'normal', 'high' ); | |
} | |
function oms_admin_scripts(){ | |
?> | |
<script type="text/javascript"> | |
jQuery('#oms-enabled').click(function(){ | |
if(jQuery(this).is(':checked')){ | |
jQuery('#oms-enabled-box').fadeIn('fast'); | |
}else{ | |
jQuery('#oms-enabled-box').hide(); | |
} | |
}); | |
</script> | |
<?php | |
} | |
function oms_admin_styles(){ | |
?> | |
<style> | |
#oms-meta-box{ | |
border: none; | |
background: #eaeaea; | |
} | |
#oms-meta-box .hndle{ | |
background-color: #34495e; | |
background-image: none; | |
padding-left: 0px !important; | |
} | |
#oms-meta-box .handlediv{ | |
color: #e74c3c !important; | |
} | |
#oms-meta-box code{ | |
font-size: 13px; | |
} | |
#oms-enabled-box{ | |
display:block; | |
padding: 0px 0px 20px 0px; | |
} | |
#oms-enabled-box label{ | |
display: block; | |
padding: 5px 0px 6px 1px; | |
color: #555; | |
font-size: 13px; | |
font-weight: 800; | |
} | |
#oms-enabled-box a.oms-newpage{ | |
color: #eaeaea; | |
background-color: #34495e; | |
padding: 2px 5px; | |
border-radius: 4px; | |
text-decoration: none; | |
} | |
#oms-enabled-box select{ | |
font-size: 16px; | |
} | |
#oms-enabled-box span{ | |
color: #808080; | |
font-size: 11px; | |
} | |
#oms-meta-box .oms-powered-by{ | |
color: #808080; | |
font-size: 11px; | |
margin-top: 10px; | |
float: right; | |
padding: 10px 0px; | |
border-top: 1px solid #ddd; | |
width: 100%; | |
text-align: right; | |
} | |
#oms-logo{ | |
background: url('http://ms-content.storage.googleapis.com/includes/img/frontpage/logo.png') no-repeat; | |
height: 22px; | |
display: block; | |
} | |
</style> | |
<?php | |
} | |
function oms_meta_box( $post ) { | |
$oms = get_post_meta($post->ID, 'oms_meta', true); | |
$is_enabled = oms_isset($oms['enabled'], false, true); | |
echo '<input type="hidden" name="_oms_meta_nonce" value="' . wp_create_nonce( 'oms-meta-nonce' ) . '" />'; | |
echo '<input type="hidden" name="oms_post_id" id="oms_post_id" value="' . $post->ID . '" />'; | |
$pages = oms_get_pages(); | |
?> | |
<label for="oms-enabled" style="display:inline;font-weight:normal"><input type="checkbox" name="oms[enabled]" id="oms-enabled" value="1" <?php echo $is_enabled ? 'checked="checked"' : ''; ?>/> | |
<span><code><?php _e('Use 1MinuteSites Page', 'oms'); ?></code></span> | |
</label> | |
<br><br> | |
<div id="oms-enabled-box" <?php echo $is_enabled ? '' : 'style="display:none;"'; ?>> | |
<select name="oms[page_id]" id="oms-page" class="widefat"> | |
<option value="-1">[-- Select Your 1MinuteSites Page --]</option> | |
<?php | |
if($pages){ | |
foreach ($pages as $k=>$v){ | |
$selected = oms_isset($oms['page_id'], 0, true) == $k ? 'selected="selected"' : ''; | |
echo '<option value="'.$k.'" '.$selected.'>'.$v.'</option>'; | |
} | |
} | |
?> | |
</select> | |
<br><br> | |
<span>Click <a class="oms-newpage" href="<?php echo OMS_URL; ?>user/newpage/" target="_blank">here</a> if you want to create a new 1MinuteSites page.</span> | |
</div> | |
<span class="oms-powered-by">Powered by: <a href="http://www.1minutesites.com" target="_blank">1MinuteSites</a></span> | |
<div style="clear:both"></div> | |
<?php | |
} | |
function oms_save_meta( $post_id ) { | |
$nonce = oms_isset($_POST['_oms_meta_nonce']); | |
if ( !wp_verify_nonce($nonce, 'oms-meta-nonce') ) | |
return $post_id; | |
if ( 'page' == $_POST['post_type'] ) { | |
if ( !current_user_can( 'edit_page', $post_id ) ) return $post_id; | |
} else { | |
if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; | |
} | |
if ( isset($_POST['oms']) ){ | |
$meta = $_POST['oms']; | |
update_post_meta( $post_id, 'oms_meta', $meta ); | |
} | |
} | |
function oms_get_pages(){ | |
$response = wp_remote_get( | |
'https://www.1minutesites.com/api/pages/allpages/status/publish/', | |
array( | |
'timeout' => 120, | |
'httpversion' => '1.1', | |
'sslverify' => true, | |
'headers' => array( | |
'1MS-USERNAME' => OMS_USERNAME, | |
'1MS-KEY' => OMS_API_KEY, | |
), | |
) | |
); | |
if ( is_wp_error( $response ) ) { | |
return false; | |
} | |
if($response['response']['code'] == 200){ | |
$results = json_decode($response['body']); | |
$pages = array(); | |
if (is_array($results) && count($results) > 0){ | |
foreach ($results as $page){ | |
$pages[$page->ID] = $page->title; | |
} | |
} | |
return $pages; | |
} | |
return false; | |
} | |
if ( !function_exists('oms_isset') ) : | |
function oms_isset( &$val, $default=NULL, $default_on_empty=false ){ | |
if(isset($val)) | |
$tmp = ($default_on_empty && empty($val)) ? $default : $val; | |
else | |
$tmp = $default; | |
return $tmp; | |
} | |
endif; | |
function oms_layout_template( $template ) { | |
global $post; | |
if ( !(is_single() || is_page()) || empty($post) ) | |
return $template; | |
$meta = get_post_meta($post->ID, 'oms_meta', true); | |
$enable = oms_isset($meta['enabled'], false, true); | |
if ( !$enable || !file_exists(OMS_PATH . 'template.php') ) return $template; | |
update_option('oms_load_page', $meta['page_id']); | |
$template = OMS_PATH . 'template.php'; // override default wp theme | |
return $template; | |
} | |
add_filter('template_include', 'oms_layout_template'); | |
if ( is_admin() ) { | |
add_action( 'admin_menu', 'oms_add_meta_box' ); | |
add_action( 'save_post', 'oms_save_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
From ad23d0e91defc04aa9fc4fa10dcc943eff3f5396 Mon Sep 17 00:00:00 2001 | |
From: Scott Lesovic <scott@scottlesovic.com> | |
Date: Tue, 2 Dec 2014 21:16:32 -0800 | |
Subject: [PATCH] | |
--- | |
1minutesites.php | 4 ++++ | |
1 file changed, 4 insertions(+) | |
diff --git a/1minutesites.php b/1minutesites.php | |
index 3a717b6..184e211 100644 | |
--- a/1minutesites.php | |
+++ b/1minutesites.php | |
@@ -180,6 +180,10 @@ function oms_get_pages(){ | |
), | |
) | |
); | |
+ | |
+ if ( is_wp_error( $response ) ) { | |
+ return false; | |
+ } | |
if($response['response']['code'] == 200){ | |
$results = json_decode($response['body']); | |
-- | |
1.9.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment