added the WIP company head shortcut and a menu for editing company stuff, instead of the user profile.

This commit is contained in:
2026-03-12 22:05:37 +01:00
parent b6d0959cf6
commit ccfb737949
12 changed files with 222 additions and 94 deletions

View File

@@ -60,21 +60,7 @@ class Partnerexpo_Core_Admin {
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Partnerexpo_Core_Loader as all of the hooks are defined
* in that particular class.
*
* The Partnerexpo_Core_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/partnerexpo-core-admin.css', array(), $this->version, 'all' );
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/partnerexpo-core-business-page.css', [], $this->version, 'all' );
}
/**
@@ -83,21 +69,33 @@ class Partnerexpo_Core_Admin {
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Partnerexpo_Core_Loader as all of the hooks are defined
* in that particular class.
*
* The Partnerexpo_Core_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/partnerexpo-core-admin.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name . '-business-page', plugin_dir_url( __FILE__ ) . 'js/partnerexpo-core-business-page.js', [ 'jquery' ], $this->version, true );
wp_localize_script(
$this->plugin_name . '-business-page',
'businessData',
[
'post_id' => get_user_meta( get_current_user_id(), 'company_logo_attachment_id', true ),
'title' => esc_html__( 'Céges logó kiválasztása', 'partnerexpo-core' ),
'button' => esc_html__( 'Kép használata', 'partnerexpo-core' ),
]
);
}
public function display_business_data_page() {
include_once plugin_dir_path( __FILE__ ) . 'partials/partnerexpo-core-admin-business.php';
}
public function add_menu() {
add_menu_page(
esc_html__( 'Üzleti adatok', 'partnerexpo-core' ),
esc_html__( 'Üzleti adatok', 'partnerexpo-core' ),
'manage_options',
'pexpo-core-business-data',
[ $this, 'display_business_data_page' ],
'dashicons-businessman',
6
);
}
}

View File

@@ -1,32 +0,0 @@
(function( $ ) {
'use strict';
/**
* All of the code for your admin-facing JavaScript source
* should reside in this file.
*
* Note: It has been assumed you will write jQuery code here, so the
* $ function reference has been prepared for usage within the scope
* of this function.
*
* This enables you to define handlers, for when the DOM is ready:
*
* $(function() {
*
* });
*
* When the window is loaded:
*
* $( window ).load(function() {
*
* });
*
* ...and/or other possibilities.
*
* Ideally, it is not considered best practise to attach more than a
* single DOM-ready or window-load handler for a particular page.
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/
})( jQuery );

View File

@@ -0,0 +1,57 @@
jQuery( document ).ready( function( $ ) {
// Uploading files
var file_frame;
var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
jQuery('#pexpo-core-upload-image-button').on('click', function( event ){
event.preventDefault();
// If the media frame already exists, reopen it.
if ( file_frame ) {
// Set the post ID to what we want
file_frame.uploader.uploader.param( 'post_id', businessData.post_id );
// Open frame
file_frame.open();
return;
} else {
// Set the wp.media post id so the uploader grabs the ID we want when initialised
wp.media.model.settings.post.id = businessData.post_id;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: businessData.title,
button: {
text: businessData.button,
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected, run a callback.
file_frame.on( 'select', function() {
// We set multiple to false so only get one image from the uploader
attachment = file_frame.state().get('selection').first().toJSON();
// Do something with attachment.id and/or attachment.url here
$( '#pexpo-core-business-logo-preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' );
$( '#pexpo-core-business-logo-attachment-id' ).val( attachment.id );
// Restore the main post ID
wp.media.model.settings.post.id = wp_media_post_id;
});
// Finally, open the modal
file_frame.open();
});
// Restore the main ID when the add media button is pressed
jQuery( 'a.add_media' ).on( 'click', function() {
wp.media.model.settings.post.id = wp_media_post_id;
});
jQuery( '#pexpo-core-submit' ).on( 'click', function() {
$window.location.reload();
});
});

View File

@@ -0,0 +1,58 @@
<?php
/**
* Provide a admin area view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link https://github.com/Duskell
* @since 1.0.0
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/admin/partials
*/
if ( isset( $_POST['pexpo-core-submit'] ) ) {
if ( isset( $_POST['image_attachment_id'] ) ) {
update_user_meta(
get_current_user_id(),
'company_logo_attachment_id',
absint( $_POST['image_attachment_id'] )
);
}
if ( isset( $_POST['company_name'] ) ) {
update_user_meta(
get_current_user_id(),
'company',
sanitize_text_field( $_POST['company_name'] )
);
}
}
$logo_id = get_user_meta( get_current_user_id(), 'company_logo_attachment_id', true );
$logo_url = $logo_id ? wp_get_attachment_url( $logo_id ) : '';
wp_enqueue_media();
?>
<div class="pexpo-core-business-wrap">
<h1><?php echo esc_html__('Céges adataid', 'partnerexpo-core'); ?></h1>
<p><?php echo esc_html__('Itt láthatod a regisztrációnál beállított céges adataidat, és szerkesztheted azokat.', 'partnerexpo-core'); ?></p>
<form method='post'>
<div class="pexpo-core-business-logo-wrapper">
<h2><?php echo esc_html__('Céges logó', 'partnerexpo-core'); ?></h2>
<div class='pexpo-core-business-logo-preview-wrapper'>
<img id='pexpo-core-business-logo-preview' src='<?php echo esc_url( $logo_url ); ?>' height='100'>
</div>
<input id="pexpo-core-upload-image-button" type="button" class="button" value="<?php _e( 'Kép feltöltése', 'partnerexpo-core' ); ?>" />
<input type='hidden' name='image_attachment_id' id='pexpo-core-business-logo-attachment-id' value='<?php echo esc_attr( $logo_id ); ?>'>
</div>
<div class="pexpo-core-business-data-wrapper">
<h2><?php echo esc_html__('Cég neve', 'partnerexpo-core'); ?></h2>
<input type="text" name="company_name" value="<?php echo esc_attr( get_user_meta( get_current_user_id(), 'company', true ) ); ?>" class="regular-text" />
</div>
<input type="submit" name="pexpo-core-submit" value="<?php _e( 'Mentés', 'partnerexpo-core' ); ?>" class="button-primary">
</form>
</div>

View File

@@ -1,16 +0,0 @@
<?php
/**
* Provide a admin area view for the plugin
*
* This file is used to markup the admin-facing aspects of the plugin.
*
* @link https://github.com/Duskell
* @since 1.0.0
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/admin/partials
*/
?>
<!-- This file should primarily consist of HTML with a little bit of PHP. -->

View File

@@ -18,6 +18,7 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
}
private function activate_fields() {
$this->loader->add_action( 'load-profile.php', $this, 'remove_custom_user_fields' );
$this->loader->add_action( 'show_user_profile', $this, 'add_custom_user_fields' );
$this->loader->add_action( 'edit_user_profile', $this, 'add_custom_user_fields' );
$this->loader->add_action( 'personal_options_update', $this, 'save_custom_user_fields' );
@@ -26,6 +27,12 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
$this->loader->add_action( 'register_form', $this, 'registration_form' );
$this->loader->add_filter( 'registration_errors', $this, 'registration_errors', 10, 3 );
$this->loader->add_filter( 'comment_post', $this, 'validate_comment' );
}
public function remove_custom_user_fields() {
remove_all_actions('show_user_profile');
remove_all_actions('edit_user_profile');
}
public function add_custom_user_fields( $user ) {

View File

@@ -165,6 +165,8 @@ class Partnerexpo_Core {
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu' );
}
/**

View File

@@ -43,6 +43,7 @@ class Partnerexpo_Core_Public {
add_shortcode( 'partnerexpo_searchbox', [ $this, 'searchbox_shortcode' ] );
add_shortcode( 'partnerexpo_comment_section', [ $this, 'comments_shortcode' ] );
add_shortcode( 'partnerexpo_company_head', [ $this, 'company_head_shortcode' ] );
}
public function searchbox_shortcode() {
@@ -67,6 +68,14 @@ class Partnerexpo_Core_Public {
return ob_get_clean();
}
public function company_head_shortcode() {
wp_enqueue_style( $this->plugin_name . '-company-head-css' );
ob_start();
include plugin_dir_path( __FILE__ ) . 'partials/partnerexpo-core-public-company-head.php';
return ob_get_clean();
}
public function register_endpoint() {
register_rest_route('pexpo/v1', '/query', [
'methods' => 'GET',
@@ -208,6 +217,14 @@ class Partnerexpo_Core_Public {
$this->version,
'all'
);
wp_register_style(
$this->plugin_name . '-company-head-css',
plugin_dir_url( __FILE__ ) . 'css/company-head.css',
[],
$this->version,
'all'
);
}
/**

View File

@@ -0,0 +1,28 @@
.pexpo-core-company-head-wrapper {
display: flex;
align-items: left;
gap: 50px;
margin: 20px;
width: 100%;
}
.pexpo-core-company-head-logo-wrapper {
flex-shrink: 0;
& .pexpo-core-company-logo {
width: max-content;
height: 100px;
object-fit: contain;
}
}
.pexpo-core-company-head-name-wrapper {
flex-grow: 1;
display: flex;
align-items: center;
& .pexpo-core-company-name {
font-size: 2em;
margin: 0;
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Displays company data for the partner offers.
*
* @link https://github.com/Duskell
* @since 1.1.6
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/public/partials
*/
$logo_id = get_user_meta( get_current_user_id(), 'company_logo_attachment_id', true );
$logo_url = $logo_id ? wp_get_attachment_url( $logo_id ) : '';
?>
<div class="pexpo-core-company-head-wrapper">
<div class="pexpo-core-company-head-logo-wrapper">
<img class="pexpo-core-company-logo" src="<?php echo esc_url( $logo_url ); ?>" alt="<?php echo esc_attr( get_user_meta( get_current_user_id(), 'company', true ) ); ?> logo">
</div>
<div class="pexpo-core-company-head-name-wrapper">
<h2 class="pexpo-core-company-name"><?php echo esc_html( get_user_meta( get_current_user_id(), 'company', true ) ); ?></h2>
</div>
</div>

View File

@@ -1,16 +0,0 @@
<?php
/**
* Provide a public-facing view for the plugin
*
* This file is used to markup the public-facing aspects of the plugin.
*
* @link https://github.com/Duskell
* @since 1.0.0
*
* @package Partnerexpo_Core
* @subpackage Partnerexpo_Core/public/partials
*/
?>
<!-- This file should primarily consist of HTML with a little bit of PHP. -->