class-activation.php
3 years ago
class-admin-interface.php
3 years ago
class-common-methods.php
3 years ago
class-content-management.php
3 years ago
class-custom-code.php
3 years ago
class-deactivation.php
3 years ago
class-disable-components.php
3 years ago
class-login-logout.php
3 years ago
class-optimizations.php
3 years ago
class-security.php
3 years ago
class-settings-fields-render.php
3 years ago
class-settings-sanitization.php
3 years ago
class-settings-sections-fields.php
3 years ago
class-utilities.php
3 years ago
class-optimizations.php
115 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class related to Optimizations features |
| 7 | * |
| 8 | * @since 3.8.0 |
| 9 | */ |
| 10 | class Optimizations { |
| 11 | |
| 12 | private $current_url_path; |
| 13 | |
| 14 | /** |
| 15 | * Maybe modify heartbeat tick frequency based on settings for each location |
| 16 | * |
| 17 | * @since 3.8.0 |
| 18 | */ |
| 19 | public function maybe_modify_heartbeat_frequency( $settings ) { |
| 20 | |
| 21 | $this->get_url_path(); // defines $current_url_path |
| 22 | |
| 23 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 24 | |
| 25 | // Disable heartbeat autostart |
| 26 | $settings['autostart'] = false; |
| 27 | |
| 28 | if ( is_admin() ) { |
| 29 | |
| 30 | if ( '/wp-admin/post.php' == $this->current_url_path || '/wp-admin/post-new.php' == $this->current_url_path ) { |
| 31 | |
| 32 | // Maybe modify interval on post edit screens |
| 33 | if ( 'modify' == $options['heartbeat_control_for_post_edit'] ) { |
| 34 | $settings['minimalInterval'] = absint( $options['heartbeat_interval_for_post_edit'] ); |
| 35 | } |
| 36 | |
| 37 | } else { |
| 38 | |
| 39 | // Maybe modify interval on admin pages |
| 40 | if ( 'modify' == $options['heartbeat_control_for_admin_pages'] ) { |
| 41 | $settings['minimalInterval'] = absint( $options['heartbeat_interval_for_admin_pages'] ); |
| 42 | } |
| 43 | |
| 44 | } |
| 45 | |
| 46 | } else { |
| 47 | |
| 48 | // Maybe modify interval on the frontend |
| 49 | if ( 'modify' == $options['heartbeat_control_for_frontend'] ) { |
| 50 | $settings['minimalInterval'] = absint( $options['heartbeat_interval_for_frontend'] ); |
| 51 | } |
| 52 | |
| 53 | } |
| 54 | |
| 55 | return $settings; |
| 56 | |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Maybe disable heartbeat ticks based on settings for each location |
| 61 | * |
| 62 | * @since 3.8.0 |
| 63 | */ |
| 64 | public function maybe_disable_heartbeat() { |
| 65 | |
| 66 | global $pagenow; |
| 67 | |
| 68 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 69 | |
| 70 | if ( is_admin() ) { |
| 71 | |
| 72 | if ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) { |
| 73 | |
| 74 | // Maybe disable on post creation / edit screens |
| 75 | if ( 'disable' == $options['heartbeat_control_for_post_edit'] ) { |
| 76 | wp_deregister_script( 'heartbeat' ); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | } else { |
| 81 | |
| 82 | // Maybe disable on the rest of admin pages |
| 83 | if ( 'disable' == $options['heartbeat_control_for_admin_pages'] ) { |
| 84 | wp_deregister_script( 'heartbeat' ); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | } |
| 89 | |
| 90 | } else { |
| 91 | |
| 92 | // Maybe disable on the frontend |
| 93 | if ( 'disable' == $options['heartbeat_control_for_frontend'] ) { |
| 94 | wp_deregister_script( 'heartbeat' ); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | } |
| 99 | |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Set current location |
| 104 | * Supported locations [editor,dashboard,frontend] |
| 105 | */ |
| 106 | public function get_url_path() { |
| 107 | |
| 108 | $url = ( isset( $_SERVER['HTTPS'] ) ? "https" : "http" ) . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
| 109 | $request_path = parse_url( $url, PHP_URL_PATH ); // e.g. '/wp-admin/post.php' |
| 110 | $this->current_url_path = $request_path; |
| 111 | |
| 112 | } |
| 113 | |
| 114 | |
| 115 | } |