| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
Plugin Name: Easy Bootstrap Shortcode |
| 5 |
Plugin URI: http://www.oscitasthemes.com |
| 6 |
Description: Add bootstrap 3.0 styles to your theme by wordpress editor shortcode buttons. |
| 7 |
Version: 2.1.0 |
| 8 |
Author: Oscitas Themes |
| 9 |
Author URI: http://www.oscitasthemes.com |
| 10 |
License: Under the GPL v2 or later |
| 11 |
*/ |
| 12 |
register_activation_hook(__FILE__, 'ebs_activate_plugin'); |
| 13 |
register_deactivation_hook(__FILE__, 'ebs_deactivate_plugin'); |
| 14 |
add_action('admin_enqueue_scripts', 'osc_add_admin_shortcode_scripts'); |
| 15 |
add_action('wp_enqueue_scripts', 'osc_add_frontend_shortcode_scripts'); |
| 16 |
add_action('admin_menu', 'ebs_add_admin_menu'); |
| 17 |
|
| 18 |
function ebs_activate_plugin() { |
| 19 |
global $wpdb; |
| 20 |
$sqlebs = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix . "ebs_settings ( |
| 21 |
id int(10) unsigned NOT NULL AUTO_INCREMENT, |
| 22 |
ebs_js varchar(100), |
| 23 |
ebs_css varchar(100), |
| 24 |
ebs_cdn_path varchar(500), |
| 25 |
PRIMARY KEY (id) |
| 26 |
)"; |
| 27 |
|
| 28 |
$wpdb->query($sqlebs); |
| 29 |
$wpdb->insert( |
| 30 |
$wpdb->prefix . 'ebs_settings', array( |
| 31 |
'ebs_js' => 'plugin', |
| 32 |
'ebs_css' => 'plugin', |
| 33 |
'ebs_cdn_path' => 'http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js' |
| 34 |
), array( |
| 35 |
'%s', |
| 36 |
'%s', |
| 37 |
'%s' |
| 38 |
) |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
function ebs_deactivate_plugin() { |
| 43 |
global $wpdb; |
| 44 |
$wpdb->query("DROP TABLE IF EXISTS " . $wpdb->prefix . "ebs_settings"); |
| 45 |
} |
| 46 |
|
| 47 |
function ebs_add_admin_menu() { |
| 48 |
add_menu_page('EBS Settings', ' EBS Settings', 'manage_options', 'ebs/ebs-settings.php', 'ebs_setting_page', plugins_url('/images/icon.png', __FILE__)); |
| 49 |
} |
| 50 |
|
| 51 |
function ebs_setting_page() { |
| 52 |
global $wpdb; |
| 53 |
$result = $wpdb->get_results('SELECT * from ' . $wpdb->prefix . "ebs_settings where id=1"); |
| 54 |
foreach ($result as $res) { |
| 55 |
$js = $res->ebs_js; |
| 56 |
$css = $res->ebs_css; |
| 57 |
$cdn = $res->ebs_cdn_path; |
| 58 |
} |
| 59 |
include 'ebs_settings.php'; |
| 60 |
if (isset($_POST['ebs_submit'])) { |
| 61 |
// $cdnins = ($_POST['b_js'] == 'cdn') ? $_POST['cdn_path'] : ''; |
| 62 |
$sqlins = 'UPDATE ' . $wpdb->prefix . 'ebs_settings set ebs_js="' . $_POST['b_js'] . '", ebs_css="' . $_POST['b_css'] . '", ebs_cdn_path="' . $_POST['cdn_path'] . '" where id=1'; |
| 63 |
$wpdb->query($sqlins); |
| 64 |
echo ' <script type="text/javascript">window.location=document.URL;</script>'; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
// add_submenu_page('optine |
| 69 |
function osc_add_admin_shortcode_scripts() { |
| 70 |
global $pagenow; |
| 71 |
$screen = get_current_screen(); |
| 72 |
if ($screen->id == 'toplevel_page_ebs/ebs-settings') { |
| 73 |
wp_enqueue_style('ebs-setting', plugins_url('/styles/ebs-setting.css', __FILE__)); |
| 74 |
} |
| 75 |
if ('post-new.php' == $pagenow || 'post.php' == $pagenow) { |
| 76 |
wp_enqueue_script('jquery'); |
| 77 |
wp_enqueue_style('thickbox'); |
| 78 |
wp_enqueue_script('media-upload'); |
| 79 |
wp_enqueue_script('thickbox'); |
| 80 |
wp_enqueue_script('jquery.fancybox', plugins_url('/js/jquery.fancybox.js', __FILE__)); |
| 81 |
wp_enqueue_style('fancyboxcss', plugins_url('/styles/jquery.fancybox.css', __FILE__)); |
| 82 |
wp_enqueue_style('bootstrap-icon', plugins_url('/styles/bootstrap-icon.css', __FILE__)); |
| 83 |
wp_enqueue_style('bootstrap_admin', plugins_url('/styles/bootstrap_admin.css', __FILE__)); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
function osc_add_frontend_shortcode_scripts() { |
| 88 |
wp_enqueue_script('jquery'); |
| 89 |
global $wpdb; |
| 90 |
$result = $wpdb->get_results('SELECT * from ' . $wpdb->prefix . "ebs_settings where id=1"); |
| 91 |
foreach ($result as $res) { |
| 92 |
$js = $res->ebs_js; |
| 93 |
$css = $res->ebs_css; |
| 94 |
$cdn = $res->ebs_cdn_path; |
| 95 |
} |
| 96 |
if ($js == 'plugin') { |
| 97 |
wp_enqueue_script('bootstrap', plugins_url('/js/bootstrap.js', __FILE__)); |
| 98 |
} elseif ($js == 'cdn') { |
| 99 |
wp_enqueue_script('bootstrap', $cdn); |
| 100 |
} |
| 101 |
if ($css == 'plugin') { |
| 102 |
wp_enqueue_style('bootstrap', plugins_url('/styles/bootstrap.css', __FILE__)); |
| 103 |
} else { |
| 104 |
wp_enqueue_style('bootstrap-icon', plugins_url('/styles/bootstrap-icon.css', __FILE__)); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
// Shortcodes |
| 109 |
include('shortcode/functions.php'); |
| 110 |
|
| 111 |
|
| 112 |
|