PluginProbe
Datafeedr API / 1.0.2
Datafeedr API v1.0.2
1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 All 181 releases
datafeedr-api / functions / admin-functions.php

admin-functions.php in Datafeedr API 1.0.2, at functions/admin-functions.php

170 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * These are the Admin pages associated with the Datafeedr API plugin.
5 *
6 * These are called from their respecitive classes.
7 */
8 function dfrapi_setting_pages( $key=false ) {
9
10 $pages = array (
11 'dfrapi-configuration' => __( 'Configuration', DFRAPI_DOMAIN ),
12 'dfrapi-networks' => __( 'Networks', DFRAPI_DOMAIN ),
13 'dfrapi-merchants' => __( 'Merchants', DFRAPI_DOMAIN ),
14 'dfrapi-tools' => __( 'Tools', DFRAPI_DOMAIN ),
15 'dfrapi-export' => __( 'Export', DFRAPI_DOMAIN ),
16 'dfrapi-import' => __( 'Import', DFRAPI_DOMAIN ),
17 'dfrapi-account' => __( 'Account', DFRAPI_DOMAIN ),
18 );
19
20 if ( isset( $pages[$key] ) ) {
21 return $pages[$key];
22 }
23
24 }
25
26 /**
27 * This stores messages to be displayed using the
28 * 'admin_notices' action.
29 */
30 function dfrapi_admin_messages( $key=false ) {
31
32 $messages = array(
33
34 // User is missing 1 or more of their API Keys.
35 'missing_api_keys' => array(
36 'class' => 'update-nag',
37 'message' => __( 'Your Datafeedr API Keys are missing.', DFRAPI_DOMAIN ),
38 'url' => 'admin.php?page=dfrapi',
39 'button_text' => __( 'Add Your API Keys', DFRAPI_DOMAIN )
40 ),
41
42 // User is missing a network
43 'missing_network_ids' => array(
44 'class' => 'update-nag',
45 'message' => __( 'You haven\'t selected any affiliate networks yet.', DFRAPI_DOMAIN ),
46 'url' => 'admin.php?page=dfrapi_networks',
47 'button_text' => __( 'Select Networks', DFRAPI_DOMAIN )
48 ),
49
50 // User is missing a merchant
51 'missing_merchant_ids' => array(
52 'class' => 'update-nag',
53 'message' => __( 'You haven\'t selected any merchants yet.', DFRAPI_DOMAIN ),
54 'url' => 'admin.php?page=dfrapi_merchants',
55 'button_text' => __( 'Select Merchants', DFRAPI_DOMAIN )
56 ),
57
58 // Display message that user has used 90%+ of API requests.
59 'usage_over_90_percent' => array(
60 'class' => 'update-nag',
61 'message' => __( 'You have used ', DFRAPI_DOMAIN ) . dfrapi_get_api_usage_percentage() . __( '% of your total Datafeedr API requests this month. ', DFRAPI_DOMAIN ),
62 'url' => 'admin.php?page=dfrapi_account',
63 'button_text' => __( 'View Account', DFRAPI_DOMAIN )
64 ),
65
66 // Missing affiliate IDs message.
67 'missing_affiliate_ids' => array(
68 'class' => 'update-nag',
69 'message' => __( 'You are missing affiliate IDs. ', DFRAPI_DOMAIN ),
70 'url' => 'admin.php?page=dfrapi_networks',
71 'button_text' => __( 'Enter your Affiliate IDs', DFRAPI_DOMAIN )
72 ),
73 );
74
75 if ( isset( $messages[$key] ) ) {
76 dfrapi_admin_notices( $key, $messages );
77 }
78
79 }
80
81 /**
82 * This gets any notices set by the plugin.
83 */
84 function dfrapi_admin_notices( $key, $messages ) {
85 $notices = get_option( 'dfrapi_admin_notices', array() );
86 $notices[$key] = $messages[$key];
87 update_option( 'dfrapi_admin_notices', $notices );
88 }
89
90 /**
91 * Button text for admin notices.
92 */
93 function dfrapi_fix_button( $url, $button_text=false ) {
94 if ( !$button_text ) {
95 $button_text = __( 'Fix This Now', DFRAPI_DOMAIN );
96 }
97 if ( substr( $url, 0, 4 ) === "http" ) {
98 return ' <a target="blank" href="' . $url . '">' .$button_text . '</a>';
99 } else {
100 return ' <a href="' . admin_url( $url ) . '">' .$button_text . '</a>';
101 }
102 }
103
104 /**
105 * Return plan IDs & names.
106 */
107 function dfrapi_get_membership_plans() {
108 return array(
109 10200 => 'Free',
110 101000 => 'Starter',
111 1025000 => 'Basic',
112 1125000 => 'Beta Tester',
113 10100000 => 'Professional',
114 10250000 => 'Enterprise',
115 );
116 }
117
118 /**
119 * Convert network group names to a css class name.
120 */
121 function dfrapi_group_name_to_css( $group ) {
122 if ( is_string( $group ) ) {
123 return strtolower(
124 str_replace(
125 array( " ", "-", "." ),
126 "",
127 $group
128 )
129 );
130 } elseif ( is_array( $group ) ) {
131 $name = str_replace( array( " ", "-", "." ), "", $group['group'] );
132 $type = ( $group['type'] == 'coupons' ) ? '_coupons' : '';
133 return strtolower( $name . $type );
134 }
135 }
136
137 /**
138 * Adds global "support" content to "Help" tabs for all Datafeedr plugins.
139 */
140 function dfrapi_help_tab( $screen ) {
141
142 $screen->add_help_tab( array(
143 'id' => 'dfrapi_support_tab',
144 'title' => __( 'Support', DFRAPI_DOMAIN ),
145 'content' =>
146 '<h2>' . __( "Datafeedr Support", DFRAPI_DOMAIN ) . '</h2>' .
147 '<p>' . sprintf(__( 'If you have a question or a problem, please search the <a href="%s?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">documentation</a> and the <a href="%s?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">support forums</a>', DFRAPI_DOMAIN ), DFRAPI_DOCS_URL, DFRAPI_QNA_URL ) . '. ' . __( 'If you are still unable to find an answer feel free to contact us using the links below.', DFRAPI_DOMAIN ) . '</p>' .
148 '<p><a href="' . DFRAPI_ASK_QUESTION_URL . '?utm_source=plugin&utm_medium=link&utm_campaign=helptab" class="button button-primary" target="_blank">' . __( 'Post a Question', DFRAPI_DOMAIN ) . '</a> (' . __( 'recommended', DFRAPI_DOMAIN ) . ')</p>' .
149 '<p><a href="' . DFRAPI_EMAIL_US_URL . '?utm_source=plugin&utm_medium=link&utm_campaign=helptab" class="button" target="_blank">' . __( 'Email Us', DFRAPI_DOMAIN ) . '</a></p>'
150
151 ) );
152
153 $screen->add_help_tab( array(
154 'id' => 'dfrapi_bug_tab',
155 'title' => __( 'Found a bug?', DFRAPI_DOMAIN ),
156 'content' =>
157 '<h2>' . __( "Found a bug?", DFRAPI_DOMAIN ) . '</h2>' .
158 '<p>' . sprintf( __( 'If you find a bug within Datafeedr please see if it\'s already been reported in <a href="%s?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">Bug Reports</a>. If it\'s a new bug, please be as descriptive as possible when reporting a bug.', DFRAPI_DOMAIN ), DFRAPI_BUG_REPORTS_URL ) . '</p>' .
159 '<p><a href="' . DFRAPI_REPORT_BUG_URL . '?utm_source=plugin&utm_medium=link&utm_campaign=helptab" class="button button-primary" target="_blank">' . __( 'Report a bug', DFRAPI_DOMAIN ) . '</a></p>'
160
161 ) );
162
163 $screen->set_help_sidebar(
164 '<p><strong>' . __( 'For more information:', DFRAPI_DOMAIN ) . '</strong></p>' .
165 '<p><a href="' . DFRAPI_HOME_URL . '?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">' . __( 'About Datafeedr', DFRAPI_DOMAIN ) . '</a></p>' .
166 '<p><a href="' . DFRAPI_HOME_URL . '/keys?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">' . __( 'Datafeedr API Keys', DFRAPI_DOMAIN ) . '</a></p>'
167 );
168
169 return $screen;
170 }