Initial
This commit is contained in:
149
lcp-paywall.php
Normal file
149
lcp-paywall.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Plugin Name: LCP Paywall
|
||||
Plugin URI: https://localcontentpro.com/paywall
|
||||
Description: Flexible and customizable paywall solution for WordPress.
|
||||
Author: Local Content Pro
|
||||
Version: 0.0.1
|
||||
Author URI: https://localcontentpro.com/
|
||||
Tags: paywall, subscriptions, metered, membership, pay wall, content monetization, metered access, metered pay wall, paid content
|
||||
Text Domain: lcp
|
||||
*/
|
||||
|
||||
|
||||
// If this file is called directly, abort.
|
||||
if (!defined('WPINC')) {
|
||||
die;
|
||||
}
|
||||
|
||||
require_once plugin_dir_path(__FILE__) . 'api.php';
|
||||
// Add menu page to the admin dashboard
|
||||
add_action('admin_menu', 'lcp_paywall_add_admin_menu');
|
||||
add_action('admin_enqueue_scripts', 'lcp_paywall_enqueue_admin_scripts');
|
||||
|
||||
function lcp_paywall_add_admin_menu() {
|
||||
add_menu_page(
|
||||
'LCP Paywall', // Page title
|
||||
'LCP Paywall', // Menu title
|
||||
'manage_options', // Capability required
|
||||
'lcp-paywall', // Menu slug
|
||||
'lcp_paywall_admin_page', // Function to output content
|
||||
'dashicons-lock', // Icon (lock icon)
|
||||
30 // Position in menu
|
||||
);
|
||||
}
|
||||
|
||||
function lcp_paywall_admin_page() {
|
||||
// Check user capabilities
|
||||
if (!current_user_can('manage_options')) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
||||
<div id="lcp-paywall-app-container">
|
||||
<!-- React app will render here -->
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function lcp_paywall_enqueue_admin_scripts($hook) {
|
||||
// Only load on our admin page
|
||||
if ('toplevel_page_lcp-paywall' !== $hook) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Enqueue the built js file
|
||||
wp_enqueue_script(
|
||||
'lcp-paywall-admin',
|
||||
plugins_url('build/index.js', __FILE__),
|
||||
['wp-element', 'wp-components'], // Added wp-components dependency
|
||||
filemtime(plugin_dir_path(__FILE__) . 'build/index.js'),
|
||||
true
|
||||
);
|
||||
|
||||
// Enqueue WordPress components styles
|
||||
wp_enqueue_style('wp-components');
|
||||
|
||||
// Get all registered post types
|
||||
$post_types = get_post_types(['public' => true], 'objects');
|
||||
$post_types_data = [];
|
||||
|
||||
foreach ($post_types as $post_type) {
|
||||
$post_types_data[] = [
|
||||
'name' => $post_type->name,
|
||||
'label' => $post_type->label,
|
||||
'singular_label' => $post_type->labels->singular_name
|
||||
];
|
||||
}
|
||||
|
||||
// Pass data to JavaScript
|
||||
wp_localize_script(
|
||||
'lcp-paywall-admin',
|
||||
'lcpPaywallData',
|
||||
[
|
||||
'postTypes' => $post_types_data,
|
||||
'nonce' => wp_create_nonce('lcp_paywall_nonce'),
|
||||
'ajaxUrl' => admin_url('admin-ajax.php')
|
||||
]
|
||||
);
|
||||
|
||||
// Add some basic styles
|
||||
wp_add_inline_style(
|
||||
'wp-admin',
|
||||
'
|
||||
.lcp-paywall-post-type {
|
||||
margin: 20px 0;
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
border: 1px solid #ccd0d4;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,.04);
|
||||
}
|
||||
.lcp-paywall-post-type.is-over {
|
||||
background: #f0f0f1;
|
||||
}
|
||||
.lcp-paywall-draggable-item {
|
||||
padding: 15px;
|
||||
margin: 5px 0;
|
||||
background: #f8f9fa;
|
||||
border: 1px dashed #ccd0d4;
|
||||
cursor: move;
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
||||
}
|
||||
.lcp-paywall-draggable-item:hover {
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
||||
}
|
||||
.lcp-paywall-draggable-item.is-dragging {
|
||||
opacity: 0.5;
|
||||
box-shadow: 0 5px 10px rgba(0,0,0,0.1);
|
||||
}
|
||||
.lcp-paywall-rule-controls {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.lcp-paywall-rule-controls .components-select-control {
|
||||
margin-bottom: 0;
|
||||
min-width: 120px;
|
||||
}
|
||||
.lcp-paywall-rule-controls .components-select-control__input {
|
||||
height: 36px;
|
||||
}
|
||||
.lcp-paywall-add-rule {
|
||||
margin-top: 15px;
|
||||
padding-top: 15px;
|
||||
border-top: 1px solid #f0f0f1;
|
||||
}
|
||||
.lcp-paywall-add-rule-button.is-secondary {
|
||||
margin-left: 0;
|
||||
}
|
||||
.lcp-paywall-rules-container {
|
||||
min-height: 50px;
|
||||
padding: 5px 0;
|
||||
}
|
||||
'
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user