Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apex_micro_site
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Ali Arshad
apex_micro_site
Commits
766b7bda
You need to sign in or sign up before continuing.
Commit
766b7bda
authored
Jan 18, 2018
by
Muhammad Usman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
taxonomy image uploaded to a new file
parent
abcefaa5
Pipeline
#173
passed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
153 deletions
+154
-153
ct_max_meta.php
.../wp-content/plugins/apex_global_lms/admin/ct_max_meta.php
+153
-0
functions.php
WWW_DATA/wp-content/plugins/apex_global_lms/functions.php
+1
-153
No files found.
WWW_DATA/wp-content/plugins/apex_global_lms/admin/ct_max_meta.php
0 → 100644
View file @
766b7bda
<?php
/**
* Plugin class
**/
if
(
!
class_exists
(
'CT_TAX_META'
)
)
{
class
CT_TAX_META
{
public
function
__construct
()
{
//
}
/*
* Initialize the class and start calling our hooks and filters
* @since 1.0.0
*/
public
function
init
()
{
add_action
(
'vq_course_taxonomy_add_form_fields'
,
array
(
$this
,
'add_category_image'
),
10
,
2
);
add_action
(
'created_vq_course_taxonomy'
,
array
(
$this
,
'save_category_image'
),
10
,
2
);
add_action
(
'vq_course_taxonomy_edit_form_fields'
,
array
(
$this
,
'update_category_image'
),
10
,
2
);
add_action
(
'edited_vq_course_taxonomy'
,
array
(
$this
,
'updated_category_image'
),
10
,
2
);
add_action
(
'admin_enqueue_scripts'
,
array
(
$this
,
'load_media'
)
);
add_action
(
'admin_footer'
,
array
(
$this
,
'add_script'
)
);
}
public
function
load_media
()
{
wp_enqueue_media
();
}
/*
* Add a form field in the new category page
* @since 1.0.0
*/
public
function
add_category_image
(
$taxonomy
)
{
?>
<div
class=
"form-field term-group"
>
<label
for=
"vq_course_taxonomy-image-id"
>
Image
</label>
<input
type=
"hidden"
id=
"vq_course_taxonomy-image-id"
name=
"vq_course_taxonomy-image-id"
class=
"custom_media_url"
value=
""
>
<div
id=
"vq_course_taxonomy-image-wrapper"
></div>
<p>
<input
type=
"button"
class=
"button button-secondary ct_tax_media_button"
id=
"ct_tax_media_button"
name=
"ct_tax_media_button"
value=
"Add Image"
/>
<input
type=
"button"
class=
"button button-secondary ct_tax_media_remove"
id=
"ct_tax_media_remove"
name=
"ct_tax_media_remove"
value=
"Remove Image"
/>
</p>
</div>
<?php
}
/*
* Save the form field
* @since 1.0.0
*/
public
function
save_category_image
(
$term_id
,
$tt_id
)
{
if
(
isset
(
$_POST
[
'vq_course_taxonomy-image-id'
]
)
&&
''
!==
$_POST
[
'vq_course_taxonomy-image-id'
]
){
$image
=
$_POST
[
'vq_course_taxonomy-image-id'
];
add_term_meta
(
$term_id
,
'vq_course_taxonomy-image-id'
,
$image
,
true
);
}
}
/*
* Edit the form field
* @since 1.0.0
*/
public
function
update_category_image
(
$term
,
$taxonomy
)
{
?>
<tr
class=
"form-field term-group-wrap"
>
<th
scope=
"row"
>
<label
for=
"vq_course_taxonomy-id"
>
<?php
__
(
'Image'
);
?>
</label>
</th>
<td>
<?php
$image_id
=
get_term_meta
(
$term
->
term_id
,
'vq_course_taxonomy-image-id'
,
true
);
?>
<input
type=
"hidden"
id=
"vq_course_taxonomy-image-id"
name=
"vq_course_taxonomy-image-id"
value=
"
<?php
echo
$image_id
;
?>
"
>
<div
id=
"vq_course_taxonomy-image-wrapper"
>
<?php
if
(
$image_id
)
{
?>
<?php
echo
wp_get_attachment_image
(
$image_id
,
'thumbnail'
);
?>
<?php
}
?>
</div>
<p>
<input
type=
"button"
class=
"button button-secondary ct_tax_media_button"
id=
"ct_tax_media_button"
name=
"ct_tax_media_button"
value=
"Add Image"
/>
<input
type=
"button"
class=
"button button-secondary ct_tax_media_remove"
id=
"ct_tax_media_remove"
name=
"ct_tax_media_remove"
value=
"Remove Image"
/>
</p>
</td>
</tr>
<?php
}
/*
* Update the form field value
* @since 1.0.0
*/
public
function
updated_category_image
(
$term_id
,
$tt_id
)
{
if
(
isset
(
$_POST
[
'vq_course_taxonomy-image-id'
]
)
&&
''
!==
$_POST
[
'vq_course_taxonomy-image-id'
]
){
$image
=
$_POST
[
'vq_course_taxonomy-image-id'
];
update_term_meta
(
$term_id
,
'vq_course_taxonomy-image-id'
,
$image
);
}
else
{
update_term_meta
(
$term_id
,
'vq_course_taxonomy-image-id'
,
''
);
}
}
/*
* Add script
* @since 1.0.0
*/
public
function
add_script
()
{
?>
<script>
jQuery
(
document
).
ready
(
function
(
$
)
{
function
ct_media_upload
(
button_class
)
{
var
_custom_media
=
true
,
_orig_send_attachment
=
wp
.
media
.
editor
.
send
.
attachment
;
$
(
'body'
).
on
(
'click'
,
button_class
,
function
(
e
)
{
var
button_id
=
'#'
+
$
(
this
).
attr
(
'id'
);
var
send_attachment_bkp
=
wp
.
media
.
editor
.
send
.
attachment
;
var
button
=
$
(
button_id
);
_custom_media
=
true
;
wp
.
media
.
editor
.
send
.
attachment
=
function
(
props
,
attachment
){
if
(
_custom_media
)
{
$
(
'#vq_course_taxonomy-image-id'
).
val
(
attachment
.
id
);
$
(
'#vq_course_taxonomy-image-wrapper'
).
html
(
'<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />'
);
$
(
'#vq_course_taxonomy-image-wrapper .custom_media_image'
).
attr
(
'src'
,
attachment
.
url
).
css
(
'display'
,
'block'
);
}
else
{
return
_orig_send_attachment
.
apply
(
button_id
,
[
props
,
attachment
]
);
}
}
wp
.
media
.
editor
.
open
(
button
);
return
false
;
});
}
ct_media_upload
(
'.ct_tax_media_button.button'
);
$
(
'body'
).
on
(
'click'
,
'.ct_tax_media_remove'
,
function
(){
$
(
'#vq_course_taxonomy-image-id'
).
val
(
''
);
$
(
'#vq_course_taxonomy-image-wrapper'
).
html
(
'<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />'
);
});
$
(
document
).
ajaxComplete
(
function
(
event
,
xhr
,
settings
)
{
var
queryStringArr
=
settings
.
data
.
split
(
'&'
);
if
(
$
.
inArray
(
'action=add-tag'
,
queryStringArr
)
!==
-
1
){
var
xml
=
xhr
.
responseXML
;
$response
=
$
(
xml
).
find
(
'term_id'
).
text
();
if
(
$response
!=
""
){
// Clear the thumb image
$
(
'#vq_course_taxonomy-image-wrapper'
).
html
(
''
);
}
}
});
});
</script>
<?php
}
}
$CT_TAX_META
=
new
CT_TAX_META
();
$CT_TAX_META
->
init
();
}
\ No newline at end of file
WWW_DATA/wp-content/plugins/apex_global_lms/functions.php
View file @
766b7bda
<?php
require_once
(
'admin/ct_max_meta.php'
);
add_action
(
'init'
,
'vq_apex_custom_posts'
);
...
...
@@ -60,155 +60,4 @@ function vq_apex_custom_taxonomies() {
'hierarchical'
=>
true
)
);
}
/**
* Plugin class
**/
if
(
!
class_exists
(
'CT_TAX_META'
)
)
{
class
CT_TAX_META
{
public
function
__construct
()
{
//
}
/*
* Initialize the class and start calling our hooks and filters
* @since 1.0.0
*/
public
function
init
()
{
add_action
(
'vq_course_taxonomy_add_form_fields'
,
array
(
$this
,
'add_category_image'
),
10
,
2
);
add_action
(
'created_vq_course_taxonomy'
,
array
(
$this
,
'save_category_image'
),
10
,
2
);
add_action
(
'vq_course_taxonomy_edit_form_fields'
,
array
(
$this
,
'update_category_image'
),
10
,
2
);
add_action
(
'edited_vq_course_taxonomy'
,
array
(
$this
,
'updated_category_image'
),
10
,
2
);
add_action
(
'admin_enqueue_scripts'
,
array
(
$this
,
'load_media'
)
);
add_action
(
'admin_footer'
,
array
(
$this
,
'add_script'
)
);
}
public
function
load_media
()
{
wp_enqueue_media
();
}
/*
* Add a form field in the new category page
* @since 1.0.0
*/
public
function
add_category_image
(
$taxonomy
)
{
?>
<div
class=
"form-field term-group"
>
<label
for=
"category-image-id"
>
<?php
_e
(
'Image'
,
'hero-theme'
);
?>
</label>
<input
type=
"hidden"
id=
"category-image-id"
name=
"category-image-id"
class=
"custom_media_url"
value=
""
>
<div
id=
"category-image-wrapper"
></div>
<p>
<input
type=
"button"
class=
"button button-secondary ct_tax_media_button"
id=
"ct_tax_media_button"
name=
"ct_tax_media_button"
value=
"
<?php
_e
(
'Add Image'
,
'hero-theme'
);
?>
"
/>
<input
type=
"button"
class=
"button button-secondary ct_tax_media_remove"
id=
"ct_tax_media_remove"
name=
"ct_tax_media_remove"
value=
"
<?php
_e
(
'Remove Image'
,
'hero-theme'
);
?>
"
/>
</p>
</div>
<?php
}
/*
* Save the form field
* @since 1.0.0
*/
public
function
save_category_image
(
$term_id
,
$tt_id
)
{
if
(
isset
(
$_POST
[
'category-image-id'
]
)
&&
''
!==
$_POST
[
'category-image-id'
]
){
$image
=
$_POST
[
'category-image-id'
];
add_term_meta
(
$term_id
,
'category-image-id'
,
$image
,
true
);
}
}
/*
* Edit the form field
* @since 1.0.0
*/
public
function
update_category_image
(
$term
,
$taxonomy
)
{
?>
<tr
class=
"form-field term-group-wrap"
>
<th
scope=
"row"
>
<label
for=
"category-image-id"
>
<?php
_e
(
'Image'
,
'hero-theme'
);
?>
</label>
</th>
<td>
<?php
$image_id
=
get_term_meta
(
$term
->
term_id
,
'category-image-id'
,
true
);
?>
<input
type=
"hidden"
id=
"category-image-id"
name=
"category-image-id"
value=
"
<?php
echo
$image_id
;
?>
"
>
<div
id=
"category-image-wrapper"
>
<?php
if
(
$image_id
)
{
?>
<?php
echo
wp_get_attachment_image
(
$image_id
,
'thumbnail'
);
?>
<?php
}
?>
</div>
<p>
<input
type=
"button"
class=
"button button-secondary ct_tax_media_button"
id=
"ct_tax_media_button"
name=
"ct_tax_media_button"
value=
"
<?php
_e
(
'Add Image'
,
'hero-theme'
);
?>
"
/>
<input
type=
"button"
class=
"button button-secondary ct_tax_media_remove"
id=
"ct_tax_media_remove"
name=
"ct_tax_media_remove"
value=
"
<?php
_e
(
'Remove Image'
,
'hero-theme'
);
?>
"
/>
</p>
</td>
</tr>
<?php
}
/*
* Update the form field value
* @since 1.0.0
*/
public
function
updated_category_image
(
$term_id
,
$tt_id
)
{
if
(
isset
(
$_POST
[
'category-image-id'
]
)
&&
''
!==
$_POST
[
'category-image-id'
]
){
$image
=
$_POST
[
'category-image-id'
];
update_term_meta
(
$term_id
,
'category-image-id'
,
$image
);
}
else
{
update_term_meta
(
$term_id
,
'category-image-id'
,
''
);
}
}
/*
* Add script
* @since 1.0.0
*/
public
function
add_script
()
{
?>
<script>
jQuery
(
document
).
ready
(
function
(
$
)
{
function
ct_media_upload
(
button_class
)
{
var
_custom_media
=
true
,
_orig_send_attachment
=
wp
.
media
.
editor
.
send
.
attachment
;
$
(
'body'
).
on
(
'click'
,
button_class
,
function
(
e
)
{
var
button_id
=
'#'
+
$
(
this
).
attr
(
'id'
);
var
send_attachment_bkp
=
wp
.
media
.
editor
.
send
.
attachment
;
var
button
=
$
(
button_id
);
_custom_media
=
true
;
wp
.
media
.
editor
.
send
.
attachment
=
function
(
props
,
attachment
){
if
(
_custom_media
)
{
$
(
'#category-image-id'
).
val
(
attachment
.
id
);
$
(
'#category-image-wrapper'
).
html
(
'<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />'
);
$
(
'#category-image-wrapper .custom_media_image'
).
attr
(
'src'
,
attachment
.
url
).
css
(
'display'
,
'block'
);
}
else
{
return
_orig_send_attachment
.
apply
(
button_id
,
[
props
,
attachment
]
);
}
}
wp
.
media
.
editor
.
open
(
button
);
return
false
;
});
}
ct_media_upload
(
'.ct_tax_media_button.button'
);
$
(
'body'
).
on
(
'click'
,
'.ct_tax_media_remove'
,
function
(){
$
(
'#category-image-id'
).
val
(
''
);
$
(
'#category-image-wrapper'
).
html
(
'<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />'
);
});
// Thanks: http://stackoverflow.com/questions/15281995/wordpress-create-category-ajax-response
$
(
document
).
ajaxComplete
(
function
(
event
,
xhr
,
settings
)
{
var
queryStringArr
=
settings
.
data
.
split
(
'&'
);
if
(
$
.
inArray
(
'action=add-tag'
,
queryStringArr
)
!==
-
1
){
var
xml
=
xhr
.
responseXML
;
$response
=
$
(
xml
).
find
(
'term_id'
).
text
();
if
(
$response
!=
""
){
// Clear the thumb image
$
(
'#category-image-wrapper'
).
html
(
''
);
}
}
});
});
</script>
<?php
}
}
$CT_TAX_META
=
new
CT_TAX_META
();
$CT_TAX_META
->
init
();
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment