easyiit_rand_fields.php 5.8 KB
<?php
/**
 * Plugin Name: 随机字段调用
 * Plugin URI: #
 * Description: 随机字段调用
 * Version: 1.0.00
 * Author: Goodao
 * Author URI: #
 */

if (!defined('IMPORT_PATH')) define('IMPORT_PATH', plugin_dir_path(__FILE__));
add_action('admin_menu', 'rand_fields_init');

function rand_fields_init() {
    add_submenu_page('easyiit_rand_fields', '变量设置', '变量设置', 7, 'easyiit_rand_fields', 'rand_fields');	
}
 
 
function rand_fields() {
if(isset($_POST['dosubmit'])){
	$rand_fields = $_POST['setting']; 
	$rand_fields['rand_pre'] = str_replace(['"',"\'\'"],'',$rand_fields['rand_pre']);
	$rand_fields['rand_suffix'] = str_replace(['"',"\'\'"],'',$rand_fields['rand_suffix']);
	$rand_fields['rand_l_suffix'] = str_replace(['"',"\'\'"],'',$rand_fields['rand_l_suffix']);
	$rand_fields['rand_feedback'] = str_replace(['"',"\'\'"],'',$rand_fields['rand_feedback']);
	update_option( "_rand_fields", $rand_fields );
	echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>保存成功。</strong></p></div>';
}
$rand_fields = get_option("_rand_fields");
?>
<div class="wrap">
<form id="logins-filter" method="post">
<h2 class="title">随机字段调用</h2>
<table class="form-table permalink-structure">
	<tbody>		 
	<tr>
		<th>
			<label>随机前缀句子:</label>
		</th>
		<td>
		    <textarea name="setting[rand_pre]" rows="6" cols="200"><?php echo stripslashes($rand_fields['rand_pre']);?></textarea>
		</td>
	</tr>
	<tr>
		<th>
			<label>随机后缀句子(短):</label>
		</th>
		<td>
		    <textarea name="setting[rand_suffix]" rows="6" cols="200"><?php echo stripslashes($rand_fields['rand_suffix']);?></textarea>
		</td>
	</tr>
	<tr>
		<th>
			<label>随机后缀句子(长):</label>
		</th>
		<td>
		    <textarea name="setting[rand_l_suffix]" rows="6" cols="200"><?php echo stripslashes($rand_fields['rand_l_suffix']);?></textarea>
		</td>
	</tr>
	<tr>
		<th>
			<label>随机Tag关键词(HTML):</label>
		</th>
		<td>
		    <textarea name="setting[rand_keywords]" rows="6" cols="200"><?php echo stripslashes($rand_fields['rand_keywords']);?></textarea>
		</td>
	</tr>

	<tr>
		<th>
			<label>随机国家地区:</label>
		</th>
		<td>
		    <textarea name="setting[rand_country]" rows="6" cols="50"><?php echo stripslashes($rand_fields['rand_country']);?></textarea>
		</td>
	</tr>


	
	
		<tr>
		<th>
			<label>随机Feedback内容:</label>
		</th>
		<td>
		    <textarea name="setting[rand_feedback]" rows="6" cols="200"><?php echo stripslashes($rand_fields['rand_feedback']);?></textarea>
		</td>
	</tr>

		<tr>
		<th>
			<label>随机Feedback名字:</label>
		</th>
		<td>
		    <textarea name="setting[rand_feedback_name]" rows="6" cols="50"><?php echo stripslashes($rand_fields['rand_feedback_name']);?></textarea>
		</td>
	</tr>

		<tr>
		<th>
			<label>随机Feedback时间:</label>
		</th>
		<td>
		    <textarea name="setting[rand_feedback_time]" rows="6" cols="50"><?php echo stripslashes($rand_fields['rand_feedback_time']);?></textarea>
		</td>
	</tr>

	
	
</tbody>
</table>

<p class="submit"><input type="submit" name="dosubmit" id="submit" class="button button-primary" value="保存更改"></p>
</form>
</div>
<div class="clear"></div>
<?php
}
function rand_pre_func( $atts ) {
	$rand_fields = get_option("_rand_fields");
	$rand_pre_arr = explode("\n",$rand_fields['rand_pre']); 
	return stripslashes($rand_pre_arr[array_rand($rand_pre_arr,1)]);
}
add_shortcode( 'rand_pre', 'rand_pre_func' );

function rand_suffix_func( $atts ) {
	$rand_fields = get_option("_rand_fields");
	$rand_suffix_arr = explode("\n",$rand_fields['rand_suffix']); 
	return stripslashes($rand_suffix_arr[array_rand($rand_suffix_arr,1)]);
}
add_shortcode( 'rand_suffix', 'rand_suffix_func' );

function rand_l_suffix_func( $atts ) {
	$rand_fields = get_option("_rand_fields");
	$rand_l_suffix_arr = explode("\n",$rand_fields['rand_l_suffix']); 
	return stripslashes($rand_l_suffix_arr[array_rand($rand_l_suffix_arr,1)]);
}
add_shortcode( 'rand_l_suffix', 'rand_l_suffix_func' );

function rand_keywords_func( $atts ) {
	$rand_fields = get_option("_rand_fields");
	$rand_keywords_arr = explode("\n",$rand_fields['rand_keywords']); 
	return stripslashes($rand_keywords_arr[array_rand($rand_keywords_arr,1)]);
}
add_shortcode( 'rand_keywords', 'rand_keywords_func' );

function rand_country_func( $atts ) {
	$rand_fields = get_option("_rand_fields");
	$rand_country_arr = explode("\n",$rand_fields['rand_country']); 
	return stripslashes($rand_country_arr[array_rand($rand_country_arr,1)]);
}
add_shortcode( 'rand_country', 'rand_country_func' );
 
 
 

function rand_feedback_func( $atts ) {
	$rand_fields = get_option("_rand_fields");
	$rand_feedback_arr = explode("\n",$rand_fields['rand_feedback']); 
	return stripslashes($rand_feedback_arr[array_rand($rand_feedback_arr,1)]);
}
add_shortcode( 'rand_feedback', 'rand_feedback_func' );
 
function rand_feedback_name_func( $atts ) {
	$rand_fields = get_option("_rand_fields");
	$rand_feedback_name_arr = explode("\n",$rand_fields['rand_feedback_name']); 
	return stripslashes($rand_feedback_name_arr[array_rand($rand_feedback_name_arr,1)]);
}
add_shortcode( 'rand_feedback_name', 'rand_feedback_name_func' );
 
function rand_feedback_time_func( $atts ) {
	$rand_fields = get_option("_rand_fields");
	$rand_feedback_time_arr = explode("\n",$rand_fields['rand_feedback_time']); 
	return stripslashes($rand_feedback_time_arr[array_rand($rand_feedback_time_arr,1)]);
}
add_shortcode( 'rand_feedback_time', 'rand_feedback_time_func' );
 
 
 
function easyiit_plugin_rand_fields_settings_link($links) {
  $rand_fields_settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=easyiit_rand_fields' ) ) . '">' . __( 'Settings' ) . '</a>';
  array_unshift($links, $rand_fields_settings_link);
  return $links;
}

$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'easyiit_plugin_rand_fields_settings_link' );