-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpcp_admin.php
129 lines (100 loc) · 3.86 KB
/
wpcp_admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
include "common/admin.php";
class MWCP_Admin extends MeowApps_Admin {
public function __construct() {
parent::__construct( 'wpcp', __FILE__, 'category-permalink' );
if ( is_admin() ) {
add_action( 'admin_menu', array( $this, 'app_menu' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
}
}
function admin_notices() {
}
function common_url( $file ) {
return trailingslashit( plugin_dir_url( __FILE__ ) ) . 'common/' . $file;
}
function app_menu() {
// SUBMENU > Settings
add_submenu_page( 'meowapps-main-menu', 'Category Permalink', 'Category Permalink', 'manage_options',
'wpcp_settings-menu', array( $this, 'admin_settings' ) );
// SUBMENU > Settings > Settings
add_settings_section( 'wpcp_settings', null, null, 'wpcp_settings-menu' );
add_settings_field( 'wpcp_hide_permalink', "Posts List",
array( $this, 'admin_hide_permalink_callback' ),
'wpcp_settings-menu', 'wpcp_settings' );
// SETTINGS
register_setting( 'wpcp_settings', 'wpcp_hide_permalink' );
}
function admin_settings() {
?>
<div class="wrap">
<?php echo $this->display_title( "WP Category Permalink" ); ?>
<p></p>
<div class="meow-row">
<div class="meow-box meow-col meow-span_2_of_2">
<h3>How to use</h3>
<div class="inside">
<?php echo _e( 'For this plugin to work, don\'t forget that you need to use a Permalink Structure that includes <b>%category%</b> (such as "/%category%/%postname%"). This %category% will be handled by the plugin. It can also handle custom post types and taxonomies (such as in gallery plugins, WooCommerce, etc).', 'category-permalink' ) ?>
</div>
</div>
</div>
<div class="meow-row">
<div class="meow-col meow-span_1_of_2">
<div class="meow-box">
<h3>Settings</h3>
<div class="inside">
<form method="post" action="options.php">
<?php settings_fields( 'wpcp_settings' ); ?>
<?php do_settings_sections( 'wpcp_settings-menu' ); ?>
<?php submit_button(); ?>
</form>
</div>
</div>
</div>
<div class="meow-col meow-span_1_of_2">
<div class="meow-box">
<h3>Permalinks</h3>
<div class="inside">
<p>The permalinks listed below are the ones based on custom post type and taxonomy created by your theme on another plugins.</p>
<?php
$fields = array();
$post_types = MWCPPost::post_types();
$map = create_function( '$a', 'return $a->query_var;' );
foreach ( $post_types as $type => $post_info )
{
echo "<h4>$post_info->label</h4>";
$taxa = MWCPPost::taxonomies( $type );
if ( empty( $taxa ) )
continue;
$query_vars = array_map( $map, $taxa );
global $wp_rewrite;
$post_link = $wp_rewrite->get_extra_permastruct( $type );
echo __( '<small>Permalink: ' ) . $post_link . '<br>' .
__( 'Post Type: ' ) . $type . '<br />' .
__( 'Taxonomies: ' ) . implode( ' ', $query_vars ) . '</small>';
}
?>
</div>
</div>
</div>
</div>
<div class="meow-row">
<form method="post" action="options.php">
</form>
</div>
</div>
<?php
}
/*
OPTIONS CALLBACKS
*/
function admin_hide_permalink_callback( $args ) {
$value = get_option( 'wpcp_hide_permalink', null );
$html = '<input type="checkbox" id="wpcp_hide_permalink" name="wpcp_hide_permalink" value="1" ' .
checked( 1, get_option( 'wpcp_hide_permalink' ), false ) . '/>';
$html .= '<label> ' . __( 'Hide Permalinks', 'category-permalink' ) . '</label><br>';
$html .= '<small class="description">' . __( 'In the listing of posts (or any other post type), don\'t display the permalink below the title.', 'category-permalink' ) . '</small>';
echo $html;
}
}
?>