'array', 'sanitize_callback' => 'autopost_sanitize_options', ) ); add_settings_section( 'autopost_main_section', __('تنظیمات عمومی پابلیکا', 'autopost'), function () { echo '

' . esc_html__('تنظیمات اتصال و انتشار رپورتاژ', 'autopost') . '

'; echo '

' . esc_html__('لطفا جهت اتصال افزونه اتوپست به پنل پابلیکا ، ابتدا پلن رپورتاژی که قصد انتشار سریع برای آن را دارید انتخاب نموده و همچنین دسته بندی انتشار را انتخاب نمایید و ذخیره کنید', 'autopost') . '

'; }, 'autopost_options_page' ); add_settings_field('reportage_plan', __('انتخاب پلن رپورتاژ', 'autopost'), function () { $options = get_option('autopost_options', []); $value = isset($options['reportage_plan']) ? $options['reportage_plan'] : ''; echo '
'; echo '
در حال بارگذاری پلن ها ...
'; // Options will be populated via AJAX echo '
'; }, 'autopost_options_page', 'autopost_main_section'); // Add publish verification settings / manual or auto add_settings_field('publish_type', __('تنظیمات انتشار خودکار', 'autopost'), function () { $options = get_option('autopost_options', []); $current_category = isset($options['publish_type']) ? $options['publish_type'] : ''; echo ''; echo ''; echo '

اگر برای منتشر شدن رپورتاژآگهی در سایت خود توسط افزونه ، نیاز به بازبینی و تایید دستی محتوا در پنل پابلیکا قبل از انتشار دارید، این گزینه را انتخاب کنید.

'; }, 'autopost_options_page', 'autopost_main_section'); } /** * Add settings page */ function autopost_add_settings_page() { add_options_page( __('تنظیمات پابلیکا', 'autopost'), __('پابلیکا', 'autopost'), 'manage_options', 'autopost-options', 'autopost_render_settings_page' ); } /** * Redirect to plugin settings page right after activation */ function autopost_maybe_redirect_to_autopost_settings() { // Only run in admin, non-ajax, non-cron, non-rest, with capability if ( ! is_admin() ) { return; } if ( defined('DOING_AJAX') && DOING_AJAX ) { return; } if ( defined('DOING_CRON') && DOING_CRON ) { return; } if ( defined('REST_REQUEST') && REST_REQUEST ) { return; } if ( is_network_admin() ) { return; // avoid network admin context } if ( isset($_GET['activate-multi']) ) { return; // skip bulk activation } if ( ! current_user_can('manage_options') ) { return; } $flag = get_option('autopost_plugin_activated'); if ( $flag ) { delete_option('autopost_plugin_activated'); $target = admin_url('options-general.php?page=autopost-options'); wp_safe_redirect($target); exit; } } /** * Enqueue admin assets */ function autopost_admin_enqueue_assets($hook_suffix) { if ($hook_suffix !== 'settings_page_autopost-options') { return; } // Enqueue Select2 for the reportage plan field wp_enqueue_script('select2', AUTOPOST_PLUGIN_URL . 'assets/js/select2.min.js', ['jquery'], '4.1.0-rc.0', true); wp_enqueue_style('select2', AUTOPOST_PLUGIN_URL . 'assets/css/select2.min.css', [], '4.1.0-rc.0'); wp_enqueue_style('autopost-admin-css', AUTOPOST_PLUGIN_URL . 'assets/css/autopost-admin.css', [], AUTOPOST_VERSION); $handle = 'autopost-admin-js'; $src = AUTOPOST_PLUGIN_URL . 'assets/js/autopost-admin.js'; wp_enqueue_script($handle, $src, ['jquery', 'select2'], AUTOPOST_VERSION, true); $panel_domain = defined('AUTOPOST_PANEL_DOMAIN') ? AUTOPOST_PANEL_DOMAIN : 'panel.publica.ir'; $options = get_option('autopost_options', []); wp_localize_script($handle, 'AUTOPOSTAdmin', [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('autopost_admin_ajax'), 'panelDomain' => $panel_domain, 'websiteUrl' => AUTOPOST_WEBSITE_URL, 'savedPlanCategory' => isset($options['plan_category']) ? $options['plan_category'] : '', ]); } /** * Render settings page */ function autopost_render_settings_page() { if (!current_user_can('manage_options')) { return; } ?>

'POST', 'timeout' => 1000, 'headers' => [ 'Accept' => 'application/json', ], 'body' => [ // Part of the Publica panel API contract — must not be renamed. 'action' => 'aanish_panel_save_reportage_plan', 'reportage_plan' => $reportage_plan, 'website_url' => defined('AUTOPOST_WEBSITE_URL') ? AUTOPOST_WEBSITE_URL : home_url(), ], ]; $response = wp_remote_post($remote_url, $args); // Log the response for debugging (optional) if (is_wp_error($response)) { error_log('Autopost Plugin: Failed to send reportage plan to panel - ' . $response->get_error_message()); } else { $code = wp_remote_retrieve_response_code($response); if ($code < 200 || $code >= 300) { error_log('Autopost Plugin: Panel returned error code ' . $code . ' when saving reportage plan'); } } } function autopost_get_option($key, $default = null) { $options = get_option('autopost_options', []); return isset($options[$key]) ? $options[$key] : $default; } /** * Include Rate Limit functionality (By Requester IP Address) */ function autopost_check_rate_limit() { session_start(); // using the originating IP $rateLimiter = new AUTOPOST_RateLimiter($_SERVER["REMOTE_ADDR"]); $limit = 2; // number of connections to limit user to per $minutes $minutes = 1; // number of $minutes to check for. $seconds = floor($minutes * 60); // retry after $minutes in seconds. try { $rateLimiter->limitRequestsInMinutes($limit, $minutes); } catch (AUTOPOST_RateExceededException $e) { header("HTTP/1.1 429 Too Many Requests"); header(sprintf("Retry-After: %d", $seconds)); $data = array( 'status' => false, 'message' => 'محدودیت تعداد درخواست. لطفا پس از گذشت یک دقیقه مجددا امتحان کنید' ); die (json_encode($data)); } } /** * attached to Activation Hook */ function autopost_plugin_activation() { if ( version_compare( $GLOBALS['wp_version'], AUTOPOST_MINIMUM_WP_VERSION, '<' ) ) { $message = '' . /* translators: 1: Current autopost version number, 2: Minimum WordPress version number required. */ sprintf( esc_html__( 'Autopost %1$s requires WordPress %2$s or higher.', 'autopost' ), AUTOPOST_VERSION, AUTOPOST_MINIMUM_WP_VERSION ) . ' ' . /* translators: 1: WordPress documentation URL, 2: autopost download URL. */ sprintf( __( 'Please upgrade WordPress to a current version, or downgrade to version 2.4 of the autopost plugin.', 'autopost' ), 'https://codex.wordpress.org/Upgrading_WordPress', 'https://wordpress.org/plugins/autopost' ); echo esc_html($message); } elseif ( ! empty( $_SERVER['SCRIPT_NAME'] ) && false !== strpos( $_SERVER['SCRIPT_NAME'], '/wp-admin/plugins.php' ) ) { add_option( 'autopost_plugin_activated', true ); } } /** * attached to Uninstall Hook */ function autopost_plugin_uninstall() { // Remove plugin options on uninstall delete_option( 'autopost_options' ); if ( is_multisite() ) { delete_site_option( 'autopost_options' ); } }