SHARE
TWEET

Untitled

a guest Aug 10th, 2015 252 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  * GavernWP functions and definitions
  5.  *
  6.  * This file contains core framework operations. It is always
  7.  * loaded before the index.php file no the front-end
  8.  *
  9.  * @package WordPress
  10.  * @subpackage GavernWP
  11.  * @since GavernWP 1.0
  12.  **/
  13.  
  14. if(!function_exists('gavern_file')) {
  15.         /**
  16.          *
  17.          * Function used to get the file absolute path - useful when child theme is used
  18.          *
  19.          * @return file absolute path (in the original theme or in the child theme if file exists)
  20.          *
  21.          **/
  22.         function gavern_file($path) {
  23.                 if(is_child_theme()) {
  24.                         if($path == false) {
  25.                                 return get_stylesheet_directory();
  26.                         } else {
  27.                                 if(is_file(get_stylesheet_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path))) {
  28.                                         return get_stylesheet_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
  29.                                 } else {
  30.                                         return get_template_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
  31.                                 }
  32.                         }
  33.                 } else {
  34.                         if($path == false) {
  35.                                 return get_template_directory();
  36.                         } else {
  37.                                 return get_template_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path);
  38.                         }
  39.                 }
  40.         }
  41. }
  42.  
  43. if(!function_exists('gavern_file_uri')) {
  44.         /**
  45.          *
  46.          * Function used to get the file URI - useful when child theme is used
  47.          *
  48.          * @return file URI (in the original theme or in the child theme if file exists)
  49.          *
  50.          **/
  51.         function gavern_file_uri($path) {
  52.                 if(is_child_theme()) {
  53.                         if($path == false) {
  54.                                 return get_stylesheet_directory_uri();
  55.                         } else {
  56.                                 if(is_file(get_stylesheet_directory() . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $path))) {
  57.                                         return get_stylesheet_directory_uri() . '/' . $path;
  58.                                 } else {
  59.                                         return get_template_directory_uri() . '/' . $path;
  60.                                 }
  61.                         }
  62.                 } else {
  63.                         if($path == false) {
  64.                                 return get_template_directory_uri();
  65.                         } else {
  66.                                 return get_template_directory_uri() . '/' . $path;
  67.                         }
  68.                 }
  69.         }
  70. }
  71. //
  72. if(!class_exists('GavernWP')) {
  73.         // include the framework base class
  74.         require(gavern_file('gavern/base.php'));
  75. }
  76. // load and parse template JSON file.
  77. $config_language = 'en_US';
  78. if(get_locale() != '' && is_dir(get_template_directory() . '/gavern/config/'. get_locale()) && is_dir(get_template_directory() . '/gavern/options/'. get_locale())) {
  79.         $config_language = get_locale();       
  80. }
  81. $json_data = json_decode(file_get_contents(get_template_directory() . '/gavern/config/'.$config_language.'/template.json'));
  82. $tpl_name = strtolower(preg_replace("/[^A-Za-z0-9]/", "", $json_data->template->name));
  83. // define constant to use with all __(), _e(), _n(), _x() and _xe() usage
  84. define('GKTPLNAME', $tpl_name);
  85. // create the framework object
  86. $tpl = new GavernWP();
  87. // Including file with helper functions
  88. require_once(gavern_file('gavern/helpers/helpers.base.php'));
  89. // Including file with template hooks
  90. require_once(gavern_file('gavern/hooks.php'));
  91. // Including file with template functions
  92. require_once(gavern_file('gavern/functions.php'));
  93. require_once(gavern_file('gavern/user.functions.php'));
  94. // Including file with woocommerce functions
  95. if (isset($woocommerce)) :
  96.         require_once(gavern_file('gavern/wc-functions.php'));
  97. endif;
  98. // Including file with template filters
  99. require_once(gavern_file('gavern/filters.php'));
  100. // Including file with template widgets
  101. require_once(gavern_file('gavern/widgets.comments.php'));
  102. require_once(gavern_file('gavern/widgets.news_gallery.php'));
  103. require_once(gavern_file('gavern/widgets.nsp.php'));
  104. // Including file with template admin features
  105. require_once(gavern_file('gavern/helpers/helpers.features.php'));
  106. // Including file with template shortcodes
  107. require_once(gavern_file('gavern/helpers/helpers.shortcodes.php'));
  108. // Including file with template layout functions
  109. require_once(gavern_file('gavern/helpers/helpers.layout.php'));
  110. // Including file with template layout functions - connected with template fragments
  111. require_once(gavern_file('gavern/helpers/helpers.layout.fragments.php'));
  112. // Including file with template branding functions
  113. require_once(gavern_file('gavern/helpers/helpers.branding.php'));
  114. // Including file with template customize functions
  115. require_once(gavern_file('gavern/helpers/helpers.customizer.php'));
  116. // initialize the framework
  117. $tpl->init();
  118. // add theme setup function
  119. add_action('after_setup_theme', 'gavern_theme_setup');
  120. // Theme setup function
  121. function gavern_theme_setup(){
  122.         // access to the global template object
  123.         global $tpl;
  124.         // variable used for redirects
  125.         global $pagenow;               
  126.         // check if the themes.php address with goto variable has been used
  127.         if ($pagenow == 'themes.php' && !empty($_GET['goto'])) {
  128.                 /**
  129.                  *
  130.                  * IMPORTANT FACT: if you're using few different redirects on a lot of subpages
  131.                  * we recommend to define it as themes.php?goto=X, because if you want to
  132.                  * change the URL for X, then you can change it on one place below :)
  133.                  *
  134.                  **/
  135.                
  136.                 // check the goto value
  137.                 switch ($_GET['goto']) {
  138.                         // make proper redirect
  139.                         case 'gavick-com':
  140.                                 wp_redirect("http://www.gavick.com");
  141.                                 break;
  142.                         case 'wiki':
  143.                                 wp_redirect("http://www.gavick.com/documentation");
  144.                                 break;
  145.                         // or use default redirect
  146.                         default:
  147.                                 wp_safe_redirect('/wp-admin/');
  148.                                 break;
  149.                 }
  150.                 exit;
  151.         }
  152.         // if the normal page was requested do following operations:
  153.        
  154.     // load and parse template JSON file.
  155.     $json_data = $tpl->get_json('config','template');
  156.     // read the configuration
  157.     $template_config = $json_data->template;
  158.     // save the lowercase non-special characters template name                         
  159.     $template_name = strtolower(preg_replace("/[^A-Za-z0-9]/", "", $template_config->name));
  160.     // load the template text_domain
  161.     load_theme_textdomain( $template_name, get_stylesheet_directory() . '/languages' );
  162. }
  163. // scripts enqueue function
  164. function gavern_enqueue_admin_js_and_css() {
  165.         // metaboxes scripts
  166.         wp_enqueue_script('gavern.metabox.js', gavern_file_uri('js/back-end/gavern.metabox.js'));
  167.         // widget rules JS
  168.         wp_register_script('widget-rules-js', gavern_file_uri('js/back-end/widget.rules.js'), array('jquery'));
  169.         wp_enqueue_script('widget-rules-js');
  170.         // widget rules CSS
  171.         wp_register_style('widget-rules-css', gavern_file_uri('css/back-end/widget.rules.css'));
  172.         wp_enqueue_style('widget-rules-css');
  173.         // metaboxes CSS
  174.         wp_register_style('gavern-metabox-css', gavern_file_uri('css/back-end/metabox.css'));
  175.         wp_enqueue_style('gavern-metabox-css');
  176.         // GK News Show Pro Widget back-end CSS
  177.         wp_register_style('nsp-admin-css', gavern_file_uri('css/back-end/nsp.css'));
  178.         wp_enqueue_style('nsp-admin-css');
  179.         // shortcodes database
  180.         if(
  181.                 get_locale() != '' &&
  182.                 is_dir(get_template_directory() . '/gavern/config/'. get_locale()) &&
  183.                 is_dir(get_template_directory() . '/gavern/options/'. get_locale())
  184.         ) {
  185.                 $language = get_locale();      
  186.         } else {
  187.                 $language = 'en_US';
  188.         }
  189.        
  190.         wp_enqueue_script('shortcodes.js', gavern_file_uri('gavern/config/'.$language.'/shortcodes.js'));
  191. }
  192.  
  193.  
  194.  
  195. /**
  196.  * Step 1 : Insert Message Field
  197.  * @version 1.0
  198.  */
  199. add_action( 'mycred_transfer_form_to', 'mycred_pro_transfer_message_field' );
  200. function mycred_pro_transfer_message_field() {
  201.         echo '<label>Message</label><input type="text" name="transfer-message" id="mycred-transfer-message" value="vgg" placeholder="Optional message to recipient" />';
  202. }
  203.  
  204. /**
  205.  * Step 2 : Save Message
  206.  * @version 1.0
  207.  */
  208. add_filter( 'mycred_transfer_data', 'mycred_pro_save_transfer_message', 10, 3 );
  209. function mycred_pro_save_transfer_message( $data, $transaction_id, $post ) {
  210.  
  211.         // Default message.
  212.         $message = 'No message';
  213.  
  214.         // If a message is set
  215.         if ( $post['transfer-message'] != '' ) {
  216.  
  217.                 $message = sanitize_text_field( $post['transfer-message'] );
  218. }
  219.         // Add to the data array
  220.         $data['message'] = $message;
  221.  
  222.         // return the results
  223.         return $data;
  224.  
  225. }
  226.  
  227. /**
  228.  * Step 3 : Show the message
  229.  * @version 1.0
  230.  */
  231. add_filter( 'mycred_parse_log_entry_transfer', 'mycred_pro_show_message_in_log', 10, 2 );
  232. function mycred_pro_show_message_in_log( $content, $log_entry ) {
  233.  
  234.         // Unserialize data
  235.         $data = maybe_unserialize( $log_entry->data );
  236.  
  237.         // Default message
  238.         $message = 'No message';
  239.  
  240.         if ( isset( $data['message'] ) )
  241.                 $message = $data['message'];
  242.  
  243.         // Replace and return
  244.         return str_replace( '%message%', $message, $content );
  245.  
  246. }
  247.  
  248.  
  249. add_filter( 'mycred_label', 'relabel_mycred' );
  250. function relabel_mycred()
  251. {
  252.         return 'BinOPT';
  253. }
  254.  
  255.  
  256. // this action enqueues scripts and styles:
  257. // http://wpdevel.wordpress.com/2011/12/12/use-wp_enqueue_scripts-not-wp_print_styles-to-enqueue-scripts-and-styles-for-the-frontend/
  258. add_action('admin_enqueue_scripts', 'gavern_enqueue_admin_js_and_css');
  259.  
  260. // remove the generator metatag due security reasons
  261. remove_action('wp_head', 'wp_generator');
  262. // EOF
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top