Skip to content

Instantly share code, notes, and snippets.

@emanuele45
Created March 31, 2015 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emanuele45/ddc0585c059fc962fb6d to your computer and use it in GitHub Desktop.
Save emanuele45/ddc0585c059fc962fb6d to your computer and use it in GitHub Desktop.
WP theme wrapper
<?php
/**
* @name ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
*
* @version 1.0.2
*
*/
if (!defined('WP_THEME_DIR'))
define('WP_THEME_DIR', 'twentyfifteen');
function add_action()
{
}
function is_admin()
{
global $user_info;
return $user_info['is_admin'];
}
function language_attributes()
{
global $context;
return $context['right_to_left'] ? ' dir="rtl"' : '';
}
function bloginfo($show)
{
return get_bloginfo($show, 'display');
}
function get_bloginfo($show, $filter)
{
global $scripturl, $context;
$known = array(
'charset' => 'utf-8',
'pingback_url' => $scripturl,
'description' => '',
'name' => $context['forum_name'],
);
if (isset($known[$show]))
echo $known[$show];
else
{
log_error('Unknown blog param &quot;' . $show . '&quot;');
echo '';
}
}
function is_customize_preview()
{
return false;
}
function get_sidebar()
{
get_template_part('sidebar');
}
function has_nav_menu ($type)
{
if ($type == 'primary')
return true;
else
return false;
}
function wp_nav_menu($params)
{
template_menu();
}
function is_active_sidebar($sidebar)
{
return false;
}
function esc_url($url)
{
if ($url === 'https://wordpress.org/')
$url = 'http://elkarte.net/';
return $url;
}
function get_template_directory_uri()
{
global $settings;
return $settings['theme_url'];
}
function is_front_page()
{
global $context;
return empty($context['current_action']);
}
function is_home()
{
global $context;
return empty($context['current_action']);
}
function home_url()
{
global $scripturl;
return $scripturl;
}
function have_posts()
{
global $context, $wpwrapper;
if (is_home())
return !empty($context['categories']) && !$wpwrapper['completed'];
// elseif (
}
function the_post()
{
global $context, $wpwrapper;
static $keys, $init = false;
$wpwrapper['completed'] = false;
if (is_home())
{
if (empty($keys) && $init)
{
$wpwrapper['completed'] = true;
return false;
}
if (empty($keys) && !$init)
{
$keys = array_keys($context['categories']);
$init = true;
}
$id = array_shift($keys);
$content = '<dl>';
foreach ($context['categories'][$id]['boards'] as $k => $board)
{
$content .= '<dt><h3><a href="' . $board['href'] . '">' . $board['name'] . '</a></h3></dt>';
$content .= '<dd>' . $board['description'] . '</dd>';
}
$content .= '</dl>';
$wpwrapper['post'] = array(
'id' => $context['categories'][$id]['id'],
'type' => 'category',
'status' => 'publish',
'sticky' => false,
'url' => $context['categories'][$id]['href'],
'name' => $context['categories'][$id]['name'],
'content' => $content,
);
}
}
function add_filter()
{
}
function has_post_thumbnail()
{
return false;
}
function comments_open()
{
return false;
}
function get_comments_number()
{
return 0;
}
function the_posts_pagination()
{
global $context;
// if (!empty($context['links']))
return false;
}
function the_ID()
{
global $wpwrapper;
echo $wpwrapper['post']['id'];
}
function post_class()
{
global $wpwrapper;
$classes = array();
$classes[] = 'post-' . $wpwrapper['post']['id'];
$classes[] = 'type-' . $wpwrapper['post']['type'];
$classes[] = 'status-' . $wpwrapper['post']['status'];
if ($wpwrapper['post']['sticky'])
$classes[] = 'sticky';
$classes[] = 'hentry';
echo 'class="' . join(' ', array_unique($classes)) . '"';
}
function post_password_required()
{
return allowedTo('post_reply');
}
function is_single()
{
return false;
}
function the_title($pre, $post, $echo = true)
{
global $wpwrapper;
$title = $pre . $wpwrapper['post']['name'] . $post;
if ($echo)
echo $title;
else
return $title;
}
function get_permalink()
{
global $wpwrapper;
return $wpwrapper['post']['url'];
}
function the_content($more = '')
{
global $wpwrapper;
echo $wpwrapper['post']['content'];
}
function get_template_part($template)
{
include(__DIR__ . '/' . WP_THEME_DIR . '/' . $template . '.php');
}
function get_post_format()
{
return '';
}
function wp_link_pages()
{
global $context;
if (!empty($context['page_index']))
echo $context['page_index'];
}
function is_sticky()
{
return false;
}
function current_theme_supports($function)
{
return false;
}
function get_post_type()
{
return null;
}
function is_attachment()
{
return false;
}
function edit_post_link()
{
return false;
}
function get_header()
{
get_template_part('header');
}
function get_footer()
{
get_template_part('footer');
}
function do_action()
{
}
function wp_footer()
{
}
function body_class()
{
global $context, $settings, $scripturl, $txt, $modSettings;
echo 'id="', $context['browser_body_id'], '" class="action_', !empty($context['current_action']) ? htmlspecialchars($context['current_action'], ENT_COMPAT, 'UTF-8') : (!empty($context['current_board']) ?
'messageindex' : (!empty($context['current_topic']) ? 'display' : 'home')), !empty($context['current_board']) ? ' board_' . htmlspecialchars($context['current_board'], ENT_COMPAT, 'UTF-8') : '', '"';
}
function __($text)
{
return _e($text);
}
function _e($text, $path = '')
{
static $parser = null;
if ($parser === null)
{
require_once(__DIR__ . '/vendor/autoload.php');
$parser = new Sepia\PoParser();
$entries = $parser->parseFile(__DIR__ . '/' . WP_THEME_DIR . '/languages/' . WP_THEME_DIR . '.pot');
}
if ($text === 'Proudly powered by %s')
$text = 'Proudly powered by ElkArte';
if (isset($entries[$text]))
return $entries[$text];
else
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment