add_action('admin_init', function () { // Branding add_filter('admin_footer_text', function ($text) { $aeria_logo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAKCAYAAAC9vt6cAAACEUlEQVQoFV1SzWsTQRR/MztJuul2E7PZkrVtWmmJCqEWKljRQ0WEIgiCKLReAt68tJcevBUpgsGDXvwDFEEU2kLwIB56VWqFqkHToDY1bWzSfLGzzSbZD3dWU8SBN8z8vt6DGVSsUh/8Xb1HhOb0k49zalCZUdtmD8bowzkZ3108L2c6mn/1DEMMqNKG5/iATKeXcsltvn9e1OswFukCv8jD5rdfdQk1pzReELoblD68MvTWtm1SqmncYQDrvLC0EU+V+I2w6MeJs7KtCAg1gbNpG6GVtb16UTMDzGDqjcdvEiOznQDMujOi5gkIqtbCl6IEQgKBArVthvfxtnV5NCReHwsBq5OycPvag9dTrCnzEjb6XGpr4l1m7766WwE4E4YKNYBNEOuxWAaSOAybNXADYTiAsmnfwuLy2mfHu4Wcw9DyFyPLlBdOBLnBQQU1dR0uDosgdHvANNwQRrtrp1i3VrImzqa/rj+aiU+StOq7uru/T26MR1qOmTBzn88E07SAau2Oz72zS5fXg+PBA6N1VBq/83x9khzkcnVH6VARKFdUQ+FNiEoB0tCbf0Y+jABoGaaLjch+nC9UIF8taziZmHgpaTur39OfvFSlnEMQy7JcIXY+QqdYjpdwiBU769Xys1f3bq6izM+S8GM7f/rpi9QtRoA/FB6NDdiK0uu+jov9txUKxfapWDR5LNr//jfP/ulncDnamgAAAABJRU5ErkJggg=='; return $text . ' - Powered by <img src="' . $aeria_logo . '" title="Aeria"> Aeria ' . AERIA . ' by <a href="http://caffeina.com" target="_blank">Caffeina</a>.'; }, 11); }); add_filter('plugin_action_links', function ($actions, $plugin_file, $plugin_data, $context) { if (isset($actions['edit'])) { unset($actions['edit']); } return $actions; }, 10, 4); add_filter('upload_mimes', function ($existing_mimes = []) { $existing_mimes['svg'] = 'image/svg+xml'; return $existing_mimes; }); // Tools: Admin edit URL for post ID function admin_edit_url_for_id($id) { return admin_url('post.php') . "?post={$id}&action=edit"; } // Add Script Select AeriaMetabox::add_script_select(); // Run Ajax Relations add_action('wp_ajax_aeria_search', 'AeriaUtils::search'); add_action('wp_ajax_aeria_search_init', 'AeriaUtils::search_init'); // Run Aeria-dependent plugins do_action('aeria_init'); } // IS_ADMIN
function fieldInfo($field_name) { return AeriaMetabox::infoForField($this->type, $field_name); }
function show_field_gallery($field, $metas, $single = false) { wp_enqueue_media(); if (empty($metas)) { $metas = ['']; } $idx = 0; $this->show_field_begin($field, $metas); $layout = (isset($field['layout']) && $field['layout']) != '' ? $field['layout'] : 'preview'; if ($layout == 'list') { foreach ((array) $metas as $meta) { echo "<table class=\"media aeria-media-gallery-" . $field['id'] . " item_" . $idx . "\" width=\"100%\"><tr><td><img id='" . $field['id'] . '_' . $idx . "_image' src='" . $meta . "'/>"; echo "</td><td><input type='text' name='" . $field['id'] . "[]' id='" . $field['id'] . '_' . $idx . "' value=\"" . html_addslashes($meta) . "\"/>"; echo "<a class='button button-primary data-type='list' aeria_upload_media_gallery_button' id='" . $field['id'] . "_button' data-target='#" . $field['id'] . '_' . $idx . "'>Select</a>"; echo "<a class='button button-secondary' onclick=\"jQuery('.aeria-media-gallery-" . $field['id'] . ".item_" . $idx . "').remove();\">Remove</a>"; echo "</td></tr></table>"; $idx++; } echo "<a class='button button-primary button-add' data-target='aeria-media-gallery-" . $field['id'] . "' onclick=\"var x=jQuery('.aeria-media-gallery-" . $field['id'] . " tr:eq(0)'),v=x.clone();v.find('input').val('');v.find('img').attr('src','');x.before(v);window.aeria_setup_media_gallery_fields();\"><b>+ Add Item</b></a>"; echo "<script>jQuery(function(){window.aeria_setup_media_gallery_fields();})</script>"; } if ($layout == 'preview') { if (!$single) { AeriaMetabox::add_script_sortable(); } if ($single) { $num_class = 'single'; } else { $num_class = 'multi'; } echo '<div class="aeria-media-gallery-' . $field['id'] . '">'; foreach ((array) $metas as $meta) { $media_id = AeriaMetabox::get_attachment_id_from_src($meta); if ($media_id) { $url_edit = 'post.php?post=' . $media_id . '&action=edit'; $meta_type = get_post_mime_type($media_id); $meta_title = get_the_title($media_id); } else { $url_edit = ''; $meta_type = ''; $meta_title = ''; } $background = ''; $class_background = 'file'; switch ($meta_type) { case 'image/jpeg': case 'image/png': case 'image/gif': $background = $meta; $class_background = 'image'; break; } $hidden_class = $meta == '' ? 'display:none;' : ''; echo '<div class="box-image item_' . $idx . '" style="' . $hidden_class . '">'; echo "<div class='image " . $num_class . " " . $class_background . "' style='background-image:url(" . $background . ");'>"; if ($class_background == 'file') { echo "<h4>" . (wp_trim_words($meta_title, 8) ?: '<i>Untitled</i>') . "</h4>"; } echo "</div>"; echo "<div class='box-controls'>\n\t\t\t\t\t\t<a class='button button-remove'><i class='glyphicon glyphicon-trash'></i></a>\n\t\t\t\t\t\t<a class='button button-edit' target='_blank' href='" . $url_edit . "'><i class='glyphicon glyphicon-pencil'></i></a>\n\t\t\t\t\t</div>"; echo "<input type='hidden' name='" . $field['id'] . "[]' value=\"" . html_addslashes($meta) . "\"/>"; echo '</div>'; $idx++; } echo "<a class='box-image add aeria_upload_media_gallery_button' data-meta_type='" . $class_background . "' data-num='" . $num_class . "' data-type='preview' data-target='aeria-media-gallery-" . $field['id'] . "'>"; if (!$single) { echo "<i class='glyphicon glyphicon-plus-sign'></i>"; } else { echo "<i class='glyphicon glyphicon-retweet'></i>"; } echo "</a>"; echo "<script>jQuery(function(){window.aeria_setup_media_gallery_fields();})</script>"; echo '</div>'; ?> <?php if (!$single) { ?> <script type="text/javascript"> jQuery(document).ready(function($){ $('.aeria-media-gallery-<?php echo $field['id']; ?> ').sortable(); }); </script> <?php } ?> <?php } $this->show_field_end($field, $metas); }
public static function register($type) { if (empty($type['id'])) { trigger_error('AeriaType: You must define a post_type id.', E_USER_ERROR); } $type['options'] = empty($type['options']) ? array() : $type['options']; $post_type = $type['id']; $post_name = isset($type['title']) ? $type['title'] : ucfirst($type['id']); static::$types[$post_type] = $type; if (false === empty($type['metabox'])) { // Support one or multiple metabox definitions if (isset($type['metabox']['id'])) { $type['metabox'] = [$type['metabox']]; } foreach ($type['metabox'] as $mbox) { if (empty($mbox['pages'])) { $mbox['pages'] = [$post_type]; } if (!in_array($post_type, $mbox['pages'])) { $mbox['pages'][] = $post_type; } AeriaMetabox::register($mbox); } unset($type['metabox']); } if (false === empty($type['taxonomy'])) { // Support one or multiple taxonomy definitions if (isset($type['taxonomy']['id'])) { $type['taxonomy'] = [$type['taxonomy']]; } foreach ($type['taxonomy'] as $tax) { if (empty($tax['types'])) { $tax['types'] = [$post_type]; } if (!in_array($post_type, $tax['types'])) { $tax['types'][] = $post_type; } AeriaTaxonomy::register($tax); } unset($type['taxonomy']); } if (false === empty($type['columns'])) { AeriaColumns::register($type['id'], $type['columns']); unset($type['columns']); } if (false === empty($type['sections'])) { $sections_args = ['type' => $post_type]; if (isset($type['sections']['fields'])) { $sections_args['fields'] = $type['sections']['fields']; } if (isset($type['sections']['description'])) { $sections_args['description'] = $type['sections']['description']; } if (isset($type['sections']['supports'])) { $sections_args['supports'] = $type['sections']['supports']; } AeriaSection::register($sections_args); unset($type['sections']); } add_action('init', function () use($type, $post_type, $post_name) { $options = array_merge_replace(array('public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => ['slug' => $post_type, 'with_front' => false], 'capability_type' => 'post', 'with_front' => false, 'has_archive' => true, 'hierarchical' => true, 'feeds' => false, 'menu_position' => null, 'reorder' => false, 'supports' => false), $type['options']); unset($type['options']); $options_supports = $options['supports']; $options_supports = !$options_supports ? 'title,editor' : str_replace(' ', '', $options_supports); $options['supports'] = explode(',', $options_supports); if ($options['hierarchical']) { $options['supports'][] = 'page-attributes'; } $options['labels'] = array_merge_replace(array('name' => $post_name, 'singular_name' => $post_name, 'add_new' => 'Add new', 'add_new_item' => 'Add new Item', 'edit_item' => 'Edit', 'new_item' => 'New', 'all_items' => 'Show all', 'view_item' => 'Show item', 'search_items' => 'Search', 'not_found' => 'Not found', 'not_found_in_trash' => 'Not found in trash', 'parent_item_colon' => '', 'taxonomies' => [], 'menu_name' => $post_name, 'menu_icon' => null), $type); register_post_type($post_type, $options); if ($options['reorder']) { new AeriaReorder(array('post_type' => $post_type, 'order' => 'ASC', 'heading' => $options['labels']['singular_name'], 'final' => '', 'initial' => '', 'menu_label' => __('Reorder', 'reorder'), 'icon' => '', 'post_status' => 'publish', 'show_title' => isset($options['reorder']['show_title']) ? $options['reorder']['show_title'] : true, 'fields' => $options['reorder']['fields'] ?: false)); } // Check and register relations $relations = isset($type['relations']) ? $type['relations'] : false; if ($relations) { $meta_fields = []; foreach ((array) $relations as $key => $relation) { $multiple = isset($relation['multiple']) ? $relation['multiple'] : false; $meta_fields[] = ['name' => $relation['title'], 'id' => 'relations_' . $post_type . '_' . $relation['type'], 'type' => 'select_ajax', 'multiple' => $multiple, 'relation' => $relation['type']]; } AeriaMetabox::register(['id' => 'relations_' . $post_type, 'title' => 'Relations ' . $options['labels']['name'], 'pages' => [$post_type], 'fields' => $meta_fields]); } }); }