| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* |
| 5 |
* Dump and Die variable or whatever |
| 6 |
* |
| 7 |
* @param $dump |
| 8 |
* |
| 9 |
*/ |
| 10 |
function logtivity_dd($dump) { |
| 11 |
echo "<pre>"; |
| 12 |
var_export($dump); |
| 13 |
echo "</pre>"; |
| 14 |
die(); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Load a view and pass variables into it |
| 19 |
* |
| 20 |
* To ouput a view you would want to echo it |
| 21 |
* |
| 22 |
* @param string $fileName excluding file extension |
| 23 |
* @param array $vars |
| 24 |
* @return string |
| 25 |
*/ |
| 26 |
function logtivity_view($fileName, $vars = array()) { |
| 27 |
|
| 28 |
foreach ($vars as $key => $value) { |
| 29 |
|
| 30 |
${$key} = $value; |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
ob_start(); |
| 35 |
|
| 36 |
include( dirname(__FILE__) . '/../views/' . str_replace('.', '/', $fileName) . '.php'); |
| 37 |
|
| 38 |
return ob_get_clean(); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Get Site API Key |
| 43 |
* |
| 44 |
* @return string |
| 45 |
*/ |
| 46 |
function logtivity_get_api_key() { |
| 47 |
return sanitize_text_field( |
| 48 |
(new Logtivity_Options)->getOption('logtivity_site_api_key') |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
function logtivity_get_the_title($post_id) { |
| 53 |
$wptexturize = remove_filter( 'the_title', 'wptexturize' ); |
| 54 |
|
| 55 |
$title = get_the_title($post_id); |
| 56 |
|
| 57 |
if ( $wptexturize ) { |
| 58 |
add_filter( 'the_title', 'wptexturize' ); |
| 59 |
} |
| 60 |
|
| 61 |
return $title; |
| 62 |
} |
| 63 |
|
| 64 |
function logtivity_get_api_url() |
| 65 |
{ |
| 66 |
if (defined('LOGTIVITY_API_URL')) { |
| 67 |
return LOGTIVITY_API_URL; |
| 68 |
} |
| 69 |
|
| 70 |
return 'https://api.logtivity.io'; |
| 71 |
} |
| 72 |
|
| 73 |
function logtivity_has_site_url_changed() |
| 74 |
{ |
| 75 |
$hash = (new Logtivity_Options)->urlHash(); |
| 76 |
|
| 77 |
if (!$hash) { |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
return $hash !== md5(home_url()); |
| 82 |
} |