Current File : /home/kelaby89/jrncommunityhousing.charity/wp-content/themes/caridad/vamtam/admin/classes/admin.php |
<?php
/**
* Framework admin enhancements
*
* @author Nikolay Yordanov <[email protected]>
* @package vamtam/caridad
*/
/**
* class VamtamAdmin
*/
class VamtamAdmin {
/**
* Initialize the theme admin
*/
public static function actions() {
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
add_action( 'admin_init', array( 'VamtamUpdateNotice', 'check' ) );
}
add_action( 'admin_footer', array( __CLASS__, 'icons_selector' ) );
add_filter( 'admin_notices', array( __CLASS__, 'update_warning' ) );
add_action( 'admin_init', array( __CLASS__, 'setup_settings' ) );
add_filter( 'upgrader_pre_download', array( __CLASS__, 'theme_upgrade_no_pkg' ) , 10, 3 );
add_filter( 'wp_prepare_themes_for_js', array( __CLASS__, 'theme_upgrade_update_message' ), 10, 1);
add_filter( 'option_auto_update_themes', array( __CLASS__, 'theme_auto_update_filter' ), 10, 3 );
self::load_functions();
self::inactive_vamtam_plugins_updates();
new VamtamPurchaseHelper;
new VamtamHelpPage;
new VamtamDiagnostics;
new VamtamMigrations;
require_once VAMTAM_ADMIN_HELPERS . 'updates/version-checker.php';
if ( ! get_option( VAMTAM_THEME_SLUG . '_vamtam_theme_activated', false ) ) {
update_option( VAMTAM_THEME_SLUG . '_vamtam_theme_activated', true );
delete_option( 'default_comment_status' );
}
}
public static function theme_auto_update_filter( $value, $option ) {
foreach ( $value as $i => $theme ) {
if ( $theme === VAMTAM_THEME_SLUG ) {
$valid_pc = Version_Checker::is_valid_purchase_code() && ! get_option( VamtamFramework::get_token_option_key() );
if ( ! $valid_pc ) {
unset( $value[ $i ] );
}
}
}
return $value;
}
public static function setup_settings() {}
public static function update_warning() {
if ( did_action( 'load-update-core.php' ) ) {
echo '<div class="updated notice fade is-dismissible"><p><strong>';
esc_html_e( 'Hey, just a polite reminder that if you update WordPress you will also need to update your theme and plugins.', 'caridad' );
echo '</strong>';
echo '</p></div>';
}
if ( did_action( 'load-update-core.php' ) || did_action( 'load-themes.php' ) ) {
echo '<div class="notice notice-success is-dismissible"><p><strong>';
esc_html_e( 'VamTam theme resources: ', 'caridad' );
echo '</strong>';
echo '<a href="https://vamtam.com/child-themes" target="_blank">';
esc_html_e( 'Sample child themes', 'caridad' );
echo '</a>; ';
echo '<a href="https://vamtam.com/changelog" target="_blank">';
esc_html_e( 'Changelog', 'caridad' );
echo '</a>';
echo '</p></div>';
}
}
public static function icons_selector() {
?>
<div class="vamtam-config-icons-selector hidden">
<input type="search" placeholder="<?php esc_attr_e( 'Filter icons', 'caridad' ) ?>" class="icons-filter"/>
<div class="icons-wrapper spinner">
<input type="radio" value="" checked="checked"/>
</div>
</div>
<?php
}
public static function theme_upgrade_no_pkg( $reply, $package, $upgrader ) {
if ( isset( $upgrader->skin->theme_info ) && false !== $upgrader->skin->theme_info ) {
$theme_slug = $upgrader->skin->theme_info->get_stylesheet();
if ( $theme_slug === VAMTAM_THEME_SLUG && empty( $package ) ) {
return new WP_Error( 'no_package', __( 'Only Envato Market clients with a valid purchase code are entitled to automatic updates. Envato Elements clients must use FTP.', 'caridad' ) );
}
}
return $reply;
}
public static function theme_upgrade_update_message( $themes ) {
if ( isset( $themes[ VAMTAM_THEME_SLUG ] ) && ( ! Version_Checker::is_valid_purchase_code() || get_option( VamtamFramework::get_token_option_key() ) ) ) { // Not valid pc or token.
// Changelog link to open in new tab.
$themes[ VAMTAM_THEME_SLUG ][ 'update' ] = preg_replace( '/<a href="[^"]+"/', '<a target=_blank href="https://vamtam.com/changelog"', $themes[ VAMTAM_THEME_SLUG ][ 'update' ] );
$themes[ VAMTAM_THEME_SLUG ][ 'update' ] = str_replace( 'thickbox ', '', $themes[ VAMTAM_THEME_SLUG ][ 'update' ] );
// Append custom msg.
$themes[ VAMTAM_THEME_SLUG ][ 'update' ] .= '<hr/><p><strong>' . __( 'Note: Only Envato Market clients with a valid purchase code are entitled to automatic updates. Envato Elements clients must use FTP.', 'caridad' ) . '</p></strong>';
// Disable auto-update
$themes[ VAMTAM_THEME_SLUG ][ 'autoupdate' ][ 'forced' ] = false;
$themes[ VAMTAM_THEME_SLUG ][ 'autoupdate' ][ 'enabled' ] = false;
$themes[ VAMTAM_THEME_SLUG ][ 'actions' ][ 'autoupdate' ] = false;
}
return $themes;
}
/**
* Admin helper functions
*/
private static function load_functions() {
require_once VAMTAM_ADMIN_HELPERS . 'base.php';
}
/**
* Function to check inactive plugins and initialize Vamtam Updates if necessary.
*/
private static function inactive_vamtam_plugins_updates() {
global $pagenow;
if ( 'plugins.php' !== $pagenow ) {
return;
}
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$all_plugins = get_plugins();
$active_plugins = get_option( 'active_plugins', array() );
foreach ( $all_plugins as $plugin_path => $plugin_data ) {
if ( in_array( $plugin_path, $active_plugins, true ) ) {
continue; // Skip active plugins.
}
$plugin_dir = dirname( WP_PLUGIN_DIR . '/' . $plugin_path );
$main_file = WP_PLUGIN_DIR . '/' . $plugin_path;
if ( file_exists( $main_file ) ) {
$content = file_get_contents( $main_file );
if ( preg_match( '/new\s+Vamtam_Updates_(\d+)\s*\(\s*__FILE__\s*\)/', $content, $matches ) ) {
$update_class = 'Vamtam_Updates_' . $matches[1];
if ( ! class_exists( $update_class ) ) {
$class_file = $plugin_dir . '/vamtam-updates/class-vamtam-updates.php';
if ( file_exists( $class_file ) ) {
include_once $class_file;
}
}
if ( class_exists( $update_class ) ) {
new $update_class( $main_file );
}
}
}
}
}
}