コード例 #1
0
ファイル: tools.php プロジェクト: devd123/wpaam
/**
 * Processes settings import functionality.
 *
 * @since 1.2.0
 * @return void
 */
function wpaam_process_settings_import()
{
    if (empty($_POST['wpaam_import_nonce'])) {
        return;
    }
    if (!wp_verify_nonce($_POST['wpaam_import_nonce'], 'wpaam_import_nonce')) {
        return;
    }
    if (!current_user_can('manage_options')) {
        return;
    }
    if (wpaam_get_file_extension($_FILES['import_file']['name']) != 'json') {
        wp_die(__('Please upload a valid .json file', 'wpaam'), __('Error', 'wpaam'), array('response' => 400));
    }
    $import_file = $_FILES['import_file']['tmp_name'];
    if (empty($import_file)) {
        wp_die(__('Please upload a file to import', 'wpaam'), __('Error', 'wpaam'), array('response' => 400));
    }
    $settings = wpaam_object_to_array(json_decode(file_get_contents($import_file)));
    update_option('wpaam_settings', $settings);
    $url = add_query_arg(array('message' => 'settings_imported'), admin_url('users.php?page=wpaam-tools'));
    wp_safe_redirect($url);
    exit;
}
コード例 #2
0
ファイル: misc-functions.php プロジェクト: devd123/wpaam
/**
 * Covert object data to array.
 *
 * @since 1.2.0
 * @param  array|object $data data to pass and convert.
 * @return array
 */
function wpaam_object_to_array($data)
{
    if (is_array($data) || is_object($data)) {
        $result = array();
        foreach ($data as $key => $value) {
            $result[$key] = wpaam_object_to_array($value);
        }
        return $result;
    }
    return $data;
}