forked from aprokopenko/justvariables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
just-variables.php
95 lines (80 loc) · 2.35 KB
/
just-variables.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/*
Plugin Name: Just Variables for Wordpress
Plugin URI: http://justcoded.com/just-labs/just-wordpress-theme-variables-plugin/
Description: This plugin add custom page with theme text variables to use inside the templates.
Tags: theme, variables, template, text data
Author: Alexander Prokopenko
Author URI: http://justcoded.com/
Version: 1.2
Donate link: http://justcoded.com/just-labs/just-wordpress-theme-variables-plugin/#donate
*/
define('JV_ROOT', dirname(__FILE__));
define('JV_TEXTDOMAIN', 'just-wp-variables');
if(!function_exists('pa')){
function pa($mixed, $stop = false) {
$ar = debug_backtrace(); $key = pathinfo($ar[0]['file']); $key = $key['basename'].':'.$ar[0]['line'];
$print = array($key => $mixed); echo( '<pre>'.htmlentities(print_r($print,1)).'</pre>' );
if($stop == 1) exit();
}
}
require_once( JV_ROOT . '/just-variables.admin.php' );
require_once( JV_ROOT . '/just-variables.theme.php' );
/**
* plugin init
*/
add_action('plugins_loaded', 'jv_init');
function jv_init(){
if( !is_admin() ) return;
/**
* load translations
*/
load_plugin_textdomain( JV_TEXTDOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
// add admin page
add_action( 'admin_menu', 'jv_admin_menu' );
}
/*
functions for templates to print variables
*/
/**
* get actual value for variable
* @param string $var variable name
* @return string return variable value or NULL
*/
function jv_get_variable_value( $var ){
$values = get_option('jv_values');
if( !empty($values[$var]) ){
return $values[$var];
}
return NULL;
}
/**
* get actual value for variable
* @param string $var variable name
* @param bool $echo print variable by default.
* @return string return variable value or NULL
*/
function just_variable( $var, $echo = true ){
$value = jv_get_variable_value( $var );
if( !is_null($value) && $echo ){
echo $value;
}
else{
return $value;
}
}
/**
* register custom shortcode to print variables in the content
* @param array $atts attributes array submitted to shortcode
* @return string return parsed shortcode
*/
function just_variable_shortcode( $atts ){
if( empty($atts['code']) ){
return '';
}
else{
return just_variable( $atts['code'], false );
}
}
add_shortcode('justvar', 'just_variable_shortcode');
?>