| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin functionality for PSM Deactivation Feedback Framework. |
| 4 |
* |
| 5 |
* @package PSM_DFR |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
class PSM_DFR_Admin { |
| 13 |
|
| 14 |
/** |
| 15 |
* Initialize. |
| 16 |
* |
| 17 |
* @return void |
| 18 |
*/ |
| 19 |
public static function init() { |
| 20 |
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) ); |
| 21 |
add_action( 'admin_footer', array( __CLASS__, 'render_modal' ) ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Enqueue assets. |
| 26 |
* |
| 27 |
* @param string $hook Current admin page. |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public static function enqueue_assets( $hook ) { |
| 31 |
|
| 32 |
if ( 'plugins.php' !== $hook ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
$plugins = PSM_DFR::get_plugins(); |
| 37 |
|
| 38 |
if ( empty( $plugins ) ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
$first = reset( $plugins ); |
| 43 |
|
| 44 |
$base_url = trailingslashit( plugin_dir_url( $first['plugin_file'] ) ) . 'deactivation-feedback/'; |
| 45 |
|
| 46 |
wp_enqueue_style( |
| 47 |
'psm-dfr', |
| 48 |
$base_url . 'assets/deactivation-feedback.css', |
| 49 |
array(), |
| 50 |
$first['plugin_version'] |
| 51 |
); |
| 52 |
|
| 53 |
wp_enqueue_script( |
| 54 |
'psm-dfr', |
| 55 |
$base_url . 'assets/deactivation-feedback.js', |
| 56 |
array( 'jquery' ), |
| 57 |
$first['plugin_version'], |
| 58 |
true |
| 59 |
); |
| 60 |
|
| 61 |
wp_add_inline_script( |
| 62 |
'psm-dfr', |
| 63 |
'window.PSM_DFR=' . wp_json_encode( |
| 64 |
array( |
| 65 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 66 |
'nonce' => wp_create_nonce( 'psm_dfr_nonce' ), |
| 67 |
'plugins' => array_values( $plugins ), |
| 68 |
) |
| 69 |
), |
| 70 |
'before' |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Render modal. |
| 76 |
* |
| 77 |
* @return void |
| 78 |
*/ |
| 79 |
public static function render_modal() { |
| 80 |
|
| 81 |
$screen = get_current_screen(); |
| 82 |
|
| 83 |
if ( empty( $screen ) || 'plugins' !== $screen->id ) { |
| 84 |
return; |
| 85 |
} |
| 86 |
?> |
| 87 |
<div id="psm-dfr-modal" style="display:none;"> |
| 88 |
<div class="psm-dfr-overlay"></div> |
| 89 |
|
| 90 |
<div class="psm-dfr-container"> |
| 91 |
|
| 92 |
<h2 id="psm-dfr-title"><?php esc_html_e( 'Quick Feedback', 'supportcandy' ); ?></h2> |
| 93 |
<p><?php esc_html_e( 'If you have a moment, please let us know why you are deactivating:', 'supportcandy' ); ?></p> |
| 94 |
|
| 95 |
<div id="psm-dfr-reasons"></div> |
| 96 |
|
| 97 |
<textarea |
| 98 |
id="psm-dfr-note" |
| 99 |
placeholder="<?php esc_attr_e( 'Additional details (optional)', 'supportcandy' ); ?>" |
| 100 |
></textarea> |
| 101 |
|
| 102 |
<div class="psm-dfr-actions"> |
| 103 |
|
| 104 |
<button |
| 105 |
type="button" |
| 106 |
class="button" |
| 107 |
id="psm-dfr-cancel"> |
| 108 |
<?php esc_html_e( 'Cancel', 'supportcandy' ); ?> |
| 109 |
</button> |
| 110 |
|
| 111 |
<button |
| 112 |
type="button" |
| 113 |
class="button" |
| 114 |
id="psm-dfr-skip"> |
| 115 |
<?php esc_html_e( 'Skip & Deactivate', 'supportcandy' ); ?> |
| 116 |
</button> |
| 117 |
|
| 118 |
<button |
| 119 |
type="button" |
| 120 |
class="button button-primary" |
| 121 |
id="psm-dfr-submit"> |
| 122 |
<?php esc_html_e( 'Submit & Deactivate', 'supportcandy' ); ?> |
| 123 |
</button> |
| 124 |
|
| 125 |
</div> |
| 126 |
<div class="psm-dfr-privacy-note"><?php esc_html_e( "We do not collect any personal data when you submit this form. It's your feedback that we value.", 'supportcandy' ); ?></div> |
| 127 |
</div> |
| 128 |
</div> |
| 129 |
<?php |
| 130 |
} |
| 131 |
} |
| 132 |
PSM_DFR_Admin::init(); |
| 133 |
|