| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
class WPCoder_Lite_Changed_Snippets { |
| 6 |
/** |
| 7 |
* @var false|mixed|null |
| 8 |
*/ |
| 9 |
private $options; |
| 10 |
|
| 11 |
public function __construct() { |
| 12 |
$options = get_option( '_wp_coder_snippets', [] ); |
| 13 |
$this->options = $options; |
| 14 |
|
| 15 |
if ( array_key_exists( 'change_revisions_control', $options ) ) { |
| 16 |
add_filter( 'wp_revisions_to_keep', [ $this, 'change_revisions_control' ] ); |
| 17 |
} |
| 18 |
|
| 19 |
if ( array_key_exists( 'change_logo_on_site_icon', $options ) ) { |
| 20 |
add_action( 'login_head', [ $this, 'change_logo_on_site_icon' ] ); |
| 21 |
} |
| 22 |
|
| 23 |
if ( array_key_exists( 'change_logo_link', $options ) ) { |
| 24 |
add_filter( 'login_headerurl', [ $this, 'logo_link' ] ); |
| 25 |
} |
| 26 |
|
| 27 |
if ( array_key_exists( 'change_redirect_after_login', $options ) ) { |
| 28 |
add_filter( 'login_redirect', [ $this, 'login_redirect' ], 10, 3 ); |
| 29 |
} |
| 30 |
|
| 31 |
if ( array_key_exists( 'change_redirect_after_logout', $options ) ) { |
| 32 |
add_filter( 'logout_redirect', [ $this, 'logout_redirect' ], 10, 3 ); |
| 33 |
} |
| 34 |
|
| 35 |
if ( array_key_exists( 'change_oEmbed_size', $options ) ) { |
| 36 |
add_filter( 'embed_defaults', [ $this, 'oembed_defaults' ] ); |
| 37 |
} |
| 38 |
|
| 39 |
if ( array_key_exists( 'change_read_more', $options ) ) { |
| 40 |
add_filter( 'the_content_more_link', [$this,'change_read_more'], 15, 2 ); |
| 41 |
} |
| 42 |
|
| 43 |
if ( array_key_exists( 'change_expiration_remember_me', $options ) ) { |
| 44 |
add_filter( 'auth_cookie_expiration', [$this, 'change_expiration_remember_me']); |
| 45 |
} |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
public function change_expiration_remember_me() { |
| 50 |
$days = ! empty( $this->options['change_expiration_remember_me_day'] ) ? $this->options['change_expiration_remember_me_day'] : 14; |
| 51 |
return absint($days) * DAY_IN_SECONDS; |
| 52 |
} |
| 53 |
|
| 54 |
public function change_read_more( $read_more, $read_more_text ) { |
| 55 |
$custom_text = ! empty( $this->options['change_read_more_text'] ) ? $this->options['change_read_more_text'] : 'Read More'; |
| 56 |
$read_more = str_replace( $read_more_text, $custom_text, $read_more ); |
| 57 |
|
| 58 |
return $read_more; |
| 59 |
} |
| 60 |
|
| 61 |
public function oembed_defaults( $sizes ) { |
| 62 |
$width = ! empty( $this->options['change_oEmbed_size_width'] ) ? $this->options['change_oEmbed_size_width'] : 400; |
| 63 |
$height = ! empty( $this->options['change_oEmbed_size_height'] ) ? $this->options['change_oEmbed_size_height'] : 280; |
| 64 |
|
| 65 |
return array( |
| 66 |
'width' => absint( $width ), |
| 67 |
'height' => absint( $height ), |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
public function logout_redirect( $redirect_to, $request, $user ) { |
| 72 |
if ( ! empty( $this->options['change_redirect_logout_link'] ) ) { |
| 73 |
$redirect_to = get_site_url() . '/' . esc_attr( $this->options['change_redirect_logout_link'] ); |
| 74 |
} else { |
| 75 |
$redirect_to = get_site_url(); |
| 76 |
} |
| 77 |
|
| 78 |
return $redirect_to; |
| 79 |
} |
| 80 |
|
| 81 |
public function login_redirect( $redirect_to, $request, $user ) { |
| 82 |
if ( ! empty( $this->options['change_redirect_login_link'] ) ) { |
| 83 |
$redirect_to = get_site_url() . '/' . esc_attr( $this->options['change_redirect_login_link'] ); |
| 84 |
} |
| 85 |
|
| 86 |
return $redirect_to; |
| 87 |
} |
| 88 |
|
| 89 |
public function logo_link() { |
| 90 |
return get_home_url(); |
| 91 |
} |
| 92 |
|
| 93 |
public function change_logo_on_site_icon(): void { |
| 94 |
$url = get_site_icon_url( 84 ); |
| 95 |
if ( ! empty( $url ) ) { |
| 96 |
echo '<style>#login h1 a { background-image: url(' . esc_url( $url ) . '); }</style>'; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
public function change_revisions_control( $limit ): int { |
| 101 |
$revision = ! empty( $this->options['change_revisions_control_number'] ) ? $this->options['change_revisions_control_number'] : '10'; |
| 102 |
|
| 103 |
return absint( $revision ); |
| 104 |
} |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
new WPCoder_Lite_Changed_Snippets; |