Nessuna descrizione

Admin.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. class PUM_Admin {
  6. public static function init() {
  7. PUM_Admin_BlockEditor::init();
  8. PUM_Admin_Pages::init();
  9. PUM_Admin_Ajax::init();
  10. PUM_Admin_Assets::init();
  11. PUM_Admin_Popups::init();
  12. PUM_Admin_Themes::init();
  13. PUM_Admin_Subscribers::init();
  14. PUM_Admin_Settings::init();
  15. PUM_Admin_Tools::init();
  16. PUM_Admin_Shortcode_UI::init();
  17. PUM_Upsell::init();
  18. PUM_Admin_Onboarding::init();
  19. add_filter( 'user_has_cap', array( __CLASS__, 'prevent_default_theme_deletion' ), 10, 3 );
  20. add_filter( 'plugin_action_links', array( __CLASS__, 'plugin_action_links' ), 10, 2 );
  21. add_action( 'admin_init', array( __CLASS__, 'after_install' ) );
  22. add_action( 'admin_head', array( __CLASS__, 'clean_ui' ) );
  23. }
  24. /**
  25. * Prevent user from deleting the current default popup_theme
  26. *
  27. * @param $allcaps
  28. * @param $caps
  29. * @param $args
  30. *
  31. * @return mixed
  32. */
  33. public static function prevent_default_theme_deletion( $allcaps, $caps, $args ) {
  34. global $wpdb;
  35. if ( isset( $args[0] ) && isset( $args[2] ) && $args[2] == pum_get_option( 'default_theme' ) && $args[0] == 'delete_post' ) {
  36. $allcaps[ $caps[0] ] = false;
  37. }
  38. return $allcaps;
  39. }
  40. /**
  41. * Render plugin action links.
  42. *
  43. * @param $links
  44. * @param $file
  45. *
  46. * @return mixed
  47. */
  48. public static function plugin_action_links( $links, $file ) {
  49. if ( $file == plugin_basename( POPMAKE ) ) {
  50. $plugin_action_links = apply_filters( 'pum_plugin_action_links', array(
  51. 'extend' => '<a href="' . admin_url( 'edit.php?post_type=popup&page=pum-extensions' ) . '">' . __( 'Integrations', 'popup-maker' ) . '</a>',
  52. 'settings' => '<a href="' . admin_url( 'edit.php?post_type=popup&page=pum-settings' ) . '">' . __( 'Settings', 'popup-maker' ) . '</a>',
  53. ) );
  54. // TODO Rewrite this to take full advantage of our polyglot detection code in Alerts for translation requests.
  55. if ( substr( get_locale(), 0, 2 ) != 'en' ) {
  56. $plugin_action_links = array_merge( array( 'translate' => '<a href="' . sprintf( 'https://translate.wordpress.org/locale/%s/default/wp-plugins/popup-maker', substr( get_locale(), 0, 2 ) ) . '" target="_blank">' . __( 'Translate', 'popup-maker' ) . '</a>' ), $plugin_action_links );
  57. }
  58. foreach ( $plugin_action_links as $link ) {
  59. array_unshift( $links, $link );
  60. }
  61. }
  62. return $links;
  63. }
  64. /**
  65. * Post-installation
  66. *
  67. * Runs just after plugin installation and exposes the
  68. * popmake_after_install hook.
  69. *
  70. * @since 1.0
  71. * @return void
  72. */
  73. public static function after_install() {
  74. if ( ! is_admin() ) {
  75. return;
  76. }
  77. $already_installed = get_option( '_pum_installed' );
  78. // Exit if not in admin or the transient doesn't exist
  79. if ( false === $already_installed ) {
  80. do_action( 'pum_after_install' );
  81. update_option( '_pum_installed', true );
  82. }
  83. }
  84. /**
  85. * Cleans the UI area within our admin pages
  86. *
  87. * @since 1.12
  88. */
  89. public static function clean_ui() {
  90. // Elementor shows an upsell notice for their popup builder targeting only our admin area. This removes that.
  91. if ( class_exists( 'Elementor\Plugin' ) && class_exists( 'Elementor\Core\Admin\Admin' ) && pum_is_admin_page() ) {
  92. $instance = Elementor\Plugin::instance();
  93. if ( isset( $instance->admin ) && is_a( $instance->admin, '\Elementor\Core\Admin\Admin' ) && method_exists( $instance->admin, 'get_component' ) ) {
  94. $notices = $instance->admin->get_component( 'admin-notices' );
  95. if ( false !== $notices && is_a( $notices, '\Elementor\Core\Admin\Admin_Notices' ) ) {
  96. remove_action( 'admin_notices', array( $notices, 'admin_notices' ), 20 );
  97. }
  98. }
  99. }
  100. }
  101. }