first commit

This commit is contained in:
User A0264400
2026-04-01 23:20:16 +03:00
commit a766acdc90
23071 changed files with 4933189 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
/**
* Disable admin notices core class
*
* Github: https://github.com/alexkovalevv
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
* @copyright (c) 2018 Webraftic Ltd
* @version 1.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class WDN_Plugin {
/**
* @var WCL_Plugin
*/
private static $app;
/**
* Конструктор
* Вы
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
* @throws \Exception
*/
public function __construct() {
if ( ! class_exists( 'WCL_Plugin' ) ) {
throw new Exception( 'Plugin Clearfy is not installed!' );
}
self::$app = WCL_Plugin::app();
$this->globalScripts();
if ( is_admin() ) {
$this->adminScripts();
}
}
/**
* @return WCL_Plugin
*/
public static function app() {
return self::$app;
}
/**
* Выполняет сценарии, которые должны быть запущены только в бекенде
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
* @since 1.1.0
*/
private function adminScripts() {
require( WDN_PLUGIN_DIR . '/admin/options.php' );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
require( WDN_PLUGIN_DIR . '/admin/ajax/hide-notice.php' );
require( WDN_PLUGIN_DIR . '/admin/ajax/restore-notice.php' );
}
require( WDN_PLUGIN_DIR . '/admin/boot.php' );
}
/**
* Выполняет сценрии, которые должны быть запущены глобально
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
* @since 1.1.0
*/
private function globalScripts() {
require( WDN_PLUGIN_DIR . '/includes/classes/class-configurate-notices.php' );
new WDN_ConfigHideNotices( self::$app );
}
}

View File

@@ -0,0 +1,113 @@
<?php
/**
* Disable admin notices core class
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
* Github: https://github.com/alexkovalevv
* @copyright (c) 2018 Webraftic Ltd
* @version 1.0
*/
// Exit if accessed directly
//use WBCR\Factory_Adverts_159\Base;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class WDN_Plugin extends Wbcr_Factory480_Plugin {
/**
* @var Wbcr_Factory480_Plugin
*/
private static $app;
private $plugin_data;
/**
* @param string $plugin_path
* @param array $data
*
* @throws Exception
*/
public function __construct( $plugin_path, $data ) {
parent::__construct( $plugin_path, $data );
self::$app = $this;
$this->plugin_data = $data;
$this->global_scripts();
if ( is_admin() ) {
$this->admin_scripts();
}
// Wordpress 6.7 fix
add_action( 'init', function () {
if ( is_admin() ) {
$this->register_pages();
}
} );
}
/**
* @return Wbcr_Factory480_Plugin
*/
public static function app() {
return self::$app;
}
private function register_pages() {
//self::app()->registerPage( 'WDN_Log_Page', WDN_PLUGIN_DIR . '/admin/pages/class-pages-log.php' );
self::app()->registerPage( 'WDN_Settings_Page', WDN_PLUGIN_DIR . '/admin/pages/class-pages-settings.php' );
if ( ! ( $this->premium->is_activate() && $this->premium->is_install_package() ) ) {
self::app()->registerPage( 'WDAN_Notices', WDN_PLUGIN_DIR . '/admin/pages/class-pages-notices.php' );
self::app()->registerPage( 'WDAN_Block_Ad_Redirects', WDN_PLUGIN_DIR . '/admin/pages/class-pages-edit-redirects.php' );
self::app()->registerPage( 'WDAN_Edit_Admin_Bar', WDN_PLUGIN_DIR . '/admin/pages/class-pages-edit-admin-bar.php' );
}
self::app()->registerPage( 'WDN_LicensePage', WDN_PLUGIN_DIR . '/admin/pages/class-pages-license.php' );
}
private function admin_scripts() {
require( WDN_PLUGIN_DIR . '/admin/options.php' );
require( WDN_PLUGIN_DIR . '/admin/class-page-basic.php' );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
require_once( WDN_PLUGIN_DIR . '/admin/ajax/hide-notice.php' );
require_once( WDN_PLUGIN_DIR . '/admin/ajax/restore-notice.php' );
}
require_once( WDN_PLUGIN_DIR . '/admin/boot.php' );
require_once( WDN_PLUGIN_DIR . '/admin/pages/class-pages-edit-admin-bar.php' );
require_once( WDN_PLUGIN_DIR . '/admin/pages/class-pages-edit-redirects.php' );
require_once( WDN_PLUGIN_DIR . '/admin/pages/class-pages-notices.php' );
/*add_action( 'plugins_loaded', function () {
$this->register_pages();
}, 30 );*/
}
private function global_scripts() {
require_once( WDN_PLUGIN_DIR . '/includes/classes/class-configurate-notices.php' );
new WDN_ConfigHideNotices( self::$app );
}
/**
* Метод проверяет активацию премиум плагина и наличие действующего лицензионнного ключа
*
* @return bool
*/
public function is_premium() {
if (
$this->premium->is_active() &&
$this->premium->is_activate()
&& $this->premium->is_install_package()
) {
return true;
} else {
return false;
}
}
}

View File

@@ -0,0 +1,381 @@
<?php
/**
* This class configures hide admin notices
*
* Github: https://github.com/alexkovalevv
*
* @author Alexander Kovalev <alex.kovalevv@gmail.com>
* @copyright (c) 2018 Webraftic Ltd
* @version 1.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class WDN_ConfigHideNotices extends WBCR\Factory_Templates_134\Configurate {
public function registerActionsAndFilters() {
if ( is_admin() ) {
$hide_notices_type = $this->getPopulateOption( 'hide_admin_notices', 'only_selected' );
if ( 'not_hide' !== $hide_notices_type && 'compact_panel' !== $hide_notices_type ) {
add_action( 'admin_print_scripts', [ $this, 'catchNotices' ], 999 );
if ( empty( $hide_notices_type ) || $hide_notices_type == 'only_selected' ) {
add_action( 'admin_head', [ $this, 'printNotices' ], 999 );
}
if ( ! empty( $hide_notices_type ) ) {
add_action( 'admin_bar_menu', [ $this, 'notificationsPanel' ], 999 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] );
}
}
}
}
public function printNotices() {
if ( is_multisite() && is_network_admin() ) {
add_action( 'network_admin_notices', [ $this, 'noticesCollection' ] );
} else {
add_action( 'admin_notices', [ $this, 'noticesCollection' ] );
}
}
public function enqueue_styles() {
wp_enqueue_style( 'wbcr-notification-hide-style', WDN_PLUGIN_URL . '/admin/assets/css/general.css', [], $this->plugin->getPluginVersion() );
if ( ! $this->getPopulateOption( 'show_notices_in_adminbar', false ) && current_user_can( 'manage_network' ) ) {
return;
}
wp_enqueue_style( 'wbcr-notification-panel-styles', WDN_PLUGIN_URL . '/admin/assets/css/notifications-panel.css', [], $this->plugin->getPluginVersion() );
wp_enqueue_script( 'wbcr-notification-panel-scripts', WDN_PLUGIN_URL . '/admin/assets/js/notifications-panel.js', [], $this->plugin->getPluginVersion() );
}
public function notificationsPanel( &$wp_admin_bar ) {
if ( ! $this->getPopulateOption( 'show_notices_in_adminbar', false ) ) {
return;
}
if ( current_user_can( 'manage_options' ) ) {
$notifications_user = get_user_meta( get_current_user_id(), $this->plugin->getOptionName( 'hidden_notices' ), true );
$notifications_all = apply_filters( 'wdan/notifications/all', [] );
if ( ! is_array( $notifications_user ) ) {
$notifications_user = [];
}
if ( empty( $notifications_user ) && empty( $notifications_all ) ) {
return;
}
$cont_notifications = sizeof( $notifications_user ) + sizeof( $notifications_all );
// Add top menu
$wp_admin_bar->add_menu( [
'id' => 'wbcr-han-notify-panel',
'parent' => 'top-secondary',
'title' => sprintf( __( 'Notifications %s', 'disable-admin-notices' ), '<span class="wbcr-han-adminbar-counter">' . $cont_notifications . '</span>' ),
'href' => $this->plugin->getPluginPageUrl( 'wdan-notices' )
] );
$i = 0;
// User
if ( ! empty( $notifications_user ) ) {
$wp_admin_bar->add_menu( [
'id' => 'wbcr-han-notify-panel-group-user',
'parent' => 'wbcr-han-notify-panel',
'title' => __( 'Hidden for you', 'disable-admin-notices' ),
'href' => false,
'meta' => [
'class' => ''
]
] );
foreach ( $notifications_user as $notice_id => $message ) {
$message = wp_kses( $message, [] );
$message = $this->getExcerpt( stripslashes( $message ), 0, 350 );
$message .= '<div class="wbcr-han-panel-restore-notify-line">';
$message .= '<a href="#" data-nonce="' . wp_create_nonce( $this->plugin->getPluginName() . '_ajax_restore_notice_nonce' );
$message .= '" data-notice-id="' . esc_attr( $notice_id ) . '" class="wbcr-han-panel-restore-notify-link">';
$message .= __( 'Restore notice', 'clearfy' );
$message .= '</a></div>';
$wp_admin_bar->add_menu( [
'id' => 'wbcr-han-notify-panel-item-' . $i,
'parent' => 'wbcr-han-notify-panel',
'title' => $message,
'href' => false,
'meta' => [
'class' => ''
]
] );
$i ++;
}
}
if ( $this->plugin->is_premium() && ( current_user_can( 'manage_options' ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ) ) {
// All
do_action( 'wdn/notifications/panel/all', $wp_admin_bar, $notifications_all, $i );
}
}
}
public function noticesCollection() {
global $wbcr_dan_plugin_all_notices;
if ( empty( $wbcr_dan_plugin_all_notices ) ) {
return;
}
?>
<!-- Disable admin notices plugin (Clearfy tools) -->
<script>
jQuery(document).ready(function ($) {
$(document).on('click', '.wbcr-dan-hide-notice-link', function () {
var self = $(this),
target = self.data('target'),
noticeID = self.data('notice-id'),
nonce = self.data('nonce'),
noticeHtml = self.closest('.wbcr-dan-hide-links').prev('.wbcr-dan-hide-notices').clone(),
contanierEl = self.closest('.wbcr-dan-hide-links').prev('.wbcr-dan-hide-notices').parent();
contanierEl.find('.wbcr-dan-hide-links').remove();
contanierEl.slideUp();
if (!noticeID) {
alert('Undefinded error. Please report the bug to our support forum.');
}
$.ajax(ajaxurl, {
type: 'post',
dataType: 'json',
data: {
action: 'wbcr-dan-hide-notices',
target: target,
security: nonce,
notice_id: noticeID,
notice_html: noticeHtml.html()
},
success: function (response) {
if (!response || !response.success) {
if (response.data.error_message) {
console.log(response.data.error_message);
self.closest('li').show();
} else {
console.log(response);
}
contanierEl.show();
return;
}
contanierEl.remove();
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(xhr.responseText);
console.log(thrownError);
}
});
return false;
});
});
</script>
<?php
foreach ( $wbcr_dan_plugin_all_notices as $val ) {
echo $val;
}
}
public
function catchNotices() {
global $wbcr_dan_plugin_all_notices;
try {
$wp_filter_admin_notices = &wdan_get_wp_filter( 'admin_notices' );
$wp_filter_all_admin_notices = &wdan_get_wp_filter( 'all_admin_notices' );
$wp_filter_notices = $this->array_merge( $wp_filter_admin_notices, $wp_filter_all_admin_notices );
} catch ( Exception $e ) {
$wp_filter_notices = null;
}
$hide_notices_type = $this->getPopulateOption( 'hide_admin_notices' );
if ( empty( $hide_notices_type ) || $hide_notices_type == 'only_selected' ) {
$get_hidden_notices = get_user_meta( get_current_user_id(), $this->plugin->getOptionName( 'hidden_notices' ), true );
$get_hidden_notices_all = apply_filters( 'wdan/notifications/all', [] );
$content = [];
foreach ( (array) $wp_filter_notices as $filters ) {
foreach ( $filters as $callback_name => $callback ) {
if ( 'usof_hide_admin_notices_start' == $callback_name || 'usof_hide_admin_notices_end' == $callback_name ) {
continue;
}
ob_start();
// #CLRF-140 fix bug for php7
// when the developers forgot to delete the argument in the function of implementing the notification.
$args = [];
$accepted_args = isset( $callback['accepted_args'] ) && ! empty( $callback['accepted_args'] ) ? $callback['accepted_args'] : 0;
if ( $accepted_args > 0 ) {
for ( $i = 0; $i < (int) $accepted_args; $i ++ ) {
$args[] = null;
}
}
//===========
call_user_func_array( $callback['function'], $args );
$cont = ob_get_clean();
if ( empty( $cont ) ) {
continue;
}
$salt = is_multisite() ? get_current_blog_id() : '';
$txt = preg_replace( '/<(script|style)([^>]+)?>(.*?)<\/(script|style)>/is', '', $cont );
$uniq_id1 = md5( strip_tags( str_replace( [ "\t", "\r", "\n", " " ], "", $txt ) ) . $salt );
$uniq_id2 = md5( $callback_name . $salt );
if ( is_array( $callback['function'] ) && sizeof( $callback['function'] ) == 2 ) {
$class = $callback['function'][0];
if ( is_object( $class ) ) {
$class_name = get_class( $class );
$method_name = $callback['function'][1];
$uniq_id2 = md5( $class_name . ':' . $method_name );
}
}
//$txt = rtrim( trim( $txt ) );
//$txt = preg_replace( '/^(<div[^>]+>)(.*?)(<\/div>)$/is', '<p>$2</p>', $txt );
// All
$skip_notice = apply_filters( 'wdn/notifications/catch/all', true, $get_hidden_notices_all, $uniq_id1, $uniq_id2 );
if ( ! $skip_notice ) {
continue;
}
if ( ! empty( $get_hidden_notices ) ) {
$skip_notice = true;
foreach ( (array) $get_hidden_notices as $key => $notice ) {
$splited_notice_id = explode( '_', $key );
if ( empty( $splited_notice_id ) || sizeof( $splited_notice_id ) < 2 ) {
continue;
}
$compare_notice_id_1 = $splited_notice_id[0];
$compare_notice_id_2 = $splited_notice_id[1];
if ( $compare_notice_id_1 == $uniq_id1 || $compare_notice_id_2 == $uniq_id2 ) {
$skip_notice = false;
break;
}
}
if ( ! $skip_notice ) {
continue;
}
}
$nonce = wp_create_nonce( $this->plugin->getPluginName() . '_ajax_hide_notices_nonce' );
$hide_link_for_me = "<button data-target='user' data-nonce='{$nonce}' data-notice-id='{$uniq_id1}_{$uniq_id2}' class='wbcr-dan-hide-notice-link'>" . __( 'Hide <b>for me</b>', 'disable-admin-notices' ) . "</button>";
$hide_link_for_all = "";
if ( $this->plugin->is_premium() && ( current_user_can( 'manage_options' ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ) ) {
$hide_link_for_all = "<button data-target='all' data-nonce='{$nonce}' data-notice-id='{$uniq_id1}_{$uniq_id2}' class='wbcr-dan-hide-notice-link'>" . __( 'Hide <b>for all</b>', 'disable-admin-notices' ) . "</button>";
}
if ( strpos( $cont, 'redux-connect-message' ) ) {
$a = 1;
}
// Fix for Woocommerce membership and Jetpack message
if ( $cont != '<div class="js-wc-memberships-admin-notice-placeholder"></div>' && false === strpos( $cont, 'jetpack-jitm-message' ) ) {
$cont = preg_replace( '/<(noscript|script|style)([^>]+)?>(.*?)<\/(noscript|script|style)>(<\/(noscript|script|style)>)*/is', '', $cont );
$cont = preg_replace( '/<!--(.*?)-->/is', '', $cont );
$cont = rtrim( trim( $cont ) );
$cont = preg_replace( '/^(<div[^>]+>)(.*?)(<\/div>)$/is',
"$1<div class='wbcr-dan-hide-notices'>$2</div><div class='wbcr-dan-hide-links'>{$hide_link_for_me} {$hide_link_for_all}</div>$3", $cont );
}
if ( empty( $cont ) ) {
continue;
}
$content[] = $cont;
}
}
$wbcr_dan_plugin_all_notices = $content;
}
wdan_clear_all_notices( 'user_admin_notices' );
wdan_clear_all_notices( 'network_admin_notices' );
wdan_clear_all_notices( 'admin_notices', [
'Learndash_Admin_Menus_Tabs',
'WC_Memberships_Admin',
'YIT_Plugin_Panel_WooCommerce'
], [ 'et_pb_export_layouts_interface' ] );
wdan_clear_all_notices( 'all_admin_notices', [
'Learndash_Admin_Menus_Tabs',
'WC_Memberships_Admin',
'YIT_Plugin_Panel_WooCommerce'
], [ 'et_pb_export_layouts_interface' ] );
}
/**
* Get excerpt from string
*
* @param String $str String to get an excerpt from
* @param Integer $startPos Position int string to start excerpt from
* @param Integer $maxLength Maximum length the excerpt may be
*
* @return String excerpt
*/
public
function getExcerpt(
$str, $startPos = 0, $maxLength = 100
) {
if ( strlen( $str ) > $maxLength ) {
$excerpt = substr( $str, $startPos, $maxLength - 3 );
$lastSpace = strrpos( $excerpt, ' ' );
$excerpt = substr( $excerpt, 0, $lastSpace );
$excerpt .= '...';
} else {
$excerpt = $str;
}
return $excerpt;
}
/**
* @param array $arr1
* @param array $arr2
*
* @return array
*/
protected
function array_merge(
array $arr1, array $arr2
) {
if ( ! empty( $arr2 ) ) {
foreach ( $arr2 as $key => $value ) {
if ( ! isset( $arr1[ $key ] ) ) {
$arr1[ $key ] = $value;
} else if ( is_array( $arr1[ $key ] ) ) {
$arr1[ $key ] = $arr1[ $key ] + $value;
}
}
}
return $arr1;
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* Helper functions
* @author Webcraftic <alex.kovalevv@gmail.com>
* @copyright (c) 05.07.2020, Webcraftic
* @version 1.0
*/
/**
* Access to global variable $wp_filter in WP core.
* Migration from WP 4.2 to 4.9
*
* @see https://codex.wordpress.org/Version_4.7 WP 4.7 changelog (WP_Hook)
*
* @param $key string filter name
*
* @return array callbacks array by link
*/
function &wdan_get_wp_filter( $key ) {
global $wp_filter;
$default = [];
if ( 'admin_notices' === $key && is_multisite() && is_network_admin() ) {
$key = 'network_admin_notices';
}
if ( ! isset( $wp_filter[ $key ] ) ) {
return $default;
}
return $wp_filter[ $key ]->callbacks;
}
/**
* @param $key
*
* @return array
*/
function wdan_collect_notices( $key ) {
$wp_filter = &wdan_get_wp_filter( $key );
$content = [];
if ( ! empty( $wp_filter ) ) {
foreach ( (array) $wp_filter as $filters ) {
foreach ( $filters as $callback_name => $callback ) {
if ( 'usof_hide_admin_notices_start' == $callback_name || 'usof_hide_admin_notices_end' == $callback_name ) {
continue;
}
ob_start();
// #CLRF-140 fix bug for php7
// when the developers forgot to delete the argument in the function of implementing the notification.
$args = [];
$accepted_args = isset( $callback['accepted_args'] ) && ! empty( $callback['accepted_args'] ) ? $callback['accepted_args'] : 0;
if ( $accepted_args > 0 ) {
for ( $i = 0; $i < (int) $accepted_args; $i ++ ) {
$args[] = null;
}
}
//===========
call_user_func_array( $callback['function'], $args );
$cont = ob_get_clean();
if ( ! empty( $cont ) ) {
$salt = is_multisite() ? get_current_blog_id() : '';
$uniq_id1 = md5( $cont . $salt );
$uniq_id2 = md5( $callback_name . $salt );
if ( is_array( $callback['function'] ) && sizeof( $callback['function'] ) == 2 ) {
$class = $callback['function'][0];
if ( is_object( $class ) ) {
$class_name = get_class( $class );
$method_name = $callback['function'][1];
$uniq_id2 = md5( $class_name . ':' . $method_name );
}
}
$content[ $uniq_id1 . "_" . $uniq_id2 ] = $cont;
}
}
}
}
return $content;
}
/**
* @param $key
* @param array $excluded_classes
* @param array $excluded_callback_names
*/
function wdan_clear_all_notices( $key, $excluded_classes = [], $excluded_callback_names = [] ) {
$wp_filter = &wdan_get_wp_filter( $key );
if ( ! empty( $wp_filter ) ) {
foreach ( (array) $wp_filter as $f_key => $f ) {
foreach ( $f as $c_name => $clback ) {
if ( is_array( $clback['function'] ) && sizeof( $clback['function'] ) == 2 ) {
$class = $clback['function'][0];
if ( is_object( $class ) ) {
$class_name = get_class( $class );
if ( in_array( $class_name, $excluded_classes ) ) {
continue;
}
}
}
if ( in_array( $c_name, $excluded_callback_names ) ) {
continue;
}
unset( $wp_filter[ $f_key ][ $c_name ] );
}
}
}
}