-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathigtestimport.php
More file actions
114 lines (95 loc) · 3.15 KB
/
igtestimport.php
File metadata and controls
114 lines (95 loc) · 3.15 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
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/*
Plugin Name: IG Test Import
Plugin URI: https://github.com/sr4136/IG-Test-Import/
Description: Imports an IG archive to posts.
Version: 0.0.1
Author: SteveRudolfi
Author URI: https://github.com/sr4136/
License: NA
License URI: NA
Text Domain: igi
*/
/*
* Additional files.
*/
require(plugin_dir_path(__FILE__) . 'helpers.php');
require(plugin_dir_path(__FILE__) . 'data_process.php');
require(plugin_dir_path(__FILE__) . 'data_output_test.php');
require(plugin_dir_path(__FILE__) . 'data_run_import.php');
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function igi_permalink_igi_permalink_block_init() {
register_block_type(__DIR__ . '/build', array(
'render_callback' => 'igi_permalink_block_render'
));
}
add_action('init', 'igi_permalink_igi_permalink_block_init');
/*
* Dynamic block render.
*/
function igi_permalink_block_render($attributes, $innerBlocks) {
$blockAtts = get_block_wrapper_attributes();
$permalink = get_the_permalink();
$markup = "<a {$blockAtts} href='{$permalink}'> {$innerBlocks} </a>";
return $markup;
}
/*
* Register options page.
*/
function igi_register_options_page() {
add_options_page('Insta Import', 'Insta Import', 'manage_options', 'igi', 'igi_register_options_page_markup');
}
add_action('admin_menu', 'igi_register_options_page');
/*
* Options page markup.
*/
function igi_register_options_page_markup() {
global $_SERVER;
// URI to this options page.
$igi_uri = $_SERVER['REQUEST_URI'];
?>
<section class="igi-header">
<h2>IG Import:</h2>
<p><strong>Note</strong>: this expects a folder (`ig_data`) at this plugin root, with the data files from the IG export nested directly inside: `posts_1.json` and `media/*`. See full documentation at <a href="https://github.com/sr4136/IG-Import">https://github.com/sr4136/IG-Import</a>.</p>
<form action=" <?php echo $igi_uri ?>" method="post">
<input type="submit" value="Test Data" name="submit_data" class="igsubmit test">
<input type="submit" value="Run Import" name="submit_data" class="igsubmit import">
</form>
</section>
<section class="igi-status">
<?php igi_handleButtons(); ?>
</section>
<?php
} // function igi_register_options_page_markup()
/*
* Enqueue CSS just for the options page.
*/
function igi_admin_enqueue($hook) {
if ('settings_page_igi' != $hook)
return;
wp_enqueue_style('igi-options-page-style', plugins_url('/options-page.css', __FILE__));
}
add_action('admin_enqueue_scripts', 'igi_admin_enqueue');
/*
* Enqueue CSS for frontend.
*/
function igi_style() {
wp_enqueue_style('igi-style', plugins_url('/build/style-index.css', __FILE__));
}
add_action('wp_enqueue_scripts', 'igi_style');
/*
* Modify query posts per page for archive/year listings.
*/
function modify_terms_query($wp_query) {
if( is_category() || is_tax() || is_date()){
$wp_query->query_vars['posts_per_page'] = 20;
}
return $wp_query;
}
add_filter('pre_get_posts', 'modify_terms_query');