Initial commit
This commit is contained in:
12
includes/back-end/editor_styles_and_scripts.php
Normal file
12
includes/back-end/editor_styles_and_scripts.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
function themeStarter_editor_enqueue()
|
||||
{
|
||||
add_theme_support('editor-styles');
|
||||
|
||||
add_editor_style([
|
||||
'assets/css/styles.css',
|
||||
'assets/css/bootstrap-icons.css',
|
||||
'assets/css/font-awesome.css'
|
||||
]);
|
||||
}
|
11
includes/back-end/query_adjustments.php
Normal file
11
includes/back-end/query_adjustments.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
function themeStarter_adjust_queries($query)
|
||||
{
|
||||
|
||||
// Projects Archive Query Adjustment
|
||||
if (!is_admin() and is_post_type_archive('project') and $query->is_main_query()) {
|
||||
$query->set('posts_per_page', '8');
|
||||
$query->set('order', 'ASC');
|
||||
}
|
||||
}
|
277
includes/back-end/wp_pg_blocks_helpers.php
Normal file
277
includes/back-end/wp_pg_blocks_helpers.php
Normal file
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Name: PG_Blocks
|
||||
* GitHub URI:
|
||||
* Description:
|
||||
* Version: 1.0
|
||||
* Author: Matjaz Trontelj - @pinegrow
|
||||
* License: GPL-2.0+
|
||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
*
|
||||
*/
|
||||
|
||||
if(! class_exists( 'PG_Blocks_v2' )) {
|
||||
class PG_Blocks_v2
|
||||
{
|
||||
|
||||
static $helpers_registered = false;
|
||||
|
||||
static $recursive_level = 0;
|
||||
|
||||
static $controls_version = '2';
|
||||
|
||||
static function register_block_type($reg_args)
|
||||
{
|
||||
if(empty($reg_args[ 'base_url' ])) {
|
||||
$reg_args[ 'base_url' ] = get_template_directory_uri();
|
||||
}
|
||||
|
||||
if(empty($reg_args[ 'base_path' ])) {
|
||||
$reg_args[ 'base_path' ] = get_template_directory();
|
||||
}
|
||||
|
||||
if(empty($reg_args[ 'version' ])) {
|
||||
$reg_args[ 'version' ] = false;
|
||||
}
|
||||
|
||||
$base_url = trailingslashit($reg_args[ 'base_url' ] );
|
||||
|
||||
if (!self::$helpers_registered) {
|
||||
self::$helpers_registered = true;
|
||||
|
||||
wp_register_script("pg-blocks-controls-" . self::$controls_version,
|
||||
$base_url . 'blocks/pg-blocks-controls-' . self::$controls_version . '.js',
|
||||
array('wp-blocks', 'wp-block-editor', 'wp-server-side-render', 'wp-media-utils', 'wp-data', 'wp-element'), $reg_args[ 'version' ]);
|
||||
|
||||
wp_register_style('pg-blocks-controls-style-' . self::$controls_version,
|
||||
$base_url . 'blocks/pg-blocks-controls-' . self::$controls_version . '.css',
|
||||
array(), $reg_args[ 'version' ]);
|
||||
}
|
||||
|
||||
$handle_prefix = 'block-' . str_replace('/', '-', $reg_args['name']);
|
||||
$editor_script_handle = $handle_prefix . '-script';
|
||||
$just_name = basename($reg_args['name']);
|
||||
$slug = dirname($reg_args['name']);
|
||||
|
||||
$style_handle = null;
|
||||
$script_handle = null;
|
||||
$view_script_handle = null;
|
||||
|
||||
if (!empty($reg_args['enqueue_style'])) {
|
||||
$style_handle = 'block-' . md5($reg_args['enqueue_style']);
|
||||
wp_register_style($style_handle, $reg_args['enqueue_style'], array(), $reg_args[ 'version' ]);
|
||||
}
|
||||
|
||||
$editor_style_handle = 'pg-blocks-controls-style-' . self::$controls_version;
|
||||
|
||||
if (!empty($reg_args['enqueue_editor_style'])) {
|
||||
$editor_style_handle = 'block-editor-' . md5($reg_args['enqueue_editor_style']);
|
||||
wp_register_style($editor_style_handle, $reg_args['enqueue_editor_style'], array('pg-blocks-controls-style-' . self::$controls_version), $reg_args[ 'version' ]);
|
||||
}
|
||||
|
||||
$script_dependencies = array('wp-blocks', 'wp-block-editor', 'wp-server-side-render', 'wp-media-utils', 'wp-data', 'wp-element', 'pg-blocks-controls-' . self::$controls_version);
|
||||
|
||||
if (!empty($reg_args['enqueue_script'])) {
|
||||
$script_handle = 'block-script-' . md5($reg_args['enqueue_script']);
|
||||
wp_register_script($script_handle, $reg_args['enqueue_script'], array(), $reg_args[ 'version' ], true);
|
||||
}
|
||||
|
||||
if (!empty($reg_args['enqueue_view_script'])) {
|
||||
$view_script_handle = 'block-script-' . md5($reg_args['enqueue_view_script']);
|
||||
wp_register_script($view_script_handle, $reg_args['enqueue_view_script'], array(), $reg_args[ 'version' ], true);
|
||||
}
|
||||
|
||||
if (!empty($reg_args['enqueue_editor_script'])) {
|
||||
$editor_custom_script_handle = 'block-script-' . md5($reg_args['enqueue_editor_script']);
|
||||
wp_register_script($editor_custom_script_handle, $reg_args['enqueue_editor_script'], $script_dependencies, $reg_args[ 'version' ]);
|
||||
$script_dependencies = array($editor_custom_script_handle);
|
||||
}
|
||||
|
||||
wp_register_script($editor_script_handle,
|
||||
$base_url . $reg_args[ 'js_file' ], $script_dependencies, $reg_args[ 'version' ]);
|
||||
|
||||
wp_localize_script($editor_script_handle,
|
||||
'pg_project_data_' . str_replace('-', '_', $slug),
|
||||
array(
|
||||
'url' => $base_url,
|
||||
)
|
||||
);
|
||||
|
||||
register_block_type($reg_args['name'], array(
|
||||
'render_callback' => empty($reg_args['dynamic']) ? null : function ($attributes, $content, $block) use ($reg_args) {
|
||||
self::$recursive_level++;
|
||||
if (self::$recursive_level > 10) {
|
||||
self::$recursive_level--;
|
||||
return 'Too many nested blocks... Are you including a post within itself?';
|
||||
}
|
||||
ob_start();
|
||||
$args = array('attributes' => $attributes, 'content' => $content, 'block' => $block);
|
||||
$template = trailingslashit($reg_args[ 'base_path' ]) . $reg_args['render_template'];
|
||||
if(file_exists( $template )) {
|
||||
require $template;
|
||||
} else {
|
||||
echo "<div>Dynamic block template $template not found.</div>";
|
||||
}
|
||||
self::$recursive_level--;
|
||||
return ob_get_clean();
|
||||
},
|
||||
'editor_script' => $editor_script_handle,
|
||||
'editor_style' => $editor_style_handle,
|
||||
'style' => $style_handle,
|
||||
'script' => $script_handle,
|
||||
'view_script' => $view_script_handle,
|
||||
'attributes' => $reg_args['attributes'],
|
||||
'supports' => isset($reg_args['supports']) ? $reg_args['supports'] : array()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
static function getDefault($args, $prop, $subprop = null)
|
||||
{
|
||||
if (isset($args['block']->block_type->attributes[$prop]['default'])) {
|
||||
if ($subprop) {
|
||||
if (isset($args['block']->block_type->attributes[$prop]['default'][$subprop])) {
|
||||
return $args['block']->block_type->attributes[$prop]['default'][$subprop];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return $args['block']->block_type->attributes[$prop]['default'];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static function getAttribute($args, $prop, $use_default = true, $null = false)
|
||||
{
|
||||
$val = isset($args['attributes']) && isset($args['attributes'][$prop]) ? $args['attributes'][$prop] : null;
|
||||
if (($val === null || $val === '') && $use_default) {
|
||||
$val = self::getDefault($args, $prop);
|
||||
}
|
||||
if($val === '' && $null) {
|
||||
$val = null;
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
static function getAttributeForAction($args, $prop, $field = null)
|
||||
{
|
||||
$val = self::getAttribute($args, $prop);
|
||||
if($field) {
|
||||
if(is_array($val) && isset($val[$field])) {
|
||||
return $val[$field];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if(is_array($val)) {
|
||||
if(isset($val['id'])) return $val['id'];
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
static function getAttributeAsPostIds($args, $prop)
|
||||
{
|
||||
$r = array();
|
||||
$list = self::getAttribute($args, $prop);
|
||||
if (is_array($list)) {
|
||||
foreach ($list as $item) {
|
||||
$r[] = $item['id'];
|
||||
}
|
||||
}
|
||||
if (count($r) === 0) $r[] = 0;
|
||||
return $r;
|
||||
}
|
||||
|
||||
static function getInnerContent($args)
|
||||
{
|
||||
return isset($args['content']) ? $args['content'] : '';
|
||||
}
|
||||
|
||||
static function getImageUrl($args, $prop, $size, $use_default = true)
|
||||
{
|
||||
$a = $args['attributes'];
|
||||
if (!isset($a[$prop])) return $use_default ? self::getDefault($args, $prop, 'url') : null;
|
||||
if (!empty($a[$prop]['url'])) {
|
||||
return $a[$prop]['url'];
|
||||
}
|
||||
if (empty($a[$prop]['id'])) return $use_default ? self::getDefault($args, $prop, 'url') : null;
|
||||
if (!empty($a[$prop]['size'])) {
|
||||
$size = $a[$prop]['size'];
|
||||
}
|
||||
return PG_Image::getUrl($a[$prop]['id'], $size);
|
||||
}
|
||||
|
||||
static function getImageSVG($args, $prop, $use_default = true)
|
||||
{
|
||||
return self::getImageField($args, $prop, 'svg', $use_default);
|
||||
}
|
||||
|
||||
static function getImageField($args, $prop, $field, $use_default = true)
|
||||
{
|
||||
$a = $args['attributes'];
|
||||
if (!isset($a[$prop])) return $use_default ? self::getDefault($args, $prop, $field) : null;
|
||||
if (!empty($a[$prop][$field])) {
|
||||
return $a[$prop][$field];
|
||||
}
|
||||
return $use_default ? self::getDefault($args, $prop, $field) : null;
|
||||
}
|
||||
|
||||
static function getLinkUrl($args, $prop, $use_default = true)
|
||||
{
|
||||
$a = self::getAttribute($args, $prop);
|
||||
if (is_array($a) && isset($a['url'])) {
|
||||
$val = $a['url'];
|
||||
} else {
|
||||
$val = $a;
|
||||
}
|
||||
if ($val === null || $val === '') $val = $use_default ? self::getDefault($args, $prop, 'url') : $val;
|
||||
return $val;
|
||||
}
|
||||
|
||||
static function mergeInlineSVGAttributes($svg, $props) {
|
||||
foreach($props as $prop => $val) {
|
||||
if($prop === 'className') $prop = 'class';
|
||||
if(is_array($val)) {
|
||||
$r = '';
|
||||
foreach($val as $key => $v) {
|
||||
$key = preg_replace_callback("/([A-Z])/g", function($m) {
|
||||
return '-'.strtolower($m[1]);
|
||||
}, $key);
|
||||
$r .= "$key:$v;";
|
||||
}
|
||||
$val = $r;
|
||||
}
|
||||
$q = '"';
|
||||
if(strpos($val, '"') >= 0) {
|
||||
$val = str_replace('"', """, $val);
|
||||
}
|
||||
$re = "/(<svg[^>]*\\s*)($prop=\"[^\"]*\")/i";
|
||||
if(preg_match($re, $svg)) {
|
||||
$svg = preg_replace($re, '$1' . $prop . '='.$q . $val . $q, $svg);
|
||||
} else {
|
||||
$svg = str_replace('<svg', "<svg $prop={$q}{$val}{$q}", $svg);
|
||||
}
|
||||
}
|
||||
return $svg;
|
||||
}
|
||||
|
||||
static function setupEditedPost() {
|
||||
global $wp_query, $post;
|
||||
if(!empty($_GET['context']) && $_GET['context'] === 'edit') {
|
||||
$referer = wp_get_raw_referer();
|
||||
if (!empty($referer)) {
|
||||
$url_info = parse_url($referer);
|
||||
$query = null;
|
||||
parse_str($url_info['query'], $query);
|
||||
if(!empty($query['post'])) {
|
||||
$post = get_post($query['post']);
|
||||
if(!empty($post)) {
|
||||
$wp_query->setup_postdata( $post );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
314
includes/back-end/wp_pg_helpers.php
Normal file
314
includes/back-end/wp_pg_helpers.php
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Name: PG_Image, PG_Helper...
|
||||
* GitHub URI:
|
||||
* Description:
|
||||
* Version: 1.0
|
||||
* Author: Matjaz Trontelj - @pinegrow
|
||||
* License: GPL-2.0+
|
||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
*
|
||||
*/
|
||||
|
||||
if(! class_exists( 'PG_Image' )) {
|
||||
class PG_Image
|
||||
{
|
||||
|
||||
static function removeSizeAttributes($img, $attr = null)
|
||||
{
|
||||
if ($attr == 'both' || $attr == 'width') {
|
||||
$img = preg_replace('/\swidth="[^"]*"/i', '', $img);
|
||||
}
|
||||
if ($attr == 'both' || $attr == 'height') {
|
||||
$img = preg_replace('/\sheight="[^"]*"/i', '', $img);
|
||||
}
|
||||
return $img;
|
||||
}
|
||||
|
||||
static function getUrl($image_or_url, $size)
|
||||
{
|
||||
if (is_array($image_or_url)) {
|
||||
if (!empty($image_or_url['sizes']) && !empty($image_or_url['sizes'][$size])) {
|
||||
return $image_or_url['sizes'][$size];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
if (!is_numeric($image_or_url)) {
|
||||
return $image_or_url;
|
||||
}
|
||||
return wp_attachment_is_image($image_or_url) ? wp_get_attachment_image_url($image_or_url, $size) : wp_get_attachment_url($image_or_url);
|
||||
}
|
||||
|
||||
static function getImages($list)
|
||||
{
|
||||
if (empty($list)) return array();
|
||||
if (is_string($list)) $list = explode(',', $list);
|
||||
$args = array(
|
||||
'post__in' => $list,
|
||||
'post_type' => 'attachment',
|
||||
'post_mime_type' => 'image',
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'post__in',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
return get_posts($args);
|
||||
}
|
||||
|
||||
static function isPostImage()
|
||||
{
|
||||
global $post;
|
||||
return $post->post_type === 'attachment' && !empty($post->post_mime_type) && strpos($post->post_mime_type, 'image') === 0;
|
||||
}
|
||||
|
||||
static function getPostImage($id, $size, $args, $remove_sizes = null, $default_img = null)
|
||||
{
|
||||
$img = '';
|
||||
|
||||
if (empty($id) && self::isPostImage()) {
|
||||
$img = wp_get_attachment_image(get_the_ID(), $size, false, $args);
|
||||
|
||||
} else if (has_post_thumbnail($id)) {
|
||||
$img = get_the_post_thumbnail($id, $size, $args);
|
||||
}
|
||||
|
||||
if (!empty($default_image) && empty($img)) {
|
||||
$img = $default_img;
|
||||
}
|
||||
|
||||
if (!empty($img) && !empty($remove_sizes)) {
|
||||
$img = self::removeSizeAttributes($img, $remove_sizes);
|
||||
}
|
||||
return $img;
|
||||
}
|
||||
|
||||
static function getAltText( $id, $default = '') {
|
||||
$r = trim( wp_strip_all_tags( get_post_meta( $id, '_wp_attachment_image_alt', true ) ) );
|
||||
return empty($r) ? $default : $r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(! class_exists( 'PG_Helper_v2' )) {
|
||||
class PG_Helper_v2
|
||||
{
|
||||
|
||||
static function getPostFromSlug($slug_or_id, $post_type)
|
||||
{
|
||||
if (is_numeric($slug_or_id)) {
|
||||
return $slug_or_id;
|
||||
}
|
||||
return get_page_by_path($slug_or_id, OBJECT, $post_type);
|
||||
}
|
||||
|
||||
static function getTermFromSlug($slug_or_id, $taxonomy)
|
||||
{
|
||||
if (is_numeric($slug_or_id)) {
|
||||
return $slug_or_id;
|
||||
}
|
||||
switch ($taxonomy) {
|
||||
case 'category':
|
||||
return get_category_by_slug($slug_or_id);
|
||||
default:
|
||||
return get_term_by('slug', $slug_or_id, $taxonomy);
|
||||
}
|
||||
}
|
||||
|
||||
static function getTermIDFromSlug($slug_or_id, $taxonomy, $def = -1)
|
||||
{
|
||||
if (is_numeric($slug_or_id)) {
|
||||
return $slug_or_id;
|
||||
}
|
||||
$term = self::getTermFromSlug($slug_or_id, $taxonomy);
|
||||
return $term ? $term->term_id : $def;
|
||||
}
|
||||
|
||||
static function addAttributesToElements($tag, $attrs, $html)
|
||||
{
|
||||
$attr_str = '';
|
||||
|
||||
foreach ($attrs as $name => $val) {
|
||||
$attr_str .= " {$name}";
|
||||
if (!is_null($val)) {
|
||||
$attr_str .= "=\"{$val}\"";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($attr_str)) {
|
||||
$html = str_replace("<{$tag} ", "<{$tag}{$attr_str} ", $html);
|
||||
$html = str_replace("<{$tag}>", "<{$tag}{$attr_str}>", $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
static $shown_posts = array();
|
||||
|
||||
static function rememberShownPost($p = null)
|
||||
{
|
||||
global $post;
|
||||
if (empty($p)) {
|
||||
$p = $post;
|
||||
}
|
||||
if (!empty($p) && !in_array($p->ID, self::$shown_posts)) {
|
||||
self::$shown_posts[] = $p->ID;
|
||||
}
|
||||
}
|
||||
|
||||
static function getShownPosts()
|
||||
{
|
||||
return self::$shown_posts;
|
||||
}
|
||||
|
||||
static function getInsightMetaFields()
|
||||
{
|
||||
$list = array();
|
||||
$meta = get_post_meta(get_the_ID());
|
||||
if ($meta) {
|
||||
foreach ($meta as $key => $values) {
|
||||
if (strpos($key, '_') !== 0) {
|
||||
$list[] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
echo '<!-- PG_FIELDS:' . implode(',', $list) . '-->';
|
||||
}
|
||||
|
||||
static function getRelationshipFieldValue($field)
|
||||
{
|
||||
if (function_exists('get_field')) {
|
||||
return get_field($field, false, false);
|
||||
} else {
|
||||
$value = get_post_meta(get_the_ID(), $field);
|
||||
if (empty($value)) {
|
||||
return null;
|
||||
}
|
||||
if (count($value) === 1) {
|
||||
if (strpos($value[0], 'a:') >= 0 && strpos($value[0], '{') >= 0) {
|
||||
return unserialize($value[0]);
|
||||
}
|
||||
if (is_string($value[0])) {
|
||||
return explode(',', $value[0]);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
static function getPostIdList($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return array(-1);
|
||||
}
|
||||
if (is_string($value)) {
|
||||
$value = explode(',', $value);
|
||||
}
|
||||
if (is_numeric($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
if (is_array($value) && count($value) === 0) {
|
||||
$value = array(-1);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
static function getBreadcrumbs($type = 'parents', $add_home = false, $home_label = '')
|
||||
{
|
||||
global $post;
|
||||
|
||||
$r = array();
|
||||
|
||||
if ($type === 'parents') {
|
||||
$parents = get_post_ancestors($post->ID);
|
||||
foreach ($parents as $parent_id) {
|
||||
$p = get_post($parent_id);
|
||||
$r[] = array(
|
||||
'name' => get_the_title($p),
|
||||
'link' => get_permalink($p)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$category = get_the_category($post->ID);
|
||||
|
||||
if (!empty($category)) {
|
||||
$parents = get_ancestors($category[0]->term_id, 'category');
|
||||
|
||||
array_unshift($parents, $category[0]->term_id);
|
||||
|
||||
foreach ($parents as $parent_id) {
|
||||
$p = get_category($parent_id);
|
||||
$r[] = array(
|
||||
'name' => $p->name,
|
||||
'link' => get_category_link($p)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( is_singular() ) {
|
||||
array_unshift($r, array(
|
||||
'name' => get_the_title($post),
|
||||
'link' => get_permalink($post)
|
||||
));
|
||||
}
|
||||
|
||||
if ($add_home) {
|
||||
$r[] = array(
|
||||
'name' => $home_label,
|
||||
'link' => home_url()
|
||||
);
|
||||
}
|
||||
|
||||
return array_reverse($r);
|
||||
}
|
||||
|
||||
static function getArray( $d, $separator = ',' ) {
|
||||
if(is_array( $d )) return $d;
|
||||
if(is_null( $d ) || $d === '') return array();
|
||||
if(is_string( $d )) {
|
||||
return array_map('trim', explode( $separator, $d));
|
||||
} else {
|
||||
return array( $d );
|
||||
}
|
||||
}
|
||||
|
||||
static function getTaxonomyQuery( $taxonomy, $terms ) {
|
||||
$is_or = true;
|
||||
if(is_string( $terms )) {
|
||||
if(strpos( $terms, '+') !== false) {
|
||||
$is_or = false;
|
||||
}
|
||||
}
|
||||
$terms = self::getArray( $terms, $is_or ? ',' : '+');
|
||||
if( count( $terms ) === 0 ) return null;
|
||||
|
||||
$field = 'term_id';
|
||||
for($i = 0; $i < count( $terms ); $i++) {
|
||||
if(!is_numeric( $terms[$i] )) {
|
||||
$field = 'slug';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'taxonomy' => $taxonomy,
|
||||
'field' => $field,
|
||||
'terms' => $terms,
|
||||
'include_children' => true,
|
||||
'operator' => $is_or ? 'IN' : 'AND'
|
||||
);
|
||||
}
|
||||
|
||||
static function getCurrentPost() {
|
||||
global $post;
|
||||
return $post;
|
||||
}
|
||||
}
|
||||
|
||||
//Compatibility with any existing custom code
|
||||
if(! class_exists( 'PG_Helper' )) {
|
||||
class PG_Helper extends PG_Helper_v2 {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
72
includes/back-end/wp_pg_pagination.php
Normal file
72
includes/back-end/wp_pg_pagination.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Name: PG_Pagination
|
||||
* GitHub URI:
|
||||
* Description:
|
||||
* Version: 1.0
|
||||
* Author: Matjaz Trontelj - @pinegrow
|
||||
* License: GPL-2.0+
|
||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class PG_Pagination
|
||||
{
|
||||
static function getQuery( $query = null ) {
|
||||
global $wp_query;
|
||||
|
||||
if(empty( $query )) {
|
||||
return $wp_query;
|
||||
} else {
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
static function getCurrentPage() {
|
||||
$name = 'paged';
|
||||
if ( 'page' == get_option( 'show_on_front' ) && is_front_page() ) {
|
||||
$name = 'page';
|
||||
}
|
||||
return intval(get_query_var( $name ) ? get_query_var( $name ) : 1);
|
||||
}
|
||||
|
||||
static function getMaxPages( $query = null ) {
|
||||
return self::getQuery( $query )->max_num_pages;
|
||||
}
|
||||
|
||||
static function isPaginated( $query = null ) {
|
||||
return self::getQuery( $query )->max_num_pages > 1;
|
||||
}
|
||||
|
||||
static function getNextPageUrl( $query = null ) {
|
||||
$max_pages = self::getMaxPages( $query );
|
||||
if(self::getCurrentPage() < $max_pages) {
|
||||
return get_pagenum_link( self::getCurrentPage() + 1 );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static function getPreviousPageUrl( $query = null ) {
|
||||
if(self::getCurrentPage() > 1) {
|
||||
return get_pagenum_link( self::getCurrentPage() - 1 );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static function getHrefAttribute( $url ) {
|
||||
if(empty( $url )) {
|
||||
return 'href="javascript:void(0)"';
|
||||
} else {
|
||||
return 'href="'.esc_url( $url ).'"';
|
||||
}
|
||||
}
|
||||
|
||||
static function getPreviousHrefAttribute( $query = null ) {
|
||||
return self::getHrefAttribute( self::getPreviousPageUrl( $query ));
|
||||
}
|
||||
|
||||
static function getNextHrefAttribute( $query = null ) {
|
||||
return self::getHrefAttribute( self::getNextPageUrl( $query ));
|
||||
}
|
||||
}
|
239
includes/back-end/wp_simple_form_mailer.php
Normal file
239
includes/back-end/wp_simple_form_mailer.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Name: PG_Simple_Form_Mailer
|
||||
* GitHub URI:
|
||||
* Description:
|
||||
* Version: 1.0
|
||||
* Author: Matjaz Trontelj - @pinegrow
|
||||
* License: GPL-2.0+
|
||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class PG_Simple_Form_Mailer {
|
||||
|
||||
static $captcha_script_included = false;
|
||||
|
||||
public $processed = false;
|
||||
public $error = true;
|
||||
public $message = 'The form was not submitted';
|
||||
public $text = null;
|
||||
public $html = null;
|
||||
|
||||
public function process( $arg_options = array() ) {
|
||||
|
||||
$admin_email = get_option('admin_email');
|
||||
|
||||
$options = array(
|
||||
'form_id' => 'contact_form',
|
||||
'send_to_email' => false,
|
||||
'email' => $admin_email,
|
||||
'title' => 'Contact form submission',
|
||||
'intro' => 'We received a new contact form submission:',
|
||||
'save_to_post_type' => null,
|
||||
'post_type' => null,
|
||||
'captcha' => false,
|
||||
'captcha_key' => null,
|
||||
'captcha_secret' => null,
|
||||
'include_captcha_script' => false,
|
||||
'log_ip' => true,
|
||||
'success_message' => 'Thank you for getting in touch!',
|
||||
'error_message' => 'There was a problem submitting this form. Please contact us directly.',
|
||||
'callback' => null
|
||||
);
|
||||
|
||||
//merge options
|
||||
foreach($arg_options as $key => $value) {
|
||||
$options[ $key ] = $value;
|
||||
}
|
||||
|
||||
if($options['captcha']) {
|
||||
if (!empty($options['include_captcha_script']) && !PG_Simple_Form_Mailer::$captcha_script_included) {
|
||||
echo '<script src="https://www.google.com/recaptcha/api.js" async defer></script>';
|
||||
PG_Simple_Form_Mailer::$captcha_script_included = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !empty($_POST[$options['form_id']]) ) {
|
||||
//the form was submitted
|
||||
//we assume the browser did the validation
|
||||
$lf = "\n\r";
|
||||
|
||||
$ignore_fields = array($options['form_id'], 'g-recaptcha-response');
|
||||
|
||||
$text = $options['intro'].$lf.$lf;
|
||||
$html = "<p>{$options['intro']}</p>";
|
||||
|
||||
$from_email = null;
|
||||
|
||||
$this->processed = true;
|
||||
|
||||
if($options['captcha']) {
|
||||
|
||||
if(empty($options['captcha_key']) || empty($options['captcha_secret'])) {
|
||||
$this->error = 'Captcha key and secret are not set.';
|
||||
return true;
|
||||
}
|
||||
|
||||
if(empty($_POST['g-recaptcha-response'])) {
|
||||
$this->error = 'Captcha response is not present.';
|
||||
return true;
|
||||
|
||||
} else if($this->validate_rechapcha($_POST['g-recaptcha-response'], $options['captcha_secret']) !== true) {
|
||||
$this->error = 'Captcha validation failed.';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$form_data = array();
|
||||
|
||||
foreach($_POST as $key => $value) {
|
||||
if(!in_array( $key, $ignore_fields)) {
|
||||
$key = htmlspecialchars($key);
|
||||
$value = htmlspecialchars($value);
|
||||
|
||||
$text .= "{$key}: {$value}".$lf;
|
||||
|
||||
if($key == 'email' || $key == 'Email') {
|
||||
$from_email = $value;
|
||||
}
|
||||
|
||||
$html .= "<p><b>{$key}</b>: {$value}</p>";
|
||||
|
||||
$form_data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$stamp = "Submitted on ".date("F j, Y, g:i a");
|
||||
if($options['log_ip'] && !empty($_SERVER['REMOTE_ADDR'])) {
|
||||
$stamp .= " from ".$_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
$text .= $stamp;
|
||||
$html .= "<p><em>{$stamp}</em></p>";
|
||||
|
||||
$this->text = $text;
|
||||
$this->html = $html;
|
||||
|
||||
$emailed = null;
|
||||
$saved = null;
|
||||
$called = null;
|
||||
|
||||
if($options['send_to_email']) {
|
||||
$headers = 'From: '. $admin_email . "\r\n";
|
||||
|
||||
$email_data = array(
|
||||
'headers' => $headers,
|
||||
'subject' => $options['title'],
|
||||
'content' => $text,
|
||||
'data' => $form_data
|
||||
);
|
||||
|
||||
$email_data = apply_filters( 'pg_form_email', $email_data);
|
||||
|
||||
$emailed = wp_mail($options['email'], $email_data['subject'], $email_data['content'], $email_data['headers']);
|
||||
}
|
||||
if($options['save_to_post_type']) {
|
||||
if(wp_insert_post( array(
|
||||
'post_title' => $options['title'].(!empty( $from_email ) ? (" - ".$from_email) : ""),
|
||||
'post_content' => $html,
|
||||
'post_type' => $options['post_type'],
|
||||
'post_status' => 'private'
|
||||
) )) {
|
||||
$saved = true;
|
||||
} else {
|
||||
$saved = false;
|
||||
}
|
||||
}
|
||||
|
||||
if($options['callback']) {
|
||||
if(function_exists($options['callback'])) {
|
||||
$called = call_user_func($options['callback'], $form_data, $options);
|
||||
} else {
|
||||
$called = false;
|
||||
}
|
||||
}
|
||||
|
||||
if((!$emailed && !$saved && !$called) || $emailed === false || $saved === false || $called === false) {
|
||||
$this->error = true;
|
||||
$this->message = $options['error_message'];
|
||||
} else {
|
||||
$this->error = false;
|
||||
$this->message = $options['success_message'];
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
//the form was not submitted
|
||||
$this->processed = false;
|
||||
$this->error = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//source https://gist.github.com/jonathanstark/dfb30bdfb522318fc819
|
||||
public function validate_rechapcha($response, $secret)
|
||||
{
|
||||
// Verifying the user's response (https://developers.google.com/recaptcha/docs/verify)
|
||||
$verifyURL = 'https://www.google.com/recaptcha/api/siteverify';
|
||||
|
||||
$query_data = [
|
||||
'secret' => $secret,
|
||||
'response' => $response,
|
||||
'remoteip' => (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER['REMOTE_ADDR'])
|
||||
];
|
||||
|
||||
// Collect and build POST data
|
||||
$post_data = http_build_query($query_data, '', '&');
|
||||
|
||||
// Send data on the best possible way
|
||||
if (function_exists('curl_init') && function_exists('curl_setopt') && function_exists('curl_exec'))
|
||||
{
|
||||
// Use cURL to get data 10x faster than using file_get_contents or other methods
|
||||
$ch = curl_init($verifyURL);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-type: application/x-www-form-urlencoded'));
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If server not have active cURL module, use file_get_contents
|
||||
$opts = array('http' =>
|
||||
array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||
'content' => $post_data
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
$response = file_get_contents($verifyURL, false, $context);
|
||||
}
|
||||
|
||||
// Verify all reponses and avoid PHP errors
|
||||
if ($response)
|
||||
{
|
||||
$result = json_decode($response);
|
||||
if ($result->success === true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Dead end
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
279
includes/back-end/wp_smart_navwalker.php
Normal file
279
includes/back-end/wp_smart_navwalker.php
Normal file
@@ -0,0 +1,279 @@
|
||||
<?php
|
||||
/**
|
||||
* Class Name: PG_Smart_Walker_Nav_Menu
|
||||
* GitHub URI:
|
||||
* Description:
|
||||
* Version: 2.0
|
||||
* Author: Matjaz Trontelj - @pinegrow
|
||||
* License: GPL-2.0+
|
||||
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
* Based on WordPress Walker_Nav_Menu code
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class PG_Smart_Walker_Nav_Menu extends Walker_Nav_Menu {
|
||||
|
||||
private static $default_options = array(
|
||||
'top_element' => 'ul',
|
||||
'sub_element' => 'ul',
|
||||
'current_class' => 'current-menu-item',
|
||||
'sub_menu_class' => 'sub-menu',
|
||||
'item_id_prefix' => 'menu-item-',
|
||||
'template' => '<li id="{ID}" class="{CLASSES}">{LINK_BEFORE}<a {ATTRS}>{TITLE}</a>{LINK_AFTER}</li>',
|
||||
'template_item_with_sublevel' => null,
|
||||
'template_sublevel' => null,
|
||||
'template_subitem' => null
|
||||
);
|
||||
|
||||
public static $options = array();
|
||||
|
||||
private static $level = 0;
|
||||
private static $current_id = '';
|
||||
private static $count = 0;
|
||||
|
||||
public static function init() {
|
||||
self::$options = self::$default_options;
|
||||
self::$level = 0;
|
||||
self::$current_id = '';
|
||||
self::$count++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the begining or end part of the template
|
||||
*
|
||||
* @param boolean $start true for begining, false for end part
|
||||
*/
|
||||
private function get_template_part( $start = true, $template = 'template' ) {
|
||||
$parts = explode('{SUB}', self::$options[ $template ]);
|
||||
if(count($parts) == 2) {
|
||||
return $start ? $parts[0] : $parts[1];
|
||||
}
|
||||
//if {SUB} is missing from the template, assume the last closing tag is the end part
|
||||
$idx = strrpos(self::$options[ $template ], '</');
|
||||
if($idx !== false) {
|
||||
return $start ? substr(self::$options[ $template ], 0, $idx) : substr(self::$options[ $template ], $idx);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the list before the elements are added.
|
||||
*
|
||||
* @see Walker::start_lvl()
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param array $args An array of arguments. @see wp_nav_menu()
|
||||
*/
|
||||
public function start_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
self::$level++;
|
||||
|
||||
$indent = str_repeat("\t", $depth);
|
||||
|
||||
if(self::$level > 0 && self::$options['template_sublevel']) {
|
||||
$output .= "\n$indent" . str_replace('{ID}', self::$current_id,self::get_template_part(true, 'template_sublevel'));
|
||||
} else {
|
||||
$tag = $depth == 0 ? self::$options['top_element'] : self::$options['sub_element'];
|
||||
if (!empty($tag)) {
|
||||
$class = self::$options['sub_menu_class'];
|
||||
$output .= "\n$indent<$tag class=\"$class\">\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the list of after the elements are added.
|
||||
*
|
||||
* @see Walker::end_lvl()
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param array $args An array of arguments. @see wp_nav_menu()
|
||||
*/
|
||||
public function end_lvl( &$output, $depth = 0, $args = array() ) {
|
||||
$indent = str_repeat("\t", $depth);
|
||||
|
||||
if(self::$level > 0 && self::$options['template_sublevel']) {
|
||||
$output .= "\n$indent" . self::get_template_part(false, 'template_sublevel');
|
||||
} else {
|
||||
$tag = $depth == 0 ? self::$options['top_element'] : self::$options['sub_element'];
|
||||
if (!empty($tag)) {
|
||||
$output .= "$indent</$tag>\n";
|
||||
}
|
||||
}
|
||||
self::$level--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the element output.
|
||||
*
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content.
|
||||
* @param object $item Menu item data object.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param array $args An array of arguments. @see wp_nav_menu()
|
||||
* @param int $id Current item ID.
|
||||
*/
|
||||
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
|
||||
|
||||
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
|
||||
$classes[] = 'menu-item-' . $item->ID;
|
||||
|
||||
/**
|
||||
* Filter the CSS class(es) applied to a menu item's list item element.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 4.1.0 The `$depth` parameter was added.
|
||||
*
|
||||
* @param array $classes The CSS classes that are applied to the menu item's `<li>` element.
|
||||
* @param object $item The current menu item.
|
||||
* @param array $args An array of {@see wp_nav_menu()} arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth );
|
||||
|
||||
foreach($classes as $i => $class) {
|
||||
if($classes[$i] == 'current-menu-item') {
|
||||
$classes[$i] = self::$options['current_class'];
|
||||
}
|
||||
}
|
||||
$class_names = join( ' ', $classes);
|
||||
|
||||
/**
|
||||
* Filter the ID applied to a menu item's list item element.
|
||||
*
|
||||
* @since 3.0.1
|
||||
* @since 4.1.0 The `$depth` parameter was added.
|
||||
*
|
||||
* @param string $menu_id The ID that is applied to the menu item's `<li>` element.
|
||||
* @param object $item The current menu item.
|
||||
* @param array $args An array of {@see wp_nav_menu()} arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$id = apply_filters( 'nav_menu_item_id', self::$options['item_id_prefix']. $item->ID, $item, $args, $depth );
|
||||
|
||||
if(empty($id)) {
|
||||
//most likely the default id was already used. Set a count based id
|
||||
$id = self::$options['item_id_prefix'].self::$count.'-'.$item->ID;
|
||||
}
|
||||
|
||||
self::$current_id = $id;
|
||||
|
||||
$output .= $indent;
|
||||
|
||||
$atts = array();
|
||||
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
|
||||
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
|
||||
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
|
||||
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
|
||||
|
||||
/**
|
||||
* Filter the HTML attributes applied to a menu item's anchor element.
|
||||
*
|
||||
* @since 3.6.0
|
||||
* @since 4.1.0 The `$depth` parameter was added.
|
||||
*
|
||||
* @param array $atts {
|
||||
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
|
||||
*
|
||||
* @type string $title Title attribute.
|
||||
* @type string $target Target attribute.
|
||||
* @type string $rel The rel attribute.
|
||||
* @type string $href The href attribute.
|
||||
* }
|
||||
* @param object $item The current menu item.
|
||||
* @param array $args An array of {@see wp_nav_menu()} arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
|
||||
|
||||
$attributes = '';
|
||||
foreach ( $atts as $attr => $value ) {
|
||||
if ( ! empty( $value ) ) {
|
||||
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
|
||||
$attributes .= ' ' . $attr . '="' . $value . '"';
|
||||
}
|
||||
}
|
||||
|
||||
$item_output = $args->before;
|
||||
|
||||
$has_sublevel = false;
|
||||
|
||||
if(isset($item->classes) && in_array('menu-item-has-children', $item->classes)) {
|
||||
$has_sublevel = true;
|
||||
}
|
||||
|
||||
$template_key = 'template';
|
||||
if(self::$level === 0 && $has_sublevel && self::$options['template_item_with_sublevel']) {
|
||||
$template_key = 'template_item_with_sublevel';
|
||||
} else if(self::$level > 0 && self::$options['template_subitem']) {
|
||||
$template_key = 'template_subitem';
|
||||
}
|
||||
|
||||
$template = $this->get_template_part(true, $template_key);
|
||||
$template = str_replace( '{LINK_BEFORE}', $args->link_before, $template);
|
||||
$template = str_replace( '{LINK_AFTER}', $args->link_after, $template);
|
||||
$template = str_replace( '{TITLE}', apply_filters( 'the_title', $item->title, $item->ID ), $template);
|
||||
|
||||
$template = str_replace( '{ATTRS}', $attributes, $template);
|
||||
$template = str_replace( '{ID}', $id, $template);
|
||||
$template = str_replace( '{CLASSES}', $class_names, $template);
|
||||
|
||||
$item_output .= $template;
|
||||
|
||||
$item_output .= $args->after;
|
||||
|
||||
/**
|
||||
* Filter a menu item's starting output.
|
||||
*
|
||||
* The menu item's starting output only includes `$args->before`, the opening `<a>`,
|
||||
* the menu item's title, the closing `</a>`, and `$args->after`. Currently, there is
|
||||
* no filter for modifying the opening and closing `<li>` for a menu item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $item_output The menu item's starting HTML output.
|
||||
* @param object $item Menu item data object.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param array $args An array of {@see wp_nav_menu()} arguments.
|
||||
*/
|
||||
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the element output, if needed.
|
||||
*
|
||||
* @see Walker::end_el()
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content.
|
||||
* @param object $item Page data object. Not used.
|
||||
* @param int $depth Depth of page. Not Used.
|
||||
* @param array $args An array of arguments. @see wp_nav_menu()
|
||||
*/
|
||||
public function end_el( &$output, $item, $depth = 0, $args = array() ) {
|
||||
$has_sublevel = false;
|
||||
|
||||
if(isset($item->classes) && in_array('menu-item-has-children', $item->classes)) {
|
||||
$has_sublevel = true;
|
||||
}
|
||||
|
||||
$template_key = 'template';
|
||||
if(self::$level === 0 && $has_sublevel && self::$options['template_item_with_sublevel']) {
|
||||
$template_key = 'template_item_with_sublevel';
|
||||
} else if(self::$level > 0 && self::$options['template_subitem']) {
|
||||
$template_key = 'template_subitem';
|
||||
}
|
||||
$output .= $this->get_template_part(false, $template_key)."\n"; //get the ending part of the template
|
||||
}
|
||||
|
||||
} // PG_Smart_Walker_Nav_Menu
|
19
includes/front-end/custom_login_screen.php
Normal file
19
includes/front-end/custom_login_screen.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Change Login Page header url
|
||||
function ourHeaderUrl()
|
||||
{
|
||||
return esc_url(site_url('/'));
|
||||
}
|
||||
|
||||
// Make login title the name of our website
|
||||
function ourLoginTitle()
|
||||
{
|
||||
return get_bloginfo('name');
|
||||
}
|
||||
|
||||
// Enqueue out stylesheet for login screen
|
||||
function ourLoginCSS()
|
||||
{
|
||||
wp_enqueue_style('login styles', get_theme_file_uri('/assets/css/styles.css'));
|
||||
}
|
13
includes/front-end/registration_form_message.php
Normal file
13
includes/front-end/registration_form_message.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
// Change Registration Message
|
||||
function change_reg_message($message)
|
||||
{
|
||||
// change messages that contain 'Register'
|
||||
if (strpos($message, 'Register') !== FALSE) {
|
||||
$newMessage = "Register with " . get_bloginfo('name');
|
||||
return '<p class="message register">' . $newMessage . '</p>';
|
||||
} else {
|
||||
return $message;
|
||||
}
|
||||
}
|
23
includes/front-end/styles_and_scripts.php
Normal file
23
includes/front-end/styles_and_scripts.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
// Enqueue styles and scripts
|
||||
function themeStarter_enqueue()
|
||||
{
|
||||
|
||||
/* Register and Enqueue Scripts */
|
||||
|
||||
wp_register_script('themeStarter-app', get_parent_theme_file_uri('/assets/js/index.js'), [], '1.0', true);
|
||||
wp_enqueue_script('themeStarter-app');
|
||||
|
||||
|
||||
/* Register and Enqueue Styles */
|
||||
|
||||
wp_register_style('themeStarter-styles', get_parent_theme_file_uri('/assets/css/styles.css'), [], '1.0', 'all');
|
||||
wp_enqueue_style('themeStarter-styles');
|
||||
|
||||
wp_register_style('bootstrap-icons', get_parent_theme_file_uri('/assets/css/bootstrap-icons.css'), [], '1.11.1', 'all');
|
||||
wp_enqueue_style('bootstrap-icons');
|
||||
|
||||
wp_register_style('font-awesome', get_parent_theme_file_uri('/assets/css/font-awesome.css'), [], '6.4.2', 'all');
|
||||
wp_enqueue_style('font-awesome');
|
||||
}
|
35
includes/front-end/technical_seo.php
Normal file
35
includes/front-end/technical_seo.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
function open_graph_twitter_card()
|
||||
{
|
||||
// Get the post or page ID
|
||||
$post_id = get_the_ID();
|
||||
|
||||
// Get the post or page title
|
||||
$title = get_the_title($post_id);
|
||||
|
||||
// Get the post or page excerpt (description)
|
||||
$description = (get_the_excerpt()) ? get_the_excerpt() : get_bloginfo('description');
|
||||
|
||||
// Get the post or page URL
|
||||
$url = get_permalink($post_id);
|
||||
|
||||
// Set default image url
|
||||
$default_image_url = get_theme_file_uri('/screenshot.png');
|
||||
|
||||
// Get the post thumbnail (featured image) URL
|
||||
$thumbnail = get_the_post_thumbnail_url($post_id);
|
||||
?>
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:title" content="<?php echo $title . ' - ' . get_bloginfo('name'); ?>" />
|
||||
<meta property="og:description" content="<?php echo $description ?>" />
|
||||
<meta property="og:url" content="<?php echo $url ?>" />
|
||||
<meta property="og:image" content="<?php echo $default_image_url ?>" />
|
||||
<!-- Twitter Card meta tags -->
|
||||
<meta name="twitter:card" content="summary" />
|
||||
<meta name="twitter:title" content="<?php echo $title . ' - ' . get_bloginfo('name'); ?>" />
|
||||
<meta name="twitter:description" content="<?php echo $description ?>" />
|
||||
<meta name="twitter:image" content="<?php echo $default_image_url ?>" />
|
||||
<?php
|
||||
|
||||
}
|
84
includes/front-end/theme_starter_setup.php
Normal file
84
includes/front-end/theme_starter_setup.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
function themeStarter_setup()
|
||||
{
|
||||
|
||||
/*
|
||||
* Make theme available for translation.
|
||||
* Translations can be filed in the /languages/ directory.
|
||||
*/
|
||||
|
||||
load_theme_textdomain('themeStarter', get_template_directory() . '/languages');
|
||||
|
||||
// Add default posts and comments RSS feed links to head.
|
||||
add_theme_support('automatic-feed-links');
|
||||
|
||||
/*
|
||||
* Let WordPress manage the document title.
|
||||
*/
|
||||
add_theme_support('title-tag');
|
||||
|
||||
/*
|
||||
* Enable support for Post Thumbnails on posts and pages.
|
||||
*/
|
||||
add_theme_support('post-thumbnails');
|
||||
//Support custom logo
|
||||
add_theme_support('custom-logo');
|
||||
|
||||
// Add menus.
|
||||
register_nav_menus(
|
||||
array(
|
||||
'primary' => __('Primary Menu', 'themeStarter'),
|
||||
'secondary' => __('Secondary Menu', 'themeStarter'),
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
* Switch default core markup for search form, comment form, and comments
|
||||
* to output valid HTML5.
|
||||
*/
|
||||
|
||||
add_theme_support(
|
||||
'html5',
|
||||
array(
|
||||
'search-form',
|
||||
'comment-form',
|
||||
'comment-list',
|
||||
'gallery',
|
||||
'caption',
|
||||
'style',
|
||||
'script'
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
* Enable support for Post Formats.
|
||||
*/
|
||||
|
||||
add_theme_support(
|
||||
'post-formats',
|
||||
array(
|
||||
'aside',
|
||||
'image',
|
||||
'video',
|
||||
'quote',
|
||||
'link',
|
||||
'gallery',
|
||||
'status',
|
||||
'audio',
|
||||
'chat'
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
* Enable support for Page excerpts.
|
||||
*/
|
||||
add_post_type_support('page', 'excerpt');
|
||||
}
|
||||
|
||||
function themeStarter_init()
|
||||
{
|
||||
// Use categories and tags with attachments
|
||||
register_taxonomy_for_object_type('category', 'attachment');
|
||||
register_taxonomy_for_object_type('post_tag', 'attachment');
|
||||
}
|
Reference in New Issue
Block a user