| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Base Functions. |
| 4 |
* |
| 5 |
* Grab MainWP Directory and check for permissions. |
| 6 |
* |
| 7 |
* @package MainWP/Dashboard |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! function_exists( 'mainwpdir' ) ) { |
| 11 |
|
| 12 |
/** |
| 13 |
* Grab MainWP Directory |
| 14 |
* |
| 15 |
* @return string |
| 16 |
*/ |
| 17 |
function mainwpdir() { |
| 18 |
return WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . dirname( plugin_basename( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
if ( ! function_exists( 'mainwp_do_not_have_permissions' ) ) { |
| 24 |
|
| 25 |
/** |
| 26 |
* Detect permission level & display message to end user. |
| 27 |
* |
| 28 |
* @param string $where User's location. |
| 29 |
* @param bool $echo Defines weather or not to echo error message. |
| 30 |
* @return string|bool $msg|false |
| 31 |
*/ |
| 32 |
function mainwp_do_not_have_permissions( $where = '', $echo = true ) { |
| 33 |
$msg = sprintf( esc_html__( 'You do not have sufficient permissions to access this page (%s).', 'mainwp' ), ucwords( $where ) ); |
| 34 |
if ( $echo ) { |
| 35 |
echo '<div class="mainwp-permission-error"><p>' . esc_html( $msg ) . '</p>If you need access to this page please contact the dashboard administrator.</div>'; |
| 36 |
} else { |
| 37 |
return $msg; |
| 38 |
} |
| 39 |
|
| 40 |
return false; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
if ( ! function_exists( 'mainwp_current_user_can' ) ) { |
| 45 |
|
| 46 |
/** |
| 47 |
* Check permission level. |
| 48 |
* |
| 49 |
* To compatible with extensions. |
| 50 |
* |
| 51 |
* @param string $cap_type Group or type of capabilities. |
| 52 |
* @param string $cap Capabilities for current user. |
| 53 |
* |
| 54 |
* @return bool true|false |
| 55 |
*/ |
| 56 |
function mainwp_current_user_can( $cap_type = '', $cap = '' ) { |
| 57 |
if ( function_exists( 'MainWP\Dashboard\mainwp_current_user_have_right' ) ) { |
| 58 |
return MainWP\Dashboard\mainwp_current_user_have_right( $cap_type, $cap ); |
| 59 |
} |
| 60 |
return true; |
| 61 |
} |
| 62 |
} |
| 63 |
|