Beispiel #1
0
/**
 * Iterate through all tokens we have registered and run the associated filter on them
 *
 * Devs can add a token to the array, and use ppp_replace_token-[token] as the filter to execute their replacements
 * @param  string $string The raw share text
 * @param  array  $args   Array of arguments, containing things like post_id
 * @return string         The raw string, with all tokens replaced
 */
function ppp_replace_text_tokens($string, $args = array())
{
    $tokens = wp_list_pluck(ppp_get_text_tokens(), 'token');
    foreach ($tokens as $key => $token) {
        $string = apply_filters('ppp_replace_token-' . $token, $string, $args);
    }
    return $string;
}
 public function test_text_tokens()
 {
     $expected = array(array('token' => 'post_title', 'description' => 'The title of the post being shared'), array('token' => 'site_title', 'description' => 'The site title, from Settings > General'));
     $this->assertEquals($expected, ppp_get_text_tokens());
 }
/**
 * Display the General settings tab
 * @return void
 */
function ppp_admin_page()
{
    global $ppp_options;
    $license = get_option('_ppp_license_key');
    $status = get_option('_ppp_license_key_status');
    ?>
	<div class="wrap">
		<div id="icon-options-general" class="icon32"></div><h1><?php 
    _e('Post Promoter Pro', 'ppp-txt');
    ?>
</h1>
		<form method="post" action="options.php">
			<?php 
    wp_nonce_field('ppp-options');
    ?>
			<table class="form-table">

				<tr valign="top">
					<th scope="row" valign="top">
						<?php 
    _e('License Key', 'ppp-txt');
    ?>
<br /><span style="font-size: x-small;"><?php 
    _e('Enter your license key', 'ppp-txt');
    ?>
</span>
					</th>
					<td>
						<input id="ppp_license_key" name="_ppp_license_key" type="text" class="regular-text" value="<?php 
    esc_attr_e($license);
    ?>
" /><?php 
    if ($status !== false && $status == 'valid') {
        ?>
						<span style="color:green;">&nbsp;<?php 
        _e('active', 'ppp-txt');
        ?>
</span><?php 
    }
    ?>
					</td>
				</tr>

				<?php 
    if (false !== $license) {
        ?>
					<tr valign="top">
						<th scope="row" valign="top">
							<?php 
        _e('Activate License', 'ppp-txt');
        ?>
						</th>
						<td>
							<?php 
        if ($status !== false && $status == 'valid') {
            ?>
								<?php 
            wp_nonce_field('ppp_deactivate_nonce', 'ppp_deactivate_nonce');
            ?>
								<input type="submit" class="button-secondary" name="ppp_license_deactivate" value="<?php 
            _e('Deactivate License', 'ppp-txt');
            ?>
"/>
							<?php 
        } else {
            wp_nonce_field('ppp_activate_nonce', 'ppp_activate_nonce');
            ?>
								<input type="submit" class="button-secondary" name="ppp_license_activate" value="<?php 
            _e('Activate License', 'ppp-txt');
            ?>
"/>
							<?php 
        }
        ?>
						</td>
					</tr>
				<?php 
    }
    ?>

				<tr valign="top">
					<th scope="row"><?php 
    _e('Default Share Text', 'ppp-txt');
    ?>
<br />
						<span style="font-size: x-small;"><a href="#" onclick="jQuery('#ppp-text-helper').toggle(); return false;"><?php 
    _e('Default Text Tips', 'ppp-txt');
    ?>
</a></span>
					</th>
					<td>
						<?php 
    $default_text = isset($ppp_options['default_text']) ? $ppp_options['default_text'] : '';
    ?>
						<input name="ppp_options[default_text]" value="<?php 
    echo $default_text;
    ?>
" placeholder="Post Title will be used if empty" size="50" />
						<p id="ppp-text-helper" style="display: none">
							<small>
							<?php 
    _e('The typical length of a link shortened on Twitter is 23 characters, so keep that in mind when writing your default text.', 'ppp-txt');
    ?>
							<br />
							<?php 
    _e('Status updates over 140 charcters will fail to post.', 'ppp-txt');
    ?>
							<br />
							<?php 
    _e('Possible Replacements:', 'ppp-txt');
    ?>
							<br />
							<?php 
    foreach (ppp_get_text_tokens() as $token) {
        ?>
								<code>{<?php 
        echo $token['token'];
        ?>
}</code> - <?php 
        echo $token['description'];
        ?>
<br />
							<?php 
    }
    ?>
							</small>
						</p>
					</td>
				</tr>

				<tr valign="top">
					<th scope="row"><?php 
    _e('Post Types', 'ppp-txt');
    ?>
<br /><span style="font-size: x-small;"><?php 
    _e('What post types do you want to schedule for?', 'ppp-txt');
    ?>
</span></th>
					<td>
						<?php 
    $post_types = get_post_types(array('public' => true, 'publicly_queryable' => true), NULL, 'and');
    ?>
						<?php 
    if (array_key_exists('attachment', $post_types)) {
        unset($post_types['attachment']);
    }
    ?>
						<?php 
    foreach ($post_types as $post_type => $type_data) {
        ?>
							<?php 
        $value = isset($ppp_options['post_types']) && isset($ppp_options['post_types'][$post_type]) ? true : false;
        ?>
							<input type="checkbox" name="ppp_options[post_types][<?php 
        echo $post_type;
        ?>
]" value="1" id="<?php 
        echo $post_type;
        ?>
" <?php 
        checked(true, $value, true);
        ?>
 />&nbsp;
							<label for="<?php 
        echo $post_type;
        ?>
"><?php 
        echo $type_data->labels->name;
        ?>
</label></br />
						<?php 
    }
    ?>
					</td>
				</tr>

				<tr valign="top">
					<th scope="row"><?php 
    _e('Advanced', 'ppp-txt');
    ?>
<br /><span style="font-size: x-small;"><?php 
    _e('Tools for troubleshooting and advanced usage', 'ppp-txt');
    ?>
</span></th>
					<td>
						<p>
						<?php 
    $debug_enabled = isset($ppp_options['enable_debug']) ? true : false;
    ?>
						<input type="checkbox" name="ppp_options[enable_debug]" <?php 
    checked(true, $debug_enabled, true);
    ?>
 value="1" /> <?php 
    _e('Enable Debug', 'ppp-txt');
    ?>
						</p>
						<p>
						<?php 
    $delete_on_uninstall = isset($ppp_options['delete_on_uninstall']) ? true : false;
    ?>
						<input type="checkbox" name="ppp_options[delete_on_uninstall]" <?php 
    checked(true, $delete_on_uninstall, true);
    ?>
 value="1" /> <?php 
    _e('Delete All Data On Uninstall', 'ppp-txt');
    ?>
						</p>
					</td>
				</tr>

				<?php 
    do_action('ppp_general_settings_after');
    ?>

				<input type="hidden" name="action" value="update" />
				<?php 
    $page_options = apply_filters('ppp_settings_page_options', array('ppp_options', '_ppp_license_key'));
    ?>
				<input type="hidden" name="page_options" value="<?php 
    echo implode(',', $page_options);
    ?>
" />
				<?php 
    settings_fields('ppp-options');
    ?>
			</table>
			<input type="submit" class="button-primary" value="<?php 
    _e('Save Changes', 'ppp-txt');
    ?>
" />
		</form>
	</div>
	<?php 
}