┌────────────────────────────────┐ │ ░░░ ░░▓ ░▓▓ ███ ▓▓░ ▓░░ │ │ ~ M O O N ~ │ └────────────────────────────────┘
prd-web-01.centraldc.gr
LOCATION:
/var/www/html/adconect/wp-content/plugins/adconect-plugin
☗ ROOT
↻ REFRESH
✎ EDIT FILE
EDITING: adconect-plugin.php
<?php /* * Plugin Name: Adconect New theme Plugin * Description: Διάφοροί κώδικες για το site που πρέπει να τρέχουν ακόμα και αν η σελίδα αλλάξει theme * Version: 1.3 * Author: Giannis Giannopoulos / adconect */ if ( ! defined( 'ABSPATH' ) ) exit; // 1. Δήλωση των Meta Fields στη βάση δεδομένων με Auth Callback function adconect_register_my_custom_sidebar_meta() { $post_types = array('post', 'page'); $meta_fields = [ 'my_custom_heading' => 'string', 'my_custom_subheading' => 'string', 'my_custom_image_id' => 'number', 'my_custom_image_url' => 'string', ]; foreach ($post_types as $post_type) { foreach ($meta_fields as $key => $type) { register_post_meta($post_type, $key, array( 'show_in_rest' => true, 'single' => true, 'type' => $type, // ΔΙΟΡΘΩΣΗ: Επιτρέπουμε σε όποιον μπορεί να κάνει edit το post, να αλλάζει και τα meta 'auth_callback' => function() { return current_user_can( 'edit_posts' ); } )); } } } add_action('init', 'adconect_register_my_custom_sidebar_meta'); // 1.1 Δικαίωμα αποθήκευσης από pages function adconect_ensure_page_meta_support() { add_post_type_support( 'page', 'custom-fields' ); } add_action( 'init', 'adconect_ensure_page_meta_support', 20 ); // 2. Εισαγωγή του JavaScript κώδικα στον Block Editor function adconect_enqueue_my_sidebar_script() { ?> <script type="text/javascript"> (function(wp) { // Ασφαλής έλεγχος για την αποφυγή Gutenberg back-end conflicts if ( ! wp || ! wp.plugins || ! wp.editPost || ! wp.blockEditor ) { return; } const { registerPlugin } = wp.plugins; const { PluginDocumentSettingPanel } = wp.editPost; const { TextControl, Button } = wp.components; const { MediaUpload, MediaUploadCheck } = wp.blockEditor; const { useSelect, useDispatch } = wp.data; const el = wp.element.createElement; const MyCustomSidebar = () => { const meta = useSelect(select => { const editor = select('core/editor'); return editor ? editor.getEditedPostAttribute('meta') : null; }); const { editPost } = useDispatch('core/editor'); const updateMeta = (key, value) => { editPost({ meta: { [key]: value } }); }; if (!meta) { return null; } const headingVal = meta['my_custom_heading'] || ''; const subheadingVal = meta['my_custom_subheading'] || ''; const imageIdVal = meta['my_custom_image_id'] || 0; const imageUrlVal = meta['my_custom_image_url'] || ''; return el( PluginDocumentSettingPanel, { name: 'my-heading-panel', title: 'Heading & Media Settings', icon: 'art', }, el(TextControl, { label: 'Κύριος Τίτλος (Heading)', value: headingVal, onChange: (val) => updateMeta('my_custom_heading', val), }), el(TextControl, { label: 'Υπότιτλος', value: subheadingVal, onChange: (val) => updateMeta('my_custom_subheading', val), }), el(MediaUploadCheck, {}, el(MediaUpload, { onSelect: (media) => { updateMeta('my_custom_image_id', media.id); updateMeta('my_custom_image_url', media.url); }, allowedTypes: ['image'], value: imageIdVal, render: ({ open }) => { return el('div', { style: { marginBottom: '15px' } }, el('label', { style: { display: 'block', marginBottom: '5px' } }, 'Εικόνα Meta'), imageUrlVal && el('img', { src: imageUrlVal, style: { width: '100%', marginBottom: '10px', display: 'block' } }), el(Button, { isSecondary: true, onClick: open }, imageIdVal ? 'Αλλαγή Εικόνας' : 'Επιλογή Εικόνας') ); } }) ) ); }; wp.domReady(function() { registerPlugin('my-heading-sidebar', { render: MyCustomSidebar }); }); })(window.wp); </script> <?php } add_action('enqueue_block_editor_assets', function() { add_action('admin_print_footer_scripts', 'adconect_enqueue_my_sidebar_script', 99); }); // 3. Φόρτωση των απαραίτητων dependencies του WordPress function adconect_my_sidebar_dependencies() { wp_enqueue_script('wp-plugins'); wp_enqueue_script('wp-edit-post'); wp_enqueue_script('wp-element'); wp_enqueue_script('wp-components'); wp_enqueue_script('wp-data'); wp_enqueue_script('wp-block-editor'); wp_enqueue_script('wp-dom-ready'); } add_action('enqueue_block_editor_assets', 'adconect_my_sidebar_dependencies'); function adconect_my_register_block_styles() { register_block_style( 'core/group', array( 'name' => 'black-section', 'label' => 'Μαύρo section', ) ); register_block_style( 'core/group', array( 'name' => 'gray-section', 'label' => 'Γκρι Section', ) ); register_block_style( array('core/group', 'core/paragraph', 'core/columns'), array( 'name' => 'full-section', 'label' => 'Πλήρες', ) ); } add_action('init', 'adconect_my_register_block_styles'); // [single_item] function adconect_single_item_shortcode($atts) { $attributes = shortcode_atts( array( 'class' => '', 'id' => '', 'active' => 'true', 'image' => 'test.png', 'link' => '', 'text' => '', ), $atts ); if (strtolower($attributes['active']) !== 'true') { return ''; } $image = $attributes['image']; $link = $attributes['link']; $text = $attributes['text']; if (empty($image) && empty($link) && empty($text)) { return ''; } $output = '<div id="'.esc_attr($attributes['id']).'" class="single_item '.esc_attr($attributes['class']).'">'; if (!empty($link)) { $output .= '<a href="' . esc_url($link) . '">'; } if (!empty($image)) { $output .= '<img src="' . esc_url($image) . '" alt="Shortcode Image" style="max-width:100%; height:auto;">'; } if (!empty($text)) { $output .= '<div class="shortcode-text-content">' . wp_kses_post($text) . '</div>'; } if (!empty($link)) { $output .= '</a>'; } $output .= '</div>'; return $output; } add_shortcode('single_item', 'adconect_single_item_shortcode');
CANCEL
Name
Type
Size
Modified
Actions
↩ ..
DIR
—
—
📄 adconect-plugin.php
PHP
8.1 KB
2026-05-19 14:25
EDIT