custom post type and ACF json syncing
This commit is contained in:
60
app/ACF/Dynamic.php
Normal file
60
app/ACF/Dynamic.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\ACF;
|
||||
|
||||
class Dynamic
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_filter('acf/load_field/name=fontawesome_regular', [ $this, 'load_fontawesome_regular_icons' ]);
|
||||
add_filter('acf/load_field/name=fontawesome_solid', [ $this, 'load_fontawesome_solid_icons' ]);
|
||||
add_filter('acf/load_field/name=fontawesome_brands', [ $this, 'load_fontawesome_brand_icons' ]);
|
||||
}
|
||||
|
||||
public function load_fontawesome_regular_icons( $field )
|
||||
{
|
||||
$field['choices'] = [];
|
||||
$field['choices'] = $this->fontawesome_choices('regular');
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function load_fontawesome_solid_icons( $field )
|
||||
{
|
||||
$field['choices'] = [];
|
||||
$field['choices'] = $this->fontawesome_choices('solid');
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function load_fontawesome_brand_icons( $field )
|
||||
{
|
||||
$field['choices'] = [];
|
||||
$field['choices'] = $this->fontawesome_choices('brands');
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function fontawesome_choices($set = 'solid')
|
||||
{
|
||||
$path = get_stylesheet_directory() . '/resources/json/font-awesome-' . $set . '.json';
|
||||
|
||||
$json = @file_get_contents($path);
|
||||
|
||||
if(!$json) return false;
|
||||
$icons = json_decode($json, true);
|
||||
|
||||
$choices = [
|
||||
'0' => '<i class="fa-solid"></i> <span>Please select an icon</span>',
|
||||
];
|
||||
|
||||
foreach($icons as $slug => $props):
|
||||
if(in_array($slug, range(0,9))) continue;
|
||||
|
||||
$choices[$slug] = '<i class="fa-'.$set.' fa-'.$slug.'" style="color: #2271b1;"></i> <span>' . (ucwords(str_replace('-', ' ', $slug))) . '</span>';
|
||||
endforeach;
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
|
||||
25
app/ACF/JSON.php
Normal file
25
app/ACF/JSON.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\ACF;
|
||||
|
||||
class JSON
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_filter('acf/settings/save_json', [$this, 'save']);
|
||||
add_filter('acf/settings/load_json', [$this, 'load']);
|
||||
}
|
||||
|
||||
public function save( $path )
|
||||
{
|
||||
$path = get_stylesheet_directory() . '/acf-json';
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function load( $paths )
|
||||
{
|
||||
unset($paths[0]);
|
||||
$paths[] = get_stylesheet_directory() . '/acf-json';
|
||||
return $paths;
|
||||
}
|
||||
}
|
||||
22
app/Admin/Enqueue.php
Normal file
22
app/Admin/Enqueue.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin;
|
||||
|
||||
class Enqueue
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_action( 'admin_enqueue_scripts', [$this, 'fontawesome']);
|
||||
}
|
||||
|
||||
public function fontawesome()
|
||||
{
|
||||
wp_enqueue_style(
|
||||
'fontawesome',
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css',
|
||||
false,
|
||||
'6.5.2',
|
||||
'all'
|
||||
);
|
||||
}
|
||||
}
|
||||
57
app/PostTypes/Social.php
Normal file
57
app/PostTypes/Social.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\PostTypes;
|
||||
|
||||
class Social
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_action('init', [$this, 'register']);
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
$td = 'sage';
|
||||
$postType = 'social';
|
||||
|
||||
register_extended_post_type(
|
||||
$postType,
|
||||
[
|
||||
'menu_position' => 28,
|
||||
'supports' => [
|
||||
'title',
|
||||
'page-attributes',
|
||||
],
|
||||
'menu_icon' => 'dashicons-share',
|
||||
'rewrite' => false,
|
||||
'has_archive' => false,
|
||||
'publicly_queryable' => false,
|
||||
'exclude_from_search' => true,
|
||||
'capability_type' => 'page',
|
||||
'show_in_nav_menus' => false,
|
||||
'admin_cols' => [
|
||||
'social_link' => [
|
||||
'title' => __('Social Link', $td),
|
||||
'meta_key' => 'fontawesome_brands',
|
||||
'function' => function(){
|
||||
$icon = get_field('fontawesome_brands');
|
||||
$url = get_field('url');
|
||||
|
||||
if($icon): ?>
|
||||
|
||||
<a
|
||||
href="<?= $url ?: '#' ?>"
|
||||
class="fa-brands fa-<?= $icon ?>"
|
||||
rel="nofollow noindex"
|
||||
style="font-size: 2em;"
|
||||
></a>
|
||||
|
||||
<?php endif;
|
||||
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,26 @@ if (! function_exists('\Roots\bootloader')) {
|
||||
|
||||
\Roots\bootloader()->boot();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoload PSR-4 files
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
function autoload_psr4($name) {
|
||||
$path = __dir__ . '/app/' . $name . '/*.php';
|
||||
$namespace = 'App\\' . $name;
|
||||
|
||||
foreach(glob($path) as $filename) {
|
||||
$class = $namespace . '\\' . basename($filename, '.php');
|
||||
new $class();
|
||||
}
|
||||
}
|
||||
|
||||
autoload_psr4('PostTypes');
|
||||
autoload_psr4('ACF');
|
||||
autoload_psr4('Admin');
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Sage Theme Files
|
||||
|
||||
3061
resources/json/font-awesome-brands.json
Normal file
3061
resources/json/font-awesome-brands.json
Normal file
File diff suppressed because one or more lines are too long
1119
resources/json/font-awesome-regular.json
Normal file
1119
resources/json/font-awesome-regular.json
Normal file
File diff suppressed because it is too large
Load Diff
9228
resources/json/font-awesome-solid.json
Normal file
9228
resources/json/font-awesome-solid.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user