| 1 |
<?php |
| 2 |
|
| 3 |
namespace WGMSRM\Traits; |
| 4 |
|
| 5 |
use WGMSRM\Classes\Migration; |
| 6 |
|
| 7 |
if (!defined('ABSPATH')) { |
| 8 |
exit; |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Trait InitActions: Init action hooks defined here |
| 13 |
*/ |
| 14 |
trait InitActions |
| 15 |
{ |
| 16 |
|
| 17 |
/** |
| 18 |
* Loading text-domain |
| 19 |
* |
| 20 |
* @since 3.0.0 |
| 21 |
*/ |
| 22 |
public function i18n() |
| 23 |
{ |
| 24 |
load_plugin_textdomain('gmap-embed', false, dirname(plugin_basename(__FILE__)) . '/languages'); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Review system action link hooks |
| 29 |
* |
| 30 |
* @since 1.7.1 |
| 31 |
*/ |
| 32 |
public function review_system_hooks() |
| 33 |
{ |
| 34 |
// Review system hooks. |
| 35 |
add_action('gmap_embed_review_already_did', array($this, 'review_already_did')); |
| 36 |
add_action('gmap_embed_review_later', array($this, 'review_later')); |
| 37 |
if ( |
| 38 |
isset($_GET['plugin']) && |
| 39 |
(isset($_GET['dismiss']) || isset($_GET['later'])) && |
| 40 |
isset($_GET['wgm_review_nonce']) && |
| 41 |
wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['wgm_review_nonce'])), 'wgm_review_action') |
| 42 |
) { |
| 43 |
$plugin = sanitize_text_field(wp_unslash($_GET['plugin'])); |
| 44 |
if ($plugin === $this->plugin_slug) { |
| 45 |
if (isset($_GET['dismiss']) && sanitize_text_field(wp_unslash($_GET['dismiss'])) == 1) { |
| 46 |
do_action('gmap_embed_review_already_did'); |
| 47 |
} |
| 48 |
if (isset($_GET['later']) && sanitize_text_field(wp_unslash($_GET['later'])) == 1) { |
| 49 |
do_action('gmap_embed_review_later'); |
| 50 |
} |
| 51 |
wp_safe_redirect($this->redirect_to()); |
| 52 |
exit; |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Doing some code in init hook |
| 59 |
* |
| 60 |
* @since 1.7.1 |
| 61 |
*/ |
| 62 |
public function do_init_actions() |
| 63 |
{ |
| 64 |
$this->i18n(); |
| 65 |
$this->review_system_hooks(); |
| 66 |
$this->register_post_type(); |
| 67 |
$this->register_frontend_scripts(); |
| 68 |
// Only allow admins to run migrations for security |
| 69 |
if (current_user_can('manage_options')) { |
| 70 |
new Migration(); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Registering wpgmapembed post type |
| 76 |
* |
| 77 |
* @since 1.7.1 |
| 78 |
*/ |
| 79 |
public function register_post_type() |
| 80 |
{ |
| 81 |
// Register Post Types. |
| 82 |
register_post_type( |
| 83 |
'wpgmapembed', |
| 84 |
array( |
| 85 |
'labels' => array( |
| 86 |
'name' => esc_html__('Google Maps', 'gmap-embed'), |
| 87 |
'singular_name' => esc_html__('Map', 'gmap-embed'), |
| 88 |
), |
| 89 |
'public' => false, |
| 90 |
'has_archive' => false, |
| 91 |
) |
| 92 |
); |
| 93 |
} |
| 94 |
} |
| 95 |
|