register_autoloader();
// register_activation_hook( WML_BASE, [ $this, 'wml_activate' ] );
// register_deactivation_hook( WML_BASE, [ $this, 'wml_deactivate' ] );
// add_action( 'wpv/wml/delete_logs', [ $this, 'wml_delete_entry' ] );
// Register Rest API
add_action( 'rest_api_init', [ $this, 'init_rest_api' ] );
// Add Adimn Menu Setting Page
add_action( 'admin_menu', [ $this, 'admin_menu' ] );
// Add Setting Page Header
add_action( 'in_admin_header', [ $this, 'in_admin_header' ] );
// Create Table
add_action( 'plugins_loaded', [ 'WML\Classes\DbTable', 'wml_plugin_activated' ] );
// Caputure Mail Register Filter
add_filter( 'wp_mail', [ 'WML\Classes\Capture_Mail', 'log_email' ] );
// for admin scripts & styles
add_action( 'admin_enqueue_scripts', [ $this, 'wml_admin_enqueue_scripts' ] );
add_action( 'admin_notices', [ $this, 'add_review_notice' ] );
add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
add_action( 'admin_init', [ $this, 'wpv_mail_review' ], 10 );
// Add Script type module
add_filter('script_loader_tag', [ $this, 'add_type_attribute' ] , 10, 3);
}
/**
* Add admin menu
*
* @since 0.3
* @return void
* @access public
*
*/
public function admin_menu() {
add_menu_page(
__( 'WP Mail Log', 'wpv-wml' ),
__( 'WP Mail Log', 'wpv-wml' ),
'manage_options',
'wp-mail-log',
[ $this, 'create_wp_mail_page' ],
// 'dashicons-chart-line',
'dashicons-email-alt',
25
);
add_submenu_page( 'wp-mail-log', __( 'WP Mail Logs', 'wpv-wml' ), __( 'Emails Logs', 'wpv-wml' ), 'manage_options', 'wp-mail-log', [ $this, 'create_wp_mail_page' ], 1 );
// add_submenu_page( 'wp-mail-log', 'WP Mail Log Settings', 'Settings', 'manage_options', 'wpv-wpml-settings', [ $this, 'wpml_settings' ], 5 );
}
/**
* Create Setting page
*
* @since 0.3
* @return void
* @access public
*
*/
public function wpml_settings() {
if ( isset( $_GET['wml_nonce'] ) && ! wp_verify_nonce( $_GET['wml_nonce'], 'wp_rest' ) ) {
die( 'Sorry, your nonce did not verify!' );
}
if ( isset( $_GET['tab'] ) ) {
$this->current_tab = sanitize_text_field( wp_unslash( $_GET['tab'] ) );
}
$setting_pages = [
'general' => __( 'General', 'wpv-wml' ),
];
?>
current_tab || 'general' === $this->current_tab ) {
?>
get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wml_entries" );
if ( $rowcount > 10 ) {
$this->wml_review_box();
}
}
}
public function sidebar() {
echo 'Sidebar Content
';
}
/**
* Create Header
*
* Create header for our plugin pages
*
* @since 0.3
* @return void
* @access public
*
*/
public function in_admin_header() {
$nav_links = $this->get_nav_links();
$current_screen = get_current_screen();
if ( ! isset( $nav_links[ $current_screen->id ] ) ) {
return;
}
?>
wml_title );
?>
[
'label' => __( 'Email Logs', 'wpv-wml' ),
'link' => admin_url( 'admin.php?page=wp-mail-log' ),
'top_nav' => true,
],
'wp-mail-log_page_wpv-wpml-settings' => [
'label' => __( 'Settings', 'wpv-wml' ),
'link' => admin_url( 'admin.php?page=wpv-wml-settings' ),
'top_nav' => true,
],
];
$nav = apply_filters( 'wml/nav_links', $nav );
return $nav;
}
/**
* Create Mail Log Page
*
* Create page to view logs, render content using react js.
*
* @since 0.3
* @return void
* @access public
*
*/
public function create_wp_mail_page() {
?>
get();
$screen = get_current_screen();
wp_enqueue_style( 'wml-admin-style', WML_URL . 'assets/css/admin.css', [], WML_VERSION );
if ( $screen->id !== 'toplevel_page_wp-mail-log' ) {
return;
}
wp_enqueue_style( 'log-style', WML_URL . 'build/css/index.css', [], WML_VERSION );
wp_enqueue_script( 'log-js', WML_URL . 'build/js/index.js', [], WML_VERSION, true );
wp_localize_script(
'log-js',
'WmlGlobalVar',
[
'site_url' => site_url(),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'admin_url' => admin_url(),
'rest_url' => get_rest_url(),
'nonce' => wp_create_nonce( 'wp_rest' ),
'ajax_nonce' => wp_create_nonce( 'wml_ajax_nonce' ),
'locale' => get_locale(),
'date-formate' => get_option( 'date_format' ),
'temp_date' => date( get_option( 'date_format' ) ),
'settings' => $settings,
'upload_dir' => wp_upload_dir()['baseurl'],
]
);
}
function add_type_attribute($tag, $handle, $src){
// if not your script, do nothing and return original $tag
if ( 'log-js' !== $handle ) {
return $tag;
}
// change the script tag by adding type="module" and return it.
$tag = '';
return $tag;
}
/**
* Add Api endopints
*
* Function fire on `rest_api_init` hook
*
* @since 0.3
* @return void
* @access public
*
*/
public function init_rest_api() {
$controllers = [
new \WML\Classes\Api(),
];
foreach ( $controllers as $controller ) {
$controller->register_routes();
}
}
/**
* Register Autoloader
*
* Register function as `__autoload()` implementation.
*
* @since 0.3
* @return void
* @access public
*
*/
private function register_autoloader() {
spl_autoload_register( [ __CLASS__, 'autoload' ] );
}
/**
* Run Autoloader
*
* Autoloader will add classes
*
* @param string $class Class name.
* @since 0.3
* @return void
* @access public
*
*/
public function autoload( $class ) {
if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
return;
}
if ( ! class_exists( $class ) ) {
$filename = strtolower(
preg_replace(
[ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
[ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
$class
)
);
$filename = WML_PATH . $filename . '.php';
if ( is_readable( $filename ) ) {
include $filename;
}
}
}
/**
* Add Mail Review Notice
*
* @since 0.3
* @return void
* @access public
*
*/
public function wpv_mail_review() {
if ( isset( $_GET['wml_remind_later'] ) || isset( $_GET['wml_review_done'] ) ) {
if ( ! empty( $_GET['wml_nonce'] ) && wp_verify_nonce( $_GET['wml_nonce'], 'wml_rest' ) ) {
$user = \wp_get_current_user();
$roles = (array) $user->roles;
if ( $roles[0] !== 'administrator' ) {
return;
}
if ( isset( $_GET['wml_remind_later'] ) ) {
$this->wml_remind_later();
} elseif (
isset( $_GET['wml_review_done'] ) ) {
$this->wml_review_done();
}
}
}
}
/**
* Set Notice to Remind Later
*
* @since 0.3
* @return void
* @access public
*
*/
public function wml_remind_later() {
set_transient( 'wml_remind_later', 'show again', WEEK_IN_SECONDS );
}
/**
* Set Review Notice to Done
*
* @since 0.3
* @return void
* @access public
*
*/
public function wml_review_done() {
update_option( 'wml_review', 'done', false );
}
/**
* Review Notice HTML
*
* @since 0.3
* @return void
* @access public
*
*/
public function wml_review_box() {
?>
Just to help us spread the word and boost our motivation.
~ Anand Upadhyay'; ?>
prefix . 'wml_entries';
$query = $wpdb->prepare( "DELETE FROM {$table_name} WHERE DATE_FORMAT(captured_gmt,GET_FORMAT(DATE,'JIS')) <= %s", $date );
$dl1 = $wpdb->query( $query );
if ( $dl1 === 0 ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
error_log( print_r( 'No rows deleted...!!!', true ) );
}
} else {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG === true ) {
error_log( print_r( 'Row Deleted...!!!', true ) );
}
}
}
/**
* Fire on Plugin Deactivation hook
*
* Write the function which will fire on plugin deactivate.
*
* @since 0.3
* @return void
* @access public
*
*/
public function wml_deactivate() {
wp_clear_scheduled_hook( 'wpv/wml/delete_logs' );
}
/**
* Update Admin Footer Text
*
* @since 0.3
* @param string $footer_text Footer Text
* @return string updated $footer_text
* @access public
*
*/
public function admin_footer_text( $footer_text ) {
$screen = get_current_screen();
// Todo:: Show on plugin screens
$wml_screens = [
'toplevel_page_wp-mail-log',
'wp-mail-log_page_wpv-wpml-settings',
];
if ( in_array( $screen->id, $wml_screens, true ) ) {
$footer_text = sprintf(
/* translators: 1: WP Mail Log, 2: Link to plugin review */
__( 'Enjoyed %1$s? Please leave us a %2$s rating. We really appreciate your support!', 'wpv-wml' ),
'' . __( 'WP Mail Log', 'wpv-wml' ) . '',
'★★★★★'
);
}
return $footer_text;
}
}
WP_MAIL_LOG::get_instance();