| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Classes; |
| 4 |
|
| 5 |
// no direct access allowed |
| 6 |
if (!defined('ABSPATH')) exit; |
| 7 |
/** |
| 8 |
* WPAdminify |
| 9 |
* |
| 10 |
* @author Jewel Theme <support@jeweltheme.com> |
| 11 |
*/ |
| 12 |
class Hooks |
| 13 |
{ |
| 14 |
public function __construct() |
| 15 |
{ |
| 16 |
// https://wordpress.stackexchange.com/questions/25034/how-to-remove-screen-options-and-help-links-in-the-admin-area |
| 17 |
// https://wordpress.stackexchange.com/questions/73561/how-to-remove-all-widgets-from-dashboard |
| 18 |
// Hide Screen Options and Contextual Help |
| 19 |
|
| 20 |
// Add Featured Image or Post Thumbnail to RSS Feed |
| 21 |
add_filter('the_excerpt_rss', [$this, 'jltwp_adminify_rss_post_thumbnail']); |
| 22 |
add_filter('the_content_feed', [$this, 'jltwp_adminify_rss_post_thumbnail']); |
| 23 |
|
| 24 |
//Add Categories to WordPress Pages, add tag and category support to pages |
| 25 |
add_action('init', [$this, 'jltwp_adminify_tags_categories_support_all']); |
| 26 |
add_action('pre_get_posts', [$this, 'jltwp_adminify_tags_categories_support_query']); |
| 27 |
|
| 28 |
// Remove WordPress Version Number |
| 29 |
add_filter('the_generator', [$this, 'jltwp_adminify_remove_version']); |
| 30 |
|
| 31 |
//Remove Default Image Links in WordPress |
| 32 |
add_action('admin_init', [$this, 'jltwp_adminify_imagelink_setup'], 10); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
// WP Adminify Custom Tweaks |
| 37 |
add_filter('manage_posts_columns', [$this, 'jltwp_adminify_columns_attachments'], 1); |
| 38 |
add_action('manage_posts_custom_column', [$this, 'jltwp_adminify_custom_columns_attachments'], 1, 2); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
function jltwp_adminify_columns_attachments($attachmentCount) |
| 43 |
{ |
| 44 |
$attachmentCount['wp_adminify_post_attachments'] = esc_html__('Attachment(s)', WP_ADMINIFY_TD); |
| 45 |
return $attachmentCount; |
| 46 |
} |
| 47 |
|
| 48 |
function jltwp_adminify_custom_columns_attachments($adminify_col_name, $id) |
| 49 |
{ |
| 50 |
if ($adminify_col_name === 'wp_adminify_post_attachments') { |
| 51 |
$attachments = get_children(array('post_parent' => $id)); |
| 52 |
$adminifyAttachments = count($attachments); |
| 53 |
if ($adminifyAttachments != 0) { |
| 54 |
echo $adminifyAttachments; |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
function jltwp_adminify_rss_post_thumbnail($content) |
| 61 |
{ |
| 62 |
global $post; |
| 63 |
if (has_post_thumbnail($post->ID)) { |
| 64 |
$content = '<p>' . get_the_post_thumbnail($post->ID) . |
| 65 |
'</p>' . get_the_content(); |
| 66 |
} |
| 67 |
return $content; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
function jltwp_adminify_tags_categories_support_all() |
| 72 |
{ |
| 73 |
register_taxonomy_for_object_type('post_tag', 'page'); |
| 74 |
register_taxonomy_for_object_type('category', 'page'); |
| 75 |
} |
| 76 |
|
| 77 |
// ensure all tags and categories are included in queries |
| 78 |
function jltwp_adminify_tags_categories_support_query($wp_query) |
| 79 |
{ |
| 80 |
if ($wp_query->get('tag')) $wp_query->set('post_type', 'any'); |
| 81 |
if ($wp_query->get('category_name')) $wp_query->set('post_type', 'any'); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
function jltwp_adminify_remove_version() |
| 86 |
{ |
| 87 |
return ''; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
function jltwp_adminify_imagelink_setup() |
| 92 |
{ |
| 93 |
$image_set = get_option('image_default_link_type'); |
| 94 |
|
| 95 |
if ($image_set !== 'none') { |
| 96 |
update_option('image_default_link_type', 'none'); |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|