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