PluginProbe
Magic Login – Magic Link & Passwordless Authentication for WordPress – Login Without Password / 2.2
Magic Login – Magic Link & Passwordless Authentication for WordPress – Login Without Password v2.2
2.8.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4 2.4.1 2.4.2 2.5 2.5.1 2.6 2.6.1 2.6.2 2.6.3 2.7 2.7.1 2.8 trunk All 48 releases
magic-login / includes / core.php

core.php in Magic Login – Magic Link & Passwordless Authentication for WordPress – Login Without Password 2.2, at includes/core.php

134 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Core plugin functionality.
4 *
5 * @package MagicLogin
6 */
7
8 namespace MagicLogin\Core;
9
10 use function MagicLogin\Utils\is_magic_login_settings_screen;
11 use \WP_Error as WP_Error;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16 /**
17 * Default setup routine
18 *
19 * @return void
20 */
21 function setup() {
22 add_action( 'init', __NAMESPACE__ . '\\i18n' );
23 add_action( 'init', __NAMESPACE__ . '\\init' );
24 add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\admin_scripts' );
25 add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\admin_styles' );
26
27 do_action( 'magic_login_loaded' );
28 }
29
30 /**
31 * Registers the default textdomain.
32 *
33 * @return void
34 */
35 function i18n() {
36 $locale = apply_filters( 'plugin_locale', get_locale(), 'magic-login' );
37 load_textdomain( 'magic-login', WP_LANG_DIR . '/magic-login/magic-login-' . $locale . '.mo' );
38 load_plugin_textdomain( 'magic-login', false, plugin_basename( MAGIC_LOGIN_PATH ) . '/languages/' );
39 }
40
41 /**
42 * Initializes the plugin and fires an action other plugins can hook into.
43 *
44 * @return void
45 */
46 function init() {
47 do_action( 'magic_login_init' );
48 }
49
50 /**
51 * The list of knows contexts for enqueuing scripts/styles.
52 *
53 * @return array
54 */
55 function get_enqueue_contexts() {
56 return [ 'admin', 'frontend', 'shared', 'shortcode', 'block-editor' ];
57 }
58
59 /**
60 * Generate an URL to a script, taking into account whether SCRIPT_DEBUG is enabled.
61 *
62 * @param string $script Script file name (no .js extension)
63 * @param string $context Context for the script ('admin', 'frontend', or 'shared')
64 *
65 * @return string|WP_Error URL
66 */
67 function script_url( $script, $context ) {
68
69 if ( ! in_array( $context, get_enqueue_contexts(), true ) ) {
70 return new WP_Error( 'invalid_enqueue_context', 'Invalid $context specified in MagicLogin script loader.' );
71 }
72
73 return MAGIC_LOGIN_URL . "dist/js/{$script}.js";
74
75 }
76
77 /**
78 * Generate an URL to a stylesheet, taking into account whether SCRIPT_DEBUG is enabled.
79 *
80 * @param string $stylesheet Stylesheet file name (no .css extension)
81 * @param string $context Context for the script ('admin', 'frontend', or 'shared')
82 *
83 * @return string URL
84 */
85 function style_url( $stylesheet, $context ) {
86
87 if ( ! in_array( $context, get_enqueue_contexts(), true ) ) {
88 return new WP_Error( 'invalid_enqueue_context', 'Invalid $context specified in MagicLogin stylesheet loader.' );
89 }
90
91 return MAGIC_LOGIN_URL . "dist/css/{$stylesheet}.css";
92
93 }
94
95
96 /**
97 * Enqueue scripts for admin.
98 *
99 * @return void
100 */
101 function admin_scripts() {
102 if ( ! is_magic_login_settings_screen() ) {
103 return;
104 }
105
106 wp_enqueue_script(
107 'magic_login_admin',
108 script_url( 'admin', 'admin' ),
109 [],
110 MAGIC_LOGIN_VERSION,
111 true
112 );
113 }
114
115 /**
116 * Enqueue styles for admin.
117 *
118 * @return void
119 */
120 function admin_styles() {
121
122 if ( ! is_magic_login_settings_screen() ) {
123 return;
124 }
125
126 wp_enqueue_style(
127 'magic_login_admin',
128 style_url( 'admin-style', 'admin' ),
129 [],
130 MAGIC_LOGIN_VERSION
131 );
132
133 }
134