class-affiliates-generator.php
3.05 KB
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
<?php
/**
* class-affiliates-generator.php
*
* Copyright (c) 2010-2012 "kento" Karim Rahimpur www.itthinx.com
*
* This code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This header and all notices must be kept intact.
*
* @author Karim Rahimpur
* @package affiliates
* @since affiliates 1.3.1
*/
if ( !defined( 'ABSPATH' ) ) {
exit;
}
/**
* Page generator
*/
class Affiliates_Generator {
/**
* Creates the default affiliate area page (or pages).
*
* @return int post ID(s)
*/
public static function setup_pages() {
global $affiliates_admin_messages;
do_action( 'affiliates_before_setup_pages' );
$post_ids = array();
// create a page with
$affiliate_area_page_content =
'[affiliates_is_not_affiliate]
<p>Please log in to access the affiliate area.</p>
[affiliates_login_redirect]
<p>If you are not an affiliate, you can join the affiliate program here:</p>
[affiliates_registration]
[/affiliates_is_not_affiliate]
[affiliates_is_affiliate]
<p>Welcome to your affiliate area. Here you can find information about your affiliate link and earnings.</p>
<h3>Affiliate Information</h3>
[affiliates_fields]
<h3>Affiliate link</h3>
<p>Your affiliate URL:<br/>
<code>[affiliates_url]</code></p>
<p>Use this code to embed your affiliate link:<br/>
<code><a href="[affiliates_url]">Affiliate link</a></code></p>
<p>Tip: You should change the text <em>Affiliate link</em> to something more attractive.</p>
<h3>Performance</h3>
<h4>Total Earnings</h4>
<h5>Commissions pending payment</h5>
[affiliates_referrals show="total" status="accepted"]
<h5>Commissions paid</h5>
[affiliates_referrals show="total" status="closed"]
<h4>Number of sales referred</h4>
<ul>
<li>Accepted referrals pending payment: [affiliates_referrals status="accepted"]</li>
<li>Referrals paid: [affiliates_referrals status="closed"]</li>
</ul>
<h4>Monthly Earnings</h4>
[affiliates_earnings]
[affiliates_logout]
[/affiliates_is_affiliate]
';
$affiliate_area_page_content = apply_filters( 'affiliates_affiliate_area_page_content', $affiliate_area_page_content );
$postarr = array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_content' => $affiliate_area_page_content,
'post_status' => 'publish',
'post_title' => __( 'Affiliate Area', AFFILIATES_PLUGIN_DOMAIN ),
'post_type' => 'page'
);
$post_id = wp_insert_post( $postarr );
if ( $post_id instanceof WP_Error ) {
$affiliates_admin_messages[] = '<div class="error">' . __( sprintf( 'The affiliate area page could not be created. Error: %s', $post_id->get_error_message() ), AFFILIATES_PLUGIN_DOMAIN ) . '</div>';
} else {
$post_ids[] = $post_id;
}
$post_ids = apply_filters( 'affiliates_setup_pages', $post_ids );
do_action( 'affiliates_after_setup_pages', $post_ids );
return $post_ids;
}
}