title: Wordpress prodruct data scraper/API
body: <p>I want to automatically get product data from other websites either by scraping it or by accessing an API with cURL. Since our website uses Wordpress, I am trying to make a plugin.
  I am now trying to get fields on the plugin's settings page to fill in the name of the website, the link format for cURL and the IDs of the products that should be imported. There will be a button on the plugin's settings page which adds the same fields another time when clicked on. I am trying to use a class with objects, since I want use multiple websites.
  I am getting HTTP Error 500 on our website, so I think am doing something wrong after the "//**START Plugin Settings Page" part in my code. It would be great if someone reviews my code and gives me a push in the right direction :).
  I am also pretty new to PHP so if there are tips on how I can make my code more readable or how I can get the product data in a better way, that would be great!</p>
  
  <p>Kind regards,
  Martijn</p>
  
  <pre><code>&lt;?php
  /**
   * Plugin Name: Dropship Data Scraper
   * Plugin URI: http://example.com/
   * Description: This plugin scrapes data from websites and puts them in product pages
   * Version: 1.0.0
   * Author: Martijn
   * Author URI: https://example.com/
   * License: Proprietary
   */
  
  //**START Adding custom fields to product options Inventory tab**
  //Display Fields
  add_action( 'woocommerce_product_options_inventory_product_data', 'woo_add_custom_general_fields' );
  
  //Save Fields
  add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
  
  function woo_add_custom_general_fields() {
  
    global $woocommerce, $post;
  
    echo '&lt;div class="options_group"&gt;';
  
    //Custom fields will be created here...
      //Purchase Price Field
      woocommerce_wp_text_input( 
          array( 
              'id'                =&gt; '_purchase_price', 
              'label'             =&gt; __( 'Purchase price', 'woocommerce' ), 
              'placeholder'       =&gt; '', 
              'desc_tip'                =&gt; 'true',
              'description'       =&gt; __( 'Enter the purchase price here.', 'woocommerce' ),
              'type'              =&gt; 'number', 
              'custom_attributes' =&gt; array(
                      'step'  =&gt; 'any',
                      'min'   =&gt; '0'
                  ) 
          )
      );
  
      //Product Link Field
      woocommerce_wp_text_input( 
          array( 
              'id'          =&gt; '_product_link', 
              'label'       =&gt; __( 'Product link', 'woocommerce' ), 
              'placeholder' =&gt; 'http://',
              'desc_tip'    =&gt; 'true',
              'description' =&gt; __( 'Enter the product link from the supplier here.', 'woocommerce' ) 
          )
      );
  
    echo '&lt;/div&gt;';
  }
  
  function woo_add_custom_general_fields_save( $post_id ){
      //Purchase Price Field
      $woocommerce_purchase_price = $_POST['_purchase_price'];
      if( !empty( $woocommerce_purchase_price ) )
          update_post_meta( $post_id, '_purchase_price', esc_attr( $woocommerce_purchase_price ) );
    elseif( empty( $woocommerce_purchase_price ) )
          update_post_meta( $post_id, '_purchase_price', NULL );
  
      //Product Link Field
      $woocommerce_product_link = $_POST['_product_link'];
      if( !empty( $woocommerce_product_link ) )
          update_post_meta( $post_id, '_product_link', esc_attr( $woocommerce_product_link ) );
    elseif( empty( $woocommerce_product_link ) )
          update_post_meta( $post_id, '_product_link', NULL );
  }
  //**END Adding custom fields to product options Inventory tab**
  
  //**START Plugin Settings Page
  //Settings page dropship ids class
  class DropshipFields {
    public static $counter = 0;
    private $dropshipIds;
  
    //Constructor to count how many DropshipFields objects are created
    function __construct() {
       self::$counter++;
    }
    //function to register settings
    public function ff_dropship_data_scraper_settings() {
      $this-&gt;dropshipIds = "dropship-ids" . BaseClass::$counter;
      return register_setting( 'ff-dropship-data-scraper-settings-group', $this-&gt;dropshipIds );
    }
    //function to display the dropship fields in ff_dropship_data_scraper_settings_page()
    public function displayFields() {
  
    }
  }
  
  //Eventually I want to put here some code that makes a new object everytime a button is pushed on the settings page
  $DropshipFields1 = new DropshipFields();
  
  //Add menu item on admin side
    add_action('admin_menu', 'ff_dropship_data_scraper_menu');
    function ff_dropship_data_scraper_menu() {
      add_menu_page('FF Dropship Data Scraper Settings', 'FF Dropship Data Scraper Settings', 'administrator', 'ff-dropship-data-scraper-settings', 'ff_dropship_data_scraper_settings_page', '
  dashicons-clipboard');
    }
  
    add_action( 'admin_init', 'ff_dropship_data_scraper_settings' );
    function ff_dropship_data_scraper_settings() {
      $DropshipFields1-&gt;ff_dropship_data_scraper_settings();
    }
  
    function ff_dropship_data_scraper_settings_page() { ?&gt;
      &lt;div class="wrap"&gt;
      &lt;h1&gt;Dropship data&lt;/h1&gt;
  
      &lt;form method="post" action="options.php"&gt;
          &lt;?php settings_fields( 'ff-dropship-data-scraper-settings-group' ); ?&gt;
          &lt;?php do_settings_sections( 'ff-dropship-data-scraper-settings-group' ); ?&gt;
          &lt;table class="form-table"&gt;
              &lt;tr valign="top"&gt;
              &lt;th scope="row"&gt;Dropship IDs&lt;/th&gt;
              &lt;td&gt;&lt;textarea placeholder="Your dropship product ids" name="dropship-ids" rows="5" cols="1000"&gt;&lt;?php echo esc_attr( get_option('dropship-ids') ); ?&gt;&lt;/textarea&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  
          &lt;table class="form-table"&gt;
              &lt;tr valign="top"&gt;
              &lt;th scope="row"&gt;Dropship IDs&lt;/th&gt;
              &lt;td&gt;&lt;textarea placeholder="Your dropship product ids" name="dropship-ids" rows="5" cols="1000"&gt;&lt;?php echo esc_attr( get_option('dropship-ids') ); ?&gt;&lt;/textarea&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  
          &lt;?php submit_button(); ?&gt;
  
      &lt;/form&gt;
      &lt;/div&gt;
    &lt;?php }
  //**END Plugin Settings Page
  
  //**START cURL Scraper
  foreach($colors as $value) {
    //Variables
    $url = "https://apibeta.banggood.com/getAccessToken?apiTest=1&amp;apiTest=1app_id=&amp;app_secret=";
    $json;
  
    //Initialize
    $ch = curl_init();
  
    //Set options
    //Url to send the request to
    curl_setopt($ch, CURLOPT_URL, $url);
  
    //Return instead of outputting directly
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
    //Include header in the output, set to false
    curl_setopt($ch, CURLOPT_HEADER, 0);
  
    //Execute the request and fetch the response. Check for errors
    $output = curl_exec($ch);
  
    if ($output === FALSE) {
      echo 'cURL ERROR: ' . curl_error($ch);
    }
  
    //Close and free up the cURL handle
    curl_close($ch);
  
    //decode json
    $json = json_decode($output, true);
  }
  
  //**END cURL Scraper
  
  //**START creating, updating or deleting dropship products
  //Put dropship-ids in an array
  $text = get_option('dropship-ids');
  //explode all separate lines into an array
  $textAr = explode("\n", $text);
  //trim all lines contained in the array.
  $textAr = array_filter($textAr, 'trim');
  
  //Update dropship products from dropship-ids
  //Array for the last dropship-ids
  $last_ids = [];
  //Update function
  function update_product_data() {
      foreach($textAr as $value) {
       if (in_array($value, $last_ids)) {
  
      }
      foreach($last_ids as $value) {
        if (in_array($value, $textAr)) {
  
        }
      }
    }
  }
  //**END creating, updating or deleting dropship products
  
  
  
  ?&gt;
  </code></pre>