added the WIP company head shortcut and a menu for editing company stuff, instead of the user profile.
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
57
admin/js/partnerexpo-core-business-page.js
Normal file
57
admin/js/partnerexpo-core-business-page.js
Normal 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();
|
||||
});
|
||||
});
|
||||
58
admin/partials/partnerexpo-core-admin-business.php
Normal file
58
admin/partials/partnerexpo-core-admin-business.php
Normal 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>
|
||||
@@ -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. -->
|
||||
Reference in New Issue
Block a user