| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if (!defined('ABSPATH')) exit; |
| 5 |
|
| 6 |
class Vimeography_Admin_Actions |
| 7 |
{ |
| 8 |
|
| 9 |
public function __construct() |
| 10 |
{ |
| 11 |
add_action('admin_init', array($this, 'vimeography_requires_wordpress_version')); |
| 12 |
add_action('admin_init', array($this, 'vimeography_maybe_add_activation_key_reset_nag')); |
| 13 |
add_action('admin_init', array($this, 'vimeography_maybe_add_pro_update_nag')); |
| 14 |
|
| 15 |
add_action('vc_before_init', array($this, 'register_visual_composer_element')); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Register a custom element for use in WPBakery Page Builder. |
| 20 |
* (formally Visual Composer) |
| 21 |
* |
| 22 |
* @since 2.0 |
| 23 |
*/ |
| 24 |
public function register_visual_composer_element() |
| 25 |
{ |
| 26 |
|
| 27 |
if (!function_exists('vc_map')) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
global $wpdb; |
| 32 |
$galleries = $wpdb->get_results('SELECT id, title FROM ' . $wpdb->vimeography_gallery); |
| 33 |
|
| 34 |
if (empty($galleries)) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
$values = array(); |
| 39 |
|
| 40 |
foreach ($galleries as $gallery) { |
| 41 |
$values[$gallery->title] = $gallery->id; |
| 42 |
} |
| 43 |
|
| 44 |
vc_map(array( |
| 45 |
'name' => wp_kses_post(__('Vimeography Gallery', 'vimeography')), |
| 46 |
'description' => wp_kses_post(__('Add a Vimeography Gallery to this page.', 'vimeography')), |
| 47 |
'base' => 'vimeography', |
| 48 |
'icon' => VIMEOGRAPHY_URL . 'lib/admin/assets/img/vimeography-logo-512px-transparent.png', |
| 49 |
'category' => 'Content', |
| 50 |
'params' => array( |
| 51 |
array( |
| 52 |
'type' => 'dropdown', |
| 53 |
'heading' => wp_kses_post(__('Choose your Gallery', 'vimeography')), |
| 54 |
'param_name' => 'id', |
| 55 |
'description' => wp_kses_post(__('To create a new gallery, visit the Vimeography Gallery Editor.', 'vimeography')), |
| 56 |
'value' => $values, |
| 57 |
'std' => $galleries[0]->title, |
| 58 |
'admin_label' => true, |
| 59 |
), |
| 60 |
) |
| 61 |
)); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
/** |
| 66 |
* Check the wordpress version is compatible, and disable plugin if not. |
| 67 |
* |
| 68 |
* @access public |
| 69 |
* @return void |
| 70 |
*/ |
| 71 |
public function vimeography_requires_wordpress_version() |
| 72 |
{ |
| 73 |
global $wp_version; |
| 74 |
|
| 75 |
if (version_compare($wp_version, "3.3", "<")) { |
| 76 |
if (is_plugin_active(VIMEOGRAPHY_BASENAME)) { |
| 77 |
deactivate_plugins(VIMEOGRAPHY_BASENAME); |
| 78 |
wp_die(sprintf( |
| 79 |
/* translators: %s refers to the URL */ |
| 80 |
wp_kses_post(__('Vimeography requires WordPress 3.3 or higher. Please upgrade WordPress and try again. <a href="%s">Back to WordPress admin</a>', 'vimeography')), |
| 81 |
wp_kses_post(admin_url()) |
| 82 |
)); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Adds a notice if the user needs to remove and reenter their license keys |
| 89 |
* @return void |
| 90 |
*/ |
| 91 |
public function vimeography_maybe_add_activation_key_reset_nag() |
| 92 |
{ |
| 93 |
if (get_site_option('vimeography_corrupt_keys_found')) { |
| 94 |
if (isset($_GET['vimeography-cancel-activation-message']) or get_site_option('vimeography_activation_keys')) { |
| 95 |
delete_site_option('vimeography_corrupt_keys_found'); |
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
if (!isset($_POST['vimeography-activate-key'])) { |
| 100 |
add_action('admin_notices', array($this, 'vimeography_corrupt_keys_notice')); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Outputs a notice if the user needs to remove and reenter their license keys |
| 107 |
* @return void |
| 108 |
*/ |
| 109 |
public function vimeography_corrupt_keys_notice() |
| 110 |
{ |
| 111 |
printf( |
| 112 |
/* translators: %1$s refers to the notice message, %2$s refers to the URL, and %3$s refers to the dismiss text */ |
| 113 |
'<div class="update-nag"> <p> %1$s | <a href="%2$s"> %3$s </a> </p> </div>', |
| 114 |
sprintf( |
| 115 |
/* translators: %s refers to the URL */ |
| 116 |
wp_kses_post(__("<strong>Notice:</strong> Vimeography found a problem with the way your Vimeography Activation Keys were saved. To resolve this error, please visit the <a href=\"%s\" title=\"Vimeography Manage Activations Page\">Vimeography Manage Activations page</a> and re-enter your activation keys that you received via email while purchasing your Vimeography products.", 'vimeography')), |
| 117 |
wp_kses_post(admin_url('admin.php?page=vimeography-manage-activations')) |
| 118 |
), |
| 119 |
esc_url(add_query_arg('vimeography-cancel-activation-message', wp_create_nonce('wptus_nag'))), |
| 120 |
wp_kses_post(__('Dismiss', 'vimeography')) |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Yells at the user to upgrade their |
| 126 |
* Pro plugin if it is installed and out of date. |
| 127 |
* |
| 128 |
* @return void |
| 129 |
*/ |
| 130 |
public function vimeography_maybe_add_pro_update_nag() |
| 131 |
{ |
| 132 |
$pro_version = get_option('vimeography_pro_db_version'); |
| 133 |
|
| 134 |
if ($pro_version) { |
| 135 |
if (version_compare($pro_version, '0.7', '<')) { |
| 136 |
add_action('admin_notices', array($this, 'vimeography_pro_upgrade_notice')); |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Adds the update message for outdated Pro versions. |
| 143 |
* |
| 144 |
* @return string | html |
| 145 |
*/ |
| 146 |
public function vimeography_pro_upgrade_notice() |
| 147 |
{ |
| 148 |
printf( |
| 149 |
'<div class="update-nag">%1$s</div>', |
| 150 |
sprintf( |
| 151 |
/* translators: %1$s refers to the notice message, %2$s refers to the activation key URL, and %3$s refers to the Plugins page URL */ |
| 152 |
wp_kses_post(__("<strong>Hey!</strong> It looks like there is an update ready for Vimeography Pro. Make sure you've entered your <a href=\"%1\$s\" title=\"Vimeography Manage Activations Page\">activation key</a>, then head on over to the <a href=\"%2\$s\" title=\"Plugins Page\">Plugins page</a> to get the latest compatible version.", 'vimeography'), admin_url('admin.php?page=vimeography-manage-activations')), |
| 153 |
wp_kses_post(admin_url('update-core.php?force-check=1')) |
| 154 |
) |
| 155 |
); |
| 156 |
} |
| 157 |
} |
| 158 |
|